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.
LDA.h
Go to the documentation of this file.
1 
31 #ifndef GRT_LDA_HEADER
32 #define GRT_LDA_HEADER
33 
34 #include "../../CoreModules/Classifier.h"
35 #include "../../Util/LUDecomposition.h"
36 
37 GRT_BEGIN_NAMESPACE
38 
39 class GRT_API LDAClassModel{
40 public:
41  LDAClassModel(){
42  classLabel = 0;
43  priorProb = 0;
44  }
45 
46  ~LDAClassModel(){
47 
48  }
49 
50  UINT getNumDimensions() const { return weights.getSize(); }
51 
52  UINT classLabel;
53  Float priorProb;
54  VectorDouble weights;
55 
56 };
57 
58 class GRT_API LDA : public Classifier
59 {
60 public:
64  LDA(bool useScaling=false,bool useNullRejection=true,Float nullRejectionCoeff=10.0);
65 
69  virtual ~LDA(void);
70 
77  LDA &operator=(const LDA &rhs){
78  if( this != &rhs ){
79  //LDA variables
80  this->models = rhs.models;
81 
82  //Classifier variables
83  copyBaseVariables( (Classifier*)&rhs );
84  }
85  return *this;
86  }
87 
88  //Override the base class methods
96  virtual bool deepCopyFrom(const Classifier *classifier){
97  if( classifier == NULL ) return false;
98 
99  if( this->getClassifierType() == classifier->getClassifierType() ){
100 
101  LDA *ptr = (LDA*)classifier;
102  //Clone the LDA values
103  this->models = ptr->models;
104 
105  //Clone the classifier variables
106  return copyBaseVariables( classifier );
107  }
108  return false;
109  }
110 
118  virtual bool train(ClassificationData trainingData);
119 
127  virtual bool predict(VectorDouble inputVector);
128 
136  virtual bool saveModelToFile( std::fstream &file ) const;
137 
145  virtual bool loadModelFromFile( std::fstream &file );
146 
147  //Getters
148  Vector< LDAClassModel > getModels(){ if( trained ){ return models; } return Vector< LDAClassModel >(); }
149 
150  //Setters
151 
152  //Tell the compiler we are using the base class train method to stop hidden virtual function warnings
153  using MLBase::saveModelToFile;
154  using MLBase::loadModelFromFile;
155 
156 private:
157  MatrixFloat computeBetweenClassScatterMatrix( ClassificationData &data );
158  MatrixFloat computeWithinClassScatterMatrix( ClassificationData &data );
159 
161 };
162 
163 GRT_END_NAMESPACE
164 
165 #endif //GRT_LDA_HEADER
166 
virtual bool predict(VectorFloat inputVector)
Definition: MLBase.cpp:113
Definition: LDA.h:58
std::string getClassifierType() const
Definition: Classifier.cpp:161
virtual bool train(ClassificationData trainingData)
Definition: MLBase.cpp:89
LDA & operator=(const LDA &rhs)
Definition: LDA.h:77
bool copyBaseVariables(const Classifier *classifier)
Definition: Classifier.cpp:93
virtual bool deepCopyFrom(const Classifier *classifier)
Definition: LDA.h:96