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:
DistributionDelta distribution.
A distribution with all its mass on
param.sample(),rsample(),mean,modeanddeterministic_samplereturnparam.log_prob()returnsinffor a value equal toparam(withinatolandrtol) and-infotherwise. It is the defaultdistribution_classofProbabilisticTensorDictModule.- Parameters:
param (Tensor) – parameter of the delta distribution;
atol (number, optional) – absolute tolerance to consider that a tensor matches the distribution parameter; Default is 1e-6
rtol (number, optional) – relative tolerance to consider that a tensor matches the distribution parameter; Default is 1e-6
batch_shape (Size, optional) – batch shape;
event_shape (Size, optional) – shape of the outcome. If neither
batch_shapenorevent_shapeis given, the last dimension ofparamis the event shape and the others are the batch shape.
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) –