Skip to content

Commit

Permalink
EDRT now support static
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Jan 27, 2012
1 parent 8a64702 commit eef8481
Show file tree
Hide file tree
Showing 15 changed files with 344 additions and 1 deletion.
11 changes: 11 additions & 0 deletions applications/edrt/octave_ltsa.m
@@ -0,0 +1,11 @@
n = 1000;
noise = 0.0;
t = (3 * pi / 2) * (1 + 2 * rand(n, 1));
height = 30 * rand(n, 1);
X = [t .* cos(t) height t .* sin(t)] + noise * randn(n, 3);

sg('set_features','TRAIN',X');
sg('set_converter','ltsa',10);
embedding = sg('embed',2);
plot(embedding(:,1),embedding(:,2),'@');

3 changes: 3 additions & 0 deletions src/shogun/converter/DiffusionMaps.h
Expand Up @@ -31,6 +31,9 @@ class CKernel;
* Applied and Computational Harmonic Analysis, 21(1), 5-30. Elsevier.
* Retrieved from http://linkinghub.elsevier.com/retrieve/pii/S1063520306000546
*
* To use this converter with static interfaces please refer it by
* sg('create_converter','diffusion_maps',t,width);
*
*/
class CDiffusionMaps: public CEmbeddingConverter
{
Expand Down
4 changes: 4 additions & 0 deletions src/shogun/converter/HessianLocallyLinearEmbedding.h
Expand Up @@ -39,6 +39,10 @@ class CDistance;
* Be sure k value is set with at least
* 1+[target dim]+1/2 [target_dim]*[1 + target dim], e.g.
* greater than 6 for target dimensionality of 2.
*
* To use this converter with static interfaces please refer it by
* sg('create_converter','hlle',k);
*
*/
class CHessianLocallyLinearEmbedding: public CLocallyLinearEmbedding
{
Expand Down
3 changes: 3 additions & 0 deletions src/shogun/converter/Isomap.h
Expand Up @@ -42,6 +42,9 @@ class CDistance;
* It is possible to apply preprocessor to specified distance using
* apply_to_distance.
*
* To use this converter with static interfaces please refer it by
* sg('create_converter','isomap',k);
*
*/
class CIsomap: public CMultidimensionalScaling
{
Expand Down
3 changes: 3 additions & 0 deletions src/shogun/converter/LaplacianEigenmaps.h
Expand Up @@ -44,6 +44,9 @@ class CDistance;
* If ARPACK is available then DSAUPD/DSEUPD is used with no extra
* memory usage.
*
* To use this converter with static interfaces please refer it by
* sg('create_converter','laplacian_eigenmaps',k,width);
*
*/
class CLaplacianEigenmaps: public CEmbeddingConverter
{
Expand Down
3 changes: 3 additions & 0 deletions src/shogun/converter/LinearLocalTangentSpaceAlignment.h
Expand Up @@ -35,6 +35,9 @@ class CDistance;
* This method is hardly applicable to very high-dimensional data due to
* necessity to solve eigenproblem involving matrix of size (dim x dim).
*
* To use this converter with static interfaces please refer it by
* sg('create_converter','lltsa',k);
*
*/
class CLinearLocalTangentSpaceAlignment: public CLocalTangentSpaceAlignment
{
Expand Down
2 changes: 2 additions & 0 deletions src/shogun/converter/LocalityPreservingProjections.h
Expand Up @@ -30,6 +30,8 @@ class CDistance;
* Matrix, 16(December), 153–160. Citeseer.
* Retrieved from http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.85.7147&rep=rep1&type=pdf
*
* To use this converter with static interfaces please refer it by
* sg('create_converter','lpp',k,width);
*
*/
class CLocalityPreservingProjections: public CLaplacianEigenmaps
Expand Down
3 changes: 3 additions & 0 deletions src/shogun/converter/LocallyLinearEmbedding.h
Expand Up @@ -59,6 +59,9 @@ class CDistance;
* Formulating LLE using alignment technique.
* Pattern Recognition, 39(11), 2233-2235.
* Retrieved from http://linkinghub.elsevier.com/retrieve/pii/S0031320306002160
*
* To use this converter with static interfaces please refer it by
* sg('create_converter','lle',k);
*
*/
class CLocallyLinearEmbedding: public CEmbeddingConverter
Expand Down
4 changes: 4 additions & 0 deletions src/shogun/converter/MultidimensionalScaling.h
Expand Up @@ -56,6 +56,10 @@ class CDistance;
* proper triangulation. For reasonable embedding accuracy greater
* values (30%-50% of total examples number) is pretty good for the
* most tasks.
*
* To use this converter with static interfaces please refer it by
* sg('create_converter','mds');
*
*/
class CMultidimensionalScaling: public CEmbeddingConverter
{
Expand Down
3 changes: 3 additions & 0 deletions src/shogun/converter/NeighborhoodPreservingEmbedding.h
Expand Up @@ -35,6 +35,9 @@ class CDistance;
* This method is hardly applicable to very high-dimensional data due to
* necessity to solve eigenproblem involving matrix of size (dim x dim).
*
* To use this converter with static interfaces please refer it by
* sg('create_converter','npe',k);
*
*/
class CNeighborhoodPreservingEmbedding: public CLocallyLinearEmbedding
{
Expand Down
2 changes: 2 additions & 0 deletions src/shogun/ui/GUICommands.h
Expand Up @@ -233,4 +233,6 @@
#define N_RUN_OCTAVE "run_octave"
#define N_RUN_R "run_r"
#define N_PR_LOQO "pr_loqo"
#define N_SET_CONVERTER "set_converter"
#define N_EMBED "embed"
#endif
123 changes: 123 additions & 0 deletions src/shogun/ui/GUIConverter.cpp
@@ -0,0 +1,123 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Written (W) 2012 Sergey Lisitsyn
* Copyright (C) 2012 Sergey Lisitsyn
*/

#include <shogun/ui/GUIConverter.h>
#include <shogun/ui/SGInterface.h>

#include <shogun/lib/config.h>
#include <shogun/io/SGIO.h>
#include <shogun/features/SimpleFeatures.h>
#include <shogun/kernel/GaussianKernel.h>

#include <shogun/converter/LocallyLinearEmbedding.h>
#include <shogun/converter/HessianLocallyLinearEmbedding.h>
#include <shogun/converter/LocalTangentSpaceAlignment.h>
#include <shogun/converter/NeighborhoodPreservingEmbedding.h>
#include <shogun/converter/LaplacianEigenmaps.h>
#include <shogun/converter/LocalityPreservingProjections.h>
#include <shogun/converter/DiffusionMaps.h>
#include <shogun/converter/LinearLocalTangentSpaceAlignment.h>
#include <shogun/converter/MultidimensionalScaling.h>
#include <shogun/converter/Isomap.h>
#include <shogun/converter/EmbeddingConverter.h>

using namespace shogun;

CGUIConverter::CGUIConverter(CSGInterface* ui)
: CSGObject(), m_ui(ui)
{
m_converter = NULL;
}

CGUIConverter::~CGUIConverter()
{
SG_UNREF(m_converter);
}

bool CGUIConverter::create_locallylinearembedding(int32_t k)
{
m_converter = new CLocallyLinearEmbedding();
((CLocallyLinearEmbedding*)m_converter)->set_k(k);
return true;
}

bool CGUIConverter::create_neighborhoodpreservingembedding(int32_t k)
{
m_converter = new CNeighborhoodPreservingEmbedding();
((CNeighborhoodPreservingEmbedding*)m_converter)->set_k(k);
return true;
}

bool CGUIConverter::create_localtangentspacealignment(int32_t k)
{
m_converter = new CLocalTangentSpaceAlignment();
((CLocalTangentSpaceAlignment*)m_converter)->set_k(k);
return true;
}

bool CGUIConverter::create_linearlocaltangentspacealignment(int32_t k)
{
m_converter = new CLinearLocalTangentSpaceAlignment();
((CLinearLocalTangentSpaceAlignment*)m_converter)->set_k(k);
return true;
}

bool CGUIConverter::create_hessianlocallylinearembedding(int32_t k)
{
m_converter = new CLocallyLinearEmbedding();
((CHessianLocallyLinearEmbedding*)m_converter)->set_k(k);
return true;
}

bool CGUIConverter::create_laplacianeigenmaps(int32_t k, float64_t width)
{
m_converter = new CLaplacianEigenmaps();
((CLaplacianEigenmaps*)m_converter)->set_k(k);
((CLaplacianEigenmaps*)m_converter)->set_tau(width);
return true;
}

bool CGUIConverter::create_localitypreservingprojections(int32_t k, float64_t width)
{
m_converter = new CLocalityPreservingProjections();
((CLocalityPreservingProjections*)m_converter)->set_k(k);
((CLocalityPreservingProjections*)m_converter)->set_tau(width);
return true;
}

bool CGUIConverter::create_diffusionmaps(int32_t t, float64_t width)
{
m_converter = new CDiffusionMaps();
((CDiffusionMaps*)m_converter)->set_t(t);
((CDiffusionMaps*)m_converter)->set_kernel(new CGaussianKernel(100,width));
return true;
}

bool CGUIConverter::create_isomap(int32_t k)
{
m_converter = new CIsomap();
((CIsomap*)m_converter)->set_k(k);
return true;
}

bool CGUIConverter::create_multidimensionalscaling()
{
m_converter = new CMultidimensionalScaling();
return true;
}

CSimpleFeatures<float64_t>* CGUIConverter::embed(int32_t target_dim)
{
if (!m_converter)
SG_ERROR("No converter created");
((CEmbeddingConverter*)m_converter)->set_target_dim(target_dim);
return ((CEmbeddingConverter*)m_converter)->embed(m_ui->ui_features->get_train_features());
}

77 changes: 77 additions & 0 deletions src/shogun/ui/GUIConverter.h
@@ -0,0 +1,77 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Written (W) 2012 Sergey Lisitsyn
* Copyright (C) 2012 Sergey Lisitsyn
*/

#ifndef __GUICONVERTER_H__
#define __GUICONVERTER_H__

#include <shogun/lib/config.h>
#include <shogun/base/SGObject.h>
#include <shogun/converter/Converter.h>
#include <shogun/features/SimpleFeatures.h>

namespace shogun
{
class CSGInterface;

/** @brief UI converter */
class CGUIConverter : public CSGObject
{
public:
/** constructor */
CGUIConverter()
{

};

/** constructor
* @param interface
*/
CGUIConverter(CSGInterface* interface);

/** create LLE */
bool create_locallylinearembedding(int32_t k);
/** create NPE */
bool create_neighborhoodpreservingembedding(int32_t k);
/** create LTSA */
bool create_localtangentspacealignment(int32_t k);
/** create LLTSA */
bool create_linearlocaltangentspacealignment(int32_t k);
/** create HLLE */
bool create_hessianlocallylinearembedding(int32_t k);
/** create Laplacian Eigenmaps */
bool create_laplacianeigenmaps(int32_t k, float64_t width);
/** create LPP */
bool create_localitypreservingprojections(int32_t k, float64_t width);
/** create Diffusion maps */
bool create_diffusionmaps(int32_t t, float64_t width);
/** create Isomap */
bool create_isomap(int32_t k);
/** create Multidimensional scaling */
bool create_multidimensionalscaling();

/** embed */
CSimpleFeatures<float64_t>* embed(int32_t target_dim);

/** destructor */
~CGUIConverter();

/** @return object name */
virtual const char* get_name() const { return "GUIPreprocessor"; }

protected:

/** converter */
CConverter* m_converter;

/** ui */
CSGInterface* m_ui;
};
}
#endif

0 comments on commit eef8481

Please sign in to comment.