Multinomial

class paddle.distribution. Multinomial ( total_count: int, probs: Tensor ) [source]

Multinomial distribution parameterized by total_count and probs.

In probability theory, the multinomial distribution is a generalization of the binomial distribution, it models the probability of counts for each side of a k-sided die rolled n times. When k is 2 and n is 1, the multinomial is the bernoulli distribution, when k is 2 and n is grater than 1, it is the binomial distribution, when k is grater than 2 and n is 1, it is the categorical distribution.

The probability mass function (PMF) for multinomial is

f(x1,...,xk;n,p1,...,pk)=n!x1!...xk!px11...pxkk

where, n is number of trials, k is the number of categories, pi denote probability of a trial falling into each category, ki=1pi=1,pi0, and xi denote count of each category.

Parameters
  • total_count (int) – Number of trials.

  • probs (Tensor) – Probability of a trial falling into each category. Last axis of probs indexes over categories, other axes index over batches. Probs value should between [0, 1], and sum to 1 along last axis. If the value over 1, it will be normalized to sum to 1 along the last axis.

Examples:

>>> import paddle
>>> paddle.seed(2023)
>>> multinomial = paddle.distribution.Multinomial(10, paddle.to_tensor([0.2, 0.3, 0.5]))
>>> print(multinomial.sample((2, 3)))
Tensor(shape=[2, 3, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
    [[[1., 5., 4.],
      [0., 4., 6.],
      [1., 3., 6.]],
    [[2., 2., 6.],
      [0., 6., 4.],
      [3., 3., 4.]]])
probs ( value: Tensor ) Tensor

probs

Probability density/mass function.

Note

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

property mean : Tensor

mean of multinomial distribution.

Returns

mean value.

Return type

Tensor

property variance : Tensor

variance of multinomial distribution.

Returns

variance value.

Return type

Tensor

prob ( value: Tensor ) Tensor

prob

probability mass function evaluated at value.

Parameters

value (Tensor) – value to be evaluated.

Returns

probability of value.

Return type

Tensor

log_prob ( value: Tensor ) Tensor

log_prob

probability mass function evaluated at value.

Parameters

value (Tensor) – value to be evaluated.

Returns

probability of value.

Return type

Tensor

sample ( shape: Iterable[int] = [] ) Tensor

sample

draw sample data from multinomial distribution

Parameters

sample_shape (list|tuple, optional) – [description]. Defaults to [].

entropy ( ) Tensor

entropy

entropy of multinomial distribution

Returns

entropy value

Return type

Tensor

property batch_shape : Sequence[int]

Returns batch shape of distribution

Returns

batch shape

Return type

Sequence[int]

property event_shape : Sequence[int]

Returns event shape of distribution

Returns

event shape

Return type

Sequence[int]

kl_divergence ( other: Distribution ) Tensor [source]

kl_divergence

The KL-divergence between self distributions and other.

rsample ( shape: Sequence[int] = [] ) Tensor

rsample

reparameterized sample