Poisson

class paddle.distribution. Poisson ( rate: float | Tensor ) [source]

The Poisson distribution with occurrence rate parameter: rate.

In probability theory and statistics, the Poisson distribution is the most basic discrete probability distribution defined on the nonnegative integer set, which is used to describe the probability distribution of the number of random events occurring per unit time.

The probability mass function (pmf) is

\[pmf(x; \lambda) = \frac{e^{-\lambda} \cdot \lambda^x}{x!}\]

In the above equation:

  • \(rate = \lambda\): is the mean occurrence rate.

Parameters

rate (int|float|Tensor) – The mean occurrence rate of Poisson distribution which should be greater than 0, meaning the expected occurrence times of an event in a fixed time interval. If the input data type is int or float, the data type of rate will be converted to a 1-D Tensor with paddle global default dtype.

Examples

>>> import paddle
>>> from paddle.distribution import Poisson
>>> paddle.set_device('cpu')
>>> paddle.seed(100)
>>> rv = Poisson(paddle.to_tensor(30.0))

>>> print(rv.sample([3]))
Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
[32., 27., 25.])

>>> print(rv.mean)
Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
30.)

>>> print(rv.entropy())
Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
3.11671519)

>>> rv1 = Poisson(paddle.to_tensor([[30.,40.],[8.,5.]]))
>>> rv2 = Poisson(paddle.to_tensor([[1000.,40.],[7.,10.]]))
>>> print(rv1.kl_divergence(rv2))
Tensor(shape=[2, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
[[864.80499268, 0.          ],
 [0.06825146  , 1.53426409  ]])
property mean : Tensor

Mean of poisson distribution.

Returns

mean value.

Return type

Tensor

property variance : Tensor

Variance of poisson distribution.

Returns

variance value.

Return type

Tensor

sample ( shape: Sequence[int] = [] ) Tensor

sample

Generate poisson samples of the specified shape. The final shape would be shape+batch_shape .

Parameters

shape (Sequence[int], optional) – Prepended shape of the generated samples.

Returns

Sampled data with shape sample_shape + batch_shape.

Return type

Tensor

entropy ( ) Tensor

entropy

Shannon entropy in nats.

The entropy is

\[\mathcal{H}(X) = - \sum_{x \in \Omega} p(x) \log{p(x)}\]

In the above equation:

  • \(\Omega\): is the support of the distribution.

Returns

Shannon entropy of poisson distribution. The data type is the same as rate.

Return type

Tensor

log_prob ( value: Tensor ) Tensor

log_prob

Log probability density/mass function.

Parameters

value (Tensor) – The input tensor.

Returns

log probability. The data type is the same as rate.

Return type

Tensor

property batch_shape : Sequence[int]

Returns batch shape of distribution

Returns

batch shape

Return type

Sequence[int]

property event_shape : Sequence[int]

Returns event shape of distribution

Returns

event shape

Return type

Sequence[int]

prob ( value: Tensor ) Tensor

prob

Probability density/mass function.

Parameters

value (Tensor) – The input tensor.

Returns

probability. The data type is the same as rate.

Return type

Tensor

probs ( value: Tensor ) Tensor

probs

Probability density/mass function.

Note

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

rsample ( shape: Sequence[int] = [] ) Tensor

rsample

reparameterized sample

kl_divergence ( other: Poisson ) Tensor [source]

kl_divergence

The KL-divergence between two poisson distributions with the same batch_shape.

The probability density function (pdf) is

\[KL\_divergence\lambda_1, \lambda_2) = \sum_x p_1(x) \log{\frac{p_1(x)}{p_2(x)}}\]
\[p_1(x) = \frac{e^{-\lambda_1} \cdot \lambda_1^x}{x!}\]
\[p_2(x) = \frac{e^{-\lambda_2} \cdot \lambda_2^x}{x!}\]
Parameters

other (Poisson) – instance of Poisson.

Returns

Tensor, kl-divergence between two poisson distributions. The data type is the same as rate.