00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 1999-2008 Gunnar Raetsch 00008 * Written (W) 1999-2008,2011 Soeren Sonnenburg 00009 * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society 00010 * Copyright (C) 2011 Berlin Institute of Technology 00011 */ 00012 00013 #ifndef PCA_H_ 00014 #define PCA_H_ 00015 #include <shogun/lib/config.h> 00016 #ifdef HAVE_LAPACK 00017 #include <shogun/mathematics/lapack.h> 00018 #include <stdio.h> 00019 #include <shogun/preprocessor/DimensionReductionPreprocessor.h> 00020 #include <shogun/features/Features.h> 00021 #include <shogun/lib/common.h> 00022 00023 namespace shogun 00024 { 00026 enum EPCAMode 00027 { 00029 THRESHOLD, 00031 VARIANCE_EXPLAINED, 00033 FIXED_NUMBER 00034 }; 00035 00048 class CPCA: public CDimensionReductionPreprocessor 00049 { 00050 public: 00051 00057 CPCA(bool do_whitening=false, EPCAMode mode=FIXED_NUMBER, float64_t thresh=1e-6); 00058 00060 virtual ~CPCA(); 00061 00065 virtual bool init(CFeatures* features); 00066 00068 virtual void cleanup(); 00069 00074 virtual SGMatrix<float64_t> apply_to_feature_matrix(CFeatures* features); 00075 00080 virtual SGVector<float64_t> apply_to_feature_vector(SGVector<float64_t> vector); 00081 00085 SGMatrix<float64_t> get_transformation_matrix(); 00086 00089 SGVector<float64_t> get_eigenvalues(); 00090 00093 SGVector<float64_t> get_mean(); 00094 00096 virtual inline const char* get_name() const { return "PCA"; } 00097 00099 virtual inline EPreprocessorType get_type() const { return P_PCA; } 00100 00101 protected: 00102 00103 void init(); 00104 00105 protected: 00106 00108 SGMatrix<float64_t> m_transformation_matrix; 00110 int32_t num_dim; 00112 int32_t num_old_dim; 00114 SGVector<float64_t> m_mean_vector; 00116 SGVector<float64_t> m_eigenvalues_vector; 00118 bool m_initialized; 00120 bool m_whitening; 00122 EPCAMode m_mode; 00124 float64_t thresh; 00125 }; 00126 } 00127 #endif 00128 #endif