Delta#
- class tensordict.nn.distributions.Delta(param: Tensor, atol: float = 1e-06, rtol: float = 1e-06, batch_shape: Sequence[int] | Size | None = None, event_shape: Sequence[int] | Size | None = None)#
Bases:
DistributionA distribution with all its mass on one value,
param.sample()andrsample()returnparam(expanded to the sample shape), andmean,modeanddeterministic_samplereturn it as it is.log_prob()returnsinffor a value equal toparam(withinatolandrtol, on every element of the event) and-infotherwise. It is the defaultdistribution_classofProbabilisticTensorDictModule, which then copies its input to its output.- Parameters:
param (Tensor) – the value that holds all the mass.
atol (float, optional) – the absolute tolerance with which
log_prob()compares a value withparam. Defaults to1e-6.rtol (float, optional) – the relative tolerance with which
log_prob()compares a value withparam. Defaults to1e-6.batch_shape (Size, optional) – the batch shape. Defaults to
None: seeevent_shape.event_shape (Size, optional) – the shape of one value. If neither
batch_shapenorevent_shapeis given (or both are empty), the last dimension ofparamis the event shape and the others are the batch shape. Defaults toNone.
Examples
>>> import torch >>> from tensordict.nn.distributions import Delta >>> dist = Delta(torch.zeros(4, 2)) >>> dist.batch_shape, dist.event_shape (torch.Size([4]), torch.Size([2])) >>> dist = Delta(torch.tensor([1.0, 2.0])) >>> dist.sample() tensor([1., 2.]) >>> dist.log_prob(torch.tensor([1.0, 2.0])), dist.log_prob(torch.tensor([1.0, 3.0])) (tensor(inf), tensor(-inf))
- log_prob(value: Tensor) Tensor#
Returns the log of the probability density/mass function evaluated at value.
- Parameters:
value (Tensor) –
- rsample(sample_shape: Sequence[int] | Size | None = None) Tensor#
Generates a sample_shape shaped reparameterized sample or sample_shape shaped batch of reparameterized samples if the distribution parameters are batched.