Skip to content

Commit

Permalink
Split validation and embedding of methods (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn authored May 22, 2024
1 parent 941c412 commit e7efda8
Show file tree
Hide file tree
Showing 21 changed files with 85 additions and 9 deletions.
1 change: 1 addition & 0 deletions include/tapkee/methods.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class DynamicImplementation : public ImplementationBase<RandomAccessIterator, Ke
if (method == X) { \
auto implementation = \
X ## Implementation<RandomAccessIterator, KernelCallback, DistanceCallback, FeaturesCallback>(self); \
implementation.validate(); \
return implementation.embed(); \
}
tapkee_method_handle(KernelLocallyLinearEmbedding);
Expand Down
4 changes: 4 additions & 0 deletions include/tapkee/methods/all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion include/tapkee/methods/diffusion_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ namespace tapkee_internal
{

__TAPKEE_IMPLEMENTATION(DiffusionMap)
TapkeeOutput embed()
void validate()
{
parameters[diffusion_map_timesteps].checked().satisfies(Positivity<IndexType>()).orThrow();
parameters[gaussian_kernel_width].checked().satisfies(Positivity<ScalarType>()).orThrow();
}

TapkeeOutput embed()
{
IndexType target_dimension_value = static_cast<IndexType>(parameters[target_dimension]);
Parameter target_dimension_add = Parameter::create("target_dimension", target_dimension_value + 1);
DenseSymmetricMatrix diffusion_matrix =
Expand Down
5 changes: 4 additions & 1 deletion include/tapkee/methods/factor_analysis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ namespace tapkee_internal
{

__TAPKEE_IMPLEMENTATION(FactorAnalysis)
TapkeeOutput embed()
void validate()
{
parameters[fa_epsilon].checked().satisfies(NonNegativity<ScalarType>()).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),
Expand Down
4 changes: 4 additions & 0 deletions include/tapkee/methods/hessian_locally_linear_embedding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ namespace tapkee_internal
{

__TAPKEE_IMPLEMENTATION(HessianLocallyLinearEmbedding)
void validate()
{
}

TapkeeOutput embed()
{
Neighbors neighbors = find_neighbors_with(kernel_distance);
Expand Down
4 changes: 4 additions & 0 deletions include/tapkee/methods/isomap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ namespace tapkee_internal
{

__TAPKEE_IMPLEMENTATION(Isomap)
void validate()
{
}

TapkeeOutput embed()
{
Neighbors neighbors = find_neighbors_with(plain_distance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ namespace tapkee_internal
{

__TAPKEE_IMPLEMENTATION(KernelLocalTangentSpaceAlignment)
void validate()
{
}

TapkeeOutput embed()
{
Neighbors neighbors = find_neighbors_with(kernel_distance);
Expand Down
4 changes: 4 additions & 0 deletions include/tapkee/methods/kernel_locally_linear_embedding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ namespace tapkee_internal
{

__TAPKEE_IMPLEMENTATION(KernelLocallyLinearEmbedding)
void validate()
{
}

TapkeeOutput embed()
{
Neighbors neighbors = find_neighbors_with(kernel_distance);
Expand Down
4 changes: 4 additions & 0 deletions include/tapkee/methods/kernel_pca.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion include/tapkee/methods/landmark_isomap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ namespace tapkee_internal
{

__TAPKEE_IMPLEMENTATION(LandmarkIsomap)
TapkeeOutput embed()
void validate()
{
parameters[landmark_ratio].checked().satisfies(InClosedRange<ScalarType>(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]);
Expand Down
6 changes: 5 additions & 1 deletion include/tapkee/methods/landmark_multidimensional_scaling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ namespace tapkee_internal
{

__TAPKEE_IMPLEMENTATION(LandmarkMultidimensionalScaling)
TapkeeOutput embed()
void validate()
{
parameters[landmark_ratio].checked().satisfies(InClosedRange<ScalarType>(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);
Expand Down
5 changes: 4 additions & 1 deletion include/tapkee/methods/laplacian_eigenmaps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ namespace tapkee_internal
{

__TAPKEE_IMPLEMENTATION(LaplacianEigenmaps)
TapkeeOutput embed()
void validate()
{
parameters[gaussian_kernel_width].checked().satisfies(Positivity<ScalarType>()).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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ namespace tapkee_internal
{

__TAPKEE_IMPLEMENTATION(LinearLocalTangentSpaceAlignment)
void validate()
{
}

TapkeeOutput embed()
{
Neighbors neighbors = find_neighbors_with(kernel_distance);
Expand Down
5 changes: 4 additions & 1 deletion include/tapkee/methods/locality_preserving_projections.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ namespace tapkee_internal
{

__TAPKEE_IMPLEMENTATION(LocalityPreservingProjections)
TapkeeOutput embed()
void validate()
{
parameters[gaussian_kernel_width].checked().satisfies(Positivity<ScalarType>()).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(
Expand Down
6 changes: 5 additions & 1 deletion include/tapkee/methods/manifold_sculpting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ namespace tapkee_internal
{

__TAPKEE_IMPLEMENTATION(ManifoldSculpting)
TapkeeOutput embed()
void validate()
{
parameters[squishing_rate].checked().satisfies(InRange<ScalarType>(0.0, 1.0)).orThrow();
}

TapkeeOutput embed()
{

DenseMatrix embedding = dense_matrix_from_features(features, current_dimension, begin, end);

Expand Down
4 changes: 4 additions & 0 deletions include/tapkee/methods/multidimensional_scaling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ namespace tapkee_internal
{

__TAPKEE_IMPLEMENTATION(MultidimensionalScaling)
void validate()
{
}

TapkeeOutput embed()
{
DenseSymmetricMatrix distance_matrix = compute_distance_matrix(begin, end, distance);
Expand Down
4 changes: 4 additions & 0 deletions include/tapkee/methods/neighborhood_preserving_embedding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ namespace tapkee_internal
{

__TAPKEE_IMPLEMENTATION(NeighborhoodPreservingEmbedding)
void validate()
{
}

TapkeeOutput embed()
{
Neighbors neighbors = find_neighbors_with(kernel_distance);
Expand Down
4 changes: 4 additions & 0 deletions include/tapkee/methods/pca.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ namespace tapkee_internal
{

__TAPKEE_IMPLEMENTATION(PrincipalComponentAnalysis)
void validate()
{
}

TapkeeOutput embed()
{
DenseVector mean_vector = compute_mean(begin, end, features, current_dimension);
Expand Down
4 changes: 4 additions & 0 deletions include/tapkee/methods/random_projection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
6 changes: 5 additions & 1 deletion include/tapkee/methods/stochastic_proximity_embedding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ namespace tapkee_internal
{

__TAPKEE_IMPLEMENTATION(StochasticProximityEmbedding)
TapkeeOutput embed()
void validate()
{
parameters[spe_tolerance].checked().satisfies(Positivity<ScalarType>()).orThrow();
parameters[spe_num_updates].checked().satisfies(Positivity<IndexType>()).orThrow();
}

TapkeeOutput embed()
{
Neighbors neighbors;
if (parameters[spe_global_strategy].is(false))
{
Expand Down
5 changes: 4 additions & 1 deletion include/tapkee/methods/tsne.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ namespace tapkee_internal
{

__TAPKEE_IMPLEMENTATION(tDistributedStochasticNeighborEmbedding)
TapkeeOutput embed()
void validate()
{
parameters[sne_perplexity].checked().satisfies(InClosedRange<ScalarType>(0.0, (n_vectors - 1) / 3.0)).orThrow();
parameters[sne_theta].checked().satisfies(NonNegativity<ScalarType>()).orThrow();
}

TapkeeOutput embed()
{
DenseMatrix data = dense_matrix_from_features(features, current_dimension, begin, end);

DenseMatrix embedding(static_cast<IndexType>(parameters[target_dimension]), n_vectors);
Expand Down

0 comments on commit e7efda8

Please sign in to comment.