mlpack  master
gamma_distribution.hpp
Go to the documentation of this file.
1 
18 #ifndef _MLPACK_CORE_DISTRIBUTIONS_GAMMA_DISTRIBUTION_HPP
19 #define _MLPACK_CORE_DISTRIBUTIONS_GAMMA_DISTRIBUTION_HPP
20 
21 #include <mlpack/prereqs.hpp>
23 #include <boost/program_options.hpp>
24 
25 namespace mlpack {
26 namespace distribution {
27 
52 {
53  public:
60  GammaDistribution(const size_t dimensionality = 0);
61 
70  GammaDistribution(const arma::mat& data, const double tol = 1e-8);
71 
78  GammaDistribution(const arma::vec& alpha, const arma::vec& beta);
79 
84 
94  void Train(const arma::mat& rdata, const double tol = 1e-8);
95 
107  void Train(const arma::mat& observations,
108  const arma::vec& probabilities,
109  const double tol = 1e-8);
110 
123  void Train(const arma::vec& logMeanxVec,
124  const arma::vec& meanLogxVec,
125  const arma::vec& meanxVec,
126  const double tol = 1e-8);
127 
128 
143  void Probability(const arma::mat& observations,
144  arma::vec& Probabilities) const;
145 
146  /*
147  * This is a shortcut to the Probability(arma::mat&, arma::vec&) function
148  * for when we want to evaluate only the probability of one dimension of the
149  * gamma.
150  *
151  * @param x The 1-dimensional observation.
152  * @param dim The dimension for which to calculate the probability
153  */
154  double Probability(double x, size_t dim) const;
155 
172  void LogProbability(const arma::mat& observations,
173  arma::vec& LogProbabilities) const;
174 
178  arma::vec Random() const;
179 
180  // Access to Gamma distribution parameters.
181 
183  double Alpha(const size_t dim) const { return alpha[dim]; }
185  double& Alpha(const size_t dim) { return alpha[dim]; }
186 
188  double Beta(const size_t dim) const { return beta[dim]; }
190  double& Beta(const size_t dim) { return beta[dim]; }
191 
193  size_t Dimensionality() const { return alpha.n_elem; }
194 
195  private:
197  arma::vec alpha;
199  arma::vec beta;
200 
212  inline bool Converged(const double aOld,
213  const double aNew,
214  const double tol);
215 };
216 
217 } // namespace distributions.
218 } // namespace mlpack.
219 
220 #endif
size_t Dimensionality() const
Get the dimensionality of the distribution.
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...
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
The core includes that mlpack expects; standard C++ includes and Armadillo.
arma::vec alpha
Array of fitted alphas.
arma::vec beta
Array of fitted betas.
double Alpha(const size_t dim) const
Get the alpha parameter of the given dimension.
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...
double Beta(const size_t dim) const
Get the beta parameter of the given dimension.
void LogProbability(const arma::mat &observations, arma::vec &LogProbabilities) const
This function returns the logarithm of the probability of a group of observations.
double & Alpha(const size_t dim)
Modify the alpha parameter of the given dimension.
GammaDistribution(const size_t dimensionality=0)
Construct the Gamma distribution with the given number of dimensions (default 0); each parameter will...
void Probability(const arma::mat &observations, arma::vec &Probabilities) const
This function returns the probability of a group of observations.
Miscellaneous math random-related routines.
This class represents the Gamma distribution.
arma::vec Random() const
This function returns an observation of this distribution.
double & Beta(const size_t dim)
Modify the beta parameter of the given dimension.