XMM - Probabilistic Models for Motion Recognition and Mapping

Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
xmm::Model< SingleClassModel, ModelType > Class Template Reference

Probabilistic machine learning model for multiclass recognition and regression. More...

#include <xmmModel.hpp>

Inheritance diagram for xmm::Model< SingleClassModel, ModelType >:
[legend]
Collaboration diagram for xmm::Model< SingleClassModel, ModelType >:
[legend]

Public Member Functions

 Model (bool bimodal=false)
 Constructor. More...
 
 Model (Model< SingleClassModel, ModelType > const &src)
 Copy Constructor. More...
 
 Model (Json::Value const &root)
 Constructor from Json Structure. More...
 
Model< SingleClassModel, ModelType > & operator= (Model< SingleClassModel, ModelType > const &src)
 Assignment. More...
 
virtual ~Model ()
 Destructor. More...
 
Class Manipulation
unsigned int size () const
 Get the number of classes in the model. More...
 
bool hasClass (std::string const &label) const
 Checks if a class exists. More...
 
int getIndex (std::string const &label) const
 Checks if a class exists. More...
 
virtual void removeClass (std::string const &label)
 Remove a specific class by label. More...
 
virtual void clear ()
 Remove all classes. More...
 
Training
bool trained () const
 Checks if the model is trained (training finished and not empty) More...
 
bool training () const
 Checks if the model is still training. More...
 
virtual void train (TrainingSet *trainingSet)
 Train all classes from the training set passed in argument. More...
 
virtual void train (TrainingSet *trainingSet, std::string const &label)
 Train a specific class from the training set passed in argument. More...
 
void cancelTraining ()
 Cancels the training of all models. More...
 
void cancelTraining (std::string const &label)
 Cancels the training of a given class. More...
 
Performance
virtual void reset ()
 Resets the fitering process (recognition or regression) More...
 
virtual void 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...
 
void fromJson (Json::Value const &root)
 Read the object from a JSON Structure. 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...
 

Public Attributes

std::shared_ptr< SharedParametersshared_parameters
 Set of Parameters shared among classes. More...
 
Configuration< ModelType > configuration
 Configuration (default and class-specific parameters) More...
 
EventGenerator< TrainingEventtraining_events
 Generator for training process events. More...
 
std::map< std::string, SingleClassModel > models
 models stored in a map. Each Model is associated with a label More...
 

Protected Member Functions

virtual void joinTraining ()
 Finishes the background training process by joining threads and deleting the models which training failed. More...
 
void onTrainingEvent (TrainingEvent const &e)
 Monitors the training of each Model of the group. More...
 
void checkTraining () const
 Checks if the Model is still training. More...
 
void checkConfigurationChanges () const
 Look for configuration changes and throws an exception if the model is not up to date. More...
 
virtual void addModelForClass (std::string const &label)
 Update training set for a specific label. More...
 

Protected Attributes

std::map< std::string, std::thread > training_threads_
 Training Threads. More...
 
std::atomic< bool > cancel_required_
 locks the Model while the models are training Used in cancel method More...
 
std::atomic< bool > is_training_
 locks the Model while the models are training Used in cancel method More...
 
std::atomic< bool > is_joining_
 specifies if a thread for joining the training process has been launched. More...
 
unsigned int models_still_training_
 Number of models that are still training. More...
 
std::mutex event_mutex_
 Mutex that prevents concurrent calls to onEvent() More...
 

Detailed Description

template<typename SingleClassModel, typename ModelType>
class xmm::Model< SingleClassModel, ModelType >

Probabilistic machine learning model for multiclass recognition and regression.

Template Parameters
SingleClassModelType of the associated Single-class Model
ModelTypeModel Type Name

Constructor & Destructor Documentation

template<typename SingleClassModel, typename ModelType>
xmm::Model< SingleClassModel, ModelType >::Model ( bool  bimodal = false)
inline

Constructor.

Parameters
bimodaluse true for a use with Regression / Generation.
template<typename SingleClassModel, typename ModelType>
xmm::Model< SingleClassModel, ModelType >::Model ( Model< SingleClassModel< SingleClassModel, ModelType >, ModelType > const &  src)
inline

Copy Constructor.

Parameters
srcSource Model
template<typename SingleClassModel, typename ModelType>
xmm::Model< SingleClassModel, ModelType >::Model ( Json::Value const &  root)
inlineexplicit

Constructor from Json Structure.

Parameters
rootJson Value
template<typename SingleClassModel, typename ModelType>
virtual xmm::Model< SingleClassModel, ModelType >::~Model ( )
inlinevirtual

Destructor.

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
template<typename SingleClassModel, typename ModelType>
virtual void xmm::Model< SingleClassModel, ModelType >::addModelForClass ( std::string const &  label)
inlineprotectedvirtual

Update training set for a specific label.

Parameters
labellabel of the sub-training set to update
Exceptions
out_of_rangeif the label does not exist

Reimplemented in xmm::HierarchicalHMM.

template<typename SingleClassModel, typename ModelType>
void xmm::Model< SingleClassModel, ModelType >::cancelTraining ( )
inline

Cancels the training of all models.

template<typename SingleClassModel, typename ModelType>
void xmm::Model< SingleClassModel, ModelType >::cancelTraining ( std::string const &  label)
inline

Cancels the training of a given class.

Parameters
labellabel of the class to cancel
template<typename SingleClassModel, typename ModelType>
void xmm::Model< SingleClassModel, ModelType >::checkConfigurationChanges ( ) const
inlineprotected

Look for configuration changes and throws an exception if the model is not up to date.

template<typename SingleClassModel, typename ModelType>
void xmm::Model< SingleClassModel, ModelType >::checkTraining ( ) const
inlineprotected

Checks if the Model is still training.

Exceptions
runtime_errorif the Model is training.
template<typename SingleClassModel, typename ModelType>
virtual void xmm::Model< SingleClassModel, ModelType >::clear ( )
inlinevirtual

Remove all classes.

Reimplemented in xmm::HierarchicalHMM.

template<typename SingleClassModel, typename ModelType>
virtual void xmm::Model< SingleClassModel, ModelType >::filter ( std::vector< float > const &  observation)
inlinevirtual

filters a incoming observation (performs recognition or regression)

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

Parameters
observationobservation vector

Reimplemented in xmm::HierarchicalHMM, and xmm::GMM.

template<typename SingleClassModel, typename ModelType>
void xmm::Model< SingleClassModel, ModelType >::fromJson ( Json::Value const &  root)
inlinevirtual

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::Writable.

template<typename SingleClassModel, typename ModelType>
int xmm::Model< SingleClassModel, ModelType >::getIndex ( std::string const &  label) const
inline

Checks if a class exists.

Parameters
labelclass label
Returns
true if the class labeled 'label' exists
template<typename SingleClassModel, typename ModelType>
bool xmm::Model< SingleClassModel, ModelType >::hasClass ( std::string const &  label) const
inline

Checks if a class exists.

Parameters
labelclass label
Returns
true if the class labeled 'label' exists
template<typename SingleClassModel, typename ModelType>
virtual void xmm::Model< SingleClassModel, ModelType >::joinTraining ( )
inlineprotectedvirtual

Finishes the background training process by joining threads and deleting the models which training failed.

Reimplemented in xmm::HierarchicalHMM.

template<typename SingleClassModel, typename ModelType>
void xmm::Model< SingleClassModel, ModelType >::onTrainingEvent ( TrainingEvent const &  e)
inlineprotected

Monitors the training of each Model of the group.

template<typename SingleClassModel, typename ModelType>
Model<SingleClassModel, ModelType>& xmm::Model< SingleClassModel, ModelType >::operator= ( Model< SingleClassModel< SingleClassModel, ModelType >, ModelType > const &  src)
inline

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
template<typename SingleClassModel, typename ModelType>
virtual void xmm::Model< SingleClassModel, ModelType >::removeClass ( std::string const &  label)
inlinevirtual

Remove a specific class by label.

Parameters
labellabel of the class to remove

Reimplemented in xmm::HierarchicalHMM.

template<typename SingleClassModel, typename ModelType>
virtual void xmm::Model< SingleClassModel, ModelType >::reset ( )
inlinevirtual

Resets the fitering process (recognition or regression)

Reimplemented in xmm::HierarchicalHMM, and xmm::GMM.

template<typename SingleClassModel, typename ModelType>
unsigned int xmm::Model< SingleClassModel, ModelType >::size ( ) const
inline

Get the number of classes in the model.

Returns
the number of classes in the model
template<typename SingleClassModel, typename ModelType>
virtual Json::Value xmm::Model< SingleClassModel, ModelType >::toJson ( ) const
inlinevirtual

Write the object to a JSON Structure.

Returns
Json value containing the object's information

Implements xmm::Writable.

Reimplemented in xmm::HierarchicalHMM.

template<typename SingleClassModel, typename ModelType>
virtual void xmm::Model< SingleClassModel, ModelType >::train ( TrainingSet trainingSet)
inlinevirtual

Train all classes from the training set passed in argument.

Parameters
trainingSetTraining Set
template<typename SingleClassModel, typename ModelType>
virtual void xmm::Model< SingleClassModel, ModelType >::train ( TrainingSet trainingSet,
std::string const &  label 
)
inlinevirtual

Train a specific class from the training set passed in argument.

Parameters
trainingSetTraining Set
labellabel of the class to train
Exceptions
out_of_rangeif the label does not exist
runtime_errorif the dimensions of the training set don't match the dimensions of the current model
template<typename SingleClassModel, typename ModelType>
bool xmm::Model< SingleClassModel, ModelType >::trained ( ) const
inline

Checks if the model is trained (training finished and not empty)

template<typename SingleClassModel, typename ModelType>
bool xmm::Model< SingleClassModel, ModelType >::training ( ) const
inline

Checks if the model is still training.

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

Member Data Documentation

template<typename SingleClassModel, typename ModelType>
std::atomic<bool> xmm::Model< SingleClassModel, ModelType >::cancel_required_
protected

locks the Model while the models are training Used in cancel method

template<typename SingleClassModel, typename ModelType>
Configuration<ModelType> xmm::Model< SingleClassModel, ModelType >::configuration

Configuration (default and class-specific parameters)

template<typename SingleClassModel, typename ModelType>
std::mutex xmm::Model< SingleClassModel, ModelType >::event_mutex_
protected

Mutex that prevents concurrent calls to onEvent()

template<typename SingleClassModel, typename ModelType>
std::atomic<bool> xmm::Model< SingleClassModel, ModelType >::is_joining_
protected

specifies if a thread for joining the training process has been launched.

template<typename SingleClassModel, typename ModelType>
std::atomic<bool> xmm::Model< SingleClassModel, ModelType >::is_training_
protected

locks the Model while the models are training Used in cancel method

template<typename SingleClassModel, typename ModelType>
std::map<std::string, SingleClassModel> xmm::Model< SingleClassModel, ModelType >::models

models stored in a map. Each Model is associated with a label

template<typename SingleClassModel, typename ModelType>
unsigned int xmm::Model< SingleClassModel, ModelType >::models_still_training_
protected

Number of models that are still training.

template<typename SingleClassModel, typename ModelType>
std::shared_ptr<SharedParameters> xmm::Model< SingleClassModel, ModelType >::shared_parameters

Set of Parameters shared among classes.

template<typename SingleClassModel, typename ModelType>
EventGenerator<TrainingEvent> xmm::Model< SingleClassModel, ModelType >::training_events

Generator for training process events.

template<typename SingleClassModel, typename ModelType>
std::map<std::string, std::thread> xmm::Model< SingleClassModel, ModelType >::training_threads_
protected

Training Threads.


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