Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1105 from vladislav-horbatiuk/vgorbati-develop
Added full implementation of manifold sculpting DR method and a smoke test for it.
- Loading branch information
Showing
17 changed files
with
731 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* 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) 2013 Vladyslav S. Gorbatiuk | ||
* Copyright (C) 2011-2013 Vladyslav S. Gorbatiuk | ||
*/ | ||
|
||
#include <shogun/converter/ManifoldSculpting.h> | ||
#ifdef HAVE_EIGEN3 | ||
#include <shogun/lib/tapkee/tapkee_shogun.hpp> | ||
#include <shogun/features/DenseFeatures.h> | ||
#include <shogun/distance/EuclideanDistance.h> | ||
|
||
using namespace shogun; | ||
|
||
CManifoldSculpting::CManifoldSculpting() : | ||
CEmbeddingConverter() | ||
{ | ||
// Default values | ||
m_k = 10; | ||
m_squishing_rate = 0.8; | ||
m_max_iteration = 80; | ||
init(); | ||
} | ||
|
||
void CManifoldSculpting::init() | ||
{ | ||
SG_ADD(&m_k, "k", "number of neighbors", MS_NOT_AVAILABLE); | ||
SG_ADD(&m_squishing_rate, "quishing_rate", | ||
"squishing rate",MS_NOT_AVAILABLE); | ||
SG_ADD(&m_max_iteration, "max_iteration", | ||
"maximum number of algorithm's iterations", MS_NOT_AVAILABLE); | ||
} | ||
|
||
CManifoldSculpting::~CManifoldSculpting() | ||
{ | ||
} | ||
|
||
const char* CManifoldSculpting::get_name() const | ||
{ | ||
return "ManifoldSculpting"; | ||
} | ||
|
||
void CManifoldSculpting::set_k(const int32_t k) | ||
{ | ||
ASSERT(k>0) | ||
m_k = k; | ||
} | ||
|
||
int32_t CManifoldSculpting::get_k() const | ||
{ | ||
return m_k; | ||
} | ||
|
||
void CManifoldSculpting::set_squishing_rate(const float64_t squishing_rate) | ||
{ | ||
ASSERT(squishing_rate >= 0 && squishing_rate < 1) | ||
m_squishing_rate = squishing_rate; | ||
} | ||
|
||
float64_t CManifoldSculpting::get_squishing_rate() const | ||
{ | ||
return m_squishing_rate; | ||
} | ||
|
||
void CManifoldSculpting::set_max_iteration(const int32_t max_iteration) | ||
{ | ||
ASSERT(max_iteration > 0) | ||
m_max_iteration = max_iteration; | ||
} | ||
|
||
int32_t CManifoldSculpting::get_max_iteration() const | ||
{ | ||
return m_max_iteration; | ||
} | ||
|
||
CFeatures* CManifoldSculpting::apply(CFeatures* features) | ||
{ | ||
CDenseFeatures<float64_t>* feats = (CDenseFeatures<float64_t>*)features; | ||
SG_REF(feats); | ||
CDistance* euclidean_distance = | ||
new CEuclideanDistance(feats, feats); | ||
|
||
TAPKEE_PARAMETERS_FOR_SHOGUN parameters; | ||
parameters.n_neighbors = m_k; | ||
parameters.squishing_rate = m_squishing_rate; | ||
parameters.max_iteration = m_max_iteration; | ||
parameters.features = feats; | ||
parameters.distance = euclidean_distance; | ||
|
||
parameters.method = SHOGUN_MANIFOLD_SCULPTING; | ||
parameters.target_dimension = m_target_dim; | ||
CDenseFeatures<float64_t>* embedding = tapkee_embed(parameters); | ||
|
||
SG_UNREF(euclidean_distance); | ||
|
||
return embedding; | ||
} | ||
|
||
#endif /* HAVE_EIGEN */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* 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) 2013 Vladyslav S. Gorbatiuk | ||
* Copyright (C) 2011-2013 Vladyslav S. Gorbatiuk | ||
*/ | ||
|
||
#ifndef MANIFOLDSCULPTING_H_ | ||
#define MANIFOLDSCULPTING_H_ | ||
#include <shogun/lib/config.h> | ||
#ifdef HAVE_EIGEN3 | ||
#include <shogun/converter/EmbeddingConverter.h> | ||
#include <shogun/features/Features.h> | ||
|
||
namespace shogun | ||
{ | ||
|
||
/** @class class CManifoldSculpting used to embed | ||
* data using manifold sculpting embedding algorithm. | ||
* | ||
* Uses implementation from the Tapkee library. | ||
* | ||
*/ | ||
class CManifoldSculpting : public CEmbeddingConverter | ||
{ | ||
public: | ||
|
||
/** constructor */ | ||
CManifoldSculpting(); | ||
|
||
/** destructor */ | ||
virtual ~CManifoldSculpting(); | ||
|
||
/** get name */ | ||
virtual const char* get_name() const; | ||
|
||
/** apply preprocessor to features | ||
* | ||
* @param features features to embed | ||
*/ | ||
virtual CFeatures* apply(CFeatures* features); | ||
|
||
/** setter for the k | ||
* | ||
* @param k the number of neighbors | ||
*/ | ||
void set_k(const int32_t k); | ||
|
||
/** getter for the number of neighbors | ||
* | ||
* @return the number of neighbors k | ||
*/ | ||
int32_t get_k() const; | ||
|
||
/** setter for squishing_rate | ||
* | ||
* @param squishing_rate the squishing rate | ||
*/ | ||
void set_squishing_rate(const float64_t squishing_rate); | ||
|
||
/** getter for squishing_rate | ||
* | ||
* @return squishing_rate | ||
*/ | ||
float64_t get_squishing_rate() const; | ||
|
||
/** setter for the maximum number of iterations | ||
* | ||
* @param max_iteration the maximum number of iterations | ||
*/ | ||
void set_max_iteration(const int32_t max_iteration); | ||
|
||
/** getter for the maximum number of iterations | ||
* | ||
* @return the maximum number of iterations | ||
*/ | ||
int32_t get_max_iteration() const; | ||
|
||
private: | ||
|
||
/** default init */ | ||
void init(); | ||
|
||
private: | ||
|
||
/** k - number of neighbors */ | ||
float64_t m_k; | ||
|
||
/** squishing_rate */ | ||
float64_t m_squishing_rate; | ||
|
||
/** max_iteration - the maximum number of algorithm's | ||
* iterations | ||
*/ | ||
float64_t m_max_iteration; | ||
|
||
}; /* class CManifoldSculpting */ | ||
|
||
} /* namespace shogun */ | ||
|
||
#endif /* HAVE_EIGEN3 */ | ||
#endif /* MANIFOLDSCULPTING_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.