Copiste  0.1
 All Classes Functions Variables Enumerations Friends Pages
pcatransformer.h
1 /*
2  * This file is part of Copiste.
3  *
4  * Copiste is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Copiste is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Copiste. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 
19 #ifndef INCLUDED_PCATRANSFORMERH
20 #define INCLUDED_PCATRANSFORMERH
21 
22 class PCATransformer;
23 
24 #include <Eigen/Dense>
25 #include <sstream>
26 
27 #include "algo/corpus.h"
28 
29 using namespace Eigen;
30 
33 {
34  public:
36  PCATransformer(bool debug = false);
37 
39  void computePCA(Corpus* corpus);
40 
42  bool load(string filename);
43 
45  bool save(string filename);
46 
48  vector<float> transform(vector<float> input);
49 
51  Corpus* transform(const Corpus &corpus, int coord = 2);
52 
54  static string serializeMatrix(MatrixXf m);
55 
57  static MatrixXf readMatrix(string m, int nbRows = 1, int nbCols = 1);
58 
59 
60  private:
61  VectorXf mEigenValues;
62  MatrixXf mEigenVectors;
63  MatrixXf mTransform;
64  MatrixXf s;
65 
66  VectorXf mMean;
67 
68  bool mDebug;
69 };
70 
71 #endif
72