SHOGUN
v1.1.0
|
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 LOCALLYLINEAREMBEDDING_H_ 00012 #define LOCALLYLINEAREMBEDDING_H_ 00013 #include <shogun/lib/config.h> 00014 #ifdef HAVE_LAPACK 00015 #include <shogun/converter/EmbeddingConverter.h> 00016 #include <shogun/features/Features.h> 00017 #include <shogun/features/SimpleFeatures.h> 00018 #include <shogun/distance/Distance.h> 00019 00020 namespace shogun 00021 { 00022 00023 class CFeatures; 00024 class CDistance; 00025 00063 class CLocallyLinearEmbedding: public CEmbeddingConverter 00064 { 00065 public: 00066 00068 CLocallyLinearEmbedding(); 00069 00071 virtual ~CLocallyLinearEmbedding(); 00072 00076 virtual CFeatures* apply(CFeatures* features); 00077 00081 void set_k(int32_t k); 00082 00086 int32_t get_k() const; 00087 00091 void set_max_k(int32_t max_k); 00092 00096 int32_t get_max_k() const; 00097 00101 void set_auto_k(bool auto_k); 00102 00106 bool get_auto_k() const; 00107 00111 void set_reconstruction_shift(float64_t reconstruction_shift); 00112 00116 float64_t get_reconstruction_shift() const; 00117 00121 void set_nullspace_shift(float64_t nullspace_shift); 00122 00126 float64_t get_nullspace_shift() const; 00127 00131 void set_use_arpack(bool use_arpack); 00132 00136 bool get_use_arpack() const; 00137 00139 virtual const char* get_name() const; 00140 00142 protected: 00143 00145 void init(); 00146 00152 virtual SGMatrix<float64_t> construct_weight_matrix(CSimpleFeatures<float64_t>* simple_features,float64_t* W_matrix, 00153 SGMatrix<int32_t> neighborhood_matrix); 00154 00160 virtual SGMatrix<float64_t> construct_embedding(SGMatrix<float64_t> matrix,int dimension); 00161 00167 virtual SGMatrix<int32_t> get_neighborhood_matrix(SGMatrix<float64_t> distance_matrix, int32_t k); 00168 00174 int32_t estimate_k(CSimpleFeatures<float64_t>* simple_features, SGMatrix<int32_t> neighborhood_matrix); 00175 00188 float64_t compute_reconstruction_error(int32_t k, int dim, int N, float64_t* feature_matrix, 00189 float64_t* z_matrix, float64_t* covariance_matrix, 00190 float64_t* resid_vector, float64_t* id_vector, 00191 SGMatrix<int32_t> neighborhood_matrix); 00192 00194 protected: 00195 00197 int32_t m_k; 00198 00200 int32_t m_max_k; 00201 00203 float64_t m_reconstruction_shift; 00204 00206 float64_t m_nullspace_shift; 00207 00209 bool m_use_arpack; 00210 00212 bool m_auto_k; 00213 00215 protected: 00216 00220 static void* run_neighborhood_thread(void* p); 00221 00225 static void* run_linearreconstruction_thread(void* p); 00226 00227 }; 00228 } 00229 00230 #endif /* HAVE_LAPACK */ 00231 #endif /* LOCALLYLINEAREMBEDDING_H_ */