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) 2011 Sergey Lisitsyn 00008 * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society 00009 */ 00010 00011 #include <shogun/converter/LocallyLinearEmbedding.h> 00012 #include <shogun/lib/config.h> 00013 #ifdef HAVE_EIGEN3 00014 #include <shogun/converter/EmbeddingConverter.h> 00015 #include <shogun/kernel/LinearKernel.h> 00016 #include <shogun/io/SGIO.h> 00017 #include <shogun/lib/Time.h> 00018 #include <shogun/lib/tapkee/tapkee_shogun.hpp> 00019 00020 using namespace shogun; 00021 00022 CLocallyLinearEmbedding::CLocallyLinearEmbedding() : 00023 CEmbeddingConverter() 00024 { 00025 m_k = 10; 00026 m_nullspace_shift = -1e-9; 00027 m_reconstruction_shift = 1e-3; 00028 init(); 00029 } 00030 00031 void CLocallyLinearEmbedding::init() 00032 { 00033 SG_ADD(&m_k, "k", "number of neighbors", MS_AVAILABLE); 00034 SG_ADD(&m_nullspace_shift, "nullspace_shift", 00035 "nullspace finding regularization shift",MS_NOT_AVAILABLE); 00036 SG_ADD(&m_reconstruction_shift, "reconstruction_shift", 00037 "shift used to regularize reconstruction step", MS_NOT_AVAILABLE); 00038 } 00039 00040 00041 CLocallyLinearEmbedding::~CLocallyLinearEmbedding() 00042 { 00043 } 00044 00045 void CLocallyLinearEmbedding::set_k(int32_t k) 00046 { 00047 ASSERT(k>0) 00048 m_k = k; 00049 } 00050 00051 int32_t CLocallyLinearEmbedding::get_k() const 00052 { 00053 return m_k; 00054 } 00055 00056 void CLocallyLinearEmbedding::set_nullspace_shift(float64_t nullspace_shift) 00057 { 00058 m_nullspace_shift = nullspace_shift; 00059 } 00060 00061 float64_t CLocallyLinearEmbedding::get_nullspace_shift() const 00062 { 00063 return m_nullspace_shift; 00064 } 00065 00066 void CLocallyLinearEmbedding::set_reconstruction_shift(float64_t reconstruction_shift) 00067 { 00068 m_reconstruction_shift = reconstruction_shift; 00069 } 00070 00071 float64_t CLocallyLinearEmbedding::get_reconstruction_shift() const 00072 { 00073 return m_reconstruction_shift; 00074 } 00075 00076 const char* CLocallyLinearEmbedding::get_name() const 00077 { 00078 return "LocallyLinearEmbedding"; 00079 } 00080 00081 CFeatures* CLocallyLinearEmbedding::apply(CFeatures* features) 00082 { 00083 // oh my let me dirty cast it 00084 CKernel* kernel = new CLinearKernel((CDotFeatures*)features,(CDotFeatures*)features); 00085 TAPKEE_PARAMETERS_FOR_SHOGUN parameters; 00086 parameters.n_neighbors = m_k; 00087 parameters.eigenshift = m_nullspace_shift; 00088 parameters.method = SHOGUN_LOCALLY_LINEAR_EMBEDDING; 00089 parameters.target_dimension = m_target_dim; 00090 parameters.kernel = kernel; 00091 CDenseFeatures<float64_t>* embedding = tapkee_embed(parameters); 00092 SG_UNREF(kernel); 00093 return embedding; 00094 } 00095 00096 #endif /* HAVE_EIGEN3 */