XMM - Probabilistic Models for Motion Recognition and Mapping

Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
xmm::TrainingSet Class Reference

Base class for the definition of training sets. More...

#include <xmmTrainingSet.hpp>

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

Public Member Functions

 TrainingSet (MemoryMode memoryMode=MemoryMode::OwnMemory, Multimodality multimodality=Multimodality::Unimodal)
 Constructor. More...
 
 TrainingSet (TrainingSet const &src)
 Copy Constructor. More...
 
 TrainingSet (Json::Value const &root)
 Constructor from Json Structure. More...
 
TrainingSetoperator= (TrainingSet const &src)
 Assignment Operator. More...
 
virtual ~TrainingSet ()
 Destructor. More...
 
Accessors
bool ownMemory () const
 checks if the training set is owns the data More...
 
bool bimodal () const
 checks if the training set is bimodal More...
 
Manipulate Phrases
bool empty () const
 checks if the training set is empty More...
 
unsigned int size () const
 Size of the training set. More...
 
std::map< int, std::shared_ptr< xmm::Phrase > >::iterator begin ()
 iterator to the beginning of phrases More...
 
std::map< int, std::shared_ptr< xmm::Phrase > >::iterator end ()
 iterator to the end of phrases More...
 
std::map< int, std::shared_ptr< xmm::Phrase > >::reverse_iterator rbegin ()
 reverse iterator to the beginning of phrases More...
 
std::map< int, std::shared_ptr< xmm::Phrase > >::reverse_iterator rend ()
 reverse iterator to the end of phrases More...
 
std::map< int, std::shared_ptr< xmm::Phrase > >::const_iterator cbegin () const
 constant iterator to the beginning of phrases More...
 
std::map< int, std::shared_ptr< xmm::Phrase > >::const_iterator cend () const
 constant iterator to the end of phrases More...
 
std::map< int, std::shared_ptr< xmm::Phrase > >::const_reverse_iterator crbegin () const
 constant reverse iterator to the beginning of phrases More...
 
std::map< int, std::shared_ptr< xmm::Phrase > >::const_reverse_iterator crend () const
 constant reverse iterator to the end of phrases More...
 
void addPhrase (int phraseIndex, std::string label="")
 add a new phrase, or reset the phrase if existing More...
 
void addPhrase (int phraseIndex, Phrase const &phrase)
 add a new phrase, or reset the phrase if existing More...
 
void addPhrase (int phraseIndex, std::shared_ptr< Phrase > phrase)
 add a new phrase, or reset the phrase if existing More...
 
void removePhrase (int phraseIndex)
 delete a phrase More...
 
void removePhrasesOfClass (std::string const &label)
 delete all phrases of a given class More...
 
std::shared_ptr< xmm::PhrasegetPhrase (int phraseIndex) const
 Access Phrase by index. More...
 
TrainingSetgetPhrasesOfClass (std::string const &label)
 get the pointer to the sub-training set containing all phrases with a given label More...
 
void clear ()
 delete all phrases More...
 
const std::set< std::string > & labels () const
 get the list of labels currently in the training set More...
 
JSON I/O
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...
 
Utilities
std::vector< float > mean () const
 Compute the global mean of all data phrases along the time axis. More...
 
std::vector< float > standardDeviation () const
 Compute the global standard deviation of all data phrases along the time axis. More...
 
std::vector< std::pair< float, float > > minmax () const
 Compute the global min/max of all data phrases along the time axis. More...
 
void rescale (std::vector< float > offset, std::vector< float > gain)
 rescale a phrase given an offset and gain More...
 
void normalize ()
 normalize the training set by rescaling all phrases to the mean/std of the whole training set 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

Attribute< unsigned int > dimension
 total dimension of the training data More...
 
Attribute< unsigned int > dimension_input
 dimension of the input modality in bimodal mode More...
 
Attribute< std::vector< std::string > > column_names
 labels of the columns of the training set (e.g. descriptor names) More...
 

Protected Member Functions

void onPhraseEvent (PhraseEvent const &e)
 Monitors the training of each Model of the group. More...
 
virtual void onAttributeChange (AttributeBase *attr_pointer)
 notification function called when a member attribute is changed More...
 
virtual void update ()
 create all the sub-training sets: one for each label More...
 

Protected Attributes

bool own_memory_
 defines if the phrase has its own memory More...
 
bool bimodal_
 defines if the phrase is bimodal More...
 
std::set< std::string > labels_
 Set containing all the labels present in the training set. More...
 
std::map< int, std::shared_ptr< Phrase > > phrases_
 Training Phrases. More...
 
std::map< std::string, TrainingSetsub_training_sets_
 Sub-ensembles of the training set for specific classes. More...
 

Detailed Description

Base class for the definition of training sets.

Training sets host a collection of phrases

Constructor & Destructor Documentation

xmm::TrainingSet::TrainingSet ( MemoryMode  memoryMode = MemoryMode::OwnMemory,
Multimodality  multimodality = Multimodality::Unimodal 
)

Constructor.

Parameters
memoryModeMemory mode (owned vs shared)
multimodalityNumber of modalities
xmm::TrainingSet::TrainingSet ( TrainingSet const &  src)

Copy Constructor.

Parameters
srcsource Training Set
xmm::TrainingSet::TrainingSet ( Json::Value const &  root)
explicit

Constructor from Json Structure.

Parameters
rootJson Value
xmm::TrainingSet::~TrainingSet ( )
virtual

Destructor.

Warning
phrases are only deleted if the training set is unlocked
See also
lock()

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::TrainingSet::addPhrase ( int  phraseIndex,
std::string  label = "" 
)

add a new phrase, or reset the phrase if existing

The phrase is set to an empty phrase with the current attributes (dimensions, etc). The phrase is created if it does not exists at the given index.

Parameters
phraseIndexindex of the data phrase in the trainingSet
labelLabel of the phrase
void xmm::TrainingSet::addPhrase ( int  phraseIndex,
Phrase const &  phrase 
)

add a new phrase, or reset the phrase if existing

The phrase is set to a copy of the phrase passed in argument The phrase is created if it does not exists at the given index.

Parameters
phraseIndexindex of the data phrase in the trainingSet
phrasesource phrase
void xmm::TrainingSet::addPhrase ( int  phraseIndex,
std::shared_ptr< Phrase phrase 
)

add a new phrase, or reset the phrase if existing

The phrase is set to point to the existing phrase passed in argument. The phrase is created if it does not exists at the given index.

Parameters
phraseIndexindex of the data phrase in the trainingSet
phrasepointer to an existing phrase
std::map< int, std::shared_ptr< xmm::Phrase > >::iterator xmm::TrainingSet::begin ( )

iterator to the beginning of phrases

bool xmm::TrainingSet::bimodal ( ) const

checks if the training set is bimodal

Returns
true if the training set is bimodal (construction with Multimodality::Bimodal)
std::map< int, std::shared_ptr< xmm::Phrase > >::const_iterator xmm::TrainingSet::cbegin ( ) const

constant iterator to the beginning of phrases

std::map< int, std::shared_ptr< xmm::Phrase > >::const_iterator xmm::TrainingSet::cend ( ) const

constant iterator to the end of phrases

void xmm::TrainingSet::clear ( )

delete all phrases

Warning
if the training set is locked, the phrases themselves are not deleted (only their references)
std::map< int, std::shared_ptr< xmm::Phrase > >::const_reverse_iterator xmm::TrainingSet::crbegin ( ) const

constant reverse iterator to the beginning of phrases

std::map< int, std::shared_ptr< xmm::Phrase > >::const_reverse_iterator xmm::TrainingSet::crend ( ) const

constant reverse iterator to the end of phrases

bool xmm::TrainingSet::empty ( ) const

checks if the training set is empty

Returns
true if the training set is empty (no training phrases)
std::map< int, std::shared_ptr< xmm::Phrase > >::iterator xmm::TrainingSet::end ( )

iterator to the end of phrases

void xmm::TrainingSet::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::Writable.

std::shared_ptr< xmm::Phrase > xmm::TrainingSet::getPhrase ( int  phraseIndex) const

Access Phrase by index.

Parameters
phraseIndexindex of the phrase
Returns
pointer to the phrase if it exists, else nullptr
xmm::TrainingSet * xmm::TrainingSet::getPhrasesOfClass ( std::string const &  label)

get the pointer to the sub-training set containing all phrases with a given label

Warning
in order to protect the phrases in the current training set, the sub-training set returned is locked
Parameters
labeltarget label
Returns
pointer to the sub-training set containing all phrases with a given label
Exceptions
out_of_rangeif the label does not exist
const std::set<std::string>& xmm::TrainingSet::labels ( ) const
inline

get the list of labels currently in the training set

Returns
reference to the set of labels in the training set
std::vector< float > xmm::TrainingSet::mean ( ) const

Compute the global mean of all data phrases along the time axis.

Returns
global mean of all phrases (along time axis, full-size)
std::vector< std::pair< float, float > > xmm::TrainingSet::minmax ( ) const

Compute the global min/max of all data phrases along the time axis.

Returns
vector of min/max pairs across all phrases (along time axis, full-size)
void xmm::TrainingSet::normalize ( )

normalize the training set by rescaling all phrases to the mean/std of the whole training set

void xmm::TrainingSet::onAttributeChange ( xmm::AttributeBase attr_pointer)
protectedvirtual

notification function called when a member attribute is changed

void xmm::TrainingSet::onPhraseEvent ( PhraseEvent const &  e)
protected

Monitors the training of each Model of the group.

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

Assignment Operator.

Parameters
srcsource Training Set
bool xmm::TrainingSet::ownMemory ( ) const

checks if the training set is owns the data

Returns
true if the training set owns data (construction with MemoryMode::OwnMemory)
std::map< int, std::shared_ptr< xmm::Phrase > >::reverse_iterator xmm::TrainingSet::rbegin ( )

reverse iterator to the beginning of phrases

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::TrainingSet::removePhrase ( int  phraseIndex)

delete a phrase

Warning
if the training set is locked, the phrase iself is not deleted (only the reference)
Parameters
phraseIndexindex of the phrase
Exceptions
out_of_boundsif the phrase does not exist
void xmm::TrainingSet::removePhrasesOfClass ( std::string const &  label)

delete all phrases of a given class

Warning
if the training set is locked, the phrases themselves are not deleted (only the references)
Parameters
labellabel of the class to delete
Exceptions
out_of_boundsif the label does not exist
std::map< int, std::shared_ptr< xmm::Phrase > >::reverse_iterator xmm::TrainingSet::rend ( )

reverse iterator to the end of phrases

void xmm::TrainingSet::rescale ( std::vector< float >  offset,
std::vector< float >  gain 
)

rescale a phrase given an offset and gain

Parameters
offsetconstant offset to be subtracted
gaingain to be applied
unsigned int xmm::TrainingSet::size ( ) const

Size of the training set.

Returns
size of the training set (number of phrases)
std::vector< float > xmm::TrainingSet::standardDeviation ( ) const

Compute the global standard deviation of all data phrases along the time axis.

Returns
global standard deviation of all phrases (along time axis, full-size)
Json::Value xmm::TrainingSet::toJson ( ) const
virtual

Write the object to a JSON Structure.

Returns
Json value containing the object's information

Implements xmm::Writable.

void xmm::TrainingSet::update ( )
protectedvirtual

create all the sub-training sets: one for each label

each subset contains only the phrase for the given label

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

bool xmm::TrainingSet::bimodal_
protected

defines if the phrase is bimodal

Attribute<std::vector<std::string> > xmm::TrainingSet::column_names

labels of the columns of the training set (e.g. descriptor names)

Attribute<unsigned int> xmm::TrainingSet::dimension

total dimension of the training data

Attribute<unsigned int> xmm::TrainingSet::dimension_input

dimension of the input modality in bimodal mode

std::set<std::string> xmm::TrainingSet::labels_
protected

Set containing all the labels present in the training set.

bool xmm::TrainingSet::own_memory_
protected

defines if the phrase has its own memory

std::map<int, std::shared_ptr<Phrase> > xmm::TrainingSet::phrases_
protected

Training Phrases.

Phrases are stored in a map: allows the easy addition/deletion of phrases by index.

std::map<std::string, TrainingSet> xmm::TrainingSet::sub_training_sets_
protected

Sub-ensembles of the training set for specific classes.


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