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 MULTIDIMENSIONALSCALING_H_ 00012 #define MULTIDIMENSIONALSCALING_H_ 00013 #include <shogun/lib/config.h> 00014 #ifdef HAVE_LAPACK 00015 #include <shogun/preprocessor/DimensionReductionPreprocessor.h> 00016 #include <shogun/features/Features.h> 00017 #include <shogun/distance/Distance.h> 00018 00019 namespace shogun 00020 { 00021 00022 class CFeatures; 00023 00024 class CDistance; 00025 00060 class CMultidimensionalScaling: public CDimensionReductionPreprocessor 00061 { 00062 public: 00063 00064 /* constructor */ 00065 CMultidimensionalScaling(); 00066 00067 /* destructor */ 00068 virtual ~CMultidimensionalScaling(); 00069 00073 virtual bool init(CFeatures* features); 00074 00077 virtual void cleanup(); 00078 00083 virtual CSimpleFeatures<float64_t>* apply_to_distance(CDistance* distance); 00084 00090 virtual SGMatrix<float64_t> apply_to_feature_matrix(CFeatures* features); 00091 00095 virtual SGVector<float64_t> apply_to_feature_vector(SGVector<float64_t> vector); 00096 00098 virtual inline const char* get_name() const { return "MultidimensionalScaling"; }; 00099 00101 virtual inline EPreprocessorType get_type() const { return P_MULTIDIMENSIONALSCALING; }; 00102 00106 SGVector<float64_t> get_eigenvalues() const 00107 { 00108 return m_eigenvalues; 00109 } 00110 00116 void set_landmark_number(int32_t num) 00117 { 00118 if (num<3) 00119 SG_ERROR("Landmark number should be greater than 3 (%d given).", num); 00120 m_landmark_number = num; 00121 }; 00122 00126 int32_t get_landmark_number() const 00127 { 00128 return m_landmark_number; 00129 }; 00130 00134 void set_landmark(bool landmark) 00135 { 00136 m_landmark = landmark; 00137 }; 00138 00142 bool get_landmark() const 00143 { 00144 return m_landmark; 00145 }; 00146 00147 protected: 00148 00150 void init(); 00151 00156 SGMatrix<float64_t> classic_embedding(SGMatrix<float64_t> distance_matrix); 00157 00162 SGMatrix<float64_t> landmark_embedding(SGMatrix<float64_t> distance_matrix); 00163 00164 protected: 00165 00169 static void* run_triangulation_thread(void* p); 00170 00177 static SGVector<int32_t> shuffle(int32_t count, int32_t total_count); 00178 00179 protected: 00180 00182 SGVector<float64_t> m_eigenvalues; 00183 00185 bool m_landmark; 00186 00188 int32_t m_landmark_number; 00189 00190 }; 00191 00192 } 00193 #endif /* HAVE_LAPACK */ 00194 #endif /* MULTIDIMENSIONALSCALING_H_ */