SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
DiffusionMaps.cpp
Go to the documentation of this file.
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/DiffusionMaps.h>
00012 #include <shogun/converter/EmbeddingConverter.h>
00013 #include <shogun/lib/config.h>
00014 #ifdef HAVE_EIGEN3
00015 #include <shogun/distance/EuclideanDistance.h>
00016 #include <shogun/lib/tapkee/tapkee_shogun.hpp>
00017 
00018 using namespace shogun;
00019 
00020 CDiffusionMaps::CDiffusionMaps() :
00021         CEmbeddingConverter()
00022 {
00023     m_t = 10;
00024     m_width = 1.0;
00025     set_distance(new CEuclideanDistance());
00026 
00027     init();
00028 }
00029 
00030 void CDiffusionMaps::init()
00031 {
00032     SG_ADD(&m_t, "t", "number of steps", MS_AVAILABLE);
00033     SG_ADD(&m_width, "width", "gaussian kernel width", MS_AVAILABLE);
00034 }
00035 
00036 CDiffusionMaps::~CDiffusionMaps()
00037 {
00038 }
00039 
00040 void CDiffusionMaps::set_t(int32_t t)
00041 {
00042     m_t = t;
00043 }
00044 
00045 int32_t CDiffusionMaps::get_t() const
00046 {
00047     return m_t;
00048 }
00049 
00050 void CDiffusionMaps::set_width(float64_t width)
00051 {
00052     m_width = width;
00053 }
00054 
00055 float64_t CDiffusionMaps::get_width() const
00056 {
00057     return m_width;
00058 }
00059 
00060 const char* CDiffusionMaps::get_name() const
00061 {
00062     return "DiffusionMaps";
00063 };
00064 
00065 CFeatures* CDiffusionMaps::apply(CFeatures* features)
00066 {
00067     ASSERT(features)
00068     // shorthand for simplefeatures
00069     SG_REF(features);
00070     // compute distance matrix
00071     ASSERT(m_distance)
00072     m_distance->init(features,features);
00073     CDenseFeatures<float64_t>* embedding = embed_distance(m_distance);
00074     m_distance->cleanup();
00075     SG_UNREF(features);
00076     return (CFeatures*)embedding;
00077 }
00078 
00079 CDenseFeatures<float64_t>* CDiffusionMaps::embed_distance(CDistance* distance)
00080 {
00081     TAPKEE_PARAMETERS_FOR_SHOGUN parameters;
00082     parameters.n_timesteps = m_t;
00083     parameters.gaussian_kernel_width = m_width;
00084     parameters.method = SHOGUN_DIFFUSION_MAPS;
00085     parameters.target_dimension = m_target_dim;
00086     parameters.distance = distance;
00087     return tapkee_embed(parameters);
00088 }
00089 #endif /* HAVE_EIGEN3 */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation