mindspore.nn.probability.distribution.Distribution

class mindspore.nn.probability.distribution.Distribution(seed, dtype, name, param)[source]

Base class for all mathematical distributions.

Parameters
  • seed (int) – The seed is used in sampling. 0 is used if it is None.

  • dtype (mindspore.dtype) – The type of the event samples.

  • name (str) – The name of the distribution.

  • param (dict) – The parameters used to initialize the distribution.

Supported Platforms:

Ascend GPU

Note

Derived class must override operations such as _mean, _prob, and _log_prob. Required arguments, such as value for _prob, must be passed in through args or kwargs. dist_spec_args which specifies a new distribution are optional.

dist_spec_args is unique for each type of distribution. For example, mean and sd are the dist_spec_args for a Normal distribution, while rate is the dist_spec_args for an Exponential distribution.

For all functions, passing in dist_spec_args, is optional. Function calls with the additional dist_spec_args passed in will evaluate the result with a new distribution specified by the dist_spec_args. However, it will not change the original distribution.

cdf(value, *args, **kwargs)[source]

Evaluate the cdf at given value.

Parameters
  • value (Tensor) – value to be evaluated.

  • *args (list) – the list of positional arguments forwarded to subclasses.

  • **kwargs (dictionary) – the dictionary of keyword arguments forwarded to subclasses.

Note

A distribution can be optionally passed to the function by passing its dist_spec_args through args or kwargs.

construct(name, *args, **kwargs)[source]

Override construct in Cell.

Note

Names of supported functions include: ‘prob’, ‘log_prob’, ‘cdf’, ‘log_cdf’, ‘survival_function’, ‘log_survival’, ‘var’, ‘sd’, ‘mode’, ‘mean’, ‘entropy’, ‘kl_loss’, ‘cross_entropy’, ‘sample’, ‘get_dist_args’, and ‘get_dist_type’.

Parameters
  • name (str) – The name of the function.

  • *args (list) – A list of positional arguments that the function needs.

  • **kwargs (dictionary) – A dictionary of keyword arguments that the function needs.

cross_entropy(dist, *args, **kwargs)[source]

Evaluate the cross_entropy between distribution a and b.

Parameters
  • dist (str) – type of the distribution.

  • *args (list) – the list of positional arguments forwarded to subclasses.

  • **kwargs (dictionary) – the dictionary of keyword arguments forwarded to subclasses.

Note

dist_spec_args of distribution b must be passed to the function through args or kwargs. Passing in dist_spec_args of distribution a is optional.

entropy(*args, **kwargs)[source]

Evaluate the entropy.

Parameters
  • *args (list) – the list of positional arguments forwarded to subclasses.

  • **kwargs (dictionary) – the dictionary of keyword arguments forwarded to subclasses.

Note

A distribution can be optionally passed to the function by passing its dist_spec_args through args or kwargs.

get_dist_args(*args, **kwargs)[source]

Check the availability and validity of default parameters and dist_spec_args.

Parameters
  • *args (list) – the list of positional arguments forwarded to subclasses.

  • **kwargs (dictionary) – the dictionary of keyword arguments forwarded to subclasses.

Note

dist_spec_args must be passed in through list or dictionary. The order of dist_spec_args should follow the initialization order of default parameters through _add_parameter. If some dist_spec_args is None, the corresponding default parameter is returned.

get_dist_type()[source]

Return the type of the distribution.

kl_loss(dist, *args, **kwargs)[source]

Evaluate the KL divergence, i.e. KL(a||b).

Parameters
  • dist (str) – type of the distribution.

  • *args (list) – the list of positional arguments forwarded to subclasses.

  • **kwargs (dictionary) – the dictionary of keyword arguments forwarded to subclasses.

Note

dist_spec_args of distribution b must be passed to the function through args or kwargs. Passing in dist_spec_args of distribution a is optional.

log_cdf(value, *args, **kwargs)[source]

Evaluate the log cdf at given value.

Parameters
  • value (Tensor) – value to be evaluated.

  • *args (list) – the list of positional arguments forwarded to subclasses.

  • **kwargs (dictionary) – the dictionary of keyword arguments forwarded to subclasses.

Note

A distribution can be optionally passed to the function by passing its dist_spec_args through args or kwargs.

log_prob(value, *args, **kwargs)[source]

Evaluate the log probability(pdf or pmf) at the given value.

Parameters
  • value (Tensor) – value to be evaluated.

  • *args (list) – the list of positional arguments forwarded to subclasses.

  • **kwargs (dictionary) – the dictionary of keyword arguments forwarded to subclasses.

Note

A distribution can be optionally passed to the function by passing its dist_spec_args through args or kwargs.

log_survival(value, *args, **kwargs)[source]

Evaluate the log survival function at given value.

Parameters
  • value (Tensor) – value to be evaluated.

  • *args (list) – the list of positional arguments forwarded to subclasses.

  • **kwargs (dictionary) – the dictionary of keyword arguments forwarded to subclasses.

Note

A distribution can be optionally passed to the function by passing its dist_spec_args through args or kwargs.

mean(*args, **kwargs)[source]

Evaluate the mean.

Parameters
  • *args (list) – the list of positional arguments forwarded to subclasses.

  • **kwargs (dictionary) – the dictionary of keyword arguments forwarded to subclasses.

Note

A distribution can be optionally passed to the function by passing its dist_spec_args through args or kwargs.

mode(*args, **kwargs)[source]

Evaluate the mode.

Parameters
  • *args (list) – the list of positional arguments forwarded to subclasses.

  • **kwargs (dictionary) – the dictionary of keyword arguments forwarded to subclasses.

Note

A distribution can be optionally passed to the function by passing its dist_spec_args through args or kwargs.

prob(value, *args, **kwargs)[source]

Evaluate the probability (pdf or pmf) at given value.

Parameters
  • value (Tensor) – value to be evaluated.

  • *args (list) – the list of positional arguments forwarded to subclasses.

  • **kwargs (dictionary) – the dictionary of keyword arguments forwarded to subclasses.

Note

A distribution can be optionally passed to the function by passing its dist_spec_args through args or kwargs.

sample(*args, **kwargs)[source]

Sampling function.

Parameters
  • shape (tuple) – shape of the sample.

  • *args (list) – the list of positional arguments forwarded to subclasses.

  • **kwargs (dictionary) – the dictionary of keyword arguments forwarded to subclasses.

Note

A distribution can be optionally passed to the function by passing its dist_spec_args through args or kwargs.

sd(*args, **kwargs)[source]

Evaluate the standard deviation.

Parameters
  • *args (list) – the list of positional arguments forwarded to subclasses.

  • **kwargs (dictionary) – the dictionary of keyword arguments forwarded to subclasses.

Note

A distribution can be optionally passed to the function by passing its dist_spec_args through args or kwargs.

survival_function(value, *args, **kwargs)[source]

Evaluate the survival function at given value.

Parameters
  • value (Tensor) – value to be evaluated.

  • *args (list) – the list of positional arguments forwarded to subclasses.

  • **kwargs (dictionary) – the dictionary of keyword arguments forwarded to subclasses.

Note

A distribution can be optionally passed to the function by passing its dist_spec_args through args or kwargs.

var(*args, **kwargs)[source]

Evaluate the variance.

Parameters
  • *args (list) – the list of positional arguments forwarded to subclasses.

  • **kwargs (dictionary) – the dictionary of keyword arguments forwarded to subclasses.

Note

A distribution can be optionally passed to the function by passing its dist_spec_args through args or kwargs.