XMM - Probabilistic Models for Motion Recognition and Mapping

Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
xmm::SingleClassHMM Class Reference

Single-Class Hidden Markov Model. More...

#include <xmmHmmSingleClass.hpp>

Inheritance diagram for xmm::SingleClassHMM:
[legend]
Collaboration diagram for xmm::SingleClassHMM:
[legend]

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...
 
SingleClassHMMoperator= (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< HMMparameters
 Convert to bimodal HMM in place. More...
 
ClassResults< HMMresults
 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< SingleClassGMMstates
 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< SharedParametersshared_parameters
 Pointer to the shared parameters owned by a multi-class model. More...
 
EventGenerator< TrainingEventtraining_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
 

Detailed Description

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

Constructor & Destructor Documentation

xmm::SingleClassHMM::SingleClassHMM ( std::shared_ptr< SharedParameters p = NULL)

Constructor.

Parameters
pShared Parameters (owned by a multiclass object)
xmm::SingleClassHMM::SingleClassHMM ( SingleClassHMM const &  src)

Copy constructor.

Parameters
srcSource Model
xmm::SingleClassHMM::SingleClassHMM ( std::shared_ptr< SharedParameters p,
Json::Value const &  root 
)
explicit

Copy constructor.

Parameters
ppointer to a shared parameters object (owned by a Model)
rootJson structure

Member Function Documentation

std::string xmm::Writable::__str__ ( ) const
inlineinherited

"print" method for python => returns the results of write method

Warning
only defined if SWIGPYTHON is defined
void xmm::SingleClassHMM::addCyclicTransition ( double  proba)
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.

Parameters
probaprobability 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

Parameters
stateIndexindex of the state to add the exit point
probaprobability to exit the gesture from this state
Exceptions
runtime_errorif the model is not hierarchical
out_of_rangeif the state index is out of bounds
void xmm::SingleClassHMM::allocate ( )
protectedvirtual

Allocate model parameters.

Implements xmm::SingleClassProbabilisticModel.

void xmm::SingleClassHMM::backward_init ( double  ct)
protected

Initialization Backward algorithm.

Parameters
ctinverse of the likelihood at time step t computed with the forward algorithm (see Rabiner 1989)
void xmm::SingleClassHMM::backward_update ( double  ct,
const float *  observation,
const float *  observation_output = NULL 
)
protected

Update of the Backward algorithm.

Parameters
ctinverse of the likelihood at time step t computed with the forward algorithm (see Rabiner 1989)
observationobservation vector at time t. If the model is bimodal, this vector should be only the observation on the input modality.
observation_outputobservation on the output modality (only used if the model is bimodal). If unspecified, the update is performed on the input modality only.
void xmm::SingleClassHMM::baumWelch_backward_update ( double  ct,
std::vector< double >::iterator  observation_likelihoods 
)
protected

Update of the Backward algorithm for Training (observation probabilities are pre-computed)

Parameters
ctinverse of the likelihood at time step t computed with the forward algorithm (see Rabiner 1989)
observation_likelihoodslikelihoods of the observations for each state
void xmm::SingleClassHMM::baumWelch_estimateCovariances ( TrainingSet trainingSet)
protected

Estimate the Covariances of the Gaussian Distribution for each state.

void xmm::SingleClassHMM::baumWelch_estimateMeans ( TrainingSet trainingSet)
protected

Estimate the Means of the Gaussian Distribution for each state.

void xmm::SingleClassHMM::baumWelch_estimateMixtureCoefficients ( TrainingSet trainingSet)
protected

Estimate the Coefficients of the Gaussian Mixture for each state.

void xmm::SingleClassHMM::baumWelch_estimatePrior ( TrainingSet trainingSet)
protected

Estimate the Prior Probabilities.

void xmm::SingleClassHMM::baumWelch_estimateTransitions ( TrainingSet trainingSet)
protected

Estimate the Transition Probabilities.

double xmm::SingleClassHMM::baumWelch_forward_update ( std::vector< double >::iterator  observation_likelihoods)
protected

Update of the forward algorithm for Training (observation probabilities are pre-computed)

Parameters
observation_likelihoodslikelihoods of the observations for each state
Returns
instantaneous likelihood
double xmm::SingleClassHMM::baumWelch_forwardBackward ( std::shared_ptr< Phrase currentPhrase,
int  phraseIndex 
)
protected

Compute the forward-backward algorithm on a phrase of the training set.

Parameters
currentPhrasepointer to the phrase of the training set
phraseIndexindex of the phrase
Returns
lieklihood of the phrase given the model's current parameters
void xmm::SingleClassHMM::baumWelch_gammaSum ( TrainingSet trainingSet)
protected

Compute the sum of the gamma variable (for use in EM)

void xmm::SingleClassProbabilisticModel::cancelTraining ( )
inherited

Cancels the training process : sets a flag so that the training stops at the next possible exit in the training process.

Warning
the model is still training when this function returns. This function only requests the training process to cancel.
bool xmm::SingleClassProbabilisticModel::cancelTrainingIfRequested ( )
protectedinherited

checks if a cancel request has been sent and accordingly cancels the training process

Returns
true if the training has been canceled.
void xmm::SingleClassProbabilisticModel::check_training ( ) const
inlineprotectedinherited

Checks if the model is still training.

Exceptions
runtime_errorif the model is training.
static const float xmm::SingleClassHMM::DEFAULT_EXITPROBABILITY_LAST_STATE ( )
inlinestatic
bool xmm::SingleClassProbabilisticModel::emAlgorithmHasConverged ( int  step,
double  log_prob,
double  old_log_prob 
) const
protectedinherited

checks if the training has converged according to the object's EM stop criterion

Parameters
stepindex of the current step of the EM algorithm
log_problog-likelihood returned by the EM update
old_log_problog-likelihood returned by the EM update at the previous step
void xmm::SingleClassHMM::emAlgorithmInit ( TrainingSet trainingSet)
protectedvirtual

Initialization of the parameters before training.

Implements xmm::SingleClassProbabilisticModel.

void xmm::SingleClassHMM::emAlgorithmTerminate ( )
protectedvirtual

Termination of the training algorithm.

Reimplemented from xmm::SingleClassProbabilisticModel.

double xmm::SingleClassHMM::emAlgorithmUpdate ( TrainingSet trainingSet)
protectedvirtual

update method of the EM algorithm (calls Baum-Welch Algorithm)

Implements xmm::SingleClassProbabilisticModel.

double xmm::SingleClassHMM::filter ( std::vector< float > const &  observation)
virtual

filters a incoming observation (performs recognition or regression)

the results of the inference process are stored in the results attribute

Parameters
observationobservation vector
Returns
likelihood of the observation

Implements xmm::SingleClassProbabilisticModel.

double xmm::SingleClassHMM::forward_init ( const float *  observation,
const float *  observation_output = NULL 
)
protected

Initialization of the forward algorithm.

Parameters
observationobservation vector at time t. If the model is bimodal, this vector should be only the observation on the input modality.
observation_outputobservation on the output modality (only used if the model is bimodal). If unspecified, the update is performed on the input modality only.
Returns
instantaneous likelihood
double xmm::SingleClassHMM::forward_update ( const float *  observation,
const float *  observation_output = NULL 
)
protected

Update of the forward algorithm.

Parameters
observationobservation vector at time t. If the model is bimodal, this vector should be only the observation on the input modality.
observation_outputobservation on the output modality (only used if the model is bimodal). If unspecified, the update is performed on the input modality only.
Returns
instantaneous likelihood
void xmm::SingleClassHMM::fromJson ( Json::Value const &  root)
virtual

Read the object from a JSON Structure.

Parameters
rootJSON value containing the object's information
Exceptions
JsonExceptionif the JSON value has a wrong format

Implements xmm::SingleClassProbabilisticModel.

void xmm::SingleClassHMM::initCovariances_fullyObserved ( TrainingSet trainingSet)
protected

initialize the covariances of each state with all training phrases (single gaussian)

void xmm::SingleClassHMM::initMeansCovariancesWithGMMEM ( TrainingSet trainingSet)
protected

initialize the means and covariances of each state using GMM-EM on segments.

void xmm::SingleClassHMM::initMeansWithAllPhrases ( TrainingSet trainingSet)
protected

initialize the means of each state with all training phrases (single gaussian)

void xmm::SingleClassHMM::initParametersToDefault ( std::vector< float > const &  dataStddev)
protected

initialize model parameters to their default values

bool xmm::SingleClassProbabilisticModel::isTraining ( ) const
inherited

Checks if the model is training.

Returns
true if the model is training
void xmm::SingleClassHMM::normalizeTransitions ( )
protected

Normalize transition probabilities.

xmm::SingleClassHMM & xmm::SingleClassHMM::operator= ( SingleClassHMM const &  src)

Assignment.

Parameters
srcSource Model
void xmm::Writable::readFile ( char *  fileName)
inlineinherited

read method for python wrapping ('read' keyword forbidden, name has to be different)

Warning
only defined if SWIGPYTHON is defined
void xmm::SingleClassHMM::regression ( std::vector< float > const &  observation_input)
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.

Parameters
observation_inputobservation on the input modality
void xmm::SingleClassHMM::reset ( )
virtual

Resets the fitering process (recognition or regression)

Reimplemented from xmm::SingleClassProbabilisticModel.

void xmm::SingleClassHMM::setErgodic ( )
protected

set the prior and transition matrix to ergodic

void xmm::SingleClassHMM::setLeftRight ( )
protected

set the prior and transition matrix to left-right (no state skip)

Json::Value xmm::SingleClassHMM::toJson ( ) const
virtual

Write the object to a JSON Structure.

Returns
Json value containing the object's information

Reimplemented from xmm::SingleClassProbabilisticModel.

void xmm::SingleClassProbabilisticModel::train ( TrainingSet trainingSet)
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.

Parameters
trainingSetTraining Set to train the model.
See also
emAlgorithmUpdate
static const float xmm::SingleClassHMM::TRANSITION_REGULARIZATION ( )
inlinestatic
void xmm::SingleClassHMM::updateAlphaWindow ( )
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.

void xmm::SingleClassHMM::updateExitProbabilities ( float *  _exitProbabilities = NULL)
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.

Parameters
_exitProbabilitiesvector of exit probabilities (size must be nbStates)
Exceptions
runtime_errorif the model is not hierarchical
void xmm::SingleClassHMM::updateResults ( )
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)

void xmm::Writable::writeFile ( char *  fileName) const
inlineinherited

write method for python wrapping ('write' keyword forbidden, name has to be different)

Warning
only defined if SWIGPYTHON is defined

Friends And Related Function Documentation

friend class HierarchicalHMM
friend
template<typename SingleClassModel , typename ModelType >
friend class Model
friend

Member Data Documentation

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)

std::vector<double> xmm::SingleClassHMM::alpha_seq_
protected

Sequence of alpha (forward) probabilities.

std::vector<double> xmm::SingleClassHMM::beta_
protected

backward state probabilities

std::vector<double> xmm::SingleClassHMM::beta_seq_
protected

Sequence of beta (backward) probabilities.

bool xmm::SingleClassProbabilisticModel::cancel_training_
protectedinherited

defines if the model received a request to cancel training

std::vector<std::vector<double> > xmm::SingleClassHMM::epsilon_sequence_
protected

Sequence of Epsilon probabilities.

std::vector<float> xmm::SingleClassHMM::exit_probabilities_
protected

Exit probabilities for a hierarchical model.

bool xmm::SingleClassHMM::forward_initialized_
protected

Defines if the forward algorithm has been initialized.

std::vector<std::vector<double> > xmm::SingleClassHMM::gamma_sequence_
protected

Sequence of Gamma probabilities.

std::vector<std::vector<std::vector<double> > > xmm::SingleClassHMM::gamma_sequence_per_mixture_
protected

Sequence of Gamma probabilities for each mixture component.

std::vector<double> xmm::SingleClassHMM::gamma_sum_
protected

Used to store the sums of the gamma variable.

std::vector<double> xmm::SingleClassHMM::gamma_sum_per_mixture_
protected

Used to store the sums of the gamma variable for each mixture component.

bool xmm::SingleClassHMM::is_hierarchical_
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.

bool xmm::SingleClassProbabilisticModel::is_training_
protectedinherited

defines if the model is being trained.

std::string xmm::SingleClassProbabilisticModel::label
inherited

label associated with the given model

CircularBuffer<double> xmm::SingleClassProbabilisticModel::likelihood_buffer_
protectedinherited

Likelihood buffer used for smoothing.

ClassParameters<HMM> xmm::SingleClassHMM::parameters

Convert to bimodal HMM in place.

Parameters
dimension_inputdimension of the input modality
Exceptions
runtime_errorif the model is already bimodal
out_of_rangeif the requested input dimension is too large Convert to unimodal HMM in place
runtime_errorif the model is already unimodal extract a submodel with the given columns
Parameters
columnscolumns indices in the target order
Exceptions
runtime_errorif the model is training
out_of_rangeif the number or indices of the requested columns exceeds the current dimension
Returns
a HMM from the current model considering only the target columns extract the submodel of the input modality
Exceptions
runtime_errorif the model is training or if it is not bimodal
Returns
a unimodal HMM of the input modality from the current bimodal model extract the submodel of the output modality
Exceptions
runtime_errorif the model is training or if it is not bimodal
Returns
a unimodal HMM of the output modality from the current bimodal model extract the model with reversed input and output modalities
Exceptions
runtime_errorif the model is training or if it is not bimodal
Returns
a bimodal HMM that swaps the input and output modalities Model Parameters
std::vector<double> xmm::SingleClassHMM::previous_alpha_
protected

used to store the alpha estimated at the previous time step

std::vector<double> xmm::SingleClassHMM::previous_beta_
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)

std::shared_ptr<SharedParameters> xmm::SingleClassProbabilisticModel::shared_parameters
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)

EventGenerator<TrainingEvent> xmm::SingleClassProbabilisticModel::training_events
inherited

Generator for events monitoring the training process.

std::mutex xmm::SingleClassProbabilisticModel::training_mutex_
protectedinherited

Mutex used in Concurrent Mode.

TrainingEvent xmm::SingleClassProbabilisticModel::training_status
inherited

Event containing information on the current status of the training process.

std::vector<float> xmm::SingleClassHMM::transition

Transition Matrix.

int xmm::SingleClassHMM::window_maxindex_
protected

minimum index of the alpha window (used for regression & time progression)

int xmm::SingleClassHMM::window_minindex_
protected

minimum index of the alpha window (used for regression & time progression)

double xmm::SingleClassHMM::window_normalization_constant_
protected

normalization constant of the alpha window (used for regression & time progression)


The documentation for this class was generated from the following files: