From 043c3e8fc397a4f7f950d78c3d0080340085746c Mon Sep 17 00:00:00 2001 From: "Fernando J. Iglesias Garcia" Date: Fri, 24 May 2024 12:06:28 +0200 Subject: [PATCH 1/3] Try 23 from 20 standard. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e6225f2..41d8a9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required (VERSION 3.24) project (Tapkee LANGUAGES CXX) # set paths -set (CMAKE_CXX_STANDARD 20) +set (CMAKE_CXX_STANDARD 23) set (TAPKEE_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") set (TAPKEE_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src") set (TAPKEE_TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/test/unit") From f598e9ab88093b60eeac6158aa9e2b46affbf358 Mon Sep 17 00:00:00 2001 From: "Fernando J. Iglesias Garcia" Date: Fri, 24 May 2024 12:37:23 +0200 Subject: [PATCH 2/3] Experiment trimming interface. --- README.md | 34 +++++++++------------ examples/minimal/minimal.cpp | 3 +- examples/precomputed/precomputed.cpp | 5 ++-- examples/rna/rna.cpp | 3 +- include/tapkee/chain_interface.hpp | 38 ++++++++--------------- src/cli/main.cpp | 9 +++--- test/unit/interface.cpp | 45 ++++++++++------------------ test/unit/projecting.cpp | 4 +-- 8 files changed, 52 insertions(+), 89 deletions(-) diff --git a/README.md b/README.md index baf63d4..ca1a2f0 100644 --- a/README.md +++ b/README.md @@ -43,10 +43,9 @@ some examples of usage Tapkee in Shogun as API --- -We provide an interface based on the method chaining technique. The chain starts from the call -of the `initialize()` method and followed with the `withParameters(const ParametersSet&)` call -which is used to provide parameters like the method to use and its settings. The provided -argument is formed with the following syntax: +We provide an interface based on the method chaining technique. The chain starts with the call +of the `with(const ParametersSet&)` method, which is used to provide parameters like the method +to use and its settings. The provided argument is formed with the following syntax: (keyword1=value1, keyword2=value2) @@ -63,24 +62,23 @@ are defined: `method`, `eigen_method`, `neighbors_method`, `num_neighbors`, `tar As an example of parameters setting, if you want to use the Isomap algorithm with the number of neighbors set to 15: - tapkee::initialize().withParameters((method=Isomap,num_neighbors=15)) + tapkee::with((method=Isomap,num_neighbors=15)) Please note that the inner parentheses are necessary as it uses the comma operator which appears to be ambiguous in this case. -Next, with initialized parameters you may either embed the provided matrix with: +Next, you may either embed the provided matrix with: - tapkee::initialize().withParameters((method=Isomap,num_neighbors=15)). - .embedUsing(matrix); + tapkee::with((method=Isomap,num_neighbors=15)).embedUsing(matrix); Or provide callbacks (kernel, distance and features) using any combination of the `withKernel(KernelCallback)`, `withDistance(DistanceCallback)` and `withFeatures(FeaturesCallback)` member functions: - tapkee::initialize().withParameters((method=Isomap,num_neighbors=15)) - .withKernel(kernel_callback) - .withDistance(distance_callback) - .withFeatures(features_callback) + tapkee::with((method=Isomap,num_neighbors=15)) + .withKernel(kernel_callback) + .withDistance(distance_callback) + .withFeatures(features_callback) Once callbacks are initialized you may either embed data using an STL-compatible sequence of indices or objects (that supports the @@ -92,17 +90,14 @@ member function. As a summary - a few examples: - TapkeeOutput output = initialize() - .withParameters((method=Isomap,num_neighbors=15)) + TapkeeOutput output = with((method=Isomap,num_neighbors=15)) .embedUsing(matrix); - TapkeeOutput output = initialize() - .withParameters((method=Isomap,num_neighbors=15)) + TapkeeOutput output = with((method=Isomap,num_neighbors=15)) .withDistance(distance_callback) .embedUsing(indices); - TapkeeOutput output = initialize() - .withParameters((method=Isomap,num_neighbors=15)) + TapkeeOutput output = with((method=Isomap,num_neighbors=15)) .withDistance(distance_callback) .embedRange(indices.begin(),indices.end()); @@ -130,8 +125,7 @@ A minimal working example of a program that uses the library is: MyDistanceCallback d; - TapkeeOutput output = tapkee::initialize() - .withParameters((method=MultidimensionalScaling,target_dimension=1)) + TapkeeOutput output = tapke::with((method=MultidimensionalScaling,target_dimension=1)) .withDistance(d) .embedUsing(indices); diff --git a/examples/minimal/minimal.cpp b/examples/minimal/minimal.cpp index 6725b4c..fdb8a96 100644 --- a/examples/minimal/minimal.cpp +++ b/examples/minimal/minimal.cpp @@ -20,8 +20,7 @@ int main(int argc, const char **argv) MyDistanceCallback distance; - TapkeeOutput output = initialize() - .withParameters((method = MultidimensionalScaling, target_dimension = 1)) + TapkeeOutput output = with((method = MultidimensionalScaling, target_dimension = 1)) .withDistance(distance) .embedUsing(indices); diff --git a/examples/precomputed/precomputed.cpp b/examples/precomputed/precomputed.cpp index 4086d7b..854b3f9 100644 --- a/examples/precomputed/precomputed.cpp +++ b/examples/precomputed/precomputed.cpp @@ -7,7 +7,7 @@ using namespace tapkee; int main(int argc, const char **argv) { const int N = 100; - tapkee::DenseMatrix distances(N, N); + DenseMatrix distances(N, N); vector indices(N); for (int i = 0; i < N; i++) { @@ -19,8 +19,7 @@ int main(int argc, const char **argv) precomputed_distance_callback distance(distances); - TapkeeOutput output = initialize() - .withParameters((method = MultidimensionalScaling, target_dimension = 1)) + TapkeeOutput output = with((method = MultidimensionalScaling, target_dimension = 1)) .withDistance(distance) .embedUsing(indices); diff --git a/examples/rna/rna.cpp b/examples/rna/rna.cpp index e8b5d4e..52fad2d 100644 --- a/examples/rna/rna.cpp +++ b/examples/rna/rna.cpp @@ -33,8 +33,7 @@ int main(int argc, const char **argv) MatchKernelCallback kernel; - TapkeeOutput result = initialize() - .withParameters((method = KernelLocallyLinearEmbedding, num_neighbors = 30)) + TapkeeOutput result = .with((method = KernelLocallyLinearEmbedding, num_neighbors = 30)) .withKernel(kernel) .embedUsing(rnas); diff --git a/include/tapkee/chain_interface.hpp b/include/tapkee/chain_interface.hpp index 53d2801..42e08a5 100644 --- a/include/tapkee/chain_interface.hpp +++ b/include/tapkee/chain_interface.hpp @@ -484,31 +484,19 @@ class ParametersInitializedState }; } /* End of namespace tapkee_internal */ -struct initialize +/** Returns an instance representing a state with initialized parameters. + * + * In the chain this method's call is followed by any of + * @ref tapkee_internal::ParametersInitializedState::embedUsing + * @ref tapkee_internal::ParametersInitializedState::withKernel + * @ref tapkee_internal::ParametersInitializedState::withDistance + * @ref tapkee_internal::ParametersInitializedState::withFeatures + * + * @param parameters a set of parameters formed by keywords assigned to values + */ +tapkee_internal::ParametersInitializedState with(const ParametersSet& parameters) { - /** Constructor that is the first required - * method in the call chain. - */ - initialize() - { - } - - /** The second required method in the call chain. Returns - * an instance representing a state with initialized parameters. - * - * In the chain this method's call is followed by any of - * * @ref tapkee_internal::ParametersInitializedState::embedUsing - * * @ref tapkee_internal::ParametersInitializedState::withKernel - * * @ref tapkee_internal::ParametersInitializedState::withDistance - * * @ref tapkee_internal::ParametersInitializedState::withFeatures - * - * @param parameters a set of parameters formed from keywords assigned - * to values - */ - tapkee_internal::ParametersInitializedState withParameters(const ParametersSet& parameters) const - { - return tapkee_internal::ParametersInitializedState(parameters); - } -}; + return tapkee_internal::ParametersInitializedState(parameters); +} } /* End of namespace tapkee */ diff --git a/src/cli/main.cpp b/src/cli/main.cpp index d203d25..b4f82f9 100644 --- a/src/cli/main.cpp +++ b/src/cli/main.cpp @@ -362,10 +362,10 @@ int run(int argc, const char **argv) } int target_dim = opt[TARGET_DIMENSION_KEYWORD].as(); - if (target_dim < 0) + if (target_dim <= 0) { tapkee::Logging::instance().message_error( - "Negative target dimensionality is not possible in current circumstances. " + "\"Only\" a positive target dimensionality larger than zero is possible in current circumstances. " "Please visit other universe"); return 1; } @@ -469,8 +469,7 @@ int run(int argc, const char **argv) tapkee::precomputed_kernel_callback kcb(kernel_matrix); tapkee::eigen_features_callback fcb(input_data); - output = tapkee::initialize() - .withParameters(parameters) + output = tapkee::with(parameters) .withKernel(kcb) .withDistance(dcb) .withFeatures(fcb) @@ -478,7 +477,7 @@ int run(int argc, const char **argv) } else { - output = tapkee::initialize().withParameters(parameters).embedUsing(input_data); + output = tapkee::with(parameters).embedUsing(input_data); } // Save obtained data if (opt.count(TRANSPOSE_OUTPUT_KEYWORD)) diff --git a/test/unit/interface.cpp b/test/unit/interface.cpp index d63acba..f386776 100644 --- a/test/unit/interface.cpp +++ b/test/unit/interface.cpp @@ -20,96 +20,81 @@ TEST(Interface, ChainInterfaceOrder) TapkeeOutput output; - ASSERT_NO_THROW(output = tapkee::initialize() - .withParameters((method = MultidimensionalScaling)) + ASSERT_NO_THROW(output = tapkee::with((method = MultidimensionalScaling)) .withKernel(kcb) .withFeatures(fcb) .withDistance(dcb) .embedRange(indices.begin(), indices.end())); - ASSERT_NO_THROW(output = tapkee::initialize() - .withParameters((method = MultidimensionalScaling)) + ASSERT_NO_THROW(output = tapkee::with((method = MultidimensionalScaling)) .withKernel(kcb) .withDistance(dcb) .withFeatures(fcb) .embedRange(indices.begin(), indices.end())); - ASSERT_NO_THROW(output = tapkee::initialize() - .withParameters((method = KernelPrincipalComponentAnalysis)) + ASSERT_NO_THROW(output = tapkee::with((method = KernelPrincipalComponentAnalysis)) .withDistance(dcb) .withKernel(kcb) .withFeatures(fcb) .embedRange(indices.begin(), indices.end())); - ASSERT_NO_THROW(output = tapkee::initialize() - .withParameters((method = PassThru)) + ASSERT_NO_THROW(output = tapkee::with((method = PassThru)) .withDistance(dcb) .withFeatures(fcb) .withKernel(kcb) .embedRange(indices.begin(), indices.end())); - ASSERT_NO_THROW(output = tapkee::initialize() - .withParameters((method = MultidimensionalScaling)) + ASSERT_NO_THROW(output = tapkee::with((method = MultidimensionalScaling)) .withFeatures(fcb) .withDistance(dcb) .withKernel(kcb) .embedRange(indices.begin(), indices.end())); - ASSERT_NO_THROW(output = tapkee::initialize() - .withParameters((method = MultidimensionalScaling)) + ASSERT_NO_THROW(output = tapkee::with((method = MultidimensionalScaling)) .withFeatures(fcb) .withKernel(kcb) .withDistance(dcb) .embedRange(indices.begin(), indices.end())); - ASSERT_NO_THROW(output = tapkee::initialize() - .withParameters((method = PassThru)) + ASSERT_NO_THROW(output = tapkee::with((method = PassThru)) .withFeatures(fcb) .withKernel(kcb) .embedRange(indices.begin(), indices.end())); - ASSERT_NO_THROW(output = tapkee::initialize() - .withParameters((method = PassThru)) + ASSERT_NO_THROW(output = tapkee::with((method = PassThru)) .withFeatures(fcb) .withDistance(dcb) .embedRange(indices.begin(), indices.end())); - ASSERT_NO_THROW(output = tapkee::initialize() - .withParameters((method = KernelPrincipalComponentAnalysis)) + ASSERT_NO_THROW(output = tapkee::with((method = KernelPrincipalComponentAnalysis)) .withKernel(kcb) .withDistance(dcb) .embedRange(indices.begin(), indices.end())); - ASSERT_NO_THROW(output = tapkee::initialize() - .withParameters((method = KernelPrincipalComponentAnalysis)) + ASSERT_NO_THROW(output = tapkee::with((method = KernelPrincipalComponentAnalysis)) .withKernel(kcb) .withFeatures(fcb) .embedRange(indices.begin(), indices.end())); - ASSERT_NO_THROW(output = tapkee::initialize() - .withParameters((method = MultidimensionalScaling)) + ASSERT_NO_THROW(output = tapkee::with((method = MultidimensionalScaling)) .withDistance(dcb) .withFeatures(fcb) .embedRange(indices.begin(), indices.end())); - ASSERT_NO_THROW(output = tapkee::initialize() - .withParameters((method = MultidimensionalScaling)) + ASSERT_NO_THROW(output = tapkee::with((method = MultidimensionalScaling)) .withDistance(dcb) .withKernel(kcb) .embedRange(indices.begin(), indices.end())); - ASSERT_NO_THROW(output = tapkee::initialize() - .withParameters((method = KernelPrincipalComponentAnalysis)) + ASSERT_NO_THROW(output = tapkee::with((method = KernelPrincipalComponentAnalysis)) .withKernel(kcb) .embedRange(indices.begin(), indices.end())); - ASSERT_NO_THROW(output = tapkee::initialize() - .withParameters((method = MultidimensionalScaling)) + ASSERT_NO_THROW(output = tapkee::with((method = MultidimensionalScaling)) .withDistance(dcb) .embedRange(indices.begin(), indices.end())); - ASSERT_NO_THROW(output = tapkee::initialize() - .withParameters((method = PassThru)) + ASSERT_NO_THROW(output = tapkee::with((method = PassThru)) .withFeatures(fcb) .embedRange(indices.begin(), indices.end())); } diff --git a/test/unit/projecting.cpp b/test/unit/projecting.cpp index 1cddcf5..bd103e8 100644 --- a/test/unit/projecting.cpp +++ b/test/unit/projecting.cpp @@ -13,7 +13,7 @@ TEST(Projecting, PrincipalComponentAnalysis) TapkeeOutput output; - ASSERT_NO_THROW(output = tapkee::initialize().withParameters((method = PrincipalComponentAnalysis, target_dimension = 2)).embedUsing(X)); + ASSERT_NO_THROW(output = tapkee::with((method = PrincipalComponentAnalysis, target_dimension = 2)).embedUsing(X)); auto projected = output.projection(X.col(0)); ASSERT_EQ(2, projected.size()); @@ -26,7 +26,7 @@ TEST(Projecting, RandomProjection) TapkeeOutput output; - ASSERT_NO_THROW(output = tapkee::initialize().withParameters((method = RandomProjection, target_dimension = 2)).embedUsing(X)); + ASSERT_NO_THROW(output = tapkee::with((method = RandomProjection, target_dimension = 2)).embedUsing(X)); auto projected = output.projection(X.col(0)); ASSERT_EQ(2, projected.size()); From da233c1d7a75e82971f30cb3a644cd22376d86dc Mon Sep 17 00:00:00 2001 From: "Fernando J. Iglesias Garcia" Date: Fri, 24 May 2024 19:44:16 +0200 Subject: [PATCH 3/3] Fix typo. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ca1a2f0..1dd27c1 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ A minimal working example of a program that uses the library is: MyDistanceCallback d; - TapkeeOutput output = tapke::with((method=MultidimensionalScaling,target_dimension=1)) + TapkeeOutput output = tapkee::with((method=MultidimensionalScaling,target_dimension=1)) .withDistance(d) .embedUsing(indices);