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) 2011 Soeren Sonnenburg 00008 * Copyright (C) 2011 Berlin Institute of Technology 00009 */ 00010 00011 #ifndef KERNELPCA_H__ 00012 #define KERNELPCA_H__ 00013 #include <shogun/lib/config.h> 00014 #ifdef HAVE_LAPACK 00015 00016 #include <shogun/preprocessor/DimensionReductionPreprocessor.h> 00017 #include <shogun/features/Features.h> 00018 #include <shogun/kernel/Kernel.h> 00019 #include <shogun/lib/common.h> 00020 00021 namespace shogun 00022 { 00023 00024 class CFeatures; 00025 class CKernel; 00026 00035 class CKernelPCA: public CDimensionReductionPreprocessor 00036 { 00037 public: 00040 CKernelPCA(); 00041 00045 CKernelPCA(CKernel* k); 00046 00047 virtual ~CKernelPCA(); 00048 00050 virtual bool init(CFeatures* features); 00052 virtual void cleanup(); 00053 00057 virtual SGMatrix<float64_t> apply_to_feature_matrix(CFeatures* features); 00058 00061 virtual SGVector<float64_t> apply_to_feature_vector(SGVector<float64_t> vector); 00062 00066 virtual CSimpleFeatures<float64_t>* apply_to_string_features(CFeatures* features); 00067 00069 CKernel* get_kernel() const 00070 { 00071 SG_REF(m_kernel); 00072 return m_kernel; 00073 } 00074 00078 void set_kernel(CKernel* k) 00079 { 00080 SG_REF(k); 00081 SG_UNREF(m_kernel); 00082 m_kernel=k; 00083 } 00084 00088 SGMatrix<float64_t> get_transformation_matrix() const 00089 { 00090 return m_transformation_matrix; 00091 } 00092 00096 SGVector<float64_t> get_bias_vector() const 00097 { 00098 return m_bias_vector; 00099 } 00100 00102 virtual inline const char* get_name() const { return "KernelPCA"; } 00103 00105 virtual inline EPreprocessorType get_type() const { return P_KERNELPCA; } 00106 00107 protected: 00108 00110 void init(); 00111 00112 protected: 00113 00115 CFeatures* m_init_features; 00116 00118 SGMatrix<float64_t> m_transformation_matrix; 00119 00121 SGVector<float64_t> m_bias_vector; 00122 00124 bool m_initialized; 00125 00127 CKernel* m_kernel; 00128 }; 00129 } 00130 #endif 00131 #endif