Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Related to #53 the neighborhood graph is not connected #83

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions include/tapkee/neighbors/neighbors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/* Tapkee includes */
#include <tapkee/defines.hpp>
#include <tapkee/utils/logging.hpp>
#include <tapkee/utils/naming.hpp>
#ifdef TAPKEE_USE_LGPL_COVERTREE
#include <tapkee/neighbors/covertree.hpp>
Expand All @@ -15,6 +16,7 @@
/* End of Tapkee includes */

#include <algorithm>
#include <string>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -190,10 +192,19 @@ Neighbors find_neighbors(NeighborsMethod method, const RandomAccessIterator& beg
neighbors = find_neighbors_covertree_impl(begin, end, callback, k);
#endif

if (check_connectivity)
if (check_connectivity && !is_connected(begin, end, neighbors))
{
if (!is_connected(begin, end, neighbors))
LoggingSingleton::instance().message_warning("The neighborhood graph is not connected.");
const std::string message = fmt::format("The neighborhood graph with {} neighbors "
"is not connected. Recomputing with a "
"larger number of neighbors {}.", k, 2 *k);
LoggingSingleton::instance().message_warning(message);
neighbors = find_neighbors(method, begin, end, callback, 2 * k, check_connectivity);
}
else
{
const std::string message = fmt::format("The neighborhood graph with {} neighbors "
"is connected.", k);
LoggingSingleton::instance().message_info(message);
}
return neighbors;
}
Expand Down
7 changes: 7 additions & 0 deletions test/unit/neighbors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include <tapkee/exceptions.hpp>
#include <tapkee/tapkee.hpp>
#ifdef TAPKEE_USE_LGPL_COVERTREE
#include <tapkee/neighbors/covertree.hpp>
#endif

#include "callbacks.hpp"

Expand Down Expand Up @@ -48,6 +51,7 @@ TEST(Neighbors, BruteDistanceNeighbors)
}
}

#ifdef TAPKEE_USE_LGPL_COVERTREE
TEST(Neighbors, CoverTreeDistanceNeighbors)
{
typedef std::vector<float> Floats;
Expand Down Expand Up @@ -83,6 +87,7 @@ TEST(Neighbors, CoverTreeDistanceNeighbors)
ASSERT_NE(neighbors_set.find(floats[i + j + 1]), neighbors_set.end());
}
}
#endif

TEST(Neighbors, BruteKernelNeighbors)
{
Expand Down Expand Up @@ -121,6 +126,7 @@ TEST(Neighbors, BruteKernelNeighbors)
}
}

#ifdef TAPKEE_USE_LGPL_COVERTREE
TEST(Neighbors, CoverTreeKernelNeighbors)
{
typedef std::vector<float> Floats;
Expand Down Expand Up @@ -156,3 +162,4 @@ TEST(Neighbors, CoverTreeKernelNeighbors)
ASSERT_NE(neighbors_set.find(floats[i + j + 1]), neighbors_set.end());
}
}
#endif
Loading