A wrapper class for HMM functionals in single Gaussian case. More...
Public Member Functions | |
void | ComputeLogLikelihood (const ArrayList< Matrix > &list_data_seq, ArrayList< double > *list_likelihood) const |
Compute the log-likelihood of a list of sequences. | |
double | ComputeLogLikelihood (const Matrix &data_seq) const |
Compute the log-likelihood of a sequence. | |
void | ComputeViterbiStateSequence (const Matrix &data_seq, Vector *state_seq) const |
Compute the most probable sequence (Viterbi). | |
void | DecodeInit (const Matrix &data_seq, Matrix *state_prob_mat, Matrix *forward_prob_mat, Matrix *backward_prob_mat, Vector *scale_vec) const |
A decode version that initialized the output matrices. | |
void | DecodeOverwrite (const Matrix &data_seq, Matrix *state_prob_mat, Matrix *forward_prob_mat, Matrix *backward_prob_mat, Vector *scale_vec) const |
Decode a sequence into probabilities of each state at each time step using scaled forward-backward algorithm. | |
void | EstimateModel (int numstate, const Matrix &data_seq, const Vector &state_seq) |
void | EstimateModel (const Matrix &data_seq, const Vector &state_seq) |
Estimate the matrices by a data sequence and a state sequence Must be already initialized. | |
void | GenerateSequence (int L, Matrix *data_seq, Vector *state_seq) const |
Generate a random data sequence of a given length. | |
void | Init (const Matrix &transmission, const ArrayList< Vector > &list_mean_vec, const ArrayList< Matrix > &list_covariance_mat) |
Initializes from computed transmission and Gaussian parameters. | |
void | InitFromData (const Matrix &data_seq, const Vector &state_seq) |
Initializes using data and state sequence as a guide. | |
void | InitFromData (const ArrayList< Matrix > &list_data_seq, int numstate) |
Initializes using K-means algorithm using data as a guide. | |
void | InitFromFile (const char *profile) |
Initializes by loading from a file. | |
const ArrayList< Matrix > & | list_covariance_mat () const |
const ArrayList< Vector > & | list_mean_vec () const |
void | LoadProfile (const char *profile) |
Load from file, used when already initialized. | |
void | SaveProfile (const char *profile) const |
Save matrices to file. | |
void | setModel (const Matrix &transmission, const ArrayList< Vector > &list_mean_vec, const ArrayList< Matrix > &list_covariance_mat) |
Setter used when already initialized. | |
void | TrainBaumWelch (const ArrayList< Matrix > &list_data_seq, int max_iteration, double tolerance) |
Train the model with a list of sequences, must be already initialized using Baum-Welch EM algorithm. | |
void | TrainViterbi (const ArrayList< Matrix > &list_data_seq, int max_iteration, double tolerance) |
Train the model with a list of sequences, must be already initialized using Viterbi algorithm to determine the state sequence of each sequence. | |
const Matrix & | transmission () const |
Getters. | |
Static Public Member Functions | |
static void | BackwardProcedure (int L, const Matrix &trans, const Matrix &emis_prob, const Vector &scales, Matrix *bs) |
static void | CalculateEmissionProb (const Matrix &seq, const ArrayList< Vector > &means, const ArrayList< Matrix > &inv_covs, const Vector &det, Matrix *emis_prob) |
static double | Decode (int L, const Matrix &trans, const Matrix &emis_prob, Matrix *pstates, Matrix *fs, Matrix *bs, Vector *scales) |
static double | Decode (const Matrix &trans, const Matrix &emis_prob, Matrix *pstates, Matrix *fs, Matrix *bs, Vector *scales) |
static void | EstimateInit (int numStates, const Matrix &seq, const Vector &states, Matrix *trans, ArrayList< Vector > *means, ArrayList< Matrix > *covs) |
static void | EstimateInit (const Matrix &seq, const Vector &states, Matrix *trans, ArrayList< Vector > *means, ArrayList< Matrix > *covs) |
Estimate transition and emission distribution from sequence and states. | |
static void | ForwardProcedure (int L, const Matrix &trans, const Matrix &emis_prob, Vector *scales, Matrix *fs) |
Calculate posteriori probabilities of states at each steps Scaled Forward - Backward procedure trans: Transition probabilities, size M x M emis_prob: Emission probabilities along the sequence, size M x L (L is the sequence length) pstates: size M x L fs: scaled forward probabities, size M x L bs: scaled backward probabities, size M x L scales: scale factors, length L RETURN: log probabilities of sequence. | |
static void | GenerateInit (int L, const Matrix &trans, const ArrayList< Vector > &means, const ArrayList< Matrix > &covs, Matrix *seq, Vector *states) |
Generating a sequence and states using transition and emission probabilities. | |
static void | InitGaussParameter (int M, const ArrayList< Matrix > &seqs, Matrix *guessTR, ArrayList< Vector > *guessME, ArrayList< Matrix > *guessCO) |
Baum-Welch and Viterbi estimation of transition and emission distribution (Gaussian). | |
static success_t | LoadProfile (const char *profile, Matrix *trans, ArrayList< Vector > *means, ArrayList< Matrix > *covs) |
static success_t | SaveProfile (const char *profile, const Matrix &trans, const ArrayList< Vector > &means, const ArrayList< Matrix > &covs) |
static void | Train (const ArrayList< Matrix > &seqs, Matrix *guessTR, ArrayList< Vector > *guessME, ArrayList< Matrix > *guessCO, int max_iter, double tol) |
static void | TrainViterbi (const ArrayList< Matrix > &seqs, Matrix *guessTR, ArrayList< Vector > *guessME, ArrayList< Matrix > *guessCO, int max_iter, double tol) |
static double | ViterbiInit (int L, const Matrix &trans, const Matrix &emis_prob, Vector *states) |
static double | ViterbiInit (const Matrix &trans, const Matrix &emis_prob, Vector *states) |
Calculate the most probable states for a sequence Viterbi algorithm trans: Transition probabilities, size M x M emis_prob: Emission probabilities, size M x L states: Unitialized, will have length L RETURN: log probability of the most probable sequence. |
A wrapper class for HMM functionals in single Gaussian case.
This class maintains transition probabilities and Gaussian parameters (mean and covariance) for each state, more details below.
Definition at line 53 of file gaussianHMM.h.
void GaussianHMM::ComputeLogLikelihood | ( | const ArrayList< Matrix > & | list_data_seq, | |
ArrayList< double > * | list_likelihood | |||
) | const |
Compute the log-likelihood of a list of sequences.
Definition at line 182 of file gaussianHMM.cc.
References ForwardProcedure(), ArrayList< TElem >::Init(), GenVector< T >::Init(), ArrayList< TElem >::PushBackCopy(), and ArrayList< TElem >::size().
double GaussianHMM::ComputeLogLikelihood | ( | const Matrix & | data_seq | ) | const |
Compute the log-likelihood of a sequence.
Definition at line 168 of file gaussianHMM.cc.
References ForwardProcedure(), and GenVector< T >::Init().
void GaussianHMM::ComputeViterbiStateSequence | ( | const Matrix & | data_seq, | |
Vector * | state_seq | |||
) | const |
Compute the most probable sequence (Viterbi).
Definition at line 202 of file gaussianHMM.cc.
References ViterbiInit().
void GaussianHMM::DecodeInit | ( | const Matrix & | data_seq, | |
Matrix * | state_prob_mat, | |||
Matrix * | forward_prob_mat, | |||
Matrix * | backward_prob_mat, | |||
Vector * | scale_vec | |||
) | const |
A decode version that initialized the output matrices.
Definition at line 153 of file gaussianHMM.cc.
References GenVector< T >::Init().
void GaussianHMM::DecodeOverwrite | ( | const Matrix & | data_seq, | |
Matrix * | state_prob_mat, | |||
Matrix * | forward_prob_mat, | |||
Matrix * | backward_prob_mat, | |||
Vector * | scale_vec | |||
) | const |
Decode a sequence into probabilities of each state at each time step using scaled forward-backward algorithm.
Also return forward, backward probabilities and scale factors
Definition at line 142 of file gaussianHMM.cc.
void GaussianHMM::EstimateInit | ( | const Matrix & | seq, | |
const Vector & | states, | |||
Matrix * | trans, | |||
ArrayList< Vector > * | means, | |||
ArrayList< Matrix > * | covs | |||
) | [static] |
Estimate transition and emission distribution from sequence and states.
Definition at line 305 of file gaussianHMM.cc.
References GenVector< T >::length().
Referenced by EstimateModel(), and InitFromData().
void GaussianHMM::EstimateModel | ( | const Matrix & | data_seq, | |
const Vector & | state_seq | |||
) |
Estimate the matrices by a data sequence and a state sequence Must be already initialized.
Definition at line 124 of file gaussianHMM.cc.
References EstimateInit().
void GaussianHMM::ForwardProcedure | ( | int | L, | |
const Matrix & | trans, | |||
const Matrix & | emis_prob, | |||
Vector * | scales, | |||
Matrix * | fs | |||
) | [static] |
Calculate posteriori probabilities of states at each steps Scaled Forward - Backward procedure trans: Transition probabilities, size M x M emis_prob: Emission probabilities along the sequence, size M x L (L is the sequence length) pstates: size M x L fs: scaled forward probabities, size M x L bs: scaled backward probabities, size M x L scales: scale factors, length L RETURN: log probabilities of sequence.
Definition at line 385 of file gaussianHMM.cc.
References GenVector< T >::get(), and GenVector< T >::SetZero().
Referenced by ComputeLogLikelihood().
void GaussianHMM::GenerateInit | ( | int | L, | |
const Matrix & | trans, | |||
const ArrayList< Vector > & | means, | |||
const ArrayList< Matrix > & | covs, | |||
Matrix * | seq, | |||
Vector * | states | |||
) | [static] |
Generating a sequence and states using transition and emission probabilities.
L: sequence length trans: Matrix M x M (M states) means: list of mean vectors length N (emission vector of length N) covs: list of square root of covariance matrices size N x N seq: generated sequence, uninitialized matrix, will have size N x L states: generated states, uninitialized vector, will have length L
Definition at line 265 of file gaussianHMM.cc.
References GenVector< T >::Init(), ArrayList< TElem >::length(), and ArrayList< TElem >::size().
Referenced by GenerateSequence().
void GaussianHMM::GenerateSequence | ( | int | L, | |
Matrix * | data_seq, | |||
Vector * | state_seq | |||
) | const |
Generate a random data sequence of a given length.
Definition at line 120 of file gaussianHMM.cc.
References GenerateInit().
void GaussianHMM::Init | ( | const Matrix & | transmission, | |
const ArrayList< Vector > & | list_mean_vec, | |||
const ArrayList< Matrix > & | list_covariance_mat | |||
) |
Initializes from computed transmission and Gaussian parameters.
Definition at line 62 of file gaussianHMM.cc.
References ArrayList< TElem >::InitCopy(), and ArrayList< TElem >::size().
void GaussianHMM::InitFromData | ( | const Matrix & | data_seq, | |
const Vector & | state_seq | |||
) |
Initializes using data and state sequence as a guide.
Definition at line 92 of file gaussianHMM.cc.
References EstimateInit().
void GaussianHMM::InitFromData | ( | const ArrayList< Matrix > & | list_data_seq, | |
int | numstate | |||
) |
Initializes using K-means algorithm using data as a guide.
Definition at line 85 of file gaussianHMM.cc.
References GenVector< T >::Init(), ArrayList< TElem >::InitCopy(), InitGaussParameter(), and ArrayList< TElem >::size().
void GaussianHMM::InitFromFile | ( | const char * | profile | ) |
Initializes by loading from a file.
Definition at line 77 of file gaussianHMM.cc.
References GenVector< T >::Init(), ArrayList< TElem >::InitCopy(), LoadProfile(), and ArrayList< TElem >::size().
Referenced by LoadProfile().
void GaussianHMM::InitGaussParameter | ( | int | M, | |
const ArrayList< Matrix > & | seqs, | |||
Matrix * | guessTR, | |||
ArrayList< Vector > * | guessME, | |||
ArrayList< Matrix > * | guessCO | |||
) | [static] |
Baum-Welch and Viterbi estimation of transition and emission distribution (Gaussian).
Definition at line 532 of file gaussianHMM.cc.
References ArrayList< TElem >::Init(), GenVector< T >::Init(), ArrayList< TElem >::PushBackCopy(), linalg__private::Scale(), GenVector< T >::SetZero(), ArrayList< TElem >::size(), and linalg__private::SubInit().
Referenced by InitFromData().
void GaussianHMM::LoadProfile | ( | const char * | profile | ) |
Load from file, used when already initialized.
Definition at line 98 of file gaussianHMM.cc.
References GenVector< T >::Destruct(), and InitFromFile().
Referenced by InitFromFile().
void GaussianHMM::SaveProfile | ( | const char * | profile | ) | const |
Save matrices to file.
Definition at line 107 of file gaussianHMM.cc.
void GaussianHMM::setModel | ( | const Matrix & | transmission, | |
const ArrayList< Vector > & | list_mean_vec, | |||
const ArrayList< Matrix > & | list_covariance_mat | |||
) |
Setter used when already initialized.
Definition at line 44 of file gaussianHMM.cc.
References ArrayList< TElem >::InitCopy(), and ArrayList< TElem >::size().
void GaussianHMM::TrainBaumWelch | ( | const ArrayList< Matrix > & | list_data_seq, | |
int | max_iteration, | |||
double | tolerance | |||
) |
Train the model with a list of sequences, must be already initialized using Baum-Welch EM algorithm.
Definition at line 210 of file gaussianHMM.cc.
void GaussianHMM::TrainViterbi | ( | const ArrayList< Matrix > & | list_data_seq, | |
int | max_iteration, | |||
double | tolerance | |||
) |
Train the model with a list of sequences, must be already initialized using Viterbi algorithm to determine the state sequence of each sequence.
Definition at line 215 of file gaussianHMM.cc.
const Matrix& GaussianHMM::transmission | ( | ) | const [inline] |
Getters.
Definition at line 82 of file gaussianHMM.h.
double GaussianHMM::ViterbiInit | ( | const Matrix & | trans, | |
const Matrix & | emis_prob, | |||
Vector * | states | |||
) | [static] |
Calculate the most probable states for a sequence Viterbi algorithm trans: Transition probabilities, size M x M emis_prob: Emission probabilities, size M x L states: Unitialized, will have length L RETURN: log probability of the most probable sequence.
Definition at line 460 of file gaussianHMM.cc.
Referenced by ComputeViterbiStateSequence().