GestureRecognitionToolkit  Version: 0.1.0
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
Clusterer.h
Go to the documentation of this file.
1 
31 #ifndef GRT_CLUSTERER_HEADER
32 #define GRT_CLUSTERER_HEADER
33 
34 #include "MLBase.h"
35 
36 GRT_BEGIN_NAMESPACE
37 
38 class Clusterer : public MLBase
39 {
40 public:
44  Clusterer(void);
45 
49  virtual ~Clusterer(void);
50 
58  virtual bool deepCopyFrom(const Clusterer *clusterer){ return false; }
59 
66  bool copyBaseVariables(const Clusterer *clusterer);
67 
74  virtual bool train_(MatrixFloat &trainingData);
75 
82  virtual bool train_(ClassificationData &trainingData);
83 
90  virtual bool train_(UnlabelledData &trainingData);
91 
98  virtual bool reset();
99 
105  virtual bool clear();
106 
113  bool getConverged() const;
114 
120  UINT getNumClusters() const;
121 
127  UINT getPredictedClusterLabel() const;
128 
136  Float getMaximumLikelihood() const;
137 
145  Float getBestDistance() const;
146 
154 
162 
169 
175  std::string getClustererType() const;
176 
185  bool setNumClusters(const UINT numClusters);
186 
190  typedef std::map< std::string, Clusterer*(*)() > StringClustererMap;
191 
198  static Clusterer* createInstanceFromString( std::string const &ClustererType );
199 
205  Clusterer* createNewInstance() const;
206 
214  Clusterer* deepCopy() const;
215 
221  const Clusterer& getBaseClusterer() const;
222 
229 
230  //Tell the compiler we are explicitly using the following classes from the base class (this stops hidden overloaded virtual function warnings)
231  using MLBase::train;
232 
233 protected:
239  bool saveClustererSettingsToFile( std::fstream &file ) const;
240 
246  bool loadClustererSettingsFromFile( std::fstream &file );
247 
248  std::string clustererType;
249  UINT numClusters;
251  Float maxLikelihood;
252  Float bestDistance;
253  VectorFloat clusterLikelihoods;
254  VectorFloat clusterDistances;
255  Vector< UINT > clusterLabels;
256  bool converged;
257  Vector<MinMax> ranges;
258 
259  static StringClustererMap *getMap() {
260  if( !stringClustererMap ){ stringClustererMap = new StringClustererMap; }
261  return stringClustererMap;
262  }
263 
264 private:
265  static StringClustererMap *stringClustererMap;
266  static UINT numClustererInstances;
267 
268 };
269 
270 //These two functions/classes are used to register any new Classification Module with the Clusterer base class
271 template< typename T > Clusterer* getNewClassificationModuleInstance() { return new T; }
272 
273 template< typename T >
275 public:
276  RegisterClustererModule( const std::string &newClassificationModuleName ) {
277  getMap()->insert( std::pair< std::string, Clusterer*(*)() >(newClassificationModuleName, &getNewClassificationModuleInstance< T > ) );
278  }
279 };
280 
281 GRT_END_NAMESPACE
282 
283 #endif //GRT_CLUSTERER_HEADER
284 
virtual ~Clusterer(void)
Definition: Clusterer.cpp:79
VectorFloat getClusterLikelihoods() const
Definition: Clusterer.cpp:247
std::string getClustererType() const
Definition: Clusterer.cpp:259
virtual bool train(ClassificationData trainingData)
Definition: MLBase.cpp:88
virtual bool deepCopyFrom(const Clusterer *clusterer)
Definition: Clusterer.h:58
Clusterer(void)
Definition: Clusterer.cpp:65
bool copyBaseVariables(const Clusterer *clusterer)
Definition: Clusterer.cpp:86
bool loadClustererSettingsFromFile(std::fstream &file)
Definition: Clusterer.cpp:178
std::map< std::string, Clusterer *(*)() > StringClustererMap
Definition: Clusterer.h:190
This is the main base class that all GRT machine learning algorithms should inherit from...
UINT predictedClusterLabel
Stores the predicted cluster label from the most recent predict( )
Definition: Clusterer.h:250
Vector< UINT > getClusterLabels() const
Definition: Clusterer.cpp:255
const Clusterer & getBaseClusterer() const
Definition: Clusterer.cpp:261
Clusterer * deepCopy() const
Definition: Clusterer.cpp:40
bool saveClustererSettingsToFile(std::fstream &file) const
Definition: Clusterer.cpp:156
virtual bool reset()
Definition: Clusterer.cpp:127
UINT numClusters
Number of clusters in the model.
Definition: Clusterer.h:249
UINT getPredictedClusterLabel() const
Definition: Clusterer.cpp:236
Float getBestDistance() const
Definition: Clusterer.cpp:243
bool getConverged() const
Definition: Clusterer.cpp:229
UINT getNumClusters() const
Definition: Clusterer.cpp:234
virtual bool train_(MatrixFloat &trainingData)
Definition: Clusterer.cpp:113
static Vector< std::string > getRegisteredClusterers()
Definition: Clusterer.cpp:54
static Clusterer * createInstanceFromString(std::string const &ClustererType)
Definition: Clusterer.cpp:28
VectorFloat getClusterDistances() const
Definition: Clusterer.cpp:251
virtual bool clear()
Definition: Clusterer.cpp:141
Float getMaximumLikelihood() const
Definition: Clusterer.cpp:239
Definition: MLBase.h:70
bool setNumClusters(const UINT numClusters)
Definition: Clusterer.cpp:265
Clusterer * createNewInstance() const
Definition: Clusterer.cpp:36