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.
HierarchicalClustering.h
Go to the documentation of this file.
1 
29 #ifndef GRT_HIERARCHICAL_CLUSTERING_HEADER
30 #define GRT_HIERARCHICAL_CLUSTERING_HEADER
31 
32 #include "../../CoreModules/Clusterer.h"
33 
34 GRT_BEGIN_NAMESPACE
35 
37 public:
38  ClusterInfo(){
39  uniqueClusterID = 0;
40  clusterVariance = 0;
41  }
42  ClusterInfo(const ClusterInfo &rhs){
43  *this = rhs;
44  }
45  ~ClusterInfo(){
46 
47  }
48 
49  ClusterInfo& operator=(const ClusterInfo &rhs){
50 
51  if( this != &rhs ){
52  this->uniqueClusterID = rhs.uniqueClusterID;
53  this->clusterVariance = rhs.clusterVariance;
54  this->indexs = rhs.indexs;
55  }
56 
57  return *this;
58  }
59 
60  UINT& operator[](const UINT &i){
61  return indexs[i];
62  }
63 
64  UINT operator[](const UINT &i) const{
65  return indexs[i];
66  }
67 
68  void addSampleToCluster(UINT i){
69  indexs.push_back( i );
70  }
71 
72  UINT getUniqueClusterID() const{
73  return uniqueClusterID;
74  }
75 
76  UINT getNumSamplesInCluster() const{
77  return (UINT)indexs.size();
78  }
79 
80  Float getClusterVariance() const{
81  return clusterVariance;
82  }
83 
84  unsigned int uniqueClusterID;
85  Float clusterVariance;
86  Vector< UINT > indexs;
87 };
88 
90 public:
91  ClusterLevel(){
92  level = 0;
93  }
94 
95  ClusterLevel(const ClusterLevel &rhs){
96  this->level = rhs.level;
97  this->clusters = rhs.clusters;
98  }
99 
100  ~ClusterLevel(){
101 
102  }
103 
104  ClusterLevel& operator=(const ClusterLevel &rhs){
105 
106  if( this != &rhs ){
107  this->level = rhs.level;
108  this->clusters = rhs.clusters;
109  }
110 
111  return *this;
112  }
113 
114  ClusterInfo& operator[](const UINT &i){
115  return clusters[i];
116  }
117 
118  ClusterInfo operator[](const UINT &i) const{
119  return clusters[i];
120  }
121 
122  UINT getLevel() const{
123  return level;
124  }
125 
126  UINT getNumClusters() const{
127  return (UINT)clusters.size();
128  }
129 
130  unsigned int level;
131  Vector< ClusterInfo > clusters;
132 };
133 
135 
136 public:
141 
148 
152  virtual ~HierarchicalClustering();
153 
161 
169  virtual bool deepCopyFrom(const Clusterer *clusterer);
170 
177  virtual bool reset();
178 
184  virtual bool clear();
185 
192  virtual bool train_(MatrixFloat &trainingData);
193 
200  virtual bool train_(ClassificationData &trainingData);
201 
208  virtual bool train_(UnlabelledData &trainingData);
209 
217  virtual bool saveModelToFile( std::fstream &file ) const;
218 
226  virtual bool loadModelFromFile( std::fstream &file );
227 
228  bool printModel();
229 
230  Vector< ClusterLevel > getClusters(){ return clusters; }
231 
232  //Tell the compiler we are using the base class train method to stop hidden virtual function warnings
235 
236 protected:
237  inline Float SQR(const Float &a) {return a*a;};
238  Float squaredEuclideanDistance(const Float *a,const Float *b);
239  Float computeClusterDistance( const ClusterInfo &clusterA, const ClusterInfo &clusterB );
240  Float computeClusterVariance( const ClusterInfo &cluster, const MatrixFloat &data );
241 
242  UINT M; //Number of training examples
243  UINT N; //Number of dimensions
244  Vector< ClusterLevel > clusters;
245  MatrixFloat distanceMatrix; //The distance matrix
246 
247 private:
249 
250 };
251 
252 GRT_END_NAMESPACE
253 
254 #endif //GRT_HIERARCHICAL_CLUSTERING_HEADER
virtual bool loadModelFromFile(std::fstream &file)
virtual bool saveModelToFile(std::fstream &file) const
virtual bool train_(MatrixFloat &trainingData)
virtual bool saveModelToFile(std::string filename) const
Definition: MLBase.cpp:146
virtual bool loadModelFromFile(std::string filename)
Definition: MLBase.cpp:168
virtual bool deepCopyFrom(const Clusterer *clusterer)
HierarchicalClustering & operator=(const HierarchicalClustering &rhs)