GestureRecognitionToolkit  Version: 0.2.5
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
Classifier Class Reference

This is the main base class that all GRT Classification algorithms should inherit from. More...

#include <Classifier.h>

Inheritance diagram for Classifier:
MLBase GRTBase Observer< TrainingResult > Observer< TestInstanceResult > AdaBoost ANBC BAG DecisionTree DTW FiniteStateMachine GMM HMM KNN MinDist ParticleClassifier RandomForests RegisterClassifierModule< T > RegisterClassifierModule< AdaBoost > RegisterClassifierModule< ANBC > RegisterClassifierModule< BAG > RegisterClassifierModule< DecisionTree > RegisterClassifierModule< DTW > RegisterClassifierModule< FiniteStateMachine > RegisterClassifierModule< GMM > RegisterClassifierModule< HMM > RegisterClassifierModule< KNN > RegisterClassifierModule< MinDist > RegisterClassifierModule< ParticleClassifier > RegisterClassifierModule< RandomForests > RegisterClassifierModule< Softmax > RegisterClassifierModule< SVM > RegisterClassifierModule< SwipeDetector > Softmax SVM SwipeDetector

Public Types

enum  ClassifierModes { STANDARD_CLASSIFIER_MODE =0, TIMESERIES_CLASSIFIER_MODE }
 
typedef std::map< std::string, Classifier *(*)() > StringClassifierMap
 
- Public Types inherited from MLBase
enum  BaseType {
  BASE_TYPE_NOT_SET =0, CLASSIFIER, REGRESSIFIER, CLUSTERER,
  PRE_PROCSSING, POST_PROCESSING, FEATURE_EXTRACTION, CONTEXT
}
 

Public Member Functions

 Classifier (const std::string &classifierId="")
 
virtual ~Classifier (void)
 
virtual bool deepCopyFrom (const Classifier *classifier)
 
bool copyBaseVariables (const Classifier *classifier)
 
virtual bool reset ()
 
virtual bool clear ()
 
virtual bool computeAccuracy (const ClassificationData &data, Float &accuracy)
 
std::string getClassifierType () const
 
bool getSupportsNullRejection () const
 
bool getNullRejectionEnabled () const
 
Float getNullRejectionCoeff () const
 
Float getMaximumLikelihood () const
 
Float getBestDistance () const
 
Float getPhase () const
 
Float getTrainingSetAccuracy () const
 
virtual UINT getNumClasses () const
 
UINT getClassLabelIndexValue (const UINT classLabel) const
 
UINT getPredictedClassLabel () const
 
VectorFloat getClassLikelihoods () const
 
VectorFloat getClassDistances () const
 
VectorFloat getNullRejectionThresholds () const
 
Vector< UINT > getClassLabels () const
 
Vector< MinMaxgetRanges () const
 
bool enableNullRejection (const bool useNullRejection)
 
virtual bool setNullRejectionCoeff (const Float nullRejectionCoeff)
 
virtual bool setNullRejectionThresholds (const VectorFloat &newRejectionThresholds)
 
virtual bool recomputeNullRejectionThresholds ()
 
bool getTimeseriesCompatible () const
 
Classifiercreate () const
 
 GRT_DEPRECATED_MSG ("createNewInstance is deprecated, use create instead.", Classifier *createNewInstance() const )
 
 GRT_DEPRECATED_MSG ("createInstanceFromString is deprecated, use create instead.", static Classifier *createInstanceFromString(const std::string &id))
 
ClassifierdeepCopy () const
 
const ClassifiergetClassifierPointer () const
 
const ClassifiergetBaseClassifier () const
 
- Public Member Functions inherited from MLBase
 MLBase (const std::string &id="", const BaseType type=BASE_TYPE_NOT_SET)
 
virtual ~MLBase (void)
 
bool copyMLBaseVariables (const MLBase *mlBase)
 
virtual bool train (ClassificationData trainingData)
 
virtual bool train_ (ClassificationData &trainingData)
 
virtual bool train (RegressionData trainingData)
 
virtual bool train_ (RegressionData &trainingData)
 
virtual bool train (RegressionData trainingData, RegressionData validationData)
 
virtual bool train_ (RegressionData &trainingData, RegressionData &validationData)
 
virtual bool train (TimeSeriesClassificationData trainingData)
 
virtual bool train_ (TimeSeriesClassificationData &trainingData)
 
virtual bool train (ClassificationDataStream trainingData)
 
virtual bool train_ (ClassificationDataStream &trainingData)
 
virtual bool train (UnlabelledData trainingData)
 
virtual bool train_ (UnlabelledData &trainingData)
 
virtual bool train (MatrixFloat data)
 
virtual bool train_ (MatrixFloat &data)
 
virtual bool predict (VectorFloat inputVector)
 
virtual bool predict_ (VectorFloat &inputVector)
 
virtual bool predict (MatrixFloat inputMatrix)
 
virtual bool predict_ (MatrixFloat &inputMatrix)
 
virtual bool map (VectorFloat inputVector)
 
virtual bool map_ (VectorFloat &inputVector)
 
virtual bool print () const
 
virtual bool save (const std::string &filename) const
 
virtual bool load (const std::string &filename)
 
virtual bool save (std::fstream &file) const
 
virtual bool load (std::fstream &file)
 
 GRT_DEPRECATED_MSG ("saveModelToFile(std::string filename) is deprecated, use save(const std::string &filename) instead", virtual bool saveModelToFile(const std::string &filename) const )
 
 GRT_DEPRECATED_MSG ("saveModelToFile(std::fstream &file) is deprecated, use save(std::fstream &file) instead", virtual bool saveModelToFile(std::fstream &file) const )
 
 GRT_DEPRECATED_MSG ("loadModelFromFile(std::string filename) is deprecated, use load(const std::string &filename) instead", virtual bool loadModelFromFile(const std::string &filename))
 
 GRT_DEPRECATED_MSG ("loadModelFromFile(std::fstream &file) is deprecated, use load(std::fstream &file) instead", virtual bool loadModelFromFile(std::fstream &file))
 
virtual bool getModel (std::ostream &stream) const
 
virtual std::string getModelAsString () const
 
DataType getInputType () const
 
DataType getOutputType () const
 
BaseType getType () const
 
UINT getNumInputFeatures () const
 
UINT getNumInputDimensions () const
 
UINT getNumOutputDimensions () const
 
UINT getMinNumEpochs () const
 
UINT getMaxNumEpochs () const
 
UINT getBatchSize () const
 
UINT getNumRestarts () const
 
UINT getValidationSetSize () const
 
UINT getNumTrainingIterationsToConverge () const
 
Float getMinChange () const
 
Float getLearningRate () const
 
Float getRMSTrainingError () const
 
 GRT_DEPRECATED_MSG ("getRootMeanSquaredTrainingError() is deprecated, use getRMSTrainingError() instead", Float getRootMeanSquaredTrainingError() const )
 
Float getTotalSquaredTrainingError () const
 
Float getRMSValidationError () const
 
Float getValidationSetAccuracy () const
 
VectorFloat getValidationSetPrecision () const
 
VectorFloat getValidationSetRecall () const
 
bool getUseValidationSet () const
 
bool getRandomiseTrainingOrder () const
 
bool getTrained () const
 
 GRT_DEPRECATED_MSG ("getModelTrained() is deprecated, use getTrained() instead", bool getModelTrained() const )
 
bool getConverged () const
 
bool getScalingEnabled () const
 
bool getIsBaseTypeClassifier () const
 
bool getIsBaseTypeRegressifier () const
 
bool getIsBaseTypeClusterer () const
 
bool getTrainingLoggingEnabled () const
 
bool getTestingLoggingEnabled () const
 
bool enableScaling (const bool useScaling)
 
bool setMaxNumEpochs (const UINT maxNumEpochs)
 
bool setBatchSize (const UINT batchSize)
 
bool setMinNumEpochs (const UINT minNumEpochs)
 
bool setNumRestarts (const UINT numRestarts)
 
bool setMinChange (const Float minChange)
 
bool setLearningRate (const Float learningRate)
 
bool setUseValidationSet (const bool useValidationSet)
 
bool setValidationSetSize (const UINT validationSetSize)
 
bool setRandomiseTrainingOrder (const bool randomiseTrainingOrder)
 
bool setTrainingLoggingEnabled (const bool loggingEnabled)
 
bool setTestingLoggingEnabled (const bool loggingEnabled)
 
bool registerTrainingResultsObserver (Observer< TrainingResult > &observer)
 
bool registerTestResultsObserver (Observer< TestInstanceResult > &observer)
 
bool removeTrainingResultsObserver (const Observer< TrainingResult > &observer)
 
bool removeTestResultsObserver (const Observer< TestInstanceResult > &observer)
 
bool removeAllTrainingObservers ()
 
bool removeAllTestObservers ()
 
bool notifyTrainingResultsObservers (const TrainingResult &data)
 
bool notifyTestResultsObservers (const TestInstanceResult &data)
 
MLBasegetMLBasePointer ()
 
const MLBasegetMLBasePointer () const
 
Vector< TrainingResultgetTrainingResults () const
 
- Public Member Functions inherited from GRTBase
 GRTBase (const std::string &id="")
 
virtual ~GRTBase (void)
 
bool copyGRTBaseVariables (const GRTBase *GRTBase)
 
 GRT_DEPRECATED_MSG ("getClassType is deprecated, use getId() instead!", std::string getClassType() const )
 
std::string getId () const
 
std::string getLastWarningMessage () const
 
std::string getLastErrorMessage () const
 
std::string getLastInfoMessage () const
 
bool setInfoLoggingEnabled (const bool loggingEnabled)
 
bool setWarningLoggingEnabled (const bool loggingEnabled)
 
bool setErrorLoggingEnabled (const bool loggingEnabled)
 
bool setDebugLoggingEnabled (const bool loggingEnabled)
 
GRTBasegetGRTBasePointer ()
 
const GRTBasegetGRTBasePointer () const
 
Float scale (const Float &x, const Float &minSource, const Float &maxSource, const Float &minTarget, const Float &maxTarget, const bool constrain=false)
 
Float SQR (const Float &x) const
 
- Public Member Functions inherited from Observer< TrainingResult >
virtual void notify (const TrainingResult &data)
 
- Public Member Functions inherited from Observer< TestInstanceResult >
virtual void notify (const TestInstanceResult &data)
 

Static Public Member Functions

static Classifiercreate (const std::string &id)
 
static Vector< std::string > getRegisteredClassifiers ()
 
- Static Public Member Functions inherited from GRTBase
static std::string getGRTVersion (bool returnRevision=true)
 
static std::string getGRTRevison ()
 

Protected Member Functions

bool saveBaseSettingsToFile (std::fstream &file) const
 
bool loadBaseSettingsFromFile (std::fstream &file)
 
- Protected Member Functions inherited from MLBase
bool saveBaseSettingsToFile (std::fstream &file) const
 
bool loadBaseSettingsFromFile (std::fstream &file)
 

Static Protected Member Functions

static StringClassifierMapgetMap ()
 

Protected Attributes

bool supportsNullRejection
 
bool useNullRejection
 
UINT numClasses
 
UINT predictedClassLabel
 
UINT classifierMode
 
Float nullRejectionCoeff
 
Float maxLikelihood
 
Float bestDistance
 
Float phase
 
Float trainingSetAccuracy
 
VectorFloat classLikelihoods
 
VectorFloat classDistances
 
VectorFloat nullRejectionThresholds
 
Vector< UINT > classLabels
 
Vector< MinMaxranges
 
- Protected Attributes inherited from MLBase
bool trained
 
bool useScaling
 
bool converged
 
DataType inputType
 
DataType outputType
 
BaseType baseType
 
UINT numInputDimensions
 
UINT numOutputDimensions
 
UINT numTrainingIterationsToConverge
 
UINT minNumEpochs
 
UINT maxNumEpochs
 
UINT batchSize
 
UINT validationSetSize
 
UINT numRestarts
 
Float learningRate
 
Float minChange
 
Float rmsTrainingError
 
Float rmsValidationError
 
Float totalSquaredTrainingError
 
Float validationSetAccuracy
 
bool useValidationSet
 
bool randomiseTrainingOrder
 
VectorFloat validationSetPrecision
 
VectorFloat validationSetRecall
 
Random random
 
Vector< TrainingResulttrainingResults
 
TrainingResultsObserverManager trainingResultsObserverManager
 
TestResultsObserverManager testResultsObserverManager
 
TrainingLog trainingLog
 
TestingLog testingLog
 
- Protected Attributes inherited from GRTBase
std::string classId
 Stores the name of the class (e.g., MinDist)
 
DebugLog debugLog
 
ErrorLog errorLog
 
InfoLog infoLog
 
WarningLog warningLog
 

Detailed Description

This is the main base class that all GRT Classification algorithms should inherit from.

A large number of the functions in this class are virtual and simply return false as these functions must be overwridden by the inheriting class.

Definition at line 41 of file Classifier.h.

Member Typedef Documentation

typedef std::map< std::string, Classifier*(*)() > Classifier::StringClassifierMap

Defines a map between a string (which will contain the name of the classifier, such as ANBC) and a function returns a new instance of that classifier

Definition at line 268 of file Classifier.h.

Constructor & Destructor Documentation

Classifier::Classifier ( const std::string &  classifierId = "")

Default Classifier Constructor

Parameters
classifierIdthe id of the parent classifier (e.g., DecisionTree)

Definition at line 77 of file Classifier.cpp.

Classifier::~Classifier ( void  )
virtual

Default Classifier Destructor

Definition at line 94 of file Classifier.cpp.

Member Function Documentation

bool Classifier::clear ( )
virtual

This function clears the classifier module, removing any trained model and setting all the base variables to their default values.

Returns
returns true if the derived class was cleared succesfully, false otherwise

Reimplemented from MLBase.

Reimplemented in DTW, HMM, FiniteStateMachine, AdaBoost, ANBC, KNN, SVM, RandomForests, DecisionTree, BAG, GMM, ParticleClassifier, Softmax, SwipeDetector, and MinDist.

Definition at line 151 of file Classifier.cpp.

bool Classifier::computeAccuracy ( const ClassificationData data,
Float &  accuracy 
)
virtual

Computes the accuracy of the current model given the input dataset. The accuracy results will be stored in the accuracy parameter and will be in the range of [0., 100.0].

Parameters
datathe dataset that will be used to test the model
accuracythe variable to which the accuracy of the model will be stored
Returns
returns true if the accuracy was computed, false otherwise

Definition at line 171 of file Classifier.cpp.

bool Classifier::copyBaseVariables ( const Classifier classifier)

This copies the Classifier base class variables from the classifier pointer to this instance.

Parameters
classifiera pointer to a classifier from which the values will be copied to this instance
Returns
returns true if the copy was successfull, false otherwise

Definition at line 101 of file Classifier.cpp.

Classifier * Classifier::create ( const std::string &  id)
static

Creates a new classifier instance based on the input string (which should contain the name of a valid classifier such as KNN).

Parameters
idthe name of the classifier
Returns
Classifier*: a pointer to the new instance of the classifier

Definition at line 32 of file Classifier.cpp.

Classifier * Classifier::create ( ) const

Creates a new classifier instance based on the current classifierType string value.

Returns
Classifier*: a pointer to the new instance of the classifier

Definition at line 45 of file Classifier.cpp.

Classifier * Classifier::deepCopy ( ) const

This creates a new Classifier instance and deep copies the variables and models from this instance into the deep copy. The function will then return a pointer to the new instance. It is up to the user who calls this function to delete the dynamic instance when they are finished using it.

Returns
returns a pointer to a new Classifier instance which is a deep copy of this instance

Definition at line 49 of file Classifier.cpp.

virtual bool Classifier::deepCopyFrom ( const Classifier classifier)
inlinevirtual

This is the base deep copy function for the Classifier modules. This function should be overwritten by the derived class. This deep copies the variables and models from the classifier pointer to this classifier instance.

Parameters
classifiera pointer to the Classifier base class, this should be pointing to another instance of a matching derived class
Returns
returns true if the clone was successfull, false otherwise (the Classifier base class will always return flase)

Reimplemented in DTW, AdaBoost, SVM, KNN, RandomForests, DecisionTree, ANBC, HMM, GMM, Softmax, BAG, MinDist, SwipeDetector, FiniteStateMachine, and ParticleClassifier.

Definition at line 64 of file Classifier.h.

bool Classifier::enableNullRejection ( const bool  useNullRejection)

Sets if the classifier should use nullRejection.

If set to true then the classifier will reject a predicted class label if the likelihood of the prediction is below (or above depending on the algorithm) the models rejectionThreshold. If a prediction is rejected then the default null class label of 0 will be returned. If set to false then the classifier will simply return the most likely predicted class.

Parameters
useNullRejectionthe new null rejection state
Returns
returns true if nullRejection was updated successfully, false otherwise
Examples:
ClassificationModulesExamples/ANBCExample/ANBCExample.cpp, and ClassificationModulesExamples/KNNExample/KNNExample.cpp.

Definition at line 249 of file Classifier.cpp.

const Classifier & Classifier::getBaseClassifier ( ) const

Returns a pointer to this classifier. This is useful for a derived class so it can get easy access to this base classifier.

Returns
Classifier&: a reference to this classifier

Definition at line 270 of file Classifier.cpp.

Float Classifier::getBestDistance ( ) const

Returns the current bestDistance value. The bestDistance value is computed during the prediction phase and is either the minimum or maximum distance, depending on the algorithm. This value will return 0 if a prediction has not been made.

Returns
returns the current bestDistance value

Definition at line 204 of file Classifier.cpp.

const Classifier * Classifier::getClassifierPointer ( ) const

Returns a pointer to the classifier.

Returns
returns a pointer the current classifier

Definition at line 62 of file Classifier.cpp.

std::string Classifier::getClassifierType ( ) const

Returns the classifier type as a string.

Returns
returns the classifier type as a string

Definition at line 175 of file Classifier.cpp.

UINT Classifier::getClassLabelIndexValue ( const UINT  classLabel) const

Gets the index of the query classLabel in the classLabels Vector. If the query classLabel does not exist in the classLabels Vector then the function will return zero.

Parameters
classLabelthe query classLabel
Returns
returns index of the query classLabel in the classLabels Vector

Definition at line 213 of file Classifier.cpp.

Vector< UINT > Classifier::getClassLabels ( ) const

Gets a Vector containing the label each class represents, this will be an N-dimensional Vector, where N is the number of classes in the model. This is useful if the model was trained with non-monotonically class labels (i.e. class labels such as [1, 3, 6, 9, 12] instead of [1, 2, 3, 4, 5]).

Returns
returns a Vector containing the class labels for each class, an empty Vector will be returned if the model has not been trained

Definition at line 241 of file Classifier.cpp.

static StringClassifierMap* Classifier::getMap ( )
inlinestaticprotected

This function returns the classifier map, only one map should exist across all classifiers. If a map has not been created then one will be created, otherwise the current map will be returned.

Returns
returns a pointer to the classifier map

Definition at line 354 of file Classifier.h.

Float Classifier::getMaximumLikelihood ( ) const

Returns the current maximumLikelihood value. The maximumLikelihood value is computed during the prediction phase and is the likelihood of the most likely model. This value will return 0 if a prediction has not been made.

Returns
returns the current maximumLikelihood value
Examples:
ClassificationModulesExamples/AdaBoostExample/AdaBoostExample.cpp, ClassificationModulesExamples/DTWExample/DTWExample.cpp, and ClassificationModulesExamples/MinDistExample/MinDistExample.cpp.

Definition at line 191 of file Classifier.cpp.

Float Classifier::getNullRejectionCoeff ( ) const

Returns the current nullRejectionCoeff value. The nullRejectionCoeff parameter is a multipler controlling the null rejection threshold for each class.

Returns
returns the current nullRejectionCoeff value

Definition at line 187 of file Classifier.cpp.

bool Classifier::getNullRejectionEnabled ( ) const

Returns true if nullRejection is enabled.

Returns
returns true if nullRejection is enabled, false otherwise

Definition at line 183 of file Classifier.cpp.

VectorFloat Classifier::getNullRejectionThresholds ( ) const

Gets a Vector containing the null rejection thresholds for each class, this will be an N-dimensional Vector, where N is the number of classes in the model.

Returns
returns a Vector containing the null rejection thresholds for each class, an empty Vector will be returned if the model has not been trained

Definition at line 236 of file Classifier.cpp.

UINT Classifier::getNumClasses ( ) const
virtual

Gets the number of classes in trained model.

Returns
returns the number of classes in the trained model, a value of 0 will be returned if the model has not been trained

Reimplemented in SVM.

Definition at line 209 of file Classifier.cpp.

Float Classifier::getPhase ( ) const

This function returns the estimated gesture phase from the most recent prediction. This value is only relevant if the classifier supports timeseries classification.

Returns
Float representing the gesture phase value from the most likely class from the most recent prediction

Definition at line 196 of file Classifier.cpp.

Vector< MinMax > Classifier::getRanges ( ) const

Gets a Vector of the ranges used to scale the data for training and prediction, these ranges are only used if the classifier has been trained with the #useScaling flag set to true. This should be an N-dimensional Vector, where N is the number of features in your data.

Returns
returns a Vector containing the ranges used to scale the data for classification, an empty Vector will be returned if the model has not been trained

Definition at line 245 of file Classifier.cpp.

Vector< std::string > Classifier::getRegisteredClassifiers ( )
static

Returns a Vector of the names of all classifiers that have been registered with the base classifier.

Returns
Vector< string >: a Vector containing the names of the classifiers that have been registered with the base classifier

Definition at line 66 of file Classifier.cpp.

bool Classifier::getSupportsNullRejection ( ) const

Returns true if the classifier instance supports null rejection, false otherwise.

Returns
returns true if the classifier instance supports null rejection, false otherwise

Definition at line 179 of file Classifier.cpp.

bool Classifier::getTimeseriesCompatible ( ) const
inline

Indicates if the classifier can be used to classify timeseries data. If true then the classifier can accept training data in the LabelledTimeSeriesClassificationData format.

return returns true if the classifier can be used to classify timeseries data, false otherwise

Definition at line 263 of file Classifier.h.

Float Classifier::getTrainingSetAccuracy ( ) const

This function returns the estimated training set accuracy from the most recent round of training. This value is only relevant if the classifier has been trained.

Returns
Float representing the training set accuracy

Definition at line 200 of file Classifier.cpp.

bool Classifier::loadBaseSettingsFromFile ( std::fstream &  file)
protected

Loads the core base settings from a file.

Returns
returns true if the base settings were loaded, false otherwise

Definition at line 321 of file Classifier.cpp.

virtual bool Classifier::recomputeNullRejectionThresholds ( )
inlinevirtual

Recomputes the null rejection thresholds for each model.

Returns
returns true if the nullRejectionThresholds were updated successfully, false otherwise

Reimplemented in DTW, AdaBoost, ANBC, KNN, GMM, MinDist, and DecisionTree.

Definition at line 255 of file Classifier.h.

bool Classifier::reset ( )
virtual

This resets the classifier. This overrides the reset function in the MLBase base class.

Returns
returns true if the classifier was reset, false otherwise

Reimplemented from MLBase.

Reimplemented in DTW, HMM, FiniteStateMachine, ParticleClassifier, SwipeDetector, ANBC, and BAG.

Definition at line 132 of file Classifier.cpp.

bool Classifier::saveBaseSettingsToFile ( std::fstream &  file) const
protected

Saves the core base settings to a file.

Returns
returns true if the base settings were saved, false otherwise

Definition at line 274 of file Classifier.cpp.

bool Classifier::setNullRejectionCoeff ( const Float  nullRejectionCoeff)
virtual

Sets the nullRejectionCoeff, this is a multipler controlling the null rejection threshold for each class.

Parameters
nullRejectionCoeffthe new null rejection value
Returns
returns true if nullRejectionCoeff was updated successfully, false otherwise

Reimplemented in KNN, AdaBoost, and MinDist.

Definition at line 254 of file Classifier.cpp.

bool Classifier::setNullRejectionThresholds ( const VectorFloat newRejectionThresholds)
virtual

Manually sets the nullRejectionThresholds, these are the thresholds used for null rejection for each class. This needs to be called after the model has been trained. Calling the setNullRejectionCoeff or recomputeNullRejectionThresholds functions will override these values. The size of the newRejectionThresholds Vector must match the number of classes in the model.

Parameters
newRejectionThresholdsthe new rejection thresholds
Returns
returns true if nullRejectionThresholds were updated successfully, false otherwise

Definition at line 262 of file Classifier.cpp.


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