From 0eed6442421f841d2bbb483dafc9f6f8c4437073 Mon Sep 17 00:00:00 2001 From: Sergey Lisitsyn Date: Mon, 6 May 2024 17:22:01 +0100 Subject: [PATCH] Add empty implementation for UMAP --- include/tapkee/defines/methods.hpp | 3 +++ include/tapkee/methods.hpp | 1 + include/tapkee/methods/all.hpp | 1 + include/tapkee/methods/umap.hpp | 25 +++++++++++++++++++++++++ src/cli/main.cpp | 2 +- src/cli/util.hpp | 2 ++ test/unit/methods.cpp | 5 +++++ 7 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 include/tapkee/methods/umap.hpp diff --git a/include/tapkee/defines/methods.hpp b/include/tapkee/defines/methods.hpp index 90382cc..04feeab 100644 --- a/include/tapkee/defines/methods.hpp +++ b/include/tapkee/defines/methods.hpp @@ -136,6 +136,9 @@ static const DimensionReductionMethod tDistributedStochasticNeighborEmbedding("t * @cite Gashler2007 */ static const DimensionReductionMethod ManifoldSculpting("Manifold Sculpting", RequiresFeatures); +/** Uniform Manifold Approximation and Projection (UMAP) */ +static const DimensionReductionMethod UniformManifoldApproximationAndProjection("Uniform Manifold Approximation and Projection", RequiresFeatures); + /** Passing through (doing nothing just passes the * data through) */ static const DimensionReductionMethod PassThru("Pass-through", RequiresFeatures); diff --git a/include/tapkee/methods.hpp b/include/tapkee/methods.hpp index 4d2cd93..c150d78 100644 --- a/include/tapkee/methods.hpp +++ b/include/tapkee/methods.hpp @@ -70,6 +70,7 @@ class DynamicImplementation : public ImplementationBase #include #include +#include /* End of Tapkee includes */ namespace tapkee diff --git a/include/tapkee/methods/umap.hpp b/include/tapkee/methods/umap.hpp new file mode 100644 index 0000000..78c1379 --- /dev/null +++ b/include/tapkee/methods/umap.hpp @@ -0,0 +1,25 @@ +/* This software is distributed under BSD 3-clause license (see LICENSE file). + * + * Copyright (c) 2024 Sergey Lisitsyn, Fernando Iglesias + */ +#pragma once + +/* Tapkee includes */ +#include +/* End of Tapkee includes */ + +namespace tapkee +{ +namespace tapkee_internal +{ + +__TAPKEE_IMPLEMENTATION(UniformManifoldApproximationAndProjection) + TapkeeOutput embed() + { + DenseMatrix feature_matrix{this->end - this->begin, static_cast(this->parameters[target_dimension])}; + return TapkeeOutput(feature_matrix, unimplementedProjectingFunction()); + } +__TAPKEE_END_IMPLEMENTATION() + +} // End of namespace tapkee_internal +} // End of namespace tapkee diff --git a/src/cli/main.cpp b/src/cli/main.cpp index b22919d..a6cbe7e 100644 --- a/src/cli/main.cpp +++ b/src/cli/main.cpp @@ -146,7 +146,7 @@ int run(int argc, const char **argv) "diffusion_map (dm), isomap, landmark_isomap (l-isomap), multidimensional_scaling (mds), \n" "landmark_multidimensional_scaling (l-mds), stochastic_proximity_embedding (spe), \n" "kernel_pca (kpca), pca, random_projection (ra), factor_analysis (fa), \n" - "t-stochastic_neighborhood_embedding (t-sne), manifold_sculpting (ms).", + "t-stochastic_neighborhood_embedding (t-sne), manifold_sculpting (ms), umap.", with_default("locally_linear_embedding"s) ) ( diff --git a/src/cli/util.hpp b/src/cli/util.hpp index 43e70d1..ec1c300 100644 --- a/src/cli/util.hpp +++ b/src/cli/util.hpp @@ -137,6 +137,8 @@ tapkee::DimensionReductionMethod parse_reduction_method(const char* str) return tapkee::tDistributedStochasticNeighborEmbedding; if (!strcmp(str, "manifold_sculpting") || !strcmp(str, "ms")) return tapkee::ManifoldSculpting; + if (!strcmp(str, "umap")) + return tapkee::UniformManifoldApproximationAndProjection; throw std::exception(); return tapkee::PassThru; diff --git a/test/unit/methods.cpp b/test/unit/methods.cpp index a7e5af2..fa390d9 100644 --- a/test/unit/methods.cpp +++ b/test/unit/methods.cpp @@ -120,3 +120,8 @@ TEST(Methods, tDistributedStochasticNeighborEmbeddingSmokeTest) { smoketest(tDistributedStochasticNeighborEmbedding); } + +TEST(Methods, UniformManifoldApproximationAndProjection) +{ + smoketest(UniformManifoldApproximationAndProjection); +}