diff --git a/include/tapkee/methods.hpp b/include/tapkee/methods.hpp index d849853..e049952 100644 --- a/include/tapkee/methods.hpp +++ b/include/tapkee/methods.hpp @@ -48,6 +48,7 @@ class DynamicImplementation : public ImplementationBase(self); \ + implementation.validate(); \ return implementation.embed(); \ } tapkee_method_handle(KernelLocallyLinearEmbedding); diff --git a/include/tapkee/methods/all.hpp b/include/tapkee/methods/all.hpp index c19bc25..c90bfca 100644 --- a/include/tapkee/methods/all.hpp +++ b/include/tapkee/methods/all.hpp @@ -33,6 +33,10 @@ namespace tapkee_internal { __TAPKEE_IMPLEMENTATION(PassThru) + void validate() + { + } + TapkeeOutput embed() { DenseMatrix feature_matrix = dense_matrix_from_features(this->features, this->current_dimension, this->begin, this->end); diff --git a/include/tapkee/methods/diffusion_map.hpp b/include/tapkee/methods/diffusion_map.hpp index 920b19a..093c83c 100644 --- a/include/tapkee/methods/diffusion_map.hpp +++ b/include/tapkee/methods/diffusion_map.hpp @@ -15,11 +15,14 @@ namespace tapkee_internal { __TAPKEE_IMPLEMENTATION(DiffusionMap) - TapkeeOutput embed() + void validate() { parameters[diffusion_map_timesteps].checked().satisfies(Positivity()).orThrow(); parameters[gaussian_kernel_width].checked().satisfies(Positivity()).orThrow(); + } + TapkeeOutput embed() + { IndexType target_dimension_value = static_cast(parameters[target_dimension]); Parameter target_dimension_add = Parameter::create("target_dimension", target_dimension_value + 1); DenseSymmetricMatrix diffusion_matrix = diff --git a/include/tapkee/methods/factor_analysis.hpp b/include/tapkee/methods/factor_analysis.hpp index 634aeaa..a9e25f7 100644 --- a/include/tapkee/methods/factor_analysis.hpp +++ b/include/tapkee/methods/factor_analysis.hpp @@ -15,10 +15,13 @@ namespace tapkee_internal { __TAPKEE_IMPLEMENTATION(FactorAnalysis) - TapkeeOutput embed() + void validate() { parameters[fa_epsilon].checked().satisfies(NonNegativity()).orThrow(); + } + TapkeeOutput embed() + { DenseVector mean_vector = compute_mean(begin, end, features, current_dimension); return TapkeeOutput(project(begin, end, features, current_dimension, parameters[max_iteration], parameters[fa_epsilon], parameters[target_dimension], mean_vector), diff --git a/include/tapkee/methods/hessian_locally_linear_embedding.hpp b/include/tapkee/methods/hessian_locally_linear_embedding.hpp index 2ca70af..47f7f87 100644 --- a/include/tapkee/methods/hessian_locally_linear_embedding.hpp +++ b/include/tapkee/methods/hessian_locally_linear_embedding.hpp @@ -15,6 +15,10 @@ namespace tapkee_internal { __TAPKEE_IMPLEMENTATION(HessianLocallyLinearEmbedding) + void validate() + { + } + TapkeeOutput embed() { Neighbors neighbors = find_neighbors_with(kernel_distance); diff --git a/include/tapkee/methods/isomap.hpp b/include/tapkee/methods/isomap.hpp index 67eb7f6..e7b9e3d 100644 --- a/include/tapkee/methods/isomap.hpp +++ b/include/tapkee/methods/isomap.hpp @@ -16,6 +16,10 @@ namespace tapkee_internal { __TAPKEE_IMPLEMENTATION(Isomap) + void validate() + { + } + TapkeeOutput embed() { Neighbors neighbors = find_neighbors_with(plain_distance); diff --git a/include/tapkee/methods/kernel_local_tangent_space_alignment.hpp b/include/tapkee/methods/kernel_local_tangent_space_alignment.hpp index 015fca6..479caed 100644 --- a/include/tapkee/methods/kernel_local_tangent_space_alignment.hpp +++ b/include/tapkee/methods/kernel_local_tangent_space_alignment.hpp @@ -15,6 +15,10 @@ namespace tapkee_internal { __TAPKEE_IMPLEMENTATION(KernelLocalTangentSpaceAlignment) + void validate() + { + } + TapkeeOutput embed() { Neighbors neighbors = find_neighbors_with(kernel_distance); diff --git a/include/tapkee/methods/kernel_locally_linear_embedding.hpp b/include/tapkee/methods/kernel_locally_linear_embedding.hpp index 87bda02..51007e3 100644 --- a/include/tapkee/methods/kernel_locally_linear_embedding.hpp +++ b/include/tapkee/methods/kernel_locally_linear_embedding.hpp @@ -15,6 +15,10 @@ namespace tapkee_internal { __TAPKEE_IMPLEMENTATION(KernelLocallyLinearEmbedding) + void validate() + { + } + TapkeeOutput embed() { Neighbors neighbors = find_neighbors_with(kernel_distance); diff --git a/include/tapkee/methods/kernel_pca.hpp b/include/tapkee/methods/kernel_pca.hpp index 1be312d..50b1477 100644 --- a/include/tapkee/methods/kernel_pca.hpp +++ b/include/tapkee/methods/kernel_pca.hpp @@ -15,6 +15,10 @@ namespace tapkee_internal { __TAPKEE_IMPLEMENTATION(KernelPrincipalComponentAnalysis) + void validate() + { + } + TapkeeOutput embed() { DenseSymmetricMatrix centered_kernel_matrix = compute_centered_kernel_matrix(begin, end, kernel); diff --git a/include/tapkee/methods/landmark_isomap.hpp b/include/tapkee/methods/landmark_isomap.hpp index 12c5219..d249937 100644 --- a/include/tapkee/methods/landmark_isomap.hpp +++ b/include/tapkee/methods/landmark_isomap.hpp @@ -17,9 +17,13 @@ namespace tapkee_internal { __TAPKEE_IMPLEMENTATION(LandmarkIsomap) - TapkeeOutput embed() + void validate() { parameters[landmark_ratio].checked().satisfies(InClosedRange(3.0 / n_vectors, 1.0)).orThrow(); + } + + TapkeeOutput embed() + { Neighbors neighbors = find_neighbors_with(plain_distance); Landmarks landmarks = select_landmarks_random(begin, end, parameters[landmark_ratio]); diff --git a/include/tapkee/methods/landmark_multidimensional_scaling.hpp b/include/tapkee/methods/landmark_multidimensional_scaling.hpp index 17cefd6..9223d90 100644 --- a/include/tapkee/methods/landmark_multidimensional_scaling.hpp +++ b/include/tapkee/methods/landmark_multidimensional_scaling.hpp @@ -16,9 +16,13 @@ namespace tapkee_internal { __TAPKEE_IMPLEMENTATION(LandmarkMultidimensionalScaling) - TapkeeOutput embed() + void validate() { parameters[landmark_ratio].checked().satisfies(InClosedRange(3.0 / n_vectors, 1.0)).orThrow(); + } + + TapkeeOutput embed() + { Landmarks landmarks = select_landmarks_random(begin, end, parameters[landmark_ratio]); DenseSymmetricMatrix distance_matrix = compute_distance_matrix(begin, end, landmarks, distance); diff --git a/include/tapkee/methods/laplacian_eigenmaps.hpp b/include/tapkee/methods/laplacian_eigenmaps.hpp index cbece81..41b4194 100644 --- a/include/tapkee/methods/laplacian_eigenmaps.hpp +++ b/include/tapkee/methods/laplacian_eigenmaps.hpp @@ -16,10 +16,13 @@ namespace tapkee_internal { __TAPKEE_IMPLEMENTATION(LaplacianEigenmaps) - TapkeeOutput embed() + void validate() { parameters[gaussian_kernel_width].checked().satisfies(Positivity()).orThrow(); + } + TapkeeOutput embed() + { Neighbors neighbors = find_neighbors_with(plain_distance); Laplacian laplacian = compute_laplacian(begin, end, neighbors, distance, parameters[gaussian_kernel_width]); return TapkeeOutput(generalized_eigendecomposition(parameters[eigen_method], parameters[computation_strategy], diff --git a/include/tapkee/methods/linear_local_tangent_space_alignment.hpp b/include/tapkee/methods/linear_local_tangent_space_alignment.hpp index d203b6f..b566d78 100644 --- a/include/tapkee/methods/linear_local_tangent_space_alignment.hpp +++ b/include/tapkee/methods/linear_local_tangent_space_alignment.hpp @@ -16,6 +16,10 @@ namespace tapkee_internal { __TAPKEE_IMPLEMENTATION(LinearLocalTangentSpaceAlignment) + void validate() + { + } + TapkeeOutput embed() { Neighbors neighbors = find_neighbors_with(kernel_distance); diff --git a/include/tapkee/methods/locality_preserving_projections.hpp b/include/tapkee/methods/locality_preserving_projections.hpp index aa8bc16..7c54893 100644 --- a/include/tapkee/methods/locality_preserving_projections.hpp +++ b/include/tapkee/methods/locality_preserving_projections.hpp @@ -17,10 +17,13 @@ namespace tapkee_internal { __TAPKEE_IMPLEMENTATION(LocalityPreservingProjections) - TapkeeOutput embed() + void validate() { parameters[gaussian_kernel_width].checked().satisfies(Positivity()).orThrow(); + } + TapkeeOutput embed() + { Neighbors neighbors = find_neighbors_with(plain_distance); Laplacian laplacian = compute_laplacian(begin, end, neighbors, distance, parameters[gaussian_kernel_width]); DenseSymmetricMatrixPair eigenproblem_matrices = construct_locality_preserving_eigenproblem( diff --git a/include/tapkee/methods/manifold_sculpting.hpp b/include/tapkee/methods/manifold_sculpting.hpp index 409f26e..576a5c8 100644 --- a/include/tapkee/methods/manifold_sculpting.hpp +++ b/include/tapkee/methods/manifold_sculpting.hpp @@ -15,9 +15,13 @@ namespace tapkee_internal { __TAPKEE_IMPLEMENTATION(ManifoldSculpting) - TapkeeOutput embed() + void validate() { parameters[squishing_rate].checked().satisfies(InRange(0.0, 1.0)).orThrow(); + } + + TapkeeOutput embed() + { DenseMatrix embedding = dense_matrix_from_features(features, current_dimension, begin, end); diff --git a/include/tapkee/methods/multidimensional_scaling.hpp b/include/tapkee/methods/multidimensional_scaling.hpp index 8a3c203..bf1b754 100644 --- a/include/tapkee/methods/multidimensional_scaling.hpp +++ b/include/tapkee/methods/multidimensional_scaling.hpp @@ -15,6 +15,10 @@ namespace tapkee_internal { __TAPKEE_IMPLEMENTATION(MultidimensionalScaling) + void validate() + { + } + TapkeeOutput embed() { DenseSymmetricMatrix distance_matrix = compute_distance_matrix(begin, end, distance); diff --git a/include/tapkee/methods/neighborhood_preserving_embedding.hpp b/include/tapkee/methods/neighborhood_preserving_embedding.hpp index 3752b78..d287e1d 100644 --- a/include/tapkee/methods/neighborhood_preserving_embedding.hpp +++ b/include/tapkee/methods/neighborhood_preserving_embedding.hpp @@ -17,6 +17,10 @@ namespace tapkee_internal { __TAPKEE_IMPLEMENTATION(NeighborhoodPreservingEmbedding) + void validate() + { + } + TapkeeOutput embed() { Neighbors neighbors = find_neighbors_with(kernel_distance); diff --git a/include/tapkee/methods/pca.hpp b/include/tapkee/methods/pca.hpp index 1f56576..92b0538 100644 --- a/include/tapkee/methods/pca.hpp +++ b/include/tapkee/methods/pca.hpp @@ -15,6 +15,10 @@ namespace tapkee_internal { __TAPKEE_IMPLEMENTATION(PrincipalComponentAnalysis) + void validate() + { + } + TapkeeOutput embed() { DenseVector mean_vector = compute_mean(begin, end, features, current_dimension); diff --git a/include/tapkee/methods/random_projection.hpp b/include/tapkee/methods/random_projection.hpp index 8054b23..c54f4ba 100644 --- a/include/tapkee/methods/random_projection.hpp +++ b/include/tapkee/methods/random_projection.hpp @@ -15,6 +15,10 @@ namespace tapkee_internal { __TAPKEE_IMPLEMENTATION(RandomProjection) + void validate() + { + } + TapkeeOutput embed() { DenseMatrix projection_matrix = gaussian_projection_matrix(current_dimension, parameters[target_dimension]); diff --git a/include/tapkee/methods/stochastic_proximity_embedding.hpp b/include/tapkee/methods/stochastic_proximity_embedding.hpp index c62e885..a2cc400 100644 --- a/include/tapkee/methods/stochastic_proximity_embedding.hpp +++ b/include/tapkee/methods/stochastic_proximity_embedding.hpp @@ -15,10 +15,14 @@ namespace tapkee_internal { __TAPKEE_IMPLEMENTATION(StochasticProximityEmbedding) - TapkeeOutput embed() + void validate() { parameters[spe_tolerance].checked().satisfies(Positivity()).orThrow(); parameters[spe_num_updates].checked().satisfies(Positivity()).orThrow(); + } + + TapkeeOutput embed() + { Neighbors neighbors; if (parameters[spe_global_strategy].is(false)) { diff --git a/include/tapkee/methods/tsne.hpp b/include/tapkee/methods/tsne.hpp index ac49e28..5b4288f 100644 --- a/include/tapkee/methods/tsne.hpp +++ b/include/tapkee/methods/tsne.hpp @@ -15,11 +15,14 @@ namespace tapkee_internal { __TAPKEE_IMPLEMENTATION(tDistributedStochasticNeighborEmbedding) - TapkeeOutput embed() + void validate() { parameters[sne_perplexity].checked().satisfies(InClosedRange(0.0, (n_vectors - 1) / 3.0)).orThrow(); parameters[sne_theta].checked().satisfies(NonNegativity()).orThrow(); + } + TapkeeOutput embed() + { DenseMatrix data = dense_matrix_from_features(features, current_dimension, begin, end); DenseMatrix embedding(static_cast(parameters[target_dimension]), n_vectors);