mindspore.nn.probability.distribution.Poisson

class mindspore.nn.probability.distribution.Poisson(rate=None, seed=None, dtype=mstype.float32, name='Poisson')[source]

Poisson Distribution. A Poisson Distribution is a discrete distribution with the range as the non-negative integers, and the probability mass function as

\[P(X = k) = \lambda^k \exp(-\lambda) / k!, k = 1, 2, ...\]

where \(\lambda\) is the rate of the distribution.

Parameters
  • rate (list, numpy.ndarray, Tensor) – The rate of the Poisson distribution. Default: None.

  • seed (int) – The seed used in sampling. The global seed is used if it is None. Default: None.

  • dtype (mindspore.dtype) – The type of the event samples. Default: mstype.float32.

  • name (str) – The name of the distribution. Default: ‘Poisson’.

Note

rate must be strictly greater than 0. dist_spec_args is rate.

Raises

ValueError – When rate <= 0.

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> import mindspore.nn as nn
>>> import mindspore.nn.probability.distribution as msd
>>> from mindspore import Tensor
>>> # To initialize an Poisson distribution of the rate 0.5.
>>> p1 = msd.Poisson([0.5], dtype=mindspore.float32)
>>> # An Poisson distribution can be initialized without arguments.
>>> # In this case, `rate` must be passed in through `args` during function calls.
>>> p2 = msd.Poisson(dtype=mindspore.float32)
>>>
>>> # Here are some tensors used below for testing
>>> value = Tensor([1, 2, 3], dtype=mindspore.int32)
>>> rate_a = Tensor([0.6], dtype=mindspore.float32)
>>> rate_b = Tensor([0.2, 0.5, 0.4], dtype=mindspore.float32)
>>>
>>> # Private interfaces of probability functions corresponding to public interfaces, including
>>> # `prob`, `log_prob`, `cdf`, `log_cdf`, `survival_function`, and `log_survival`, are the same as follows.
>>> # Args:
>>> #     value (Tensor): the value to be evaluated.
>>> #     rate (Tensor): the rate of the distribution. Default: self.rate.
>>> # Examples of `prob`.
>>> # Similar calls can be made to other probability functions
>>> # by replacing `prob` by the name of the function.
>>> ans = p1.prob(value)
>>> print(ans.shape)
(3,)
>>> # Evaluate with respect to distribution b.
>>> ans = p1.prob(value, rate_b)
>>> print(ans.shape)
(3,)
>>> # `rate` must be passed in during function calls.
>>> ans = p2.prob(value, rate_a)
>>> print(ans.shape)
(3,)
>>> # Functions `mean`, `mode`, `sd`, and 'var' have the same arguments as follows.
>>> # Args:
>>> #     rate (Tensor): the rate of the distribution. Default: self.rate.
>>> # Examples of `mean`, `sd`, `mode`, and `var` are similar.
>>> ans = p1.mean() # return 2
>>> print(ans.shape)
(1,)
>>> ans = p1.mean(rate_b) # return 1 / rate_b
>>> print(ans.shape)
(3,)
>>> # `rate` must be passed in during function calls.
>>> ans = p2.mean(rate_a)
>>> print(ans.shape)
(1,)
>>> # Examples of `sample`.
>>> # Args:
>>> #     shape (tuple): the shape of the sample. Default: ()
>>> #     probs1 (Tensor): the rate of the distribution. Default: self.rate.
>>> ans = p1.sample()
>>> print(ans.shape)
(1, )
>>> ans = p1.sample((2,3))
>>> print(ans.shape)
(2, 3, 1)
>>> ans = p1.sample((2,3), rate_b)
>>> print(ans.shape)
(2, 3, 3)
>>> ans = p2.sample((2,3), rate_a)
>>> print(ans.shape)
(2, 3, 1)
property rate

Return rate parameter.

Returns

Tensor, the value of the rate.

cdf(value, rate)

Compute the cumulatuve distribution function(CDF) of the given value.

Parameters

  • value (Tensor) - the value to compute.

  • rate (Tensor) - the value of the rate. Default value: None.

Returns

Tensor, the value of the cumulatuve distribution function for the given input.

log_cdf(value, rate)

Compute the log value of the cumulatuve distribution function.

Parameters

  • value (Tensor) - the value to compute.

  • rate (Tensor) - the value of the rate. Default value: None.

Returns

Tensor, the log value of the cumulatuve distribution function.

log_prob(value, rate)

the log value of the probability.

Parameters

  • value (Tensor) - the value to compute.

  • rate (Tensor) - the value of the rate. Default value: None.

Returns

Tensor, the log value of the probability.

log_survival(value, rate)

Compute the log value of the survival function.

Parameters

  • value (Tensor) - the value to compute.

  • rate (Tensor) - the value of the rate. Default value: None.

Returns

Tensor, the value of the K-L loss.

mean(rate)

Compute the mean value of the distribution.

Parameters

  • rate (Tensor) - the value of the rate. Default value: None.

Returns

Tensor, the mean of the distribution.

mode(rate)

Compute the mode value of the distribution.

Parameters

  • rate (Tensor) - the value of the rate. Default value: None.

Returns

Tensor, the mode of the distribution.

prob(value, rate)

The probability of the given value. For the discrete distribution, it is the probability mass function(pmf).

Parameters

  • value (Tensor) - the value to compute.

  • rate (Tensor) - the value of the rate. Default value: None.

Returns

Tensor, the value of the probability.

sample(shape, rate)

Generate samples.

Parameters

  • shape (tuple) - the shape of the tensor.

  • rate (Tensor) - the value of the rate. Default value: None.

Returns

Tensor, the sample following the distribution.

sd(rate)

The standard deviation.

Parameters

  • rate (Tensor) - the value of the rate. Default value: None.

Returns

Tensor, the standard deviation of the distribution.

survival_function(value, rate)

Compute the value of the survival function.

Parameters

  • value (Tensor) - the value to compute.

  • rate (Tensor) - the value of the rate. Default value: None.

Returns

Tensor, the value of the survival function.

var(rate)

Compute the variance of the distribution.

Parameters

  • rate (Tensor) - the value of the rate. Default value: None.

Returns

Tensor, the variance of the distribution.