Class NearestNeighbors

Inheritance Relationships

Derived Types

Class Documentation

class NearestNeighbors

An abstract class for data structures that implement nearest neighbor search.

Subclassed by dim_red::Bruteforce, dim_red::CompressedCoverTree, dim_red::CoverTree

Public Functions

inline virtual ~NearestNeighbors()
virtual std::pair<Vector, IntVector> query(const Eigen::Ref<const Vector> &point, int k, bool sort_results = true) const = 0

Retrieves the k-nearest neighbors for the query point.

Parameters
  • point – the query point.

  • k – the number of nearest neighbors to search for.

  • sort_results – if true, the neighbors will be sorted by distances in ascending order.

Returns

the k-nearest neighbors: {distances, indices}.

virtual std::pair<Vector, IntVector> queryRadius(const Eigen::Ref<const Vector> &point, double radius, bool sort_results = false) const = 0

Retrieves all the neighbors of the query point in the specified radius.

Parameters
  • point – the query point.

  • radius – the search radius.

  • sort_results – if true, the neighbors will be sorted by distances in ascending order.

Returns

the nearest neighbors in the specified radius: {distances, indices}.

Protected Functions

void validate(int data_size, int k, double radius, bool k_nearest) const
std::pair<Vector, IntVector> processNeighbors(int k, bool sort_results, std::vector<std::pair<double, int>> *neighbors, std::vector<std::pair<double, int>> *bound_neighbors) const