Darwin  1.10(beta)
drwnPCA.h
1 /******************************************************************************
2 ** DARWIN: A FRAMEWORK FOR MACHINE LEARNING RESEARCH AND DEVELOPMENT
3 ** Distributed under the terms of the BSD license (see the LICENSE file)
4 ** Copyright (c) 2007-2017, Stephen Gould
5 ** All rights reserved.
6 **
7 ******************************************************************************
8 ** FILENAME: drwnPCA.h
9 ** AUTHOR(S): Stephen Gould <stephen.gould@anu.edu.au>
10 **
11 *****************************************************************************/
12 
13 #pragma once
14 
15 #include <vector>
16 #include <limits>
17 
18 #include "Eigen/Core"
19 
20 #include "drwnBase.h"
21 #include "drwnFeatureTransform.h"
22 #include "drwnSuffStats.h"
23 
24 using namespace std;
25 using namespace Eigen;
26 
27 // drwnPCA class --------------------------------------------------------------
54 
56  private:
57  int _numOutputDims;
58  double _energyThreshold;
59  bool _doNormalization;
60 
61  VectorXd _translation;
62  MatrixXd _projection;
63 
64  public:
66  drwnPCA();
69  drwnPCA(const drwnSuffStats& stats, double energyThreshold = 1.0, bool doNormalization = true);
71  drwnPCA(const drwnPCA& fw);
72  ~drwnPCA();
73 
74  // access functions
75  const char *type() const { return "drwnPCA"; }
76  drwnPCA *clone() const { return new drwnPCA(*this); }
77 
78  // i/o
79  void clear();
80  bool save(drwnXMLNode& node) const;
81  bool load(drwnXMLNode& node);
82 
83  // input/output size
85  int numInputs() const { return _projection.cols(); }
87  int numOutputs() const { return _projection.rows(); }
88 
89  // training
93  double train(const drwnSuffStats& stats);
94  double train(const vector<vector<double> >& features);
95  double train(const vector<vector<double> >& features, const drwnFeatureTransform& xform);
96 
97  // evaluation
99  void transform(const vector<double>& x, vector<double>& y) const;
100 };
virtual void transform(vector< double > &x) const
transforms a feature vector in-place
Definition: drwnFeatureTransform.cpp:57
Implements the interface for a generic feature transforms possibly with learned parameters, e.g., PCA (unsupervised) or LDA (supervised).
Definition: drwnFeatureTransform.h:31
virtual double train(const vector< vector< double > > &features)=0
Estimate the parameters of the features transformation. This function must be implemented in the deri...
int numOutputs() const
feature vector size for the output space
Definition: drwnPCA.h:87
int numInputs() const
feature vector size for the input space
Definition: drwnPCA.h:85
Implements interface for unsupervised feature transforms (i.e, without class labels).
Definition: drwnFeatureTransform.h:118
Implements a class for accumulating first- and second-order sufficient statistics (moments)...
Definition: drwnSuffStats.h:43
Principal component analysis feature transformation.
Definition: drwnPCA.h:55
drwnPCA * clone() const
returns a copy of the class usually implemented as virtual Foo* clone() { return new Foo(*this); } ...
Definition: drwnPCA.h:76
const char * type() const
returns object type as a string (e.g., Foo::type() { return "Foo"; })
Definition: drwnPCA.h:75