SHOGUN
v3.2.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) 2012 Sergey Lisitsyn 00008 * Copyright (C) 2012 Sergey Lisitsyn 00009 */ 00010 00011 #include <shogun/ui/GUIConverter.h> 00012 #include <shogun/ui/SGInterface.h> 00013 00014 #include <shogun/lib/config.h> 00015 #include <shogun/io/SGIO.h> 00016 #include <shogun/features/DenseFeatures.h> 00017 #include <shogun/kernel/GaussianKernel.h> 00018 00019 #include <shogun/converter/LocallyLinearEmbedding.h> 00020 #include <shogun/converter/HessianLocallyLinearEmbedding.h> 00021 #include <shogun/converter/LocalTangentSpaceAlignment.h> 00022 #include <shogun/converter/NeighborhoodPreservingEmbedding.h> 00023 #include <shogun/converter/LaplacianEigenmaps.h> 00024 #include <shogun/converter/LocalityPreservingProjections.h> 00025 #include <shogun/converter/DiffusionMaps.h> 00026 #include <shogun/converter/LinearLocalTangentSpaceAlignment.h> 00027 #include <shogun/converter/MultidimensionalScaling.h> 00028 #include <shogun/converter/Isomap.h> 00029 #include <shogun/converter/EmbeddingConverter.h> 00030 #include <shogun/converter/ica/Jade.h> 00031 00032 using namespace shogun; 00033 00034 CGUIConverter::CGUIConverter(CSGInterface* ui) 00035 : CSGObject(), m_ui(ui) 00036 { 00037 m_converter = NULL; 00038 } 00039 00040 CGUIConverter::~CGUIConverter() 00041 { 00042 SG_UNREF(m_converter); 00043 } 00044 00045 bool CGUIConverter::create_locallylinearembedding(int32_t k) 00046 { 00047 #ifdef HAVE_EIGEN3 00048 m_converter = new CLocallyLinearEmbedding(); 00049 ((CLocallyLinearEmbedding*)m_converter)->set_k(k); 00050 #else 00051 SG_ERROR("Requires EIGEN3 to be enabled at compile time\n") 00052 #endif 00053 return true; 00054 } 00055 00056 bool CGUIConverter::create_neighborhoodpreservingembedding(int32_t k) 00057 { 00058 #ifdef HAVE_EIGEN3 00059 m_converter = new CNeighborhoodPreservingEmbedding(); 00060 ((CNeighborhoodPreservingEmbedding*)m_converter)->set_k(k); 00061 #else 00062 SG_ERROR("Requires EIGEN3 to be enabled at compile time\n") 00063 #endif 00064 return true; 00065 } 00066 00067 bool CGUIConverter::create_localtangentspacealignment(int32_t k) 00068 { 00069 #ifdef HAVE_EIGEN3 00070 m_converter = new CLocalTangentSpaceAlignment(); 00071 ((CLocalTangentSpaceAlignment*)m_converter)->set_k(k); 00072 #else 00073 SG_ERROR("Requires EIGEN3 to be enabled at compile time\n") 00074 #endif 00075 return true; 00076 } 00077 00078 bool CGUIConverter::create_linearlocaltangentspacealignment(int32_t k) 00079 { 00080 #ifdef HAVE_EIGEN3 00081 m_converter = new CLinearLocalTangentSpaceAlignment(); 00082 ((CLinearLocalTangentSpaceAlignment*)m_converter)->set_k(k); 00083 #else 00084 SG_ERROR("Requires EIGEN3 to be enabled at compile time\n") 00085 #endif 00086 return true; 00087 } 00088 00089 bool CGUIConverter::create_hessianlocallylinearembedding(int32_t k) 00090 { 00091 #ifdef HAVE_EIGEN3 00092 m_converter = new CLocallyLinearEmbedding(); 00093 ((CHessianLocallyLinearEmbedding*)m_converter)->set_k(k); 00094 #else 00095 SG_ERROR("Requires EIGEN3 to be enabled at compile time\n") 00096 #endif 00097 return true; 00098 } 00099 00100 bool CGUIConverter::create_laplacianeigenmaps(int32_t k, float64_t width) 00101 { 00102 #ifdef HAVE_EIGEN3 00103 m_converter = new CLaplacianEigenmaps(); 00104 ((CLaplacianEigenmaps*)m_converter)->set_k(k); 00105 ((CLaplacianEigenmaps*)m_converter)->set_tau(width); 00106 #else 00107 SG_ERROR("Requires EIGEN3 to be enabled at compile time\n") 00108 #endif 00109 return true; 00110 } 00111 00112 bool CGUIConverter::create_localitypreservingprojections(int32_t k, float64_t width) 00113 { 00114 #ifdef HAVE_EIGEN3 00115 m_converter = new CLocalityPreservingProjections(); 00116 ((CLocalityPreservingProjections*)m_converter)->set_k(k); 00117 ((CLocalityPreservingProjections*)m_converter)->set_tau(width); 00118 #else 00119 SG_ERROR("Requires EIGEN3 to be enabled at compile time\n") 00120 #endif 00121 return true; 00122 } 00123 00124 bool CGUIConverter::create_diffusionmaps(int32_t t, float64_t width) 00125 { 00126 #ifdef HAVE_EIGEN3 00127 m_converter = new CDiffusionMaps(); 00128 ((CDiffusionMaps*)m_converter)->set_t(t); 00129 ((CDiffusionMaps*)m_converter)->set_kernel(new CGaussianKernel(100,width)); 00130 #else 00131 SG_ERROR("Requires EIGEN3 to be enabled at compile time\n") 00132 #endif 00133 return true; 00134 } 00135 00136 bool CGUIConverter::create_isomap(int32_t k) 00137 { 00138 #ifdef HAVE_EIGEN3 00139 m_converter = new CIsomap(); 00140 ((CIsomap*)m_converter)->set_k(k); 00141 #else 00142 SG_ERROR("Requires EIGEN3 to be enabled at compile time\n") 00143 #endif 00144 return true; 00145 } 00146 00147 bool CGUIConverter::create_multidimensionalscaling() 00148 { 00149 #ifdef HAVE_EIGEN3 00150 m_converter = new CMultidimensionalScaling(); 00151 #else 00152 SG_ERROR("Requires EIGEN3 to be enabled at compile time\n") 00153 #endif 00154 return true; 00155 } 00156 00157 bool CGUIConverter::create_jade() 00158 { 00159 #ifdef HAVE_EIGEN3 00160 m_converter = new CJade(); 00161 #else 00162 SG_ERROR("Requires EIGEN3 to be enabled at compile time\n") 00163 #endif 00164 return true; 00165 } 00166 00167 CDenseFeatures<float64_t>* CGUIConverter::apply() 00168 { 00169 if (!m_converter) 00170 SG_ERROR("No converter created") 00171 return (CDenseFeatures<float64_t>*)m_converter->apply(m_ui->ui_features->get_train_features()); 00172 } 00173 00174 CDenseFeatures<float64_t>* CGUIConverter::embed(int32_t target_dim) 00175 { 00176 if (!m_converter) 00177 SG_ERROR("No converter created") 00178 ((CEmbeddingConverter*)m_converter)->set_target_dim(target_dim); 00179 return ((CEmbeddingConverter*)m_converter)->embed(m_ui->ui_features->get_train_features()); 00180 } 00181