gaussianHMM.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  */
00041 #ifndef FASTLIB_GAUSSIAN_HMM_H
00042 #define FASTLIB_GAUSSIAN_HMM_H
00043 
00044 #include "fastlib/fastlib.h"
00045 
00053 class GaussianHMM {
00055  private:
00057   Matrix transmission_;
00058 
00060   ArrayList<Vector> list_mean_vec_;
00061 
00063   ArrayList<Matrix> list_covariance_mat_;
00064   
00066   ArrayList<Matrix> list_inverse_cov_mat_;
00067 
00069   Vector gauss_const_vec_;
00070 
00071   OT_DEF(GaussianHMM) {
00072     OT_MY_OBJECT(transmission_);
00073     OT_MY_OBJECT(list_mean_vec_);
00074     OT_MY_OBJECT(list_covariance_mat_);
00075     OT_MY_OBJECT(list_inverse_cov_mat_);
00076   }
00077 
00079   void CalculateInverse();
00080  public:
00082   const Matrix& transmission() const { return transmission_; }
00083   const ArrayList<Vector>& list_mean_vec() const { return list_mean_vec_; }
00084   const ArrayList<Matrix>& list_covariance_mat() const { return list_covariance_mat_; }
00085 
00087   void setModel(const Matrix& transmission,  const ArrayList<Vector>& list_mean_vec,
00088                 const ArrayList<Matrix>& list_covariance_mat);
00089 
00091   void Init(const Matrix& transmission,  const ArrayList<Vector>& list_mean_vec,
00092             const ArrayList<Matrix>& list_covariance_mat);
00093   
00095   void InitFromFile(const char* profile);
00096 
00098   void InitFromData(const ArrayList<Matrix>& list_data_seq, int numstate);
00099 
00101   void InitFromData(const Matrix& data_seq, const Vector& state_seq);
00102 
00104   void LoadProfile(const char* profile);
00105 
00107   void SaveProfile(const char* profile) const;
00108 
00110   void GenerateSequence(int L, Matrix* data_seq, Vector* state_seq) const;
00111 
00117   void EstimateModel(const Matrix& data_seq, const Vector& state_seq);
00118   void EstimateModel(int numstate, 
00119                      const Matrix& data_seq, const Vector& state_seq);
00120 
00126   void DecodeOverwrite(const Matrix& data_seq, Matrix* state_prob_mat, Matrix* forward_prob_mat, 
00127                        Matrix* backward_prob_mat, Vector* scale_vec) const;
00128 
00130   void DecodeInit(const Matrix& data_seq, Matrix* state_prob_mat, Matrix* forward_prob_mat, 
00131                   Matrix* backward_prob_mat, Vector* scale_vec) const;
00132 
00134   double ComputeLogLikelihood(const Matrix& data_seq) const;
00135 
00137   void ComputeLogLikelihood(const ArrayList<Matrix>& list_data_seq, 
00138                             ArrayList<double>* list_likelihood) const;
00139   
00141   void ComputeViterbiStateSequence(const Matrix& data_seq, Vector* state_seq) const;
00142 
00147   void TrainBaumWelch(const ArrayList<Matrix>& list_data_seq, 
00148                       int max_iteration, double tolerance);
00149 
00154   void TrainViterbi(const ArrayList<Matrix>& list_data_seq, 
00155                     int max_iteration, double tolerance);
00156 
00157 
00159 
00160   static success_t LoadProfile(const char* profile, Matrix* trans, 
00161                                ArrayList<Vector>* means, ArrayList<Matrix>* covs);
00162   static success_t SaveProfile(const char* profile, const Matrix& trans, 
00163                                const ArrayList<Vector>& means, 
00164                                const ArrayList<Matrix>& covs);
00174   static void GenerateInit(int L, const Matrix& trans, const ArrayList<Vector>& means, 
00175                            const ArrayList<Matrix>& covs, Matrix* seq, Vector* states);
00176 
00178   static void EstimateInit(const Matrix& seq, const Vector& states, Matrix* trans, 
00179                            ArrayList<Vector>* means, ArrayList<Matrix>* covs);
00180   static void EstimateInit(int numStates, const Matrix& seq, const Vector& states, 
00181                            Matrix* trans, ArrayList<Vector>* means, 
00182                            ArrayList<Matrix>* covs);
00183 
00196   static void ForwardProcedure(int L, const Matrix& trans, const Matrix& emis_prob, 
00197                                Vector *scales, Matrix* fs);
00198   static void BackwardProcedure(int L, const Matrix& trans, const Matrix& emis_prob, 
00199                                 const Vector& scales, Matrix* bs);
00200   static double Decode(const Matrix& trans, const Matrix& emis_prob, Matrix* pstates, 
00201                        Matrix* fs, Matrix* bs, Vector* scales);
00202   static double Decode(int L, const Matrix& trans, const Matrix& emis_prob, 
00203                        Matrix* pstates, Matrix* fs, Matrix* bs, Vector* scales);
00204   static void CalculateEmissionProb(const Matrix& seq, const ArrayList<Vector>& means, 
00205                                     const ArrayList<Matrix>& inv_covs, const Vector& det,
00206                                     Matrix* emis_prob);
00207 
00216   static double ViterbiInit(const Matrix& trans, const Matrix& emis_prob, Vector* states);
00217   static double ViterbiInit(int L, const Matrix& trans, const Matrix& emis_prob, Vector* states);
00218 
00223   static void InitGaussParameter(int M, const ArrayList<Matrix>& seqs, 
00224                                  Matrix* guessTR, ArrayList<Vector>* guessME, ArrayList<Matrix>* guessCO);
00225 
00226   static void Train(const ArrayList<Matrix>& seqs, Matrix* guessTR, 
00227                     ArrayList<Vector>* guessME, ArrayList<Matrix>* guessCO, 
00228                     int max_iter, double tol);
00229 
00230   static void TrainViterbi(const ArrayList<Matrix>& seqs, Matrix* guessTR, 
00231                            ArrayList<Vector>* guessME, ArrayList<Matrix>* guessCO, 
00232                            int max_iter, double tol);
00233 };
00234 #endif
Generated on Mon Jan 24 12:04:38 2011 for FASTlib by  doxygen 1.6.3