discreteHMM.h

Go to the documentation of this file.
00001 /* MLPACK 0.2
00002  *
00003  * Copyright (c) 2008, 2009 Alexander Gray,
00004  *                          Garry Boyer,
00005  *                          Ryan Riegel,
00006  *                          Nikolaos Vasiloglou,
00007  *                          Dongryeol Lee,
00008  *                          Chip Mappus, 
00009  *                          Nishant Mehta,
00010  *                          Hua Ouyang,
00011  *                          Parikshit Ram,
00012  *                          Long Tran,
00013  *                          Wee Chin Wong
00014  *
00015  * Copyright (c) 2008, 2009 Georgia Institute of Technology
00016  *
00017  * This program is free software; you can redistribute it and/or
00018  * modify it under the terms of the GNU General Public License as
00019  * published by the Free Software Foundation; either version 2 of the
00020  * License, or (at your option) any later version.
00021  *
00022  * This program is distributed in the hope that it will be useful, but
00023  * WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025  * General Public License for more details.
00026  *
00027  * You should have received a copy of the GNU General Public License
00028  * along with this program; if not, write to the Free Software
00029  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00030  * 02110-1301, USA.
00031  */
00042 #ifndef FASTLIB_DISCRETE_HMM_H
00043 #define FASTLIB_DISCRETE_HMM_H
00044 
00045 #include "fastlib/fastlib.h"
00046 
00055 class DiscreteHMM {
00057  private:
00059   Matrix transmission_;
00060 
00062   Matrix emission_;
00063 
00064   OT_DEF(DiscreteHMM) {
00065     OT_MY_OBJECT(transmission_);
00066     OT_MY_OBJECT(emission_);
00067   }
00068 
00069  public:
00071   const Matrix& transmission() const { return transmission_; }
00072   const Matrix& emission() const { return emission_; }
00073 
00075   void setModel(const Matrix& transmission, const Matrix& emission);
00076 
00078   void Init(const Matrix& transmission, const Matrix& emission);
00079 
00081   void InitFromFile(const char* profile);
00082 
00084   void InitFromData(const ArrayList<Vector>& list_data_seq, int numstate);
00085 
00087   void LoadProfile(const char* profile);
00088 
00090   void SaveProfile(const char* profile) const;
00091 
00093   void GenerateSequence(int length, Vector* data_seq, Vector* state_seq) const;
00094 
00099   void EstimateModel(const Vector& data_seq, const Vector& state_seq);
00100   void EstimateModel(int numstate, int numsymbol, const Vector& data_seq, const Vector& state_seq);
00101 
00107   void DecodeOverwrite(const Vector& data_seq, Matrix* state_prob_mat, Matrix* forward_prob_mat, Matrix* backward_prob_mat, Vector* scale_vec) const;
00108 
00110   void DecodeInit(const Vector& data_seq, Matrix* state_prob_mat, Matrix* forward_prob_mat, Matrix* backward_prob_mat, Vector* scale_vec) const;
00111 
00113   double ComputeLogLikelihood(const Vector& data_seq) const;
00114 
00116   void ComputeLogLikelihood(const ArrayList<Vector>& list_data_seq, ArrayList<double>* list_likelihood) const;
00117 
00119   void ComputeViterbiStateSequence(const Vector& data_seq, Vector* state_seq) const;
00120 
00125   void TrainBaumWelch(const ArrayList<Vector>& list_data_seq, int max_iteration, double tolerance);
00126 
00131   void TrainViterbi(const ArrayList<Vector>& list_data_seq, int max_iteration, double tolerance);
00132 
00133 
00135 
00144   static void GenerateInit(int L, const Matrix& trans, const Matrix& emis, Vector* seq, Vector * states);
00145 
00147   static void EstimateInit(const Vector& seq, const Vector& states, Matrix* trans, Matrix* emis);
00148   static void EstimateInit(int numSymbols, int numStates, const Vector& seq, const Vector& states, Matrix* trans, Matrix* emis);
00149 
00161   static void ForwardProcedure(const Vector& seq, const Matrix& trans, const Matrix& emis, Vector *scales, Matrix* fs);
00162   static void BackwardProcedure(const Vector& seq, const Matrix& trans, const Matrix& emis, const Vector& scales, Matrix* bs);
00163   static double Decode(const Vector& seq, const Matrix& trans, const Matrix& emis, Matrix* pstates, Matrix* fs, Matrix* bs, Vector* scales);
00164 
00173   static double ViterbiInit(const Vector& seq, const Matrix& trans, const Matrix& emis, Vector* states);
00174   static double ViterbiInit(int L, const Vector& seq, const Matrix& trans, const Matrix& emis, Vector* states);
00175 
00177   static void Train(const ArrayList<Vector>& seqs, Matrix* guessTR, Matrix* guessEM, int max_iter, double tol);
00178 
00180   static void TrainViterbi(const ArrayList<Vector>& seqs, Matrix* guessTR, Matrix* guessEM, int max_iter, double tol);
00181 
00182 };
00183 #endif
Generated on Mon Jan 24 12:04:38 2011 for FASTlib by  doxygen 1.6.3