Independent

class paddle.distribution. Independent ( base, reinterpreted_batch_rank ) [source]

Reinterprets some of the batch dimensions of a distribution as event dimensions.

This is mainly useful for changing the shape of the result of log_prob().

Parameters
  • base (Distribution) – The base distribution.

  • reinterpreted_batch_rank (int) – The number of batch dimensions to reinterpret as event dimensions.

Examples

>>> import paddle
>>> from paddle.distribution import independent

>>> beta = paddle.distribution.Beta(paddle.to_tensor([0.5, 0.5]), paddle.to_tensor([0.5, 0.5]))
>>> print(beta.batch_shape, beta.event_shape)
(2,) ()
>>> print(beta.log_prob(paddle.to_tensor(0.2)))
Tensor(shape=[2], dtype=float32, place=Place(gpu:0), stop_gradient=True,
        [-0.22843921, -0.22843921])
>>> reinterpreted_beta = independent.Independent(beta, 1)
>>> print(reinterpreted_beta.batch_shape, reinterpreted_beta.event_shape)
() (2,)
>>> print(reinterpreted_beta.log_prob(paddle.to_tensor([0.2,  0.2])))
Tensor(shape=[], dtype=float32, place=Place(gpu:0), stop_gradient=True,
        -0.45687842)
property mean

Mean of distribution

property variance

Variance of distribution

sample ( shape=() )

sample

Sampling from the distribution.

log_prob ( value )

log_prob

Log probability density/mass function.

prob ( value )

prob

Probability density/mass function evaluated at value.

Parameters

value (Tensor) – value which will be evaluated

entropy ( )

entropy

The entropy of the distribution.

property batch_shape

Returns batch shape of distribution

Returns

batch shape

Return type

Sequence[int]

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.

probs ( value )

probs

Probability density/mass function.

Note

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

rsample ( shape=() )

rsample

reparameterized sample