mindspore.ops.Gamma

View Source On Gitee
class mindspore.ops.Gamma(seed=0, seed2=0)[source]

Produces random positive floating-point values x, distributed according to probability density function:

\[\text{P}(x|α,β) = \frac{\exp(-x/β)}{{β^α}\cdot{\Gamma(α)}}\cdot{x^{α-1}}\]

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 .

Inputs:
  • shape (tuple) - The shape of random tensor to be generated. Only constant value is allowed.

  • alpha (Tensor) - α is the shape parameter of Gamma distribution, which mainly determines the shape of the curve. It must be greater than 0. The data type is float32.

  • beta (Tensor) - β is the inverse scale parameter of the Gamma distribution, which mainly determines how steep the curve is. It must be greater than 0. The data type is float32.

Outputs:

Tensor. The shape must be the broadcasted shape of Input “shape” and shapes of alpha and beta. The dtype is float32.

Raises
  • TypeError – If data type of seed or seed2 is not int.

  • TypeError – If alpha or beta is not a Tensor.

  • TypeError – If data type of alpha or beta is not float32.

  • ValueError – If shape is not a constant value.

Supported Platforms:

Ascend

Examples

>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> from mindspore import dtype as mstype
>>> shape = (3, 1, 2)
>>> alpha = Tensor(np.array([[3, 4], [5, 6]]), mstype.float32)
>>> beta = Tensor(np.array([1.0]), mstype.float32)
>>> gamma = ops.Gamma(seed=3)
>>> output = gamma(shape, alpha, beta)
>>> result = output.shape
>>> print(result)
(3, 2, 2)