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 Sergey Lisitsyn 00008 * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society 00009 */ 00010 00011 #ifndef DIMENSIONREDUCTIONPREPROCESSOR_H_ 00012 #define DIMENSIONREDUCTIONPREPROCESSOR_H_ 00013 00014 #include <shogun/preprocessor/SimplePreprocessor.h> 00015 #include <shogun/features/Features.h> 00016 #include <shogun/distance/Distance.h> 00017 00018 namespace shogun 00019 { 00020 00021 class CFeatures; 00022 00027 class CDimensionReductionPreprocessor: public CSimplePreprocessor<float64_t> 00028 { 00029 public: 00030 00031 /* constructor */ 00032 CDimensionReductionPreprocessor() : CSimplePreprocessor<float64_t>() 00033 { 00034 m_target_dim = 1; 00035 00036 init(); 00037 }; 00038 00039 /* destructor */ 00040 virtual ~CDimensionReductionPreprocessor() {}; 00041 00046 virtual bool init(CFeatures* data) 00047 { 00048 return true; 00049 }; 00050 00055 virtual void cleanup() 00056 { 00057 00058 }; 00059 00063 virtual SGMatrix<float64_t> apply_to_feature_matrix(CFeatures* features) 00064 { 00065 return ((CSimpleFeatures<float64_t>*)features)->get_feature_matrix(); 00066 }; 00067 00071 virtual SGVector<float64_t> apply_to_feature_vector(SGVector<float64_t> vector) 00072 { 00073 return vector; 00074 }; 00075 00077 virtual inline const char* get_name() const { return "DIMREDUCTIONPREPROCESSOR"; }; 00078 00080 virtual inline EPreprocessorType get_type() const { return P_DIMENSIONREDUCTIONPREPROCESSOR; }; 00081 00085 void inline set_target_dim(int32_t dim) 00086 { 00087 ASSERT(dim>0); 00088 m_target_dim = dim; 00089 } 00090 00094 int32_t inline get_target_dim() 00095 { 00096 return m_target_dim; 00097 } 00098 00099 public: 00100 00102 static const int32_t AUTO_TARGET_DIM = -1; 00103 00104 protected: 00105 00107 void init() 00108 { 00109 m_parameters->add(&m_target_dim, "target_dim", 00110 "target dimensionality of preprocessor"); 00111 } 00112 00113 protected: 00114 00116 int32_t m_target_dim; 00117 00118 }; 00119 } 00120 00121 #endif /* DIMENSIONREDUCTIONPREPROCESSOR_H_ */