mlpack  master
Public Member Functions | Private Member Functions | Private Attributes | List of all members
mlpack::distribution::GammaDistribution Class Reference

This class represents the Gamma distribution. More...

Public Member Functions

 GammaDistribution (const size_t dimensionality=0)
 Construct the Gamma distribution with the given number of dimensions (default 0); each parameter will be initialized to 0. More...
 
 GammaDistribution (const arma::mat &data, const double tol=1e-8)
 Construct the Gamma distribution, training on the given parameters. More...
 
 GammaDistribution (const arma::vec &alpha, const arma::vec &beta)
 Construct the Gamma distribution given two vectors alpha and beta. More...
 
 ~GammaDistribution ()
 Destructor. More...
 
double Alpha (const size_t dim) const
 Get the alpha parameter of the given dimension. More...
 
double & Alpha (const size_t dim)
 Modify the alpha parameter of the given dimension. More...
 
double Beta (const size_t dim) const
 Get the beta parameter of the given dimension. More...
 
double & Beta (const size_t dim)
 Modify the beta parameter of the given dimension. More...
 
size_t Dimensionality () const
 Get the dimensionality of the distribution. More...
 
void LogProbability (const arma::mat &observations, arma::vec &LogProbabilities) const
 This function returns the logarithm of the probability of a group of observations. More...
 
void Probability (const arma::mat &observations, arma::vec &Probabilities) const
 This function returns the probability of a group of observations. More...
 
double Probability (double x, size_t dim) const
 
arma::vec Random () const
 This function returns an observation of this distribution. More...
 
void Train (const arma::mat &rdata, const double tol=1e-8)
 This function trains (fits distribution parameters) to new data or the dataset the object owns. More...
 
void Train (const arma::mat &observations, const arma::vec &probabilities, const double tol=1e-8)
 Fits an alpha and beta parameter according to observation probabilities. More...
 
void Train (const arma::vec &logMeanxVec, const arma::vec &meanLogxVec, const arma::vec &meanxVec, const double tol=1e-8)
 This function trains (fits distribution parameters) to a dataset with pre-computed statistics logMeanx, meanLogx, meanx for each dimension. More...
 

Private Member Functions

bool Converged (const double aOld, const double aNew, const double tol)
 This is a small function that returns true if the update of alpha is smaller than the tolerance ratio. More...
 

Private Attributes

arma::vec alpha
 Array of fitted alphas. More...
 
arma::vec beta
 Array of fitted betas. More...
 

Detailed Description

This class represents the Gamma distribution.

It supports training a Gamma distribution on a given dataset and accessing the fitted alpha and beta parameters.

This class supports multidimensional Gamma distributions; however, it is assumed that each dimension is independent; therefore, a multidimensional Gamma distribution here may be seen as a set of independent single-dimensional Gamma distributions—and the parameters are estimated under this assumption.

The estimation algorithm used can be found in the following paper:

@techreport{minka2002estimating,
title={Estimating a {G}amma distribution},
author={Minka, Thomas P.},
institution={Microsoft Research},
address={Cambridge, U.K.},
year={2002}
}

Definition at line 51 of file gamma_distribution.hpp.

Constructor & Destructor Documentation

mlpack::distribution::GammaDistribution::GammaDistribution ( const size_t  dimensionality = 0)

Construct the Gamma distribution with the given number of dimensions (default 0); each parameter will be initialized to 0.

Parameters
dimensionalityNumber of dimensions.
mlpack::distribution::GammaDistribution::GammaDistribution ( const arma::mat &  data,
const double  tol = 1e-8 
)

Construct the Gamma distribution, training on the given parameters.

Parameters
dataData to train the distribution on.
tolConvergence tolerance. This is not an absolute measure: It will stop the approximation once the change in the value is smaller than tol.
mlpack::distribution::GammaDistribution::GammaDistribution ( const arma::vec &  alpha,
const arma::vec &  beta 
)

Construct the Gamma distribution given two vectors alpha and beta.

Parameters
alphaThe vector of alphas, one per dimension.
betaThe vector of betas, one per dimension.
mlpack::distribution::GammaDistribution::~GammaDistribution ( )
inline

Destructor.

Definition at line 83 of file gamma_distribution.hpp.

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

Member Function Documentation

double mlpack::distribution::GammaDistribution::Alpha ( const size_t  dim) const
inline

Get the alpha parameter of the given dimension.

Definition at line 183 of file gamma_distribution.hpp.

double& mlpack::distribution::GammaDistribution::Alpha ( const size_t  dim)
inline

Modify the alpha parameter of the given dimension.

Definition at line 185 of file gamma_distribution.hpp.

double mlpack::distribution::GammaDistribution::Beta ( const size_t  dim) const
inline

Get the beta parameter of the given dimension.

Definition at line 188 of file gamma_distribution.hpp.

double& mlpack::distribution::GammaDistribution::Beta ( const size_t  dim)
inline

Modify the beta parameter of the given dimension.

Definition at line 190 of file gamma_distribution.hpp.

bool mlpack::distribution::GammaDistribution::Converged ( const double  aOld,
const double  aNew,
const double  tol 
)
inlineprivate

This is a small function that returns true if the update of alpha is smaller than the tolerance ratio.

Parameters
aOldold value of parameter we want to estimate (alpha in our case).
aNewnew value of parameter (the value after 1 iteration from aOld).
tolConvergence tolerance. Relative measure (see documentation of GammaDistribution::Train).
size_t mlpack::distribution::GammaDistribution::Dimensionality ( ) const
inline

Get the dimensionality of the distribution.

Definition at line 193 of file gamma_distribution.hpp.

void mlpack::distribution::GammaDistribution::LogProbability ( const arma::mat &  observations,
arma::vec &  LogProbabilities 
) const

This function returns the logarithm of the probability of a group of observations.

The logarithm of the probability of a value x is

log({x^( - 1)}{() * ^} * e ^ {-{x}{}})

for one dimension. This implementation assumes each dimension is independent, so the product rule is used.

Parameters
observationsMatrix of observations, one per column.
logProbabilitiescolumn vector of log probabilities, one per observation.

Referenced by ~GammaDistribution().

void mlpack::distribution::GammaDistribution::Probability ( const arma::mat &  observations,
arma::vec &  Probabilities 
) const

This function returns the probability of a group of observations.

The probability of the value x is

{x^( - 1)}{() * ^} * e ^ {-{x}{}}

for one dimension. This implementation assumes each dimension is independent, so the product rule is used.

Parameters
observationsMatrix of observations, one per column.
probabilitiescolumn vector of probabilities, one per observation.

Referenced by ~GammaDistribution().

double mlpack::distribution::GammaDistribution::Probability ( double  x,
size_t  dim 
) const
arma::vec mlpack::distribution::GammaDistribution::Random ( ) const

This function returns an observation of this distribution.

Referenced by ~GammaDistribution().

void mlpack::distribution::GammaDistribution::Train ( const arma::mat &  rdata,
const double  tol = 1e-8 
)

This function trains (fits distribution parameters) to new data or the dataset the object owns.

Parameters
rdataReference data to fit parameters to.
tolConvergence tolerance. This is not an absolute measure: It will stop the approximation once the change in the value is smaller than tol.

Referenced by ~GammaDistribution().

void mlpack::distribution::GammaDistribution::Train ( const arma::mat &  observations,
const arma::vec &  probabilities,
const double  tol = 1e-8 
)

Fits an alpha and beta parameter according to observation probabilities.

This method is not yet implemented.

Parameters
observationsThe reference data, one observation per column
probabilitiesThe probability of each observation. One value per column of the observations matrix.
tolConvergence tolerance. This is not an absolute measure: It will stop the approximation once the change in the value is smaller than tol.
void mlpack::distribution::GammaDistribution::Train ( const arma::vec &  logMeanxVec,
const arma::vec &  meanLogxVec,
const arma::vec &  meanxVec,
const double  tol = 1e-8 
)

This function trains (fits distribution parameters) to a dataset with pre-computed statistics logMeanx, meanLogx, meanx for each dimension.

Parameters
logMeanxVecIs each dimension's logarithm of the mean (log(mean(x))).
meanLogxVecIs each dimension's mean of logarithms (mean(log(x))).
meanxVecIs each dimension's mean (mean(x)).
tolConvergence tolerance. This is not an absolute measure: It will stop the approximation once the change in the value is smaller than tol.

Member Data Documentation

arma::vec mlpack::distribution::GammaDistribution::alpha
private

Array of fitted alphas.

Definition at line 197 of file gamma_distribution.hpp.

arma::vec mlpack::distribution::GammaDistribution::beta
private

Array of fitted betas.

Definition at line 199 of file gamma_distribution.hpp.


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