mxfusion.components.distributions.categorical

Members

class mxfusion.components.distributions.categorical.Categorical(log_prob, num_classes, one_hot_encoding=False, normalization=True, axis=-1, rand_gen=None, dtype=None, ctx=None)

Bases: mxfusion.components.distributions.univariate.UnivariateDistribution

The Categorical distribution.

Parameters:
  • log_prob (Variable) – the logarithm of the probability being in each of the classes.
  • num_classes (int) – the number of classes.
  • one_hot_encoding (boolean) – If true, the random variable is one-hot encoded.
  • normalization (boolean) – If true, a softmax normalization is applied.
  • axis (int) – the axis in which the categorical distribution is assumed (default: -1).
  • rand_gen (RandomGenerator) – the random generator (default: MXNetRandomGenerator).
  • dtype (numpy.float32 or numpy.float64) – the data type for float point numbers.
  • ctx (None or mxnet.cpu or mxnet.gpu) – the mxnet context (default: None/current context).
replicate_self(attribute_map=None)

This functions as a copy constructor for the object. In order to do a copy constructor we first call __new__ on the class which creates a blank object. We then initialize that object using the methods standard init procedures, and do any extra copying of attributes.

Replicates this Factor, using new inputs, outputs, and a new uuid. Used during model replication to functionally replicate a factor into a new graph.

Parameters:
  • inputs (List of tuples of name to node e.g. [('random_variable': Variable y)] or None) – new input variables of the factor.
  • outputs (List of tuples of name to node e.g. [('random_variable': Variable y)] or None) – new output variables of the factor.
log_pdf_impl(log_prob, random_variable, F=None)

Computes the logarithm of probabilistic mass function of the Categorical distribution.

Parameters:
  • F – MXNet computation type <mx.sym, mx.nd>.
  • log_prob (MXNet NDArray or MXNet Symbol) – the logarithm of the probability being in each of the classes.
  • random_variable (MXNet NDArray or MXNet Symbol) – the point to compute the log pdf for.
Returns:

log pdf of the distribution.

Rtypes:

MXNet NDArray or MXNet Symbol

draw_samples_impl(log_prob, rv_shape, num_samples=1, F=None)

Draw a number of samples from the Categorical distribution.

Parameters:
  • log_prob (MXNet NDArray or MXNet Symbol) – the logarithm of the probability being in each of the classes.
  • rv_shape (tuple) – the shape of each sample.
  • num_samples (int) – the number of drawn samples (default: one).
  • F – the MXNet computation mode (mxnet.symbol or mxnet.ndarray).
Returns:

a set samples of the Categorical distribution

Rtypes:

MXNet NDArray or MXNet Symbol

static define_variable(log_prob, num_classes, shape=None, one_hot_encoding=False, normalization=True, axis=-1, rand_gen=None, dtype=None, ctx=None)

Creates and returns a random variable drawn from a Categorical distribution.

Parameters:
  • log_prob (Variable) – the logarithm of the probability being in each of the classes.
  • num_classes (int) – the number of classes.
  • shape (tuple of int) – the shape of the Categorical variable.
  • one_hot_encoding (boolean) – If true, the random variable is one-hot encoded.
  • normalization (boolean) – If true, a softmax normalization is applied.
  • axis (int) – the axis in which the categorical distribution is assumed (default: -1).
  • rand_gen (RandomGenerator) – the random generator (default: MXNetRandomGenerator).
  • dtype (numpy.float32 or numpy.float64) – the data type for float point numbers.
  • ctx (None or mxnet.cpu or mxnet.gpu) – the mxnet context (default: None/current context).
Returns:

RandomVariable drawn from the Categorical distribution.

Rtypes:

Variable