From 1dddf45fee6833fc240a34bb7885c1afc5430da1 Mon Sep 17 00:00:00 2001 From: "Fernando J. Iglesias Garcia" Date: Mon, 8 Apr 2024 12:57:57 +0200 Subject: [PATCH] Add a couple of numerical checks. https://github.com/lisitsyn/tapkee/issues/53#issuecomment-2042207422 Obviously, this is not to merge. --- include/tapkee/methods.hpp | 5 +++++ include/tapkee/neighbors/neighbors.hpp | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/include/tapkee/methods.hpp b/include/tapkee/methods.hpp index 3cab8e8..f32a2cd 100644 --- a/include/tapkee/methods.hpp +++ b/include/tapkee/methods.hpp @@ -154,6 +154,11 @@ class ImplementationBase Neighbors neighbors = findNeighborsWith(kernel_distance); SparseWeightMatrix weight_matrix = linear_weight_matrix(begin, end, neighbors, kernel, parameters[nullspace_shift], parameters[klle_shift]); + for (int k = 0; k < weight_matrix.outerSize(); ++k) { + for (Eigen::SparseMatrix::InnerIterator it(weight_matrix, k); it; ++it) { + assert(std::isfinite(it.value())); + } + } DenseMatrix embedding = eigendecomposition(parameters[eigen_method], parameters[computation_strategy], SmallestEigenvalues, weight_matrix, parameters[target_dimension]) .first; diff --git a/include/tapkee/neighbors/neighbors.hpp b/include/tapkee/neighbors/neighbors.hpp index 55cdab8..18f5f14 100644 --- a/include/tapkee/neighbors/neighbors.hpp +++ b/include/tapkee/neighbors/neighbors.hpp @@ -15,6 +15,7 @@ /* End of Tapkee includes */ #include +#include #include #include @@ -195,6 +196,14 @@ Neighbors find_neighbors(NeighborsMethod method, const RandomAccessIterator& beg if (!is_connected(begin, end, neighbors)) LoggingSingleton::instance().message_warning("The neighborhood graph is not connected."); } + int min_element = 10000000, max_element = -1; + for (auto const& neighbor : neighbors) { + for (auto const& item : neighbor) { + assert(std::isfinite(item)); + min_element = std::min(min_element, item); + max_element = std::max(max_element, item); + } + } return neighbors; }