Gamma

class paddle.distribution. Gamma ( concentration, rate ) [source]

Gamma distribution parameterized by concentration (aka “alpha”) and rate (aka “beta”).

The probability density function (pdf) is

\[ \begin{align}\begin{aligned}f(x; \alpha, \beta, x > 0) = \frac{\beta^{\alpha}}{\Gamma(\alpha)} x^{\alpha-1}e^{-\beta x}\\\Gamma(\alpha)=\int_{0}^{\infty} x^{\alpha-1} e^{-x} \mathrm{~d} x, (\alpha>0)\end{aligned}\end{align} \]
Parameters
  • concentration (float|Tensor) – Concentration parameter. It supports broadcast semantics. The value of concentration must be positive. When the parameter is a tensor, it represents multiple independent distribution with a batch_shape(refer to Distribution).

  • rate (float|Tensor) – Rate parameter. It supports broadcast semantics. The value of rate must be positive. When the parameter is tensor, it represent multiple independent distribution with a batch_shape(refer to Distribution).

Example

>>> import paddle

>>> # scale input
>>> gamma = paddle.distribution.Gamma(0.5, 0.5)
>>> print(gamma.mean)
Tensor(shape=[], dtype=float32, place=Place(gpu:0), stop_gradient=True,
       1.)

>>> print(gamma.variance)
Tensor(shape=[], dtype=float32, place=Place(gpu:0), stop_gradient=True,
       2.)

>>> print(gamma.entropy())
Tensor(shape=[], dtype=float32, place=Place(gpu:0), stop_gradient=True,
       0.78375685)

>>> # tensor input with broadcast
>>> gamma = paddle.distribution.Gamma(paddle.to_tensor([0.2, 0.4]), paddle.to_tensor(0.6))
>>> print(gamma.mean)
Tensor(shape=[2], dtype=float32, place=Place(gpu:0), stop_gradient=True,
       [0.33333331, 0.66666663])

>>> print(gamma.variance)
Tensor(shape=[2], dtype=float32, place=Place(gpu:0), stop_gradient=True,
       [0.55555552, 1.11111104])

>>> print(gamma.entropy())
Tensor(shape=[2], dtype=float32, place=Place(gpu:0), stop_gradient=True,
       [-1.99634242,  0.17067254])
property mean

Mean of gamma distribution.

Returns

mean value.

Return type

Tensor

property variance

Variance of gamma distribution.

Returns

variance value.

Return type

Tensor

prob ( value )

prob

Probability density function evaluated at value

Parameters

value (float|Tensor) – Value to be evaluated.

Returns

Probability.

Return type

Tensor

log_prob ( value )

log_prob

Log probability density function evaluated at value

Parameters

value (float|Tensor) – Value to be evaluated

Returns

Log probability.

Return type

Tensor

entropy ( )

entropy

Entropy of gamma distribution

Returns

Entropy.

Return type

Tensor

sample ( shape=() )

sample

Generate samples of the specified shape.

Parameters

shape (Sequence[int], optional) – Shape of the generated samples.

Returns

Tensor, A tensor with prepended dimensions shape.The data type is float32.

rsample ( shape=() )

rsample

Generate reparameterized samples of the specified shape.

Parameters

shape (Sequence[int], optional) – Shape of the generated samples.

Returns

A tensor with prepended dimensions shape.The data type is float32.

Return type

Tensor

property batch_shape

Returns batch shape of distribution

Returns

batch shape

Return type

Sequence[int]

property event_shape

Returns event shape of distribution

Returns

event shape

Return type

Sequence[int]

kl_divergence ( other ) [source]

kl_divergence

The KL-divergence between two gamma distributions.

Parameters

other (Gamma) – instance of Gamma.

Returns

kl-divergence between two gamma distributions.

Return type

Tensor

probs ( value )

probs

Probability density/mass function.

Note

This method will be deprecated in the future, please use prob instead.