Rate this Page
★ ★ ★ ★ ★

TruncatedStandardNormal#

class tensordict.nn.distributions.truncated_normal.TruncatedStandardNormal(a: Number | Tensor, b: Number | Tensor, validate_args: bool | None = None)#

Bases: Distribution

A standard normal distribution restricted to the interval [a, b].

The distribution before truncation has mean 0 and standard deviation 1. Its samples are reparameterized (rsample). For other means and standard deviations, use TruncatedNormal.

Source: https://people.sc.fsu.edu/~jburkardt/presentations/truncated_normal.pdf

Parameters:
  • a (Number or Tensor) – the lower bound of the support.

  • b (Number or Tensor) – the upper bound of the support. a and b are broadcast together, and give the batch shape.

  • validate_args (bool, optional) – passed to Distribution. Defaults to None.

Raises:

ValueError – if a and b have different dtypes, or if a is not smaller than b everywhere.

Examples

>>> import torch
>>> from tensordict.nn.distributions.truncated_normal import TruncatedStandardNormal
>>> dist = TruncatedStandardNormal(a=torch.zeros(2), b=torch.tensor([1.0, 2.0]))
>>> dist.mean
tensor([0.4599, 0.7228])
>>> dist.auc
tensor([0.3413, 0.4772])
property auc: Tensor#

The mass of the standard normal distribution between a and b, before truncation.

cdf(value: Tensor) → Tensor#

Returns the cumulative density/mass function evaluated at value.

Parameters:

value (Tensor) –

entropy() → Tensor#

Returns entropy of distribution, batched over batch_shape.

Returns:

Tensor of shape batch_shape.

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 mean: Tensor#

Returns the mean of the distribution.

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.

property support: constraints.Constraints#

Returns a Constraint object representing this distribution’s support.

property variance: Tensor#

Returns the variance of the distribution.