GestureRecognitionToolkit  Version: 0.2.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 GRT_API 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 
153  VectorFloat getClusterLikelihoods() const;
154 
161  VectorFloat getClusterDistances() const;
162 
168  Vector< UINT > getClusterLabels() const;
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 
228  static Vector< std::string > getRegisteredClusterers();
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 bool reset()
Definition: MLBase.cpp:125
virtual bool train(ClassificationData trainingData)
Definition: MLBase.cpp:89
virtual bool deepCopyFrom(const Clusterer *clusterer)
Definition: Clusterer.h:58
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
UINT numClusters
Number of clusters in the model.
Definition: Clusterer.h:249
virtual bool clear()
Definition: MLBase.cpp:127
virtual bool train_(ClassificationData &trainingData)
Definition: MLBase.cpp:91
Definition: MLBase.h:70