mlpack  master
Public Member Functions | Private Attributes | List of all members
mlpack::distribution::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...
 
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...
 
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 unsigned int)
 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...
 

Private Attributes

std::vector< arma::vec > probabilities
 The probabilities for each dimension; each arma::vec represents the probabilities for the observations in each dimension. 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.

Constructor & Destructor Documentation

mlpack::distribution::DiscreteDistribution::DiscreteDistribution ( )
inline

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

Definition at line 51 of file discrete_distribution.hpp.

mlpack::distribution::DiscreteDistribution::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
numObservationsNumber of possible observations this distribution can have.

Definition at line 62 of file discrete_distribution.hpp.

mlpack::distribution::DiscreteDistribution::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
numObservationsNumber of possible observations this distribution can have.

Definition at line 75 of file discrete_distribution.hpp.

References probabilities.

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

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

Parameters
probabilitiesProbabilities of each possible observation.

Definition at line 97 of file discrete_distribution.hpp.

Member Function Documentation

size_t mlpack::distribution::DiscreteDistribution::Dimensionality ( ) const
inline

Get the dimensionality of the distribution.

Definition at line 116 of file discrete_distribution.hpp.

References probabilities.

double mlpack::distribution::DiscreteDistribution::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
observationObservation to return the log probability of.
Returns
Log probability of the given observation.

Definition at line 164 of file discrete_distribution.hpp.

References probabilities, Probability(), Random(), and Train().

arma::vec& mlpack::distribution::DiscreteDistribution::Probabilities ( const size_t  dim = 0)
inline

Return the vector of probabilities for the given dimension.

Definition at line 201 of file discrete_distribution.hpp.

const arma::vec& mlpack::distribution::DiscreteDistribution::Probabilities ( const size_t  dim = 0) const
inline

Modify the vector of probabilities for the given dimension.

Definition at line 203 of file discrete_distribution.hpp.

double mlpack::distribution::DiscreteDistribution::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
observationObservation to return the probability of.
Returns
Probability of the given observation.

Definition at line 126 of file discrete_distribution.hpp.

References mlpack::Log::Debug, and probabilities.

Referenced by LogProbability().

arma::vec mlpack::distribution::DiscreteDistribution::Random ( ) const

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

Returns
Random observation.

Referenced by LogProbability().

template<typename Archive >
void mlpack::distribution::DiscreteDistribution::Serialize ( Archive &  ar,
const unsigned  int 
)
inline

Serialize the distribution.

Definition at line 210 of file discrete_distribution.hpp.

References mlpack::data::CreateNVP().

void mlpack::distribution::DiscreteDistribution::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
observationsList of observations.

Referenced by LogProbability().

void mlpack::distribution::DiscreteDistribution::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
observationsList of observations.
probabilitiesList of probabilities that each observation is actually from this distribution.

Member Data Documentation

std::vector<arma::vec> mlpack::distribution::DiscreteDistribution::probabilities
private

The probabilities for each dimension; each arma::vec represents the probabilities for the observations in each dimension.

Definition at line 235 of file discrete_distribution.hpp.

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


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