TransformedDistribution

class paddle.distribution. TransformedDistribution ( base, transforms ) [source]

Applies a sequence of Transforms to a base distribution.

Parameters
  • base (Distribution) – The base distribution.

  • transforms (Sequence[Transform]) – A sequence of Transform .

Examples

>>> import paddle
>>> paddle.seed(2023)
>>> from paddle.distribution import transformed_distribution

>>> d = transformed_distribution.TransformedDistribution(
...     paddle.distribution.Normal(0., 1.),
...     [paddle.distribution.AffineTransform(paddle.to_tensor(1.), paddle.to_tensor(2.))]
... )

>>> 
>>> print(d.sample([10]))
Tensor(shape=[10], dtype=float32, place=Place(cpu), stop_gradient=True,
    [ 3.22699189,  1.12264419,  0.50283587,  1.83812487, -2.00740123,
    -2.70338631,  1.26663208,  4.47909021, -0.11529565,  4.32719326])
>>> print(d.log_prob(paddle.to_tensor(0.5)))
Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
    -1.64333570)
>>> 
sample ( shape=() )

sample

Sample from TransformedDistribution.

Parameters

shape (Sequence[int], optional) – The sample shape. Defaults to ().

Returns

The sample result.

Return type

[Tensor]

rsample ( shape=() )

rsample

Reparameterized sample from TransformedDistribution.

Parameters

shape (Sequence[int], optional) – The sample shape. Defaults to ().

Returns

The sample result.

Return type

[Tensor]

log_prob ( value )

log_prob

The log probability evaluated at value.

Parameters

value (Tensor) – The value to be evaluated.

Returns

The log probability.

Return type

Tensor

property batch_shape

Returns batch shape of distribution

Returns

batch shape

Return type

Sequence[int]

entropy ( )

entropy

The entropy of the distribution.

property event_shape

Returns event shape of distribution

Returns

event shape

Return type

Sequence[int]

kl_divergence ( other ) [source]

kl_divergence

The KL-divergence between self distributions and other.

property mean

Mean of distribution

prob ( value )

prob

Probability density/mass function evaluated at value.

Parameters

value (Tensor) – value which will be evaluated

probs ( value )

probs

Probability density/mass function.

Note

This method will be deprecated in the future, please use prob instead.

property variance

Variance of distribution