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’.

Inputs and Outputs of APIs:

The accessible APIs of the Poisson distribution are defined in the base class, including:

  • prob, log_prob, cdf, log_cdf, survival_function, and log_survival

  • mean, sd, mode, var, and entropy

  • kl_loss and cross_entropy

  • sample

For more details of all APIs, including the inputs and outputs of all APIs of the Poisson distribution, please refer to mindspore.nn.probability.distribution.Distribution, and examples below.

Supported Platforms:

Ascend

Note

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

Raises

ValueError – When rate <= 0.

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)
extend_repr()[source]

Display instance object as string.

property rate

Return rate of the distribution after casting to dtype.

Output:

Tensor, the rate parameter of the distribution.