10 #include <shogun/lib/tapkee/tapkee_shogun.hpp>
13 #define CUSTOM_UNIFORM_RANDOM_INDEX_FUNCTION shogun::CMath::random()
14 #define CUSTOM_UNIFORM_RANDOM_FUNCTION shogun::CMath::random(static_cast<tapkee::ScalarType>(0),static_cast<tapkee::ScalarType>(1))
15 #define CUSTOM_GAUSSIAN_RANDOM_FUNCTION shogun::CMath::normal_random(static_cast<tapkee::ScalarType>(0),static_cast<tapkee::ScalarType>(1))
16 #define TAPKEE_EIGEN_INCLUDE_FILE <shogun/mathematics/eigen3.h>
19 #define TAPKEE_WITH_ARPACK
21 #define TAPKEE_USE_LGPL_COVERTREE
22 #include <shogun/lib/tapkee/tapkee.hpp>
23 #include <shogun/lib/tapkee/callbacks/pimpl_callbacks.hpp>
29 virtual void message_info(
const std::string& msg)
33 virtual void message_warning(
const std::string& msg)
37 virtual void message_error(
const std::string& msg)
41 virtual void message_debug(
const std::string& msg)
45 virtual void message_benchmark(
const std::string& msg)
57 return (dim = features->get_dim_feature_space());
61 inline void vector(
int i, tapkee::DenseVector& v)
const
64 features->add_to_dense_vec(1.0,i,v.data(),dim);
74 tapkee::LoggingSingleton::instance().enable_benchmark();
75 tapkee::LoggingSingleton::instance().enable_info();
77 pimpl_kernel_callback<CKernel> kernel_callback(parameters.kernel);
78 pimpl_distance_callback<CDistance> distance_callback(parameters.distance);
81 tapkee::DimensionReductionMethod method;
83 tapkee::EigenMethod eigen_method = tapkee::Arpack;
85 tapkee::EigenMethod eigen_method = tapkee::Dense;
87 tapkee::NeighborsMethod neighbors_method = tapkee::CoverTree;
90 switch (parameters.method)
92 case SHOGUN_KERNEL_LOCALLY_LINEAR_EMBEDDING:
93 case SHOGUN_LOCALLY_LINEAR_EMBEDDING:
94 method = tapkee::KernelLocallyLinearEmbedding;
95 N = parameters.kernel->get_num_vec_lhs();
97 case SHOGUN_NEIGHBORHOOD_PRESERVING_EMBEDDING:
98 method = tapkee::NeighborhoodPreservingEmbedding;
99 N = parameters.kernel->get_num_vec_lhs();
101 case SHOGUN_LOCAL_TANGENT_SPACE_ALIGNMENT:
102 method = tapkee::KernelLocalTangentSpaceAlignment;
103 N = parameters.kernel->get_num_vec_lhs();
105 case SHOGUN_LINEAR_LOCAL_TANGENT_SPACE_ALIGNMENT:
106 method = tapkee::LinearLocalTangentSpaceAlignment;
107 N = parameters.kernel->get_num_vec_lhs();
109 case SHOGUN_HESSIAN_LOCALLY_LINEAR_EMBEDDING:
110 method = tapkee::HessianLocallyLinearEmbedding;
111 N = parameters.kernel->get_num_vec_lhs();
113 case SHOGUN_DIFFUSION_MAPS:
114 method = tapkee::DiffusionMap;
115 N = parameters.distance->get_num_vec_lhs();
117 case SHOGUN_LAPLACIAN_EIGENMAPS:
118 method = tapkee::LaplacianEigenmaps;
119 N = parameters.distance->get_num_vec_lhs();
121 case SHOGUN_LOCALITY_PRESERVING_PROJECTIONS:
122 method = tapkee::LocalityPreservingProjections;
123 N = parameters.distance->get_num_vec_lhs();
125 case SHOGUN_MULTIDIMENSIONAL_SCALING:
126 method = tapkee::MultidimensionalScaling;
127 N = parameters.distance->get_num_vec_lhs();
129 case SHOGUN_LANDMARK_MULTIDIMENSIONAL_SCALING:
130 method = tapkee::LandmarkMultidimensionalScaling;
131 N = parameters.distance->get_num_vec_lhs();
134 method = tapkee::Isomap;
135 N = parameters.distance->get_num_vec_lhs();
137 case SHOGUN_LANDMARK_ISOMAP:
138 method = tapkee::LandmarkIsomap;
139 N = parameters.distance->get_num_vec_lhs();
141 case SHOGUN_STOCHASTIC_PROXIMITY_EMBEDDING:
142 method = tapkee::StochasticProximityEmbedding;
143 N = parameters.distance->get_num_vec_lhs();
145 case SHOGUN_FACTOR_ANALYSIS:
146 method = tapkee::FactorAnalysis;
147 N = parameters.features->get_num_vectors();
149 case SHOGUN_TDISTRIBUTED_STOCHASTIC_NEIGHBOR_EMBEDDING:
150 method = tapkee::tDistributedStochasticNeighborEmbedding;
151 N = parameters.features->get_num_vectors();
153 case SHOGUN_MANIFOLD_SCULPTING:
154 method = tapkee::ManifoldSculpting;
155 N = parameters.features->get_num_vectors();
159 std::vector<int32_t> indices(N);
160 for (
size_t i=0; i<N; i++)
163 tapkee::ParametersSet parameters_set =
164 (tapkee::keywords::method=method,
165 tapkee::keywords::eigen_method=eigen_method,
166 tapkee::keywords::neighbors_method=neighbors_method,
167 tapkee::keywords::num_neighbors=parameters.n_neighbors,
168 tapkee::keywords::diffusion_map_timesteps = parameters.n_timesteps,
169 tapkee::keywords::target_dimension = parameters.target_dimension,
170 tapkee::keywords::spe_num_updates = parameters.spe_num_updates,
171 tapkee::keywords::nullspace_shift = parameters.eigenshift,
172 tapkee::keywords::landmark_ratio = parameters.landmark_ratio,
173 tapkee::keywords::gaussian_kernel_width = parameters.gaussian_kernel_width,
174 tapkee::keywords::spe_tolerance = parameters.spe_tolerance,
175 tapkee::keywords::spe_global_strategy = parameters.spe_global_strategy,
176 tapkee::keywords::max_iteration = parameters.max_iteration,
177 tapkee::keywords::fa_epsilon = parameters.fa_epsilon,
178 tapkee::keywords::sne_perplexity = parameters.sne_perplexity,
179 tapkee::keywords::sne_theta = parameters.sne_theta,
180 tapkee::keywords::squishing_rate = parameters.squishing_rate
183 tapkee::TapkeeOutput output = tapkee::embed(indices.begin(),indices.end(),
184 kernel_callback,distance_callback,features_callback,parameters_set);
185 tapkee::DenseMatrix result_embedding = output.embedding;
187 output.projection.clear();
191 for (uint32_t i=0; i<N; i++)
193 for (uint32_t j=0; j<parameters.target_dimension; j++)
195 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