latest version v1.9 - last update 10 Apr 2010 |
This class defines training and classification methods for Hidden Markov Models (HMM) using observation sequences. More...
#include <ltiHmmClassifier.h>
Classes | |
class | parameters |
the parameters for the class hmmClassifier More... | |
Public Member Functions | |
hmmClassifier () | |
hmmClassifier (const hmmClassifier &other) | |
virtual | ~hmmClassifier () |
virtual const char * | getTypeName () const |
hmmClassifier & | copy (const hmmClassifier &other) |
hmmClassifier & | operator= (const hmmClassifier &other) |
virtual classifier * | clone () const |
const parameters & | getParameters () const |
virtual bool | write (ioHandler &handler, const bool complete=true) const |
virtual bool | read (ioHandler &handler, const bool complete=true) |
Training routines | |
virtual bool | train (const std::vector< sequence< dvector > > &input, const ivector &ids) |
bool | train (std::vector< sequence< dvector > > &input, int id) |
void | reset () |
Classification routines. | |
virtual bool | classify (const sequence< dvector > &observations, outputVector &result) |
bool | reducedClassify (const sequence< dvector > &observations, outputVector &result, std::map< int, std::string > usedModelsIDNameMap) |
Direct access routines | |
ivector | getIDs () |
hiddenMarkovModel | getHMM (int id) const |
bool | setHMM (hiddenMarkovModel &model, int id) |
bool | deleteHMM (int id) |
void | setName (int id, const std::string &theName) |
void | generateIndexNameMap (std::map< int, std::string > &theMap) const |
int | getShortestModelLength () const |
Protected Attributes | |
std::map< int, hiddenMarkovModel > | theModels |
int | featureDimension |
This class defines training and classification methods for Hidden Markov Models (HMM) using observation sequences.
The algorithms are taken from "Fundamentals of speech recognition" (L. Rabiner and B.-H. Juang, Prentice Hall, 1993) and can also be found in "Erkennung kontinuierlicher Gebärdensprache mit Ganzwortmodellen" (H. C. Hienz, PhD thesis, Chair of Technical Computer Science, 2000). The notation in this documentation is taken from the latter literature.
In case of classification, the probability of the observation sequence is approximated by the observation probability of the best path . The best path is found with the Viterbi algorithm. Increased computational efficiency and precision are achieved by using scores with instead of probabilities. Note that the lowest score corresponds to the highest probability and thus represents the best recognition result.
Note: The values in the outputVector are not probabilities! To match the value criteria (higher values represent better recognition results, positive values only), scores are mapped to values between 0.0 and 1.0. Currently exponential, linear, and none are available.
lti::hmmClassifier::hmmClassifier | ( | ) |
default constructor
lti::hmmClassifier::hmmClassifier | ( | const hmmClassifier & | other | ) |
copy constructor
other | the object to be copied |
virtual lti::hmmClassifier::~hmmClassifier | ( | ) | [virtual] |
destructor
virtual bool lti::hmmClassifier::classify | ( | const sequence< dvector > & | observations, | |
outputVector & | result | |||
) | [virtual] |
Classification.
Classifies the sequence of features and returns the outputVector with the classification result.
observations | the sequence to be classified | |
result | the result of the classification |
Implements lti::supervisedSequenceClassifier.
virtual classifier* lti::hmmClassifier::clone | ( | ) | const [virtual] |
returns a pointer to a clone of this functor.
Implements lti::classifier.
Reimplemented in lti::hmmOnlineClassifier.
hmmClassifier& lti::hmmClassifier::copy | ( | const hmmClassifier & | other | ) |
copy data of "other" functor.
other | the functor to be copied |
Reimplemented from lti::supervisedSequenceClassifier.
Reimplemented in lti::hmmOnlineClassifier.
bool lti::hmmClassifier::deleteHMM | ( | int | id | ) |
Delete the model with the given id.
Note: the output template may contain incorrect values after this!
void lti::hmmClassifier::generateIndexNameMap | ( | std::map< int, std::string > & | theMap | ) | const |
Generate a map ID -> name for all loaded models.
hiddenMarkovModel lti::hmmClassifier::getHMM | ( | int | id | ) | const |
Returns a copy of the model with the given id.
If no such model exists, the empty default model given in parameters is returned.
ivector lti::hmmClassifier::getIDs | ( | ) |
Query id's of trained models.
const parameters& lti::hmmClassifier::getParameters | ( | ) | const |
returns used parameters
Reimplemented from lti::supervisedSequenceClassifier.
Reimplemented in lti::hmmOnlineClassifier.
int lti::hmmClassifier::getShortestModelLength | ( | ) | const |
Returns the length of the shortest model.
This allows to tell if an observation of a certain length can be classified by this classifier. If no models are available, -1 will be returned.
virtual const char* lti::hmmClassifier::getTypeName | ( | ) | const [virtual] |
returns the name of this type ("hmmClassifier")
Reimplemented from lti::supervisedSequenceClassifier.
Reimplemented in lti::hmmOnlineClassifier.
hmmClassifier& lti::hmmClassifier::operator= | ( | const hmmClassifier & | other | ) |
alias for copy member
other | the classifier to be copied |
Reimplemented from lti::supervisedSequenceClassifier.
Reimplemented in lti::hmmOnlineClassifier.
virtual bool lti::hmmClassifier::read | ( | ioHandler & | handler, | |
const bool | complete = true | |||
) | [virtual] |
bool lti::hmmClassifier::reducedClassify | ( | const sequence< dvector > & | observations, | |
outputVector & | result, | |||
std::map< int, std::string > | usedModelsIDNameMap | |||
) |
Reduced Classification.
Classifies the sequence of features only with a reduced number of models given in usedModelsIDNameMap. Returns the outputVector with the classification result.
observations | the sequence to be classified | |
result | the result of the classification | |
usedModelsIDNameMap | map of hmm models given by id and name |
void lti::hmmClassifier::reset | ( | ) |
Deletes all models saved internally.
Reimplemented in lti::hmmOnlineClassifier.
bool lti::hmmClassifier::setHMM | ( | hiddenMarkovModel & | model, | |
int | id | |||
) |
Set the model to be used for the given id.
Note: the output template may contain incorrect values hereafter!
void lti::hmmClassifier::setName | ( | int | id, | |
const std::string & | theName | |||
) |
Set the name of a specific model (if a model with the given ID exists).
Training of a single model.
The given sequences are used to train the model of the given id. If such a model already exists internally, it will be overwritten. Training is performed with the training parameters given in the parameters class.
Note: if you train a single model this way, the output template may contain incorrect values!
virtual bool lti::hmmClassifier::train | ( | const std::vector< sequence< dvector > > & | input, | |
const ivector & | ids | |||
) | [virtual] |
Supervised sequence training.
The sequences in the input
vector are used for training the sequence classifier. Each sequence is associated with an id given in the vector ids
. Hidden Markov models are created for all given ids, existing models being deleted first. After the training process, the outputTemplate is generated on the training set.
input | vector of training sequences | |
ids | the classes of the training sequences |
Implements lti::supervisedSequenceClassifier.
virtual bool lti::hmmClassifier::write | ( | ioHandler & | handler, | |
const bool | complete = true | |||
) | const [virtual] |
int lti::hmmClassifier::featureDimension [protected] |
feature dimension (saved here for faster access)
std::map<int, hiddenMarkovModel> lti::hmmClassifier::theModels [protected] |
the models with the given ids.