megengine.random.poisson

poisson(lam, size=None)

Random variable with poisson distribution \(\operatorname{Poisson}(\lambda)\).

The corresponding probability density function is

\[f(k ; \lambda)=\frac{\lambda^{k} e^{-\lambda}}{k !},\]

where k is the number of occurrences \(({\displaystyle k=0,1,2...})\).

Parameters
  • lam (Union[float, Tensor]) – the lambda parameter of the distribution. Must be positive.

  • size (Optional[Iterable[int]]) – the size of output tensor. If lam is a scalar and given size is, e.g., (m, n), then the output shape is (m, n). If lam is a Tensor with shape (k, v) and given size is, e.g., (m, n), then the output shape is (m, n, k, v). Default: None.

Returns

tensor. The random variable with Poisson distribution.

Return type

Return type

Examples

>>> import megengine.random as rand
>>> x = rand.poisson(lam=2., size=(1, 3))
>>> x.numpy()   
array([[1., 2., 2.]], dtype=float32)
>>> lam = mge.Tensor([[1.,1.],
...                 [10,10]], dtype="float32")
>>> x = rand.poisson(lam=lam)
>>> x.numpy()   
array([[ 1.,  2.],
       [11., 11.]], dtype=float32)
>>> x = rand.poisson(lam=lam, size=(1,3))
>>> x.numpy()   
array([[[[ 2.,  1.],
         [10.,  8.]],
[[ 5., 2.],

[10., 10.]],

[[ 1., 2.],

[ 8., 10.]]]], dtype=float32)