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

Method exponential

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

r"""Random variable with exponential distribution :math:`\operatorname{Exponential}(\lambda)`. The corresponding probability density function is .. math:: f\left( x;\lambda \right) =\lambda e^{-\lambda x} for x > 0 and 0 elsewhere. where`rate = lambda`. Ar

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

Source from the content-addressed store, hash-verified

663 inp._reset(_shuffle(inp=inp, seed=_seed, handle=self._handle))
664
665 def exponential(
666 self, rate: Union[float, Tensor] = 1.0, size: Optional[Iterable[int]] = None
667 ):
668 r"""Random variable with exponential distribution :math:`\operatorname{Exponential}(\lambda)`.
669 The corresponding probability density function is
670 .. math::
671 f\left( x;\lambda \right) =\lambda e^{-\lambda x}
672 for x > 0 and 0 elsewhere. where`rate = lambda`.
673 Args:
674 rate: the lambda parameter of the distribution. Must be non-negative. rate = 1 / scale of the distribution.
675 size: the size of output tensor. If scale is a scalar and given size is, e.g., `(m, n)`,
676 then the output shape is `(m, n)`. If scale is a Tensor with shape `(k, v)` and given
677 size is, e.g., `(m, n)`, then the output shape is `(m, n, k, v)`. Default: None.
678 Returns:
679 the output tensor.
680 Examples:
681 >>> import megengine.random as rand
682 >>> x = rand.exponential(rate=0.5, size=(1, 3))
683 >>> x.numpy() # doctest: +SKIP
684 array([[0.29976687, 2.0183907, 2.0183907]], dtype=float32)
685 >>> rate = mge.Tensor([[1.,1.],
686 ... [0.1,0.1]], dtype="float32")
687 >>> x = rand.exponential(rate=rate)
688 >>> x.numpy() # doctest: +SKIP
689 array([[ 0.60264504, 0.1853687],
690 [15.97864, 1.3586639]], dtype=float32)
691 >>> x = rand.exponential(rate=rate, size=(1,3))
692 >>> x.numpy() # doctest: +SKIP
693 array([[[[ 0.505074, 0.10852259],
694 [6.77063, 23.688671]],
695 [[ 0.08482812, 0.32527232],
696 [4.942598, 20.326012]],
697 [[ 0.72095776, 1.6217546],
698 [ 37.02024, 35.46942]]]], dtype=float32)
699 """
700 _seed = self._seed() if callable(self._seed) else self._seed
701 return _exponential(rate=rate, size=size, seed=_seed, handle=self._handle)
702
703 def __del__(self):
704 if self._handle != 0:

Callers 2

test_ExponentialRNGFunction · 0.95
fnFunction · 0.80

Calls 1

_exponentialFunction · 0.85

Tested by 2

test_ExponentialRNGFunction · 0.76
fnFunction · 0.64