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.
|
Public Types | |
enum | TrainingAlgorithm { ONLINE_GRADIENT_DESCENT =0 } |
Public Types inherited from Regressifier | |
typedef std::map< std::string, Regressifier *(*)() > | StringRegressifierMap |
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 | |
MLP () | |
MLP (const MLP &rhs) | |
virtual | ~MLP () |
MLP & | operator= (const MLP &rhs) |
virtual bool | deepCopyFrom (const Regressifier *regressifier) |
virtual bool | train_ (ClassificationData &trainingData) |
virtual bool | train_ (RegressionData &trainingData) |
virtual bool | predict_ (VectorFloat &inputVector) |
virtual bool | clear () |
virtual bool | print () const |
virtual bool | save (std::fstream &file) const |
virtual bool | load (std::fstream &file) |
UINT | getNumClasses () const |
bool | init (const UINT numInputNeurons, const UINT numHiddenNeurons, const UINT numOutputNeurons) |
bool | init (const UINT numInputNeurons, const UINT numHiddenNeurons, const UINT numOutputNeurons, const Neuron::Type inputLayerActivationFunction, const Neuron::Type hiddenLayerActivationFunction, const Neuron::Type outputLayerActivationFunction) |
void | printNetwork () const |
bool | checkForNAN () const |
std::string | activationFunctionToString (const Neuron::Type activationFunction) const |
Neuron::Type | activationFunctionFromString (const std::string activationName) const |
bool | validateActivationFunction (const Neuron::Type avactivationFunction) const |
UINT | getNumInputNeurons () const |
UINT | getNumHiddenNeurons () const |
UINT | getNumOutputNeurons () const |
UINT | getNumRandomTrainingIterations () const |
Neuron::Type | getInputLayerActivationFunction () const |
Neuron::Type | getHiddenLayerActivationFunction () const |
Neuron::Type | getOutputLayerActivationFunction () const |
Float | getTrainingRate () const |
Float | getMomentum () const |
Float | getGamma () const |
Float | getTrainingError () const |
bool | getClassificationModeActive () const |
bool | getRegressionModeActive () const |
Vector< Neuron > | getInputLayer () const |
Vector< Neuron > | getHiddenLayer () const |
Vector< Neuron > | getOutputLayer () const |
Vector< VectorFloat > | getTrainingLog () const |
bool | getNullRejectionEnabled () const |
Float | getNullRejectionCoeff () const |
Float | getNullRejectionThreshold () const |
Float | getMaximumLikelihood () const |
VectorFloat | getClassLikelihoods () const |
VectorFloat | getClassDistances () const |
UINT | getPredictedClassLabel () const |
bool | setInputLayerActivationFunction (const Neuron::Type activationFunction) |
bool | setHiddenLayerActivationFunction (const Neuron::Type activationFunction) |
bool | setOutputLayerActivationFunction (const Neuron::Type activationFunction) |
bool | setTrainingRate (const Float trainingRate) |
bool | setMomentum (const Float momentum) |
bool | setGamma (const Float gamma) |
GRT_DEPRECATED_MSG ("setNumRandomTrainingIterations() is deprecated, use setNumRestarts() instead", bool setNumRandomTrainingIterations(const UINT numRandomTrainingIterations)) | |
bool | setNullRejection (const bool useNullRejection) |
bool | setNullRejectionCoeff (const Float nullRejectionCoeff) |
Public Member Functions inherited from Regressifier | |
Regressifier (const std::string &id="") | |
virtual | ~Regressifier (void) |
bool | copyBaseVariables (const Regressifier *regressifier) |
virtual bool | reset () override |
VectorFloat | getRegressionData () const |
Vector< MinMax > | getInputRanges () const |
Vector< MinMax > | getOutputRanges () const |
Regressifier * | deepCopy () const |
const Regressifier & | getBaseRegressifier () const |
Regressifier * | create () const |
GRT_DEPRECATED_MSG ("createNewInstance is deprecated, use create() instead.", Regressifier *createNewInstance() const ) | |
GRT_DEPRECATED_MSG ("createInstanceFromString(id) is deprecated, use create(id) instead.", static Regressifier *createInstanceFromString(const std::string &id)) | |
GRT_DEPRECATED_MSG ("getRegressifierType is deprecated, use getId() instead", std::string getRegressifierType() 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 (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 (MatrixFloat inputMatrix) |
virtual bool | predict_ (MatrixFloat &inputMatrix) |
virtual bool | map (VectorFloat inputVector) |
virtual bool | map_ (VectorFloat &inputVector) |
virtual bool | save (const std::string &filename) const |
virtual bool | load (const std::string &filename) |
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) |
MLBase * | getMLBasePointer () |
const MLBase * | getMLBasePointer () const |
Vector< TrainingResult > | getTrainingResults () 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) |
GRTBase * | getGRTBasePointer () |
const GRTBase * | getGRTBasePointer () 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 std::string | getId () |
Static Public Member Functions inherited from Regressifier | |
static Vector< std::string > | getRegisteredRegressifiers () |
static Regressifier * | create (const std::string &id) |
Static Public Member Functions inherited from GRTBase | |
static std::string | getGRTVersion (bool returnRevision=true) |
static std::string | getGRTRevison () |
Protected Member Functions | |
bool | isNAN (const Float &v) const |
bool | setOutputTargets () |
bool | trainModel (RegressionData &trainingData) |
bool | trainOnlineGradientDescentClassification (const RegressionData &trainingData, const RegressionData &validationData) |
bool | trainOnlineGradientDescentRegression (const RegressionData &trainingData, const RegressionData &validationData) |
bool | loadLegacyModelFromFile (std::fstream &file) |
Float | back_prop (const VectorFloat &inputVector, const VectorFloat &targetVector, const Float alpha, const Float beta) |
VectorFloat | feedforward (VectorFloat data) |
void | feedforward (const VectorFloat &data, VectorFloat &inputNeuronsOutput, VectorFloat &hiddenNeuronsOutput, VectorFloat &outputNeuronsOutput) |
Protected Member Functions inherited from Regressifier | |
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) |
Protected Attributes | |
UINT | numInputNeurons |
UINT | numHiddenNeurons |
UINT | numOutputNeurons |
Neuron::Type | inputLayerActivationFunction |
Neuron::Type | hiddenLayerActivationFunction |
Neuron::Type | outputLayerActivationFunction |
UINT | trainingMode |
Float | momentum |
Float | gamma |
Float | trainingError |
MinMax | outputTargets |
bool | initialized |
Vector< Neuron > | inputLayer |
Vector< Neuron > | hiddenLayer |
Vector< Neuron > | outputLayer |
Vector< VectorFloat > | trainingErrorLog |
bool | classificationModeActive |
bool | useNullRejection |
UINT | predictedClassLabel |
Float | nullRejectionThreshold |
Float | nullRejectionCoeff |
Float | maxLikelihood |
VectorFloat | classLikelihoods |
VectorFloat | inputNeuronsOutput |
VectorFloat | hiddenNeuronsOutput |
VectorFloat | outputNeuronsOutput |
VectorFloat | deltaO |
VectorFloat | deltaH |
Protected Attributes inherited from Regressifier | |
std::string | regressifierType |
VectorFloat | regressionData |
Vector< MinMax > | inputVectorRanges |
Vector< MinMax > | targetVectorRanges |
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< TrainingResult > | trainingResults |
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 |
Additional Inherited Members | |
Static Protected Member Functions inherited from Regressifier | |
static StringRegressifierMap * | getMap () |
MLP::MLP | ( | const MLP & | rhs | ) |
Neuron::Type MLP::activationFunctionFromString | ( | const std::string | activationName | ) | const |
std::string MLP::activationFunctionToString | ( | const Neuron::Type | activationFunction | ) | const |
Gets a string representation of the activation function
activationFunction | the activation function you want to convert to a string |
|
protected |
Performs one round of back propagation, using the training example and target Vector
inputVector | the input Vector to use for back propagation |
targetVector | the target Vector to use for back propagation |
alpha | the training rate |
beta | the momentum |
bool MLP::checkForNAN | ( | ) | const |
|
virtual |
Clears any previous model or settings.
Reimplemented from Regressifier.
|
virtual |
This is required for the Gesture Recognition Pipeline for when the pipeline.setRegressifier(...) method is called. It clones the data from the Base Class Regressifier pointer (which should be pointing to an MLP instance) into this instance
regressifier | a pointer to the Regressifier Base Class, this should be pointing to another MLP instance |
Reimplemented from Regressifier.
|
protected |
|
protected |
Performs the feedforward step for back propagation, using the input data
data | the input Vector to use for the feedforward |
inputNeuronsOutput | the results of the input layer |
hiddenNeuronsOutput | the results of the hidden layer |
outputNeuronsOutput | the results of the output layer |
VectorFloat MLP::getClassDistances | ( | ) | const |
bool MLP::getClassificationModeActive | ( | ) | const |
VectorFloat MLP::getClassLikelihoods | ( | ) | const |
Float MLP::getGamma | ( | ) | const |
Neuron::Type MLP::getHiddenLayerActivationFunction | ( | ) | const |
|
static |
Neuron::Type MLP::getInputLayerActivationFunction | ( | ) | const |
Float MLP::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 is only relevant if the MLP is in classification mode. This value will return 0 if a prediction has not been made.
Float MLP::getMomentum | ( | ) | const |
Float MLP::getNullRejectionCoeff | ( | ) | const |
Returns the current null rejection coefficient value. The null rejection coefficient is a multipler controlling the null rejection threshold for each class. This is only relevant if the MLP is in classification mode.
bool MLP::getNullRejectionEnabled | ( | ) | const |
Float MLP::getNullRejectionThreshold | ( | ) | const |
Returns the current null rejection threshold value. The null rejection threshold is value controlling if a classification result should be rejected or accepted. This is only relevant if the MLP is in classification mode.
UINT MLP::getNumClasses | ( | ) | const |
UINT MLP::getNumHiddenNeurons | ( | ) | const |
UINT MLP::getNumInputNeurons | ( | ) | const |
UINT MLP::getNumOutputNeurons | ( | ) | const |
UINT MLP::getNumRandomTrainingIterations | ( | ) | const |
Gets the number of random training iterations that should be performed during the training phase. The MLP back propagation algorithm starts with random values, and the accuracy of a trained model can depend on which random values the algorithm started with. The GRT MLP algorithm therefore trains a number of models and picks the best one. This value therefore represents the number of random training iterations that should be used.
Neuron::Type MLP::getOutputLayerActivationFunction | ( | ) | const |
UINT MLP::getPredictedClassLabel | ( | ) | const |
bool MLP::getRegressionModeActive | ( | ) | const |
Float MLP::getTrainingError | ( | ) | const |
Vector< VectorFloat > MLP::getTrainingLog | ( | ) | const |
Returns a Vector of VectorFloat representing the training log for each random round of training. The outer Vector represents each round and the inner Vector represents each epoch in that round.
Float MLP::getTrainingRate | ( | ) | const |
MLP::GRT_DEPRECATED_MSG | ( | "setNumRandomTrainingIterations() is | deprecated, |
use setNumRestarts() instead" | , | ||
bool | setNumRandomTrainingIterationsconst UINT numRandomTrainingIterations | ||
) |
Setting this value to a high number (i.e. 100) will most likely give you a better model, however it will take much longer to train the overall model. Setting this value to a low number (i.e. 5) will make the training process much faster, but you might not get the best model.
numRandomTrainingIterations | the number of times you want to randomly train the MLP model to search for the best results |
bool MLP::init | ( | const UINT | numInputNeurons, |
const UINT | numHiddenNeurons, | ||
const UINT | numOutputNeurons | ||
) |
Initializes the MLP for training. This should be called before the MLP is trained. The number of input neurons should match the number of input dimensions in your training data. The number of output neurons should match the number of target dimensions in your training data. The number of hidden units should be chosen by the user, a common rule of thumb is to set this as a value somewhere between the number of input neurons and the number of output neurons. Initializaling the MLP will clear any previous model or settings.
This function calls the other init function below, passing in the layer activation functions.
numInputNeurons | the number of input neurons (should match the number of input dimensions in your training data) |
numHiddenNeurons | the number of hidden neurons |
numOutputNeurons | the number of output neurons (should match the number of target dimensions in your training data) |
bool MLP::init | ( | const UINT | numInputNeurons, |
const UINT | numHiddenNeurons, | ||
const UINT | numOutputNeurons, | ||
const Neuron::Type | inputLayerActivationFunction, | ||
const Neuron::Type | hiddenLayerActivationFunction, | ||
const Neuron::Type | outputLayerActivationFunction | ||
) |
Initializes the MLP for training. This should be called before the MLP is trained. The number of input neurons should match the number of input dimensions in your training data. The number of output neurons should match the number of target dimensions in your training data. The number of hidden units should be chosen by the user, a common rule of thumb is to set this as a value somewhere between the number of input neurons and the number of output neurons. The activation functions should be one of the Neuron ActivationFunctions enums. Initializaling the MLP will clear any previous model or settings.
numInputNeurons | the number of input neurons (should match the number of input dimensions in your training data) |
numHiddenNeurons | the number of hidden neurons |
numOutputNeurons | the number of output neurons (should match the number of target dimensions in your training data) |
inputLayerActivationFunction | the activation function to use for the input layer |
hiddenLayerActivationFunction | the activation function to use for the input layer |
outputLayerActivationFunction | the activation function to use for the input layer |
|
virtual |
|
virtual |
This function either predicts the class of the input Vector (if the MLP is in Classification Mode), or it performs regression using the MLP model.
inputVector | the input Vector to classify or perform regression on |
Reimplemented from MLBase.
|
virtual |
void MLP::printNetwork | ( | ) | const |
|
virtual |
bool MLP::setGamma | ( | const Float | gamma | ) |
Sets the gamma parameter for the Neurons. Gamma must be greater than zero. If the MLP instance has been initialized then this function will also call the init function to reinitialize the instance.
gamma | the gamma value for each Neuron, gamma must be greater than zero |
bool MLP::setHiddenLayerActivationFunction | ( | const Neuron::Type | activationFunction | ) |
This function sets the activation function for all the Neurons in the hidden layer. If the MLP instance has been initialized then this function will also call the init function to reinitialize the instance.
activationFunction | the activation function for the hidden layer, this should be one of the Neuron ActivationFunctions enums |
bool MLP::setInputLayerActivationFunction | ( | const Neuron::Type | activationFunction | ) |
This function sets the activation function for all the Neurons in the input layer. If the MLP instance has been initialized then this function will also call the init function to reinitialize the instance.
activationFunction | the activation function for the input layer, this should be one of the Neuron ActivationFunctions enums |
bool MLP::setMomentum | ( | const Float | momentum | ) |
Sets the momentum parameter. This is used to update the weights at each step of the stochastic gradient descent. The momentum parameter is normally set between [0.1 0.9], with 0.5 being a common value.
momentum | the momentum value used during the training phase, must be greater than zero |
bool MLP::setNullRejection | ( | const bool | useNullRejection | ) |
Sets if null rejection should be used for the real-time prediction. This is only used if the MLP is in classificationMode.
useNullRejection | if true then null rejection will be used |
bool MLP::setNullRejectionCoeff | ( | const Float | nullRejectionCoeff | ) |
This function lets you manually control the null rejection threshold. Any class with a prediction value less than the null rejection threshold will be rejected, setting the predicted class label to 0.
This is only used if the MLP is in classificationMode.
nullRejectionCoeff | the new null rejection threshold |
bool MLP::setOutputLayerActivationFunction | ( | const Neuron::Type | activationFunction | ) |
This function sets the activation function for all the Neurons in the output layer. If the MLP instance has been initialized then this function will also call the init function to reinitialize the instance.
activationFunction | the activation function for the output layer, this should be one of the Neuron ActivationFunctions enums |
bool MLP::setTrainingRate | ( | const Float | trainingRate | ) |
Sets the training rate, which controls the learning rate parameter. This is used to update the weights at each step of the stochastic gradient descent. The learningRate value must be greater than zero, a value of 0.1 normally works well. If you find the MLP fails to train with this value then try setting the learning rate to a smaller value (for example 0.01).
trainingRate | the learningRate value used during the training phase, must be greater than zero |
|
virtual |
This trains the MLP model, using the labelled classification data. Calling this function sets the MLP into Classification Model.
trainingData | the training data that will be used to train the classification model |
Reimplemented from MLBase.
|
virtual |
This trains the MLP model, using the labelled regression data. Calling this function sets the MLP into Regression Model.
trainingData | the training data that will be used to train the regression model |
Reimplemented from MLBase.
bool MLP::validateActivationFunction | ( | const Neuron::Type | avactivationFunction | ) | const |