SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
KernelLocallyLinearEmbedding.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-2013 Sergey Lisitsyn
00008  * Copyright (C) 2011-2013 Berlin Institute of Technology and Max-Planck-Society
00009  */
00010 
00011 #include <shogun/converter/KernelLocallyLinearEmbedding.h>
00012 #ifdef HAVE_EIGEN3
00013 #include <shogun/io/SGIO.h>
00014 #include <shogun/lib/tapkee/tapkee_shogun.hpp>
00015 
00016 #ifdef HAVE_PTHREAD
00017 #include <pthread.h>
00018 #endif
00019 
00020 using namespace shogun;
00021 
00022 CKernelLocallyLinearEmbedding::CKernelLocallyLinearEmbedding() :
00023         CLocallyLinearEmbedding()
00024 {
00025 }
00026 
00027 CKernelLocallyLinearEmbedding::CKernelLocallyLinearEmbedding(CKernel* kernel) :
00028         CLocallyLinearEmbedding()
00029 {
00030     set_kernel(kernel);
00031 }
00032 
00033 const char* CKernelLocallyLinearEmbedding::get_name() const
00034 {
00035     return "KernelLocallyLinearEmbedding";
00036 };
00037 
00038 CKernelLocallyLinearEmbedding::~CKernelLocallyLinearEmbedding()
00039 {
00040 }
00041 
00042 CFeatures* CKernelLocallyLinearEmbedding::apply(CFeatures* features)
00043 {
00044     ASSERT(features)
00045     SG_REF(features);
00046 
00047     // get dimensionality and number of vectors of data
00048     int32_t N = features->get_num_vectors();
00049     if (m_k>=N)
00050         SG_ERROR("Number of neighbors (%d) should be less than number of objects (%d).\n",
00051                  m_k, N);
00052 
00053     // compute kernel matrix
00054     ASSERT(m_kernel)
00055     m_kernel->init(features,features);
00056     CDenseFeatures<float64_t>* embedding = embed_kernel(m_kernel);
00057     m_kernel->cleanup();
00058     SG_UNREF(features);
00059     return (CFeatures*)embedding;
00060 }
00061 
00062 CDenseFeatures<float64_t>* CKernelLocallyLinearEmbedding::embed_kernel(CKernel* kernel)
00063 {
00064     TAPKEE_PARAMETERS_FOR_SHOGUN parameters;
00065     parameters.n_neighbors = m_k;
00066     parameters.eigenshift = m_nullspace_shift;
00067     parameters.method = SHOGUN_KERNEL_LOCALLY_LINEAR_EMBEDDING;
00068     parameters.target_dimension = m_target_dim;
00069     parameters.kernel = kernel;
00070     CDenseFeatures<float64_t>* embedding = tapkee_embed(parameters);
00071     return embedding;
00072 }
00073 
00074 #endif /* HAVE_EIGEN3 */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation