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.
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 
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 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
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 
Definition: LDA.h:58
std::string getClassifierType() const
Definition: Classifier.cpp:160
virtual bool predict(VectorDouble inputVector)
Definition: LDA.cpp:199
unsigned int getSize() const
Definition: Vector.h:193
LDA & operator=(const LDA &rhs)
Definition: LDA.h:77
virtual bool train(ClassificationData trainingData)
Definition: LDA.cpp:43
LDA(bool useScaling=false, bool useNullRejection=true, Float nullRejectionCoeff=10.0)
Definition: LDA.cpp:25
virtual bool saveModelToFile(std::string filename) const
Definition: MLBase.cpp:146
bool copyBaseVariables(const Classifier *classifier)
Definition: Classifier.cpp:92
virtual ~LDA(void)
Definition: LDA.cpp:39
virtual bool loadModelFromFile(std::string filename)
Definition: MLBase.cpp:168
virtual bool saveModelToFile(std::fstream &file) const
Definition: LDA.cpp:254
virtual bool loadModelFromFile(std::fstream &file)
Definition: LDA.cpp:291
virtual bool deepCopyFrom(const Classifier *classifier)
Definition: LDA.h:96