Single-Class Hidden Markov Model. More...
#include <xmmHmmSingleClass.hpp>
Public Member Functions | |
SingleClassHMM (std::shared_ptr< SharedParameters > p=NULL) | |
Constructor. More... | |
SingleClassHMM (SingleClassHMM const &src) | |
Copy constructor. More... | |
SingleClassHMM (std::shared_ptr< SharedParameters > p, Json::Value const &root) | |
Copy constructor. More... | |
SingleClassHMM & | operator= (SingleClassHMM const &src) |
Assignment. More... | |
Accessors | |
void | addExitPoint (int stateIndex, float proba) |
Set the exit probability of a specific state. More... | |
Performance | |
void | reset () |
Resets the fitering process (recognition or regression) More... | |
double | filter (std::vector< float > const &observation) |
filters a incoming observation (performs recognition or regression) More... | |
Json I/O | |
virtual Json::Value | toJson () const |
Write the object to a JSON Structure. More... | |
virtual void | fromJson (Json::Value const &root) |
Read the object from a JSON Structure. More... | |
Training | |
bool | isTraining () const |
Checks if the model is training. More... | |
void | train (TrainingSet *trainingSet) |
Main training method based on the EM algorithm. More... | |
void | cancelTraining () |
Cancels the training process : sets a flag so that the training stops at the next possible exit in the training process. More... | |
Python File I/O | |
void | writeFile (char *fileName) const |
write method for python wrapping ('write' keyword forbidden, name has to be different) More... | |
void | readFile (char *fileName) |
read method for python wrapping ('read' keyword forbidden, name has to be different) More... | |
std::string | __str__ () const |
"print" method for python => returns the results of write method More... | |
Static Public Member Functions | |
static const float | DEFAULT_EXITPROBABILITY_LAST_STATE () |
static const float | TRANSITION_REGULARIZATION () |
Public Attributes | |
ClassParameters< HMM > | parameters |
Convert to bimodal HMM in place. More... | |
ClassResults< HMM > | results |
Results of the filtering process (recognition & regression) More... | |
std::vector< double > | alpha |
State probabilities estimated by the forward algorithm. More... | |
std::vector< double > | alpha_h [3] |
State probabilities estimated by the hierarchical forward algorithm. More... | |
std::vector< SingleClassGMM > | states |
States of the model (Gaussian Mixture Models) More... | |
std::vector< float > | prior |
Prior probabilities. More... | |
std::vector< float > | transition |
Transition Matrix. More... | |
std::string | label |
label associated with the given model More... | |
std::shared_ptr< SharedParameters > | shared_parameters |
Pointer to the shared parameters owned by a multi-class model. More... | |
EventGenerator< TrainingEvent > | training_events |
Generator for events monitoring the training process. More... | |
TrainingEvent | training_status |
Event containing information on the current status of the training process. More... | |
Protected Member Functions | |
void | allocate () |
Allocate model parameters. More... | |
void | initParametersToDefault (std::vector< float > const &dataStddev) |
initialize model parameters to their default values More... | |
void | initMeansWithAllPhrases (TrainingSet *trainingSet) |
initialize the means of each state with all training phrases (single gaussian) More... | |
void | initCovariances_fullyObserved (TrainingSet *trainingSet) |
initialize the covariances of each state with all training phrases (single gaussian) More... | |
void | initMeansCovariancesWithGMMEM (TrainingSet *trainingSet) |
initialize the means and covariances of each state using GMM-EM on segments. More... | |
void | setErgodic () |
set the prior and transition matrix to ergodic More... | |
void | setLeftRight () |
set the prior and transition matrix to left-right (no state skip) More... | |
void | normalizeTransitions () |
Normalize transition probabilities. More... | |
double | forward_init (const float *observation, const float *observation_output=NULL) |
Initialization of the forward algorithm. More... | |
double | forward_update (const float *observation, const float *observation_output=NULL) |
Update of the forward algorithm. More... | |
void | backward_init (double ct) |
Initialization Backward algorithm. More... | |
void | backward_update (double ct, const float *observation, const float *observation_output=NULL) |
Update of the Backward algorithm. More... | |
void | emAlgorithmInit (TrainingSet *trainingSet) |
Initialization of the parameters before training. More... | |
void | emAlgorithmTerminate () |
Termination of the training algorithm. More... | |
virtual double | emAlgorithmUpdate (TrainingSet *trainingSet) |
update method of the EM algorithm (calls Baum-Welch Algorithm) More... | |
double | baumWelch_forwardBackward (std::shared_ptr< Phrase > currentPhrase, int phraseIndex) |
Compute the forward-backward algorithm on a phrase of the training set. More... | |
double | baumWelch_forward_update (std::vector< double >::iterator observation_likelihoods) |
Update of the forward algorithm for Training (observation probabilities are pre-computed) More... | |
void | baumWelch_backward_update (double ct, std::vector< double >::iterator observation_likelihoods) |
Update of the Backward algorithm for Training (observation probabilities are pre-computed) More... | |
void | baumWelch_gammaSum (TrainingSet *trainingSet) |
Compute the sum of the gamma variable (for use in EM) More... | |
void | baumWelch_estimateMixtureCoefficients (TrainingSet *trainingSet) |
Estimate the Coefficients of the Gaussian Mixture for each state. More... | |
void | baumWelch_estimateMeans (TrainingSet *trainingSet) |
Estimate the Means of the Gaussian Distribution for each state. More... | |
void | baumWelch_estimateCovariances (TrainingSet *trainingSet) |
Estimate the Covariances of the Gaussian Distribution for each state. More... | |
void | baumWelch_estimatePrior (TrainingSet *trainingSet) |
Estimate the Prior Probabilities. More... | |
void | baumWelch_estimateTransitions (TrainingSet *trainingSet) |
Estimate the Transition Probabilities. More... | |
void | addCyclicTransition (double proba) |
Adds a cyclic Transition probability (from last state to first state) More... | |
void | updateAlphaWindow () |
Estimates the likeliest state and compute the bounds of the windows over the states. More... | |
void | regression (std::vector< float > const &observation_input) |
Compute the regression for the case of a bimodal model, given the estimated state probabilities estimated by forward algorithm. More... | |
void | updateResults () |
update the content of the likelihood buffer and return average likelihood. More... | |
void | updateExitProbabilities (float *_exitProbabilities=NULL) |
Update the exit probability vector given the probabilities. More... | |
bool | emAlgorithmHasConverged (int step, double log_prob, double old_log_prob) const |
checks if the training has converged according to the object's EM stop criterion More... | |
bool | cancelTrainingIfRequested () |
checks if a cancel request has been sent and accordingly cancels the training process More... | |
void | check_training () const |
Checks if the model is still training. More... | |
Protected Attributes | |
bool | forward_initialized_ |
Defines if the forward algorithm has been initialized. More... | |
std::vector< double > | previous_alpha_ |
used to store the alpha estimated at the previous time step More... | |
std::vector< double > | beta_ |
backward state probabilities More... | |
std::vector< double > | previous_beta_ |
used to store the beta estimated at the previous time step More... | |
std::vector< std::vector< double > > | gamma_sequence_ |
Sequence of Gamma probabilities. More... | |
std::vector< std::vector< double > > | epsilon_sequence_ |
Sequence of Epsilon probabilities. More... | |
std::vector< std::vector< std::vector< double > > > | gamma_sequence_per_mixture_ |
Sequence of Gamma probabilities for each mixture component. More... | |
std::vector< double > | alpha_seq_ |
Sequence of alpha (forward) probabilities. More... | |
std::vector< double > | beta_seq_ |
Sequence of beta (backward) probabilities. More... | |
std::vector< double > | gamma_sum_ |
Used to store the sums of the gamma variable. More... | |
std::vector< double > | gamma_sum_per_mixture_ |
Used to store the sums of the gamma variable for each mixture component. More... | |
bool | is_hierarchical_ |
Defines if the model is a submodel of a hierarchical HMM. More... | |
std::vector< float > | exit_probabilities_ |
Exit probabilities for a hierarchical model. More... | |
int | window_minindex_ |
minimum index of the alpha window (used for regression & time progression) More... | |
int | window_maxindex_ |
minimum index of the alpha window (used for regression & time progression) More... | |
double | window_normalization_constant_ |
normalization constant of the alpha window (used for regression & time progression) More... | |
CircularBuffer< double > | likelihood_buffer_ |
Likelihood buffer used for smoothing. More... | |
std::mutex | training_mutex_ |
Mutex used in Concurrent Mode. More... | |
bool | is_training_ |
defines if the model is being trained. More... | |
bool | cancel_training_ |
defines if the model received a request to cancel training More... | |
Friends | |
template<typename SingleClassModel , typename ModelType > | |
class | Model |
class | HierarchicalHMM |
Single-Class Hidden Markov Model.
Hidden Markov Model with Multivariate Gaussian Mixture Model Observation Distributions. Supports Bimodal data and Hidden Markov Regression. Built for Hierarchical HMMs
xmm::SingleClassHMM::SingleClassHMM | ( | std::shared_ptr< SharedParameters > | p = NULL | ) |
Constructor.
p | Shared Parameters (owned by a multiclass object) |
xmm::SingleClassHMM::SingleClassHMM | ( | SingleClassHMM const & | src | ) |
Copy constructor.
src | Source Model |
|
explicit |
Copy constructor.
p | pointer to a shared parameters object (owned by a Model) |
root | Json structure |
|
inlineinherited |
"print" method for python => returns the results of write method
|
protected |
Adds a cyclic Transition probability (from last state to first state)
avoids getting stuck at the end of the model. this method is idle for a hierarchical model.
proba | probability of the transition form last to first state |
void xmm::SingleClassHMM::addExitPoint | ( | int | stateIndex, |
float | proba | ||
) |
Set the exit probability of a specific state.
this method is only active in 'HIERARCHICAL' mode. The probability
stateIndex | index of the state to add the exit point |
proba | probability to exit the gesture from this state |
runtime_error | if the model is not hierarchical |
out_of_range | if the state index is out of bounds |
|
protectedvirtual |
Allocate model parameters.
Implements xmm::SingleClassProbabilisticModel.
|
protected |
Initialization Backward algorithm.
ct | inverse of the likelihood at time step t computed with the forward algorithm (see Rabiner 1989) |
|
protected |
Update of the Backward algorithm.
ct | inverse of the likelihood at time step t computed with the forward algorithm (see Rabiner 1989) |
observation | observation vector at time t. If the model is bimodal, this vector should be only the observation on the input modality. |
observation_output | observation on the output modality (only used if the model is bimodal). If unspecified, the update is performed on the input modality only. |
|
protected |
Update of the Backward algorithm for Training (observation probabilities are pre-computed)
ct | inverse of the likelihood at time step t computed with the forward algorithm (see Rabiner 1989) |
observation_likelihoods | likelihoods of the observations for each state |
|
protected |
Estimate the Covariances of the Gaussian Distribution for each state.
|
protected |
Estimate the Means of the Gaussian Distribution for each state.
|
protected |
Estimate the Coefficients of the Gaussian Mixture for each state.
|
protected |
Estimate the Prior Probabilities.
|
protected |
Estimate the Transition Probabilities.
|
protected |
Update of the forward algorithm for Training (observation probabilities are pre-computed)
observation_likelihoods | likelihoods of the observations for each state |
|
protected |
Compute the forward-backward algorithm on a phrase of the training set.
currentPhrase | pointer to the phrase of the training set |
phraseIndex | index of the phrase |
|
protected |
Compute the sum of the gamma variable (for use in EM)
|
inherited |
Cancels the training process : sets a flag so that the training stops at the next possible exit in the training process.
|
protectedinherited |
checks if a cancel request has been sent and accordingly cancels the training process
|
inlineprotectedinherited |
Checks if the model is still training.
runtime_error | if the model is training. |
|
inlinestatic |
|
protectedinherited |
checks if the training has converged according to the object's EM stop criterion
step | index of the current step of the EM algorithm |
log_prob | log-likelihood returned by the EM update |
old_log_prob | log-likelihood returned by the EM update at the previous step |
|
protectedvirtual |
Initialization of the parameters before training.
Implements xmm::SingleClassProbabilisticModel.
|
protectedvirtual |
Termination of the training algorithm.
Reimplemented from xmm::SingleClassProbabilisticModel.
|
protectedvirtual |
update method of the EM algorithm (calls Baum-Welch Algorithm)
Implements xmm::SingleClassProbabilisticModel.
|
virtual |
filters a incoming observation (performs recognition or regression)
the results of the inference process are stored in the results attribute
observation | observation vector |
Implements xmm::SingleClassProbabilisticModel.
|
protected |
Initialization of the forward algorithm.
observation | observation vector at time t. If the model is bimodal, this vector should be only the observation on the input modality. |
observation_output | observation on the output modality (only used if the model is bimodal). If unspecified, the update is performed on the input modality only. |
|
protected |
Update of the forward algorithm.
observation | observation vector at time t. If the model is bimodal, this vector should be only the observation on the input modality. |
observation_output | observation on the output modality (only used if the model is bimodal). If unspecified, the update is performed on the input modality only. |
|
virtual |
Read the object from a JSON Structure.
root | JSON value containing the object's information |
JsonException | if the JSON value has a wrong format |
Implements xmm::SingleClassProbabilisticModel.
|
protected |
initialize the covariances of each state with all training phrases (single gaussian)
|
protected |
initialize the means and covariances of each state using GMM-EM on segments.
|
protected |
initialize the means of each state with all training phrases (single gaussian)
|
protected |
initialize model parameters to their default values
|
inherited |
Checks if the model is training.
|
protected |
Normalize transition probabilities.
xmm::SingleClassHMM & xmm::SingleClassHMM::operator= | ( | SingleClassHMM const & | src | ) |
Assignment.
src | Source Model |
|
inlineinherited |
read method for python wrapping ('read' keyword forbidden, name has to be different)
|
protected |
Compute the regression for the case of a bimodal model, given the estimated state probabilities estimated by forward algorithm.
predicted output parameters are stored in the result structure.
observation_input | observation on the input modality |
|
virtual |
Resets the fitering process (recognition or regression)
Reimplemented from xmm::SingleClassProbabilisticModel.
|
protected |
set the prior and transition matrix to ergodic
|
protected |
set the prior and transition matrix to left-right (no state skip)
|
virtual |
Write the object to a JSON Structure.
Reimplemented from xmm::SingleClassProbabilisticModel.
|
inherited |
Main training method based on the EM algorithm.
the method performs a loop over the pure virtual method emAlgorithmUpdate() until convergence. The emAlgorithmUpdate method computes both E and M steps of the EM algorithm.
trainingSet | Training Set to train the model. |
|
inlinestatic |
|
protected |
Estimates the likeliest state and compute the bounds of the windows over the states.
The window is centered around the likeliest state, and its size is the number of states. The window is clipped to the first and last states.
|
protected |
Update the exit probability vector given the probabilities.
this method is only active in 'HIERARCHICAL' mode. The probability vector defines the probability of exiting the gesture from each state. If unspecified, only the last state of the gesture has a non-zero probability.
_exitProbabilities | vector of exit probabilities (size must be nbStates) |
runtime_error | if the model is not hierarchical |
|
protected |
update the content of the likelihood buffer and return average likelihood.
The method also updates the cumulative log-likelihood computed over a window (cumulativeloglikelihood)
|
inlineinherited |
write method for python wrapping ('write' keyword forbidden, name has to be different)
|
friend |
|
friend |
std::vector<double> xmm::SingleClassHMM::alpha |
State probabilities estimated by the forward algorithm.
std::vector<double> xmm::SingleClassHMM::alpha_h[3] |
State probabilities estimated by the hierarchical forward algorithm.
the variable is only allocated/used in hierarchical mode (see 'HIERARCHICAL' flag)
|
protected |
Sequence of alpha (forward) probabilities.
|
protected |
backward state probabilities
|
protected |
Sequence of beta (backward) probabilities.
|
protectedinherited |
defines if the model received a request to cancel training
|
protected |
Sequence of Epsilon probabilities.
|
protected |
Exit probabilities for a hierarchical model.
|
protected |
Defines if the forward algorithm has been initialized.
|
protected |
Sequence of Gamma probabilities.
|
protected |
Sequence of Gamma probabilities for each mixture component.
|
protected |
Used to store the sums of the gamma variable.
|
protected |
Used to store the sums of the gamma variable for each mixture component.
|
protected |
Defines if the model is a submodel of a hierarchical HMM.
in practice this adds exit probabilities to each state. These probabilities are set to the last state by default.
|
protectedinherited |
defines if the model is being trained.
|
inherited |
label associated with the given model
|
protectedinherited |
Likelihood buffer used for smoothing.
ClassParameters<HMM> xmm::SingleClassHMM::parameters |
Convert to bimodal HMM in place.
dimension_input | dimension of the input modality |
runtime_error | if the model is already bimodal |
out_of_range | if the requested input dimension is too large Convert to unimodal HMM in place |
runtime_error | if the model is already unimodal extract a submodel with the given columns |
columns | columns indices in the target order |
runtime_error | if the model is training |
out_of_range | if the number or indices of the requested columns exceeds the current dimension |
runtime_error | if the model is training or if it is not bimodal |
runtime_error | if the model is training or if it is not bimodal |
runtime_error | if the model is training or if it is not bimodal |
|
protected |
used to store the alpha estimated at the previous time step
|
protected |
used to store the beta estimated at the previous time step
std::vector<float> xmm::SingleClassHMM::prior |
Prior probabilities.
ClassResults<HMM> xmm::SingleClassHMM::results |
Results of the filtering process (recognition & regression)
|
inherited |
Pointer to the shared parameters owned by a multi-class model.
std::vector<SingleClassGMM> xmm::SingleClassHMM::states |
States of the model (Gaussian Mixture Models)
|
inherited |
Generator for events monitoring the training process.
|
protectedinherited |
Mutex used in Concurrent Mode.
|
inherited |
Event containing information on the current status of the training process.
std::vector<float> xmm::SingleClassHMM::transition |
Transition Matrix.
|
protected |
minimum index of the alpha window (used for regression & time progression)
|
protected |
minimum index of the alpha window (used for regression & time progression)
|
protected |
normalization constant of the alpha window (used for regression & time progression)