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-2013 Sergey Lisitsyn 00008 * Copyright (C) 2011-2013 Berlin Institute of Technology and Max-Planck-Society 00009 */ 00010 00011 #include <shogun/converter/LaplacianEigenmaps.h> 00012 #include <shogun/converter/EmbeddingConverter.h> 00013 #ifdef HAVE_EIGEN3 00014 #include <shogun/distance/EuclideanDistance.h> 00015 #include <shogun/lib/tapkee/tapkee_shogun.hpp> 00016 00017 using namespace shogun; 00018 00019 CLaplacianEigenmaps::CLaplacianEigenmaps() : 00020 CEmbeddingConverter() 00021 { 00022 m_k = 3; 00023 m_tau = 1.0; 00024 00025 init(); 00026 } 00027 00028 void CLaplacianEigenmaps::init() 00029 { 00030 SG_ADD(&m_k, "k", "number of neighbors", MS_AVAILABLE); 00031 SG_ADD(&m_tau, "tau", "heat distribution coefficient", MS_AVAILABLE); 00032 } 00033 00034 CLaplacianEigenmaps::~CLaplacianEigenmaps() 00035 { 00036 } 00037 00038 void CLaplacianEigenmaps::set_k(int32_t k) 00039 { 00040 ASSERT(k>0) 00041 m_k = k; 00042 } 00043 00044 int32_t CLaplacianEigenmaps::get_k() const 00045 { 00046 return m_k; 00047 } 00048 00049 void CLaplacianEigenmaps::set_tau(float64_t tau) 00050 { 00051 m_tau = tau; 00052 } 00053 00054 float64_t CLaplacianEigenmaps::get_tau() const 00055 { 00056 return m_tau; 00057 } 00058 00059 const char* CLaplacianEigenmaps::get_name() const 00060 { 00061 return "LaplacianEigenmaps"; 00062 }; 00063 00064 CFeatures* CLaplacianEigenmaps::apply(CFeatures* features) 00065 { 00066 // shorthand for simplefeatures 00067 SG_REF(features); 00068 00069 // get dimensionality and number of vectors of data 00070 int32_t N = features->get_num_vectors(); 00071 ASSERT(m_k<N) 00072 ASSERT(m_target_dim<N) 00073 00074 // compute distance matrix 00075 ASSERT(m_distance) 00076 m_distance->init(features,features); 00077 CDenseFeatures<float64_t>* embedding = embed_distance(m_distance); 00078 m_distance->remove_lhs_and_rhs(); 00079 SG_UNREF(features); 00080 return (CFeatures*)embedding; 00081 } 00082 00083 CDenseFeatures<float64_t>* CLaplacianEigenmaps::embed_distance(CDistance* distance) 00084 { 00085 TAPKEE_PARAMETERS_FOR_SHOGUN parameters; 00086 parameters.n_neighbors = m_k; 00087 parameters.gaussian_kernel_width = m_tau; 00088 parameters.method = SHOGUN_LAPLACIAN_EIGENMAPS; 00089 parameters.target_dimension = m_target_dim; 00090 parameters.distance = distance; 00091 return tapkee_embed(parameters); 00092 } 00093 #endif /* HAVE_EIGEN3 */