MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / poisson

Method poisson

imperative/python/megengine/random/rng.py:490–535  ·  view source on GitHub ↗

r"""Random variable with poisson distribution :math:`\operatorname{Poisson}(\lambda)`. The corresponding probability density function is .. math:: f(k ; \lambda)=\frac{\lambda^{k} e^{-\lambda}}{k !}, where k is the number of occurrences :math:`({\displaystyle

(self, lam: Union[float, Tensor], size: Optional[Iterable[int]] = None)

Source from the content-addressed store, hash-verified

488 return _beta(alpha=alpha, beta=beta, size=size, seed=_seed, handle=self._handle)
489
490 def poisson(self, lam: Union[float, Tensor], size: Optional[Iterable[int]] = None):
491 r"""Random variable with poisson distribution :math:`\operatorname{Poisson}(\lambda)`.
492
493 The corresponding probability density function is
494
495 .. math::
496
497 f(k ; \lambda)=\frac{\lambda^{k} e^{-\lambda}}{k !},
498
499 where k is the number of occurrences :math:`({\displaystyle k=0,1,2...})`.
500
501 Args:
502 lam(Union[float, Tensor]): the lambda parameter of the distribution. Must be positive.
503 size(Optional[Iterable[int]]): the size of output tensor. If lam is a scalar and given size is, e.g., `(m, n)`,
504 then the output shape is `(m, n)`. If lam is a Tensor with shape `(k, v)` and given
505 size is, e.g., `(m, n)`, then the output shape is `(m, n, k, v)`. Default: None.
506
507 Returns:
508 Return type: tensor. The random variable with Poisson distribution.
509
510
511
512 Examples:
513 >>> import megengine.random as rand
514 >>> x = rand.poisson(lam=2., size=(1, 3))
515 >>> x.numpy() # doctest: +SKIP
516 array([[1., 2., 2.]], dtype=float32)
517 >>> lam = mge.Tensor([[1.,1.],
518 ... [10,10]], dtype="float32")
519 >>> x = rand.poisson(lam=lam)
520 >>> x.numpy() # doctest: +SKIP
521 array([[ 1., 2.],
522 [11., 11.]], dtype=float32)
523 >>> x = rand.poisson(lam=lam, size=(1,3))
524 >>> x.numpy() # doctest: +SKIP
525 array([[[[ 2., 1.],
526 [10., 8.]],
527
528 [[ 5., 2.],
529 [10., 10.]],
530
531 [[ 1., 2.],
532 [ 8., 10.]]]], dtype=float32)
533 """
534 _seed = self._seed() if callable(self._seed) else self._seed
535 return _poisson(lam=lam, size=size, seed=_seed, handle=self._handle)
536
537 def multinomial(
538 self, input: Tensor, num_samples: int, replacement: Optional[bool] = False

Callers 2

test_PoissonRNGFunction · 0.95
fnFunction · 0.80

Calls 1

_poissonFunction · 0.85

Tested by 2

test_PoissonRNGFunction · 0.76
fnFunction · 0.64