mlpack
Public Member Functions | List of all members
mlpack::distribution::DiscreteDistribution Class Reference

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

#include <discrete_distribution.hpp>

Public Member Functions

 DiscreteDistribution ()
 Default constructor, which creates a distribution that has no observations.
 
 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.
 
double Probability (const arma::vec &observation) const
 Return the probability of the given observation. More...
 
double LogProbability (const arma::vec &observation) const
 Return the log 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...
 
void LogProbability (const arma::mat &x, arma::vec &logProbabilities) const
 Returns the Log probability of 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...
 
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...
 
arma::vec & Probabilities (const size_t dim=0)
 Return the vector of probabilities for the given dimension.
 
const arma::vec & Probabilities (const size_t dim=0) const
 Modify the vector of probabilities for the given dimension.
 
template<typename Archive >
void serialize (Archive &ar, const uint32_t)
 Serialize the distribution.
 

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.

Constructor & Destructor Documentation

◆ DiscreteDistribution() [1/3]

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.

◆ DiscreteDistribution() [2/3]

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.

◆ DiscreteDistribution() [3/3]

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.

Member Function Documentation

◆ LogProbability() [1/2]

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.

◆ LogProbability() [2/2]

void mlpack::distribution::DiscreteDistribution::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
xList of observations.
logProbabilitiesOutput log-probabilities for each input observation.

◆ Probability() [1/2]

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.

◆ Probability() [2/2]

void mlpack::distribution::DiscreteDistribution::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
xList of observations.
probabilitiesOutput probabilities for each input observation.

◆ Random()

arma::vec DiscreteDistribution::Random ( ) const

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

Return a randomly generated observation according to the probability distribution defined by this object.

Returns
Random observation.

◆ Train() [1/2]

void 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.

◆ Train() [2/2]

void 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.

Estimate the probability distribution from the given observations when also given probabilities that each observation is from this distribution.

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

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