DiscreteDistribution Class Reference

A discrete distribution where the only observations are discrete observations. More...

## Public Member Functions

DiscreteDistribution ()
Default constructor, which creates a distribution that has no observations. More...

DiscreteDistribution (const size_t numObservations)
Define the discrete distribution as having numObservations possible observations. More...

DiscreteDistribution (const arma::Col< size_t > &numObservations)
Define the multidimensional discrete distribution as having numObservations possible observations. More...

DiscreteDistribution (const std::vector< arma::vec > &probabilities)
Define the multidimensional discrete distribution as having the given probabilities for each observation. More...

size_t Dimensionality () const
Get the dimensionality of the distribution. More...

double LogProbability (const arma::vec &observation) const
Return the log probability of the given observation. More...

void LogProbability (const arma::mat &x, arma::vec &logProbabilities) const
Returns the Log probability of the given matrix. More...

arma::vec & Probabilities (const size_t dim=0)
Return the vector of probabilities for the given dimension. More...

const arma::vec & Probabilities (const size_t dim=0) const
Modify the vector of probabilities for the given dimension. More...

double Probability (const arma::vec &observation) const
Return the probability of the given observation. More...

void Probability (const arma::mat &x, arma::vec &probabilities) const
Calculates the Discrete probability density function for each data point (column) in the given matrix. More...

arma::vec Random () const
Return a randomly generated observation (one-dimensional vector; one observation) according to the probability distribution defined by this object. More...

template
<
typename
Archive
>
void serialize (Archive &ar, const uint32_t)
Serialize the distribution. More...

void Train (const arma::mat &observations)
Estimate the probability distribution directly from the given observations. More...

void Train (const arma::mat &observations, const arma::vec &probabilities)
Estimate the probability distribution from the given observations, taking into account the probability of each observation actually being from this distribution. More...

## Detailed Description

A discrete distribution where the only observations are discrete observations.

This is useful (for example) with discrete Hidden Markov Models, where observations are non-negative integers representing specific emissions.

No bounds checking is performed for observations, so if an invalid observation is passed (i.e. observation > numObservations), a crash will probably occur.

This distribution only supports one-dimensional observations, so when passing an arma::vec as an observation, it should only have one dimension (vec.n_rows == 1). Any additional dimensions will simply be ignored.

Note
This class, like every other class in mlpack, uses arma::vec to represent observations. While a discrete distribution only has positive integers (size_t) as observations, these can be converted to doubles (which is what arma::vec holds). This distribution internally converts those doubles back into size_t before comparisons.

Definition at line 45 of file discrete_distribution.hpp.

## ◆ DiscreteDistribution() [1/4]

 DiscreteDistribution ( )
inline

Default constructor, which creates a distribution that has no observations.

Definition at line 52 of file discrete_distribution.hpp.

## ◆ DiscreteDistribution() [2/4]

 DiscreteDistribution ( const size_t numObservations )
inline

Define the discrete distribution as having numObservations possible observations.

The probability in each state will be set to (1 / numObservations).

Parameters
 numObservations Number of possible observations this distribution can have.

Definition at line 63 of file discrete_distribution.hpp.

## ◆ DiscreteDistribution() [3/4]

 DiscreteDistribution ( const arma::Col< size_t > & numObservations )
inline

Define the multidimensional discrete distribution as having numObservations possible observations.

The probability in each state will be set to (1 / numObservations of each dimension).

Parameters
 numObservations Number of possible observations this distribution can have.

Definition at line 76 of file discrete_distribution.hpp.

## ◆ DiscreteDistribution() [4/4]

 DiscreteDistribution ( const std::vector< arma::vec > & probabilities )
inline

Define the multidimensional discrete distribution as having the given probabilities for each observation.

Parameters
 probabilities Probabilities of each possible observation.

Definition at line 98 of file discrete_distribution.hpp.

## ◆ Dimensionality()

 size_t Dimensionality ( ) const
inline

Get the dimensionality of the distribution.

Definition at line 117 of file discrete_distribution.hpp.

## ◆ LogProbability() [1/2]

 double LogProbability ( const arma::vec & observation ) const
inline

Return the log probability of the given observation.

If the observation is greater than the number of possible observations, then a crash will probably occur – bounds checking is not performed.

Parameters
 observation Observation to return the log probability of.
Returns
Log probability of the given observation.

Definition at line 166 of file discrete_distribution.hpp.

References DiscreteDistribution::Probability().

## ◆ LogProbability() [2/2]

 void LogProbability ( const arma::mat & x, arma::vec & logProbabilities ) const
inline

Returns the Log probability of the given matrix.

These values are stored in logProbabilities.

Parameters
 x List of observations. logProbabilities Output log-probabilities for each input observation.

Definition at line 194 of file discrete_distribution.hpp.

## ◆ Probabilities() [1/2]

 arma::vec& Probabilities ( const size_t dim = `0` )
inline

Return the vector of probabilities for the given dimension.

Definition at line 232 of file discrete_distribution.hpp.

## ◆ Probabilities() [2/2]

 const arma::vec& Probabilities ( const size_t dim = `0` ) const
inline

Modify the vector of probabilities for the given dimension.

Definition at line 234 of file discrete_distribution.hpp.

## ◆ Probability() [1/2]

 double Probability ( const arma::vec & observation ) const
inline

Return the probability of the given observation.

If the observation is greater than the number of possible observations, then a crash will probably occur – bounds checking is not performed.

Parameters
 observation Observation to return the probability of.
Returns
Probability of the given observation.

Definition at line 127 of file discrete_distribution.hpp.

References Log::Fatal.

Referenced by DiscreteDistribution::LogProbability(), and DiscreteDistribution::Probability().

## ◆ Probability() [2/2]

 void Probability ( const arma::mat & x, arma::vec & probabilities ) const
inline

Calculates the Discrete probability density function for each data point (column) in the given matrix.

Parameters
 x List of observations. probabilities Output probabilities for each input observation.

Definition at line 179 of file discrete_distribution.hpp.

References DiscreteDistribution::Probability().

## ◆ Random()

 arma::vec Random ( ) const

Return a randomly generated observation (one-dimensional vector; one observation) according to the probability distribution defined by this object.

Returns
Random observation.

## ◆ serialize()

 void serialize ( Archive & ar, const uint32_t )
inline

Serialize the distribution.

Definition at line 241 of file discrete_distribution.hpp.

## ◆ Train() [1/2]

 void Train ( const arma::mat & observations )

Estimate the probability distribution directly from the given observations.

If any of the observations is greater than numObservations, a crash is likely to occur.

Parameters
 observations List of observations.

Referenced by DiscreteDistribution::LogProbability().

## ◆ Train() [2/2]

 void Train ( const arma::mat & observations, const arma::vec & probabilities )

Estimate the probability distribution from the given observations, taking into account the probability of each observation actually being from this distribution.

Parameters
 observations List of observations. probabilities List of probabilities that each observation is actually from this distribution.

The documentation for this class was generated from the following file: