SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PCA.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 1999-2008 Gunnar Raetsch
8  * Written (W) 1999-2008,2011 Soeren Sonnenburg
9  * Written (W) 2014 Parijat Mazumdar
10  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
11  * Copyright (C) 2011 Berlin Institute of Technology
12  */
13 
14 #ifndef PCA_H_
15 #define PCA_H_
16 
17 #include <shogun/lib/config.h>
18 
19 #ifdef HAVE_EIGEN3
21 #include <stdio.h>
24 #include <shogun/lib/common.h>
25 
26 namespace shogun
27 {
30 {
34  AUTO = 10,
36  SVD = 20,
40  EVD = 30
41 };
42 
45 {
52 };
53 
56 {
67 };
68 
116 {
117  public:
118 
127  CPCA(bool do_whitening=false, EPCAMode mode=FIXED_NUMBER, float64_t thresh=1e-6,
128  EPCAMethod method=AUTO, EPCAMemoryMode mem_mode=MEM_REALLOCATE);
129 
136  CPCA(EPCAMethod method, bool do_whitening=false, EPCAMemoryMode mem=MEM_REALLOCATE);
137 
139  virtual ~CPCA();
140 
144  virtual bool init(CFeatures* features);
145 
147  virtual void cleanup();
148 
154 
160 
165 
169 
173 
175  virtual const char* get_name() const { return "PCA"; }
176 
178  virtual EPreprocessorType get_type() const { return P_PCA; }
179 
182 
187 
191  void set_eigenvalue_zero_tolerance(float64_t eigenvalue_zero_tolerance=1e-15);
192 
197 
198  protected:
199 
200  void init();
201 
202  protected:
203 
207  int32_t num_dim;
209  int32_t num_old_dim;
231 };
232 }
233 #endif // HAVE_EIGEN3
234 #endif // PCA_H_
void set_memory_mode(EPCAMemoryMode e)
Definition: PCA.cpp:372
the class DimensionReductionPreprocessor, a base class for preprocessors used to lower the dimensiona...
EPCAMemoryMode m_mem_mode
Definition: PCA.h:223
SGVector< float64_t > m_mean_vector
Definition: PCA.h:211
int32_t num_old_dim
Definition: PCA.h:209
EPreprocessorType
Definition: Preprocessor.h:32
EPCAMode m_mode
Definition: PCA.h:219
void set_eigenvalue_zero_tolerance(float64_t eigenvalue_zero_tolerance=1e-15)
Definition: PCA.cpp:377
EPCAMemoryMode
Definition: PCA.h:55
virtual void cleanup()
Definition: PCA.cpp:273
SGVector< float64_t > m_eigenvalues_vector
Definition: PCA.h:213
float64_t m_thresh
Definition: PCA.h:221
float64_t get_eigenvalue_zero_tolerance() const
Definition: PCA.cpp:382
virtual SGVector< float64_t > apply_to_feature_vector(SGVector< float64_t > vector)
Definition: PCA.cpp:335
CPCA(bool do_whitening=false, EPCAMode mode=FIXED_NUMBER, float64_t thresh=1e-6, EPCAMethod method=AUTO, EPCAMemoryMode mem_mode=MEM_REALLOCATE)
Definition: PCA.cpp:29
void init()
Definition: PCA.cpp:49
SGMatrix< float64_t > m_transformation_matrix
Definition: PCA.h:205
virtual EPreprocessorType get_type() const
Definition: PCA.h:178
virtual const char * get_name() const
Definition: PCA.h:175
SGVector< float64_t > get_mean()
Definition: PCA.cpp:362
int32_t num_dim
Definition: PCA.h:207
bool m_initialized
Definition: PCA.h:215
double float64_t
Definition: common.h:50
bool m_whitening
Definition: PCA.h:217
EPCAMethod
Definition: PCA.h:29
EPCAMethod m_method
Definition: PCA.h:225
SGVector< float64_t > get_eigenvalues()
Definition: PCA.cpp:357
virtual ~CPCA()
Definition: PCA.cpp:83
The class Features is the base class of all feature objects.
Definition: Features.h:68
Preprocessor PCA performs principial component analysis on input feature vectors/matrices. When the init method in PCA is called with proper feature matrix X (with say N number of vectors and D feature dimension), a transformation matrix is computed and stored internally. This transformation matrix is then used to transform all D-dimensional feature vectors or feature matrices (with D feature dimensions) supplied via apply_to_feature_matrix or apply_to_feature_vector methods. This tranformation outputs the T-Dimensional approximation of all these input vectors and matrices (where T<=min(D,N)). The transformation matrix is essentially a DxT matrix, the columns of which correspond to the eigenvectors of the covariance matrix(XX') having top T eigenvalues.
Definition: PCA.h:115
EPCAMemoryMode get_memory_mode() const
Definition: PCA.cpp:367
EPCAMode
Definition: PCA.h:44
virtual SGMatrix< float64_t > apply_to_feature_matrix(CFeatures *features)
Definition: PCA.cpp:281
float64_t m_eigenvalue_zero_tolerance
Definition: PCA.h:230
SGMatrix< float64_t > get_transformation_matrix()
Definition: PCA.cpp:352

SHOGUN Machine Learning Toolbox - Documentation