TruncatedNormal#
- class tensordict.nn.distributions.TruncatedNormal(loc: Number | Tensor, scale: Number | Tensor, a: Number | Tensor, b: Number | Tensor, validate_args: bool | None = None)#
Bases:
TruncatedStandardNormalA normal distribution of mean
locand standard deviationscale, restricted to[a, b].Its samples are reparameterized (
rsample).Source: https://people.sc.fsu.edu/~jburkardt/presentations/truncated_normal.pdf
- Parameters:
loc (Number or Tensor) – the mean of the normal distribution before truncation.
scale (Number or Tensor) – the standard deviation of the normal distribution before truncation. Values under
1e-6are set to1e-6.a (Number or Tensor) – the lower bound of the support, in the same units as
loc.b (Number or Tensor) – the upper bound of the support, in the same units as
loc.validate_args (bool, optional) – passed to
Distribution. Defaults toNone.
- Raises:
ValueError – if
ais not smaller thanbeverywhere.
Examples
>>> import torch >>> from tensordict.nn.distributions import TruncatedNormal >>> _ = torch.manual_seed(0) >>> dist = TruncatedNormal(loc=torch.zeros(3), scale=torch.ones(3), a=-1.0, b=1.0) >>> dist.sample() tensor([-0.0064, 0.4764, -0.7754]) >>> dist.mean tensor([0., 0., 0.]) >>> TruncatedNormal(loc=5.0, scale=1.0, a=4.0, b=6.0).mean tensor(5.)
- cdf(value: Tensor) Tensor#
Returns the cumulative density/mass function evaluated at value.
- Parameters:
value (Tensor) –
- icdf(value: Tensor) Tensor#
Returns the inverse cumulative density/mass function evaluated at value.
- Parameters:
value (Tensor) –
- log_prob(value: Tensor) Tensor#
Returns the log of the probability density/mass function evaluated at value.
- Parameters:
value (Tensor) –
- property support: Constraint#
Returns a
Constraintobject representing this distribution’s support.