mindspore.ops.RandomPoisson

View Source On Gitee
class mindspore.ops.RandomPoisson(seed=0, seed2=0, dtype=mstype.int64)[source]

Produces random non-negative values i, distributed according to discrete probability function:

\[\text{P}(i|μ) = \frac{\exp(-μ)μ^{i}}{i!}\]

Note

  • Random seed: a set of regular random numbers can be obtained through some complex mathematical algorithms, and the random seed determines the initial value of this random number. If the random seed is the same in two separate calls, the random number generated will not change.

  • Using the Philox algorithm to scramble seed and seed2 to obtain random seed so that the user doesn't need to worry about which seed is more important.

Parameters
  • seed (int, optional) – The operator-level random seed, used to generate random numbers, must be non-negative. Default: 0 .

  • seed2 (int, optional) – The global random seed, which combines with the operator-level random seed to determine the final generated random number, must be non-negative. Default: 0 .

  • dtype (mindspore.dtype, optional) – The type of output. Default: mstype.int64 .

Inputs:
  • shape (Tensor) - The shape of random tensor to be generated, 1-D Tensor, whose dtype must be in [int32, int64].

  • rate (Tensor) - μ parameter the distribution was constructed with. The parameter defines mean number of occurrences of the event. Its type must be in [float16, float32, float64, int32, int64].

Outputs:

Tensor. Its shape is \((*shape, *rate.shape)\). Its type is specified by dtype.

Raises
  • TypeError – If shape is not a Tensor or its dtype is not int32 or int64.

  • TypeError – If dtype is not int32 or int64.

  • ValueError – If shape is not a 1-D tensor.

  • ValueError – If shape elements are negative.

Supported Platforms:

GPU CPU

Examples

>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> from mindspore import dtype as mstype
>>> shape = Tensor(np.array([2, 3]), mstype.int32)
>>> rate = Tensor(np.array([2, 2]), mstype.int32)
>>> seed = 0
>>> seed2 = 0
>>> random_poisson = ops.RandomPoisson(seed=seed, seed2=seed2)
>>> output = random_poisson(shape,rate)
>>> print(output.shape)
(2, 3, 2)