Beta

class paddle.distribution. Beta ( alpha, beta ) [source]

Beta distribution parameterized by alpha and beta.

In probability theory and statistics, the beta distribution is a family of continuous probability distributions defined on the interval [0, 1] parameterized by two positive shape parameters, denoted by alpha and beta, that appear as exponents of the random variable and control the shape of the distribution. The generalization to multiple variables is called a Dirichlet distribution.

The probability density function (pdf) is

\[f(x; \alpha, \beta) = \frac{1}{B(\alpha, \beta)}x^{\alpha-1}(1-x)^{\beta-1}\]

where the normalization, B, is the beta function,

\[B(\alpha, \beta) = \int_{0}^{1} t^{\alpha - 1} (1-t)^{\beta - 1}\mathrm{d}t\]
Parameters
  • alpha (float|Tensor) – Alpha parameter. It supports broadcast semantics. The value of alpha must be positive. When the parameter is a tensor, it represents multiple independent distribution with a batch_shape(refer to Distribution ).

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

Examples

>>> import paddle

>>> # scale input
>>> beta = paddle.distribution.Beta(alpha=0.5, beta=0.5)
>>> print(beta.mean)
Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
0.50000000)

>>> print(beta.variance)
Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
0.12500000)

>>> print(beta.entropy())
Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
-0.24156499)

>>> # tensor input with broadcast
>>> beta = paddle.distribution.Beta(alpha=paddle.to_tensor([0.2, 0.4]), beta=0.6)
>>> print(beta.mean)
Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
[0.25000000, 0.40000001])

>>> print(beta.variance)
Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
[0.10416666, 0.12000000])

>>> print(beta.entropy())
Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
[-1.91923141, -0.38095081])
property mean

Mean of beta distribution.

property variance

Variance of beat distribution

prob ( value )

prob

Probability density function evaluated at value

Parameters

value (Tensor) – Value to be evaluated.

Returns

Probability.

Return type

Tensor

log_prob ( value )

log_prob

Log probability density function evaluated at value

Parameters

value (Tensor) – Value to be evaluated

Returns

Log probability.

Return type

Tensor

sample ( shape=() )

sample

Sample from beta distribution with sample shape.

Parameters

shape (Sequence[int], optional) – Sample shape.

Returns

Sampled data with shape sample_shape + batch_shape + event_shape.

entropy ( )

entropy

Entropy of dirichlet distribution

Returns

Entropy.

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 self distributions and other.

probs ( value )

probs

Probability density/mass function.

Note

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

rsample ( shape=() )

rsample

reparameterized sample