# 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
>>> print(gamma.mean)
1.)

>>> print(gamma.variance)
2.)

>>> print(gamma.entropy())
0.78375685)

>>> # tensor input with broadcast
>>> print(gamma.mean)
[0.33333331, 0.66666663])

>>> print(gamma.variance)
[0.55555552, 1.11111104])

>>> print(gamma.entropy())
[-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 )

Probability density function evaluated at value

Parameters

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

Returns

Probability.

Return type

Tensor

log_prob ( value )

Log probability density function evaluated at value

Parameters

value (float|Tensor) – Value to be evaluated

Returns

Log probability.

Return type

Tensor

entropy ( )

Entropy of gamma distribution

Returns

Entropy.

Return type

Tensor

sample ( shape=() )

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=() )

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]

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 )

Probability density/mass function.

Note

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