00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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