mxnet.gluon.probability.distributions.categorical

Categorical class.

Classes

Categorical(num_events[, prob, logit, ...])

Create a categorical distribution object.

class mxnet.gluon.probability.distributions.categorical.Categorical(num_events, prob=None, logit=None, validate_args=None)[source]

Bases: Distribution

Create a categorical distribution object.

Parameters:
  • num_events (Int) – Number of events.

  • prob (Tensor) – Probabilities of each event.

  • logit (Tensor) – The log-odds of each event

broadcast_to(batch_shape)[source]

Returns a new distribution instance with parameters expanded to batch_shape. This method calls numpy.broadcast_to on the parameters.

Parameters:

batch_shape (Tuple) – The batch shape of the desired distribution.

enumerate_support()[source]

Returns a tensor that contains all values supported by a discrete distribution.

log_prob(value)[source]

Compute the log-likelihood of value

Parameters:

value (Tensor) – samples from Categorical distribution

Returns:

log-likelihood of value

Return type:

Tensor

logit()[source]

Get the log probability of sampling each class.

Returns:

Parameter tensor.

Return type:

Tensor

prob()[source]

Get the probability of sampling each class.

Returns:

Parameter tensor.

Return type:

Tensor

sample(size=None)[source]

Sample from categorical distribution. Given logit/prob of size (batch_size, num_events), batch_size samples will be drawn. If size is given, np.broadcast(size, batch_size) samples will be drawn.

Parameters:

size (int or tuple of ints)

Returns:

out – Samples from the categorical distribution.

Return type:

Tensor

sample_n(size=None)[source]

Generate samples of (n + parameter_shape) from the distribution.

property support

Returns a function representing the distribution’s support.