MLPACK  1.0.4
hmm.hpp
Go to the documentation of this file.
00001 
00023 #ifndef __MLPACK_METHODS_HMM_HMM_HPP
00024 #define __MLPACK_METHODS_HMM_HMM_HPP
00025 
00026 #include <mlpack/core.hpp>
00027 
00028 namespace mlpack {
00029 namespace hmm  {
00030 
00092 template<typename Distribution = distribution::DiscreteDistribution>
00093 class HMM
00094 {
00095  private:
00097   arma::mat transition;
00098 
00100   std::vector<Distribution> emission;
00101 
00102  public:
00110   HMM(const size_t states, const Distribution emissions);
00111 
00126   HMM(const arma::mat& transition, const std::vector<Distribution>& emission);
00127 
00141   void Train(const std::vector<arma::mat>& dataSeq);
00142 
00157   void Train(const std::vector<arma::mat>& dataSeq,
00158              const std::vector<arma::Col<size_t> >& stateSeq);
00159 
00178   double Estimate(const arma::mat& dataSeq,
00179                   arma::mat& stateProb,
00180                   arma::mat& forwardProb,
00181                   arma::mat& backwardProb,
00182                   arma::vec& scales) const;
00183 
00195   double Estimate(const arma::mat& dataSeq,
00196                   arma::mat& stateProb) const;
00197 
00208   void Generate(const size_t length,
00209                 arma::mat& dataSequence,
00210                 arma::Col<size_t>& stateSequence,
00211                 const size_t startState = 0) const;
00212 
00223   double Predict(const arma::mat& dataSeq,
00224                  arma::Col<size_t>& stateSeq) const;
00225 
00232   double LogLikelihood(const arma::mat& dataSeq) const;
00233 
00237   const arma::mat& Transition() const { return transition; }
00238 
00242   arma::mat& Transition() { return transition; }
00243 
00247   const std::vector<Distribution>& Emission() const { return emission; }
00248 
00252   std::vector<Distribution>& Emission() { return emission; }
00253 
00255   size_t Dimensionality() const { return dimensionality; }
00257   size_t& Dimensionality() { return dimensionality; }
00258 
00259  private:
00260   // Helper functions.
00261 
00272   void Forward(const arma::mat& dataSeq,
00273                arma::vec& scales,
00274                arma::mat& forwardProb) const;
00275 
00287   void Backward(const arma::mat& dataSeq,
00288                 const arma::vec& scales,
00289                 arma::mat& backwardProb) const;
00290 
00292   size_t dimensionality;
00293 };
00294 
00295 }; // namespace hmm
00296 }; // namespace mlpack
00297 
00298 // Include implementation.
00299 #include "hmm_impl.hpp"
00300 
00301 #endif