10 #include <shogun/lib/tapkee/tapkee_shogun.hpp>
14 #define CUSTOM_UNIFORM_RANDOM_INDEX_FUNCTION shogun::CMath::random()
15 #define CUSTOM_UNIFORM_RANDOM_FUNCTION shogun::CMath::random(static_cast<tapkee::ScalarType>(0),static_cast<tapkee::ScalarType>(1))
16 #define CUSTOM_GAUSSIAN_RANDOM_FUNCTION shogun::CMath::normal_random(static_cast<tapkee::ScalarType>(0),static_cast<tapkee::ScalarType>(1))
17 #define TAPKEE_EIGEN_INCLUDE_FILE <shogun/mathematics/eigen3.h>
20 #define TAPKEE_WITH_ARPACK
22 #define TAPKEE_USE_LGPL_COVERTREE
23 #include <shogun/lib/tapkee/tapkee.hpp>
24 #include <shogun/lib/tapkee/callbacks/pimpl_callbacks.hpp>
30 virtual void message_info(
const std::string& msg)
34 virtual void message_warning(
const std::string& msg)
38 virtual void message_error(
const std::string& msg)
42 virtual void message_debug(
const std::string& msg)
46 virtual void message_benchmark(
const std::string& msg)
58 return (dim = features->get_dim_feature_space());
62 inline void vector(
int i, tapkee::DenseVector& v)
const
65 features->add_to_dense_vec(1.0,i,v.data(),dim);
75 tapkee::LoggingSingleton::instance().enable_benchmark();
76 tapkee::LoggingSingleton::instance().enable_info();
78 pimpl_kernel_callback<CKernel> kernel_callback(parameters.kernel);
79 pimpl_distance_callback<CDistance> distance_callback(parameters.distance);
82 tapkee::DimensionReductionMethod method;
84 tapkee::EigenMethod eigen_method = tapkee::Arpack;
86 tapkee::EigenMethod eigen_method = tapkee::Dense;
88 tapkee::NeighborsMethod neighbors_method = tapkee::CoverTree;
91 switch (parameters.method)
93 case SHOGUN_KERNEL_LOCALLY_LINEAR_EMBEDDING:
94 case SHOGUN_LOCALLY_LINEAR_EMBEDDING:
95 method = tapkee::KernelLocallyLinearEmbedding;
96 N = parameters.kernel->get_num_vec_lhs();
98 case SHOGUN_NEIGHBORHOOD_PRESERVING_EMBEDDING:
99 method = tapkee::NeighborhoodPreservingEmbedding;
100 N = parameters.kernel->get_num_vec_lhs();
102 case SHOGUN_LOCAL_TANGENT_SPACE_ALIGNMENT:
103 method = tapkee::KernelLocalTangentSpaceAlignment;
104 N = parameters.kernel->get_num_vec_lhs();
106 case SHOGUN_LINEAR_LOCAL_TANGENT_SPACE_ALIGNMENT:
107 method = tapkee::LinearLocalTangentSpaceAlignment;
108 N = parameters.kernel->get_num_vec_lhs();
110 case SHOGUN_HESSIAN_LOCALLY_LINEAR_EMBEDDING:
111 method = tapkee::HessianLocallyLinearEmbedding;
112 N = parameters.kernel->get_num_vec_lhs();
114 case SHOGUN_DIFFUSION_MAPS:
115 method = tapkee::DiffusionMap;
116 N = parameters.distance->get_num_vec_lhs();
118 case SHOGUN_LAPLACIAN_EIGENMAPS:
119 method = tapkee::LaplacianEigenmaps;
120 N = parameters.distance->get_num_vec_lhs();
122 case SHOGUN_LOCALITY_PRESERVING_PROJECTIONS:
123 method = tapkee::LocalityPreservingProjections;
124 N = parameters.distance->get_num_vec_lhs();
126 case SHOGUN_MULTIDIMENSIONAL_SCALING:
127 method = tapkee::MultidimensionalScaling;
128 N = parameters.distance->get_num_vec_lhs();
130 case SHOGUN_LANDMARK_MULTIDIMENSIONAL_SCALING:
131 method = tapkee::LandmarkMultidimensionalScaling;
132 N = parameters.distance->get_num_vec_lhs();
135 method = tapkee::Isomap;
136 N = parameters.distance->get_num_vec_lhs();
138 case SHOGUN_LANDMARK_ISOMAP:
139 method = tapkee::LandmarkIsomap;
140 N = parameters.distance->get_num_vec_lhs();
142 case SHOGUN_STOCHASTIC_PROXIMITY_EMBEDDING:
143 method = tapkee::StochasticProximityEmbedding;
144 N = parameters.distance->get_num_vec_lhs();
146 case SHOGUN_FACTOR_ANALYSIS:
147 method = tapkee::FactorAnalysis;
148 N = parameters.features->get_num_vectors();
150 case SHOGUN_TDISTRIBUTED_STOCHASTIC_NEIGHBOR_EMBEDDING:
151 method = tapkee::tDistributedStochasticNeighborEmbedding;
152 N = parameters.features->get_num_vectors();
154 case SHOGUN_MANIFOLD_SCULPTING:
155 method = tapkee::ManifoldSculpting;
156 N = parameters.features->get_num_vectors();
160 std::vector<int32_t> indices(N);
161 for (
size_t i=0; i<N; i++)
164 tapkee::ParametersSet parameters_set =
165 (tapkee::keywords::method=method,
166 tapkee::keywords::eigen_method=eigen_method,
167 tapkee::keywords::neighbors_method=neighbors_method,
168 tapkee::keywords::num_neighbors=parameters.n_neighbors,
169 tapkee::keywords::diffusion_map_timesteps = parameters.n_timesteps,
170 tapkee::keywords::target_dimension = parameters.target_dimension,
171 tapkee::keywords::spe_num_updates = parameters.spe_num_updates,
172 tapkee::keywords::nullspace_shift = parameters.eigenshift,
173 tapkee::keywords::landmark_ratio = parameters.landmark_ratio,
174 tapkee::keywords::gaussian_kernel_width = parameters.gaussian_kernel_width,
175 tapkee::keywords::spe_tolerance = parameters.spe_tolerance,
176 tapkee::keywords::spe_global_strategy = parameters.spe_global_strategy,
177 tapkee::keywords::max_iteration = parameters.max_iteration,
178 tapkee::keywords::fa_epsilon = parameters.fa_epsilon,
179 tapkee::keywords::sne_perplexity = parameters.sne_perplexity,
180 tapkee::keywords::sne_theta = parameters.sne_theta,
181 tapkee::keywords::squishing_rate = parameters.squishing_rate
184 tapkee::TapkeeOutput output = tapkee::embed(indices.begin(),indices.end(),
185 kernel_callback,distance_callback,features_callback,parameters_set);
186 tapkee::DenseMatrix result_embedding = output.embedding;
188 output.projection.clear();
192 for (uint32_t i=0; i<N; i++)
194 for (uint32_t j=0; j<parameters.target_dimension; j++)
196 feature_matrix(j,i) = result_embedding(i,j);
void vector(int i, tapkee::DenseVector &v) const
Features that support dot products among other operations.
all of classes and functions are contained in the shogun namespace
ShogunFeatureVectorCallback(CDotFeatures *f)
tapkee::IndexType dimension() const