# mindspore.nn.probability.distribution.Poisson

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

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

• rate (int, float, list, numpy.ndarray, Tensor) - 泊松分布的率参数。默认值：None。

• seed (int) - 采样时使用的种子。如果为None，则使用全局种子。默认值：None。

• dtype (mindspore.dtype) - 事件样例的类型。默认值：mstype.float32。

• name (str) - 分布的名称。默认值：’Poisson’。

Note

rate 必须大于0。

• ValueError - rate 中元素小于0。

Ascend

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

Tensor，rate 参数的值。

cdf(value, rate)

• value (Tensor) - 要计算的值。

• rate (Tensor) - 率参数(rate)。默认值：None。

Tensor，累积分布函数的值。

log_cdf(value, rate)

• value (Tensor) - 要计算的值。

• rate (Tensor) - 率参数(rate)。默认值：None。

Tensor，累积分布函数的对数。

log_prob(value, rate)

• value (Tensor) - 要计算的值。

• rate (Tensor) - 率参数(rate)。默认值：None。

Tensor，累积分布函数的对数。

log_survival(value, rate)

• value (Tensor) - 要计算的值。

• rate (Tensor) - 率参数(rate)。默认值：None。

Tensor，生存函数的对数。

mean(rate)

• rate (Tensor) - 率参数(rate)。默认值：None。

Tensor，概率分布的期望。

mode(rate)

• rate (Tensor) - 率参数(rate)。默认值：None。

Tensor，概率分布的众数。

prob(value, rate)

• value (Tensor) - 要计算的值。

• rate (Tensor) - 率参数(rate)。默认值：None。

Tensor，概率值。

sample(shape, rate)

• shape (tuple) - 样本的shape。

• rate (Tensor) - 率参数(rate)。默认值：None。

Tensor，根据概率分布采样的样本。

sd(rate)

• rate (Tensor) - 率参数(rate)。默认值：None。

Tensor，概率分布的标准差。

survival_function(value, rate)

• value (Tensor) - 要计算的值。

• rate (Tensor) - 率参数(rate)。默认值：None。

Tensor，生存函数的值。

var(rate)

• rate (Tensor) - 率参数(rate)。默认值：None。

Tensor，概率分布的方差。