mixgaussHMM.h

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  */
00041 #ifndef FASTLIB_MIXGAUSS_HMM_H
00042 #define FASTLIB_MIXGAUSS_HMM_H
00043 
00044 #include "fastlib/fastlib.h"
00045 #include "mixtureDST.h"
00046 
00053 class MixtureofGaussianHMM {
00055  private:
00057   Matrix transmission_;
00058 
00060   ArrayList<MixtureGauss> list_mixture_gauss_;
00061 
00062   OT_DEF(MixtureofGaussianHMM) {
00063     OT_MY_OBJECT(transmission_);
00064     OT_MY_OBJECT(list_mixture_gauss_);
00065   }
00066  public:
00068   const Matrix& transmission() const { return transmission_; }
00069   const ArrayList<MixtureGauss>& list_mixture_gauss() const { return list_mixture_gauss_; }
00070 
00072   void setModel(const Matrix& transmission,
00073                 const ArrayList<MixtureGauss>& list_mixture_gauss);
00074 
00076   void Init(const Matrix& transmission, const ArrayList<MixtureGauss>& list_mixture_gauss);
00077 
00079   void InitFromFile(const char* profile);
00080 
00082   void Init() {
00083     transmission_.Init(0, 0);
00084     list_mixture_gauss_.Init();
00085   }
00086 
00088   void LoadProfile(const char* profile);
00089 
00091   void SaveProfile(const char* profile) const;
00092 
00094   void GenerateSequence(int L, Matrix* data_seq, Vector* state_seq) const;
00095 
00101   void EstimateModel(int numcluster, const Matrix& data_seq, const Vector& state_seq);
00102   void EstimateModel(int numstate, int numcluster, 
00103                      const Matrix& data_seq, const Vector& state_seq);
00104 
00110   void DecodeOverwrite(const Matrix& data_seq, Matrix* state_prob_mat, Matrix* forward_prob_mat, 
00111                        Matrix* backward_prob_mat, Vector* scale_vec) const;
00112 
00114   void DecodeInit(const Matrix& data_seq, Matrix* state_prob_mat, Matrix* forward_prob_mat, 
00115                   Matrix* backward_prob_mat, Vector* scale_vec) const;
00116 
00118   double ComputeLogLikelihood(const Matrix& data_seq) const;
00119 
00121   void ComputeLogLikelihood(const ArrayList<Matrix>& list_data_seq, ArrayList<double>* list_likelihood) const;
00122 
00124   void ComputeViterbiStateSequence(const Matrix& data_seq, Vector* state_seq) const;
00125 
00130   void TrainBaumWelch(const ArrayList<Matrix>& list_data_seq, int max_iteration, double tolerance);
00131 
00136   void TrainViterbi(const ArrayList<Matrix>& list_data_seq, int max_iteration, double tolerance);
00137 
00138 
00140   static success_t LoadProfile(const char* profile, Matrix* trans, ArrayList<MixtureGauss>* mixs);
00141   static success_t SaveProfile(const char* profile, const Matrix& trans, const ArrayList<MixtureGauss>& mixs);
00142 
00152   static void GenerateInit(int L, const Matrix& trans, const ArrayList<MixtureGauss>& mixs, Matrix* seq, Vector* states);
00153 
00155   static void EstimateInit(int NumClusters, const Matrix& seq, const Vector& states, 
00156                            Matrix* trans, ArrayList<MixtureGauss>* mixs);
00157   static void EstimateInit(int numStates, int NumClusters, const Matrix& seq, 
00158                            const Vector& states, Matrix* trans, ArrayList<MixtureGauss>* mixs);
00159 
00172   static void ForwardProcedure(int L, const Matrix& trans, const Matrix& emis_prob, 
00173                                Vector *scales, Matrix* fs);
00174   static void BackwardProcedure(int L, const Matrix& trans, const Matrix& emis_prob, 
00175                                 const Vector& scales, Matrix* bs);
00176   static double Decode(const Matrix& trans, const Matrix& emis_prob, Matrix* pstates, 
00177                        Matrix* fs, Matrix* bs, Vector* scales);
00178   static double Decode(int L, const Matrix& trans, const Matrix& emis_prob, 
00179                        Matrix* pstates, Matrix* fs, Matrix* bs, Vector* scales);
00180 
00181   static void CalculateEmissionProb(const Matrix& seq, const ArrayList<MixtureGauss>& mixs, Matrix* emis_prob);
00182 
00191   static double ViterbiInit(const Matrix& trans, const Matrix& emis_prob, Vector* states);
00192   static double ViterbiInit(int L, const Matrix& trans, const Matrix& emis_prob, Vector* states);
00193 
00198   static void Train(const ArrayList<Matrix>& seqs, Matrix* guessTR, 
00199                     ArrayList<MixtureGauss>* guessMG, int max_iter, double tol);
00200   static void TrainViterbi(const ArrayList<Matrix>& seqs, Matrix* guessTR, 
00201                            ArrayList<MixtureGauss>* guessMG, int max_iter, double tol);
00202 };
00203 #endif
Generated on Mon Jan 24 12:04:38 2011 for FASTlib by  doxygen 1.6.3