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.
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:
45  Clusterer( const std::string &id = "" );
46 
50  virtual ~Clusterer(void);
51 
59  virtual bool deepCopyFrom(const Clusterer *clusterer){ return false; }
60 
67  bool copyBaseVariables(const Clusterer *clusterer);
68 
75  virtual bool train_(MatrixFloat &trainingData) override;
76 
83  virtual bool train_(ClassificationData &trainingData) override;
84 
91  virtual bool train_(UnlabelledData &trainingData) override;
92 
99  virtual bool reset() override;
100 
106  virtual bool clear() override;
107 
113  UINT getNumClusters() const;
114 
120  UINT getPredictedClusterLabel() const;
121 
129  Float getMaximumLikelihood() const;
130 
138  Float getBestDistance() const;
139 
146  VectorFloat getClusterLikelihoods() const;
147 
154  VectorFloat getClusterDistances() const;
155 
161  Vector< UINT > getClusterLabels() const;
162 
163  GRT_DEPRECATED_MSG( "getClustererType() is deprecated, use getId() or getBaseId() instead", std::string getClustererType() const );
164 
173  bool setNumClusters(const UINT numClusters);
174 
178  typedef std::map< std::string, Clusterer*(*)() > StringClustererMap;
179 
186  static Clusterer* create( std::string const &id );
187 
193  Clusterer* create() const;
194 
195  GRT_DEPRECATED_MSG( "createNewInstance is deprecated, use create instead.", Clusterer* createNewInstance() const );
196  GRT_DEPRECATED_MSG( "createInstanceFromString is deprecated, use create instead.", static Clusterer* createInstanceFromString( const std::string &id ) );
197 
205  Clusterer* deepCopy() const;
206 
212  const Clusterer& getBaseClusterer() const;
213 
219  static Vector< std::string > getRegisteredClusterers();
220 
221  //Tell the compiler we are explicitly using the following classes from the base class (this stops hidden overloaded virtual function warnings)
222  using MLBase::train;
223 
224 protected:
230  bool saveClustererSettingsToFile( std::fstream &file ) const;
231 
237  bool loadClustererSettingsFromFile( std::fstream &file );
238 
239  UINT numClusters;
241  Float maxLikelihood;
242  Float bestDistance;
243  VectorFloat clusterLikelihoods;
244  VectorFloat clusterDistances;
245  Vector< UINT > clusterLabels;
246  bool converged;
247  Vector<MinMax> ranges;
248 
249  static StringClustererMap *getMap() {
250  if( !stringClustererMap ){ stringClustererMap = new StringClustererMap; }
251  return stringClustererMap;
252  }
253 
254 private:
255  static StringClustererMap *stringClustererMap;
256  static UINT numClustererInstances;
257 
258 };
259 
260 template< typename T > Clusterer* createNewClustererModuleInstance() { return new T; }
261 
266 template< typename T >
268 public:
269  RegisterClustererModule( const std::string &newModuleId ) {
270  getMap()->insert( std::pair< std::string, Clusterer*(*)() >(newModuleId, &createNewClustererModuleInstance< T > ) );
271  }
272 };
273 
274 GRT_END_NAMESPACE
275 
276 #endif //GRT_CLUSTERER_HEADER
277 
virtual bool reset()
Definition: MLBase.cpp:147
Clusterer * createNewClustererModuleInstance()
Returns a pointer to a new instance of the template class, the caller is responsible for deleting the...
Definition: Clusterer.h:260
virtual bool train(ClassificationData trainingData)
Definition: MLBase.cpp:107
virtual bool deepCopyFrom(const Clusterer *clusterer)
Definition: Clusterer.h:59
std::map< std::string, Clusterer *(*)() > StringClustererMap
Definition: Clusterer.h:178
UINT predictedClusterLabel
Stores the predicted cluster label from the most recent predict( )
Definition: Clusterer.h:240
This class provides an interface for classes to register themselves with the clusterer base class...
Definition: Clusterer.h:267
UINT numClusters
Number of clusters in the model.
Definition: Clusterer.h:239
virtual bool clear()
Definition: MLBase.cpp:149
virtual bool train_(ClassificationData &trainingData)
Definition: MLBase.cpp:109
GRT_DEPRECATED_MSG("saveModelToFile(std::string filename) is deprecated, use save(const std::string &filename) instead", virtual bool saveModelToFile(const std::string &filename) const )
This is the main base class that all GRT machine learning algorithms should inherit from...
Definition: MLBase.h:72