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.
EvolutionaryAlgorithm< INDIVIDUAL > Class Template Reference

This class implements a template based EvolutionaryAlgorithm. More...

#include <EvolutionaryAlgorithm.h>

Inheritance diagram for EvolutionaryAlgorithm< INDIVIDUAL >:
MLBase GRTBase Observer< TrainingResult > Observer< TestInstanceResult >

Public Member Functions

 EvolutionaryAlgorithm (const UINT populationSize=0, const UINT geneSize=0)
 
virtual ~EvolutionaryAlgorithm ()
 
INDIVIDUAL & operator[] (const UINT &index)
 
virtual bool initPopulation (const UINT populationSize, const UINT geneSize)
 
virtual bool estimatePopulationFitness (const MatrixFloat &trainingData, Float &bestFitness, UINT &bestIndex)
 
virtual bool evolvePopulation ()
 
virtual Float evaluateFitness (INDIVIDUAL &individual, const MatrixFloat &trainingData)
 
virtual bool train (const MatrixFloat &trainingData)
 
UINT getPopulationSize () const
 
bool getInitialized () const
 
Vector< INDIVIDUAL > getPopulation () const
 
bool setPopulationSize (const UINT populationSize)
 
bool setMinNumIterationsNoChange (const UINT minNumIterationsNoChange)
 
bool setMaxIterations (const UINT maxIteration)
 
bool setStoreRate (const UINT storeRate)
 
bool setStoreHistory (const bool storeHistory)
 
bool setBaiseWeights (const bool baiseWeights)
 
bool setBaiseCoeff (const Float baiseCoeff)
 
bool setMutationRate (const Float mutationRate)
 
bool setMinChange (const Float minChange)
 
virtual bool setPopulation (const Vector< INDIVIDUAL > &newPopulation)
 
virtual Float generateRandomGeneValue ()
 
virtual bool customConvergenceCheck ()
 
virtual bool printBest () 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 reset ()
 
virtual bool clear ()
 
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)
 

Public Attributes

bool initialized
 
bool useElitism
 
bool storeHistory
 
bool baiseWeights
 
UINT populationSize
 
UINT geneSize
 
UINT minNumIterationsNoChange
 
UINT maxIteration
 
UINT storeRate
 
UINT bestIndividualIndex
 
Float bestIndividualFitness
 
Float mutationRate
 
Float minChange
 
Float baiseCoeff
 
Random rand
 
Vector< INDIVIDUAL > population
 
Vector< INDIVIDUAL > parents
 
Vector< IndexedDoublepopulationWeights
 
Vector< Vector< INDIVIDUAL > > populationHistory
 
Vector< IndexedDoublefitnessHistory
 
VectorFloat accumSumLookup
 

Additional Inherited Members

- Public Types inherited from MLBase
enum  BaseType {
  BASE_TYPE_NOT_SET =0, CLASSIFIER, REGRESSIFIER, CLUSTERER,
  PRE_PROCSSING, POST_PROCESSING, FEATURE_EXTRACTION, CONTEXT
}
 
- Static Public Member Functions inherited from GRTBase
static std::string getGRTVersion (bool returnRevision=true)
 
static std::string getGRTRevison ()
 
- Protected Member Functions inherited from MLBase
bool saveBaseSettingsToFile (std::fstream &file) const
 
bool loadBaseSettingsFromFile (std::fstream &file)
 
- 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

template<typename INDIVIDUAL>
class EvolutionaryAlgorithm< INDIVIDUAL >

This class implements a template based EvolutionaryAlgorithm.

Remarks
This implementation is based on Michalewicz, Zbigniew. Genetic algorithms + data structures= evolution programs. springer, 1996.

Definition at line 39 of file EvolutionaryAlgorithm.h.

Constructor & Destructor Documentation

template<typename INDIVIDUAL >
EvolutionaryAlgorithm< INDIVIDUAL >::EvolutionaryAlgorithm ( const UINT  populationSize = 0,
const UINT  geneSize = 0 
)
inline

Default Constructor, if the populationSize and geneSize parameters are greater than zero then the algorithm will be initialized.

Parameters
populationSizethe number of individuals in the population. Default value = 0
geneSizethe number of elements in each individuals gene. Default value = 0

Definition at line 49 of file EvolutionaryAlgorithm.h.

template<typename INDIVIDUAL >
virtual EvolutionaryAlgorithm< INDIVIDUAL >::~EvolutionaryAlgorithm ( )
inlinevirtual

Default Destructor.

Definition at line 70 of file EvolutionaryAlgorithm.h.

Member Function Documentation

template<typename INDIVIDUAL >
virtual bool EvolutionaryAlgorithm< INDIVIDUAL >::estimatePopulationFitness ( const MatrixFloat trainingData,
Float &  bestFitness,
UINT &  bestIndex 
)
inlinevirtual

This function estimates the populations fitness, based on the training data. It will return a reference to the bestFitness value and the index of the individual with the best fitness.

Parameters
trainingDataa reference to the trainingData that will be used to estimate the fitness
bestFitnessa reference that will return the best fitness value
bestIndexa reference that will return the index of the individual with the best fitness
Returns
returns true if the population fitness was estimated, false otherwise

Definition at line 155 of file EvolutionaryAlgorithm.h.

template<typename INDIVIDUAL >
virtual Float EvolutionaryAlgorithm< INDIVIDUAL >::evaluateFitness ( INDIVIDUAL &  individual,
const MatrixFloat trainingData 
)
inlinevirtual

This function evaluates the fitness of an individual, using the training data. This function assumes that each row in the training data is an example, each column must therefore match the geneSize.

Parameters
individuala reference to the individual you want to compute the fitness for
trainingDataa reference to the training data that will be used to compute the individual's fitness
Returns
returns the fitness of the individual

Definition at line 302 of file EvolutionaryAlgorithm.h.

template<typename INDIVIDUAL >
virtual bool EvolutionaryAlgorithm< INDIVIDUAL >::evolvePopulation ( )
inlinevirtual

This function evolves the current population, based on the fitness of each individual. You should compute the fitness of each individual first before using this function.

Returns
returns true if the population was evolved, false otherwise

Definition at line 191 of file EvolutionaryAlgorithm.h.

template<typename INDIVIDUAL >
virtual bool EvolutionaryAlgorithm< INDIVIDUAL >::initPopulation ( const UINT  populationSize,
const UINT  geneSize 
)
inlinevirtual

This function initalizes the population, setting each individual's genes to a random value in the range [0.0 1.0]. Both the populationSize and geneSize parameters must be greater than zero.

Parameters
populationSizethe number of individuals in the population
geneSizethe number of elements in each individuals gene
Returns
returns true if the population was initalized, false otherwise

Definition at line 93 of file EvolutionaryAlgorithm.h.

template<typename INDIVIDUAL >
INDIVIDUAL& EvolutionaryAlgorithm< INDIVIDUAL >::operator[] ( const UINT &  index)
inline

This operator allows you to directly access each individual in the population. The user must ensure that index is a valid number in the range of [0 populationSize-1].

Parameters
indexthe index of the individual you want to access
Returns
returns a reference to the individual in the population at the specific index

Definition at line 81 of file EvolutionaryAlgorithm.h.


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