NearestNeighborsGNATNoThreadSafety.h
94 , rebuildSize_(rebalancing ? maxNumPtsPerLeaf * degree : std::numeric_limits<std::size_t>::max())
109 void setDistanceFunction(const typename NearestNeighbors<_T>::DistanceFunction &distFun) override
263 friend std::ostream &operator<<(std::ostream &out, const NearestNeighborsGNATNoThreadSafety<_T> &gnat)
359 if (node->distToPivot_ > node->maxRadius_ + dist || node->distToPivot_ < node->minRadius_ - dist)
530 bool insertNeighborK(NearQueue &nbh, std::size_t k, const _T &data, const _T &key, double dist) const
An instance of this class can be used to greedily select a given number of representatives from a set...
Definition: GreedyKCenters.h:51
Eigen::MatrixXd Matrix
A matrix type for storing distances between points and centers.
Definition: GreedyKCenters.h:56
The class used internally to define the GNAT.
Definition: NearestNeighborsGNATNoThreadSafety.h:375
Node(int degree, int capacity, _T pivot)
Construct a node of given degree with at most capacity data elements and with given pivot.
Definition: NearestNeighborsGNATNoThreadSafety.h:379
void split(GNAT &gnat)
The split operation finds pivot elements for the child nodes and moves each data element of this node...
Definition: NearestNeighborsGNATNoThreadSafety.h:479
void nearestK(const GNAT &gnat, const _T &data, std::size_t k, bool &isPivot) const
Compute the k nearest neighbors of data in the tree. For k=1, isPivot is true if the nearest neighbor...
Definition: NearestNeighborsGNATNoThreadSafety.h:550
std::vector< Node * > children_
The child nodes of this node. By definition, only internal nodes have child nodes.
Definition: NearestNeighborsGNATNoThreadSafety.h:728
double distToPivot_
Scratch space to store distance to pivot during nearest neighbor queries.
Definition: NearestNeighborsGNATNoThreadSafety.h:731
void nearestR(const GNAT &gnat, const _T &data, double r) const
Return all elements that are within distance r in nbh.
Definition: NearestNeighborsGNATNoThreadSafety.h:602
const _T pivot_
Data element stored in this Node.
Definition: NearestNeighborsGNATNoThreadSafety.h:712
double minRadius_
Minimum distance between the pivot element and the elements stored in data_.
Definition: NearestNeighborsGNATNoThreadSafety.h:714
bool needToSplit(const GNAT &gnat) const
Return true iff the node needs to be split into child nodes.
Definition: NearestNeighborsGNATNoThreadSafety.h:471
bool insertNeighborK(NearQueue &nbh, std::size_t k, const _T &data, const _T &key, double dist) const
Insert data in nbh if it is a near neighbor. Return true iff data was added to nbh.
Definition: NearestNeighborsGNATNoThreadSafety.h:530
void updateRadius(double dist)
Update minRadius_ and maxRadius_, given that an element was added with distance dist to the pivot.
Definition: NearestNeighborsGNATNoThreadSafety.h:403
std::vector< double > maxRange_
The i-th element in maxRange_ is the maximum distance between the pivot and any data_ element in the ...
Definition: NearestNeighborsGNATNoThreadSafety.h:722
void insertNeighborR(NearQueue &nbh, double r, const _T &data, double dist) const
Insert data in nbh if it is a near neighbor.
Definition: NearestNeighborsGNATNoThreadSafety.h:596
void updateRange(unsigned int i, double dist)
Update minRange_[i] and maxRange_[i], given that an element was added to the i-th child of the parent...
Definition: NearestNeighborsGNATNoThreadSafety.h:423
double maxRadius_
Maximum distance between the pivot element and the elements stored in data_.
Definition: NearestNeighborsGNATNoThreadSafety.h:716
void add(GNAT &gnat, const _T &data)
Add an element to the tree rooted at this node.
Definition: NearestNeighborsGNATNoThreadSafety.h:431
std::vector< _T > data_
The data elements stored in this node (in addition to the pivot element). An internal node has no ele...
Definition: NearestNeighborsGNATNoThreadSafety.h:725
std::vector< double > minRange_
The i-th element in minRange_ is the minimum distance between the pivot and any data_ element in the ...
Definition: NearestNeighborsGNATNoThreadSafety.h:719
Geometric Near-neighbor Access Tree (GNAT), a data structure for nearest neighbor search.
Definition: NearestNeighborsGNATNoThreadSafety.h:72
bool reportsSortedResults() const override
Return true if the solutions reported by this data structure are sorted, when calling nearestK / near...
Definition: NearestNeighborsGNATNoThreadSafety.h:130
void postprocessNearest(std::vector< _T > &nbh) const
Convert the internal data structure used for storing neighbors to the vector that NearestNeighbor API...
Definition: NearestNeighborsGNATNoThreadSafety.h:366
Node * tree_
The data structure containing the elements stored in this structure.
Definition: NearestNeighborsGNATNoThreadSafety.h:758
std::vector< unsigned int > pivots_
Pivot indices within a vector of elements as selected by GreedyKCenters.
Definition: NearestNeighborsGNATNoThreadSafety.h:797
void nearestR(const _T &data, double radius, std::vector< _T > &nbh) const override
Return the nearest neighbors within distance radius in sorted order.
Definition: NearestNeighborsGNATNoThreadSafety.h:226
unsigned int minDegree_
After splitting a Node, each child Node has degree equal to the default degree times the fraction of ...
Definition: NearestNeighborsGNATNoThreadSafety.h:765
unsigned int maxDegree_
After splitting a Node, each child Node has degree equal to the default degree times the fraction of ...
Definition: NearestNeighborsGNATNoThreadSafety.h:770
void nearestRInternal(const _T &data, double radius) const
Return in nearQueue_ the elements that are within distance radius of data.
Definition: NearestNeighborsGNATNoThreadSafety.h:347
std::unordered_set< const _T * > removed_
Cache of removed elements.
Definition: NearestNeighborsGNATNoThreadSafety.h:786
std::size_t rebuildSize_
If size_ exceeds rebuildSize_, the tree will be rebuilt (and automatically rebalanced),...
Definition: NearestNeighborsGNATNoThreadSafety.h:778
unsigned int maxNumPtsPerLeaf_
Maximum number of elements allowed to be stored in a Node before it needs to be split into several no...
Definition: NearestNeighborsGNATNoThreadSafety.h:773
bool nearestKInternal(const _T &data, std::size_t k) const
Return in nearQueue_ the k nearest neighbors of data. For k=1, return true if the nearest neighbor is...
Definition: NearestNeighborsGNATNoThreadSafety.h:325
NodeQueue nodeQueue_
Nodes yet to be processed for possible nearest neighbors.
Definition: NearestNeighborsGNATNoThreadSafety.h:793
_T nearest(const _T &data) const override
Get the nearest neighbor of a point.
Definition: NearestNeighborsGNATNoThreadSafety.h:197
bool remove(const _T &data) override
Remove data from the tree. The element won't actually be removed immediately, but just marked for rem...
Definition: NearestNeighborsGNATNoThreadSafety.h:178
unsigned int degree_
The desired degree of each node.
Definition: NearestNeighborsGNATNoThreadSafety.h:760
std::size_t removedCacheSize_
Maximum number of removed elements that can be stored in the removed_ cache. If the cache is full,...
Definition: NearestNeighborsGNATNoThreadSafety.h:782
GreedyKCenters< _T >::Matrix distances_
Matrix of distances to pivots.
Definition: NearestNeighborsGNATNoThreadSafety.h:799
std::size_t size() const override
Get the number of elements in the datastructure.
Definition: NearestNeighborsGNATNoThreadSafety.h:238
std::size_t size_
Number of elements stored in the tree.
Definition: NearestNeighborsGNATNoThreadSafety.h:775
GreedyKCenters< _T > pivotSelector_
The data structure used to split data into subtrees.
Definition: NearestNeighborsGNATNoThreadSafety.h:784
void add(const std::vector< _T > &data) override
Add a vector of points.
Definition: NearestNeighborsGNATNoThreadSafety.h:149
void nearestK(const _T &data, std::size_t k, std::vector< _T > &nbh) const override
Return the k nearest neighbors in sorted order.
Definition: NearestNeighborsGNATNoThreadSafety.h:213
bool isRemoved(const _T &data) const
Return true iff data has been marked for removal.
Definition: NearestNeighborsGNATNoThreadSafety.h:317
void add(const _T &data) override
Add an element to the datastructure.
Definition: NearestNeighborsGNATNoThreadSafety.h:135
Permutation permutation_
Permutation of indices to process children of a node in random order.
Definition: NearestNeighborsGNATNoThreadSafety.h:795
friend std::ostream & operator<<(std::ostream &out, const NearestNeighborsGNATNoThreadSafety< _T > &gnat)
Print a GNAT structure (mostly useful for debugging purposes).
Definition: NearestNeighborsGNATNoThreadSafety.h:263
void setDistanceFunction(const typename NearestNeighbors< _T >::DistanceFunction &distFun) override
Set the distance function to use.
Definition: NearestNeighborsGNATNoThreadSafety.h:109
void list(std::vector< _T > &data) const override
Get all the elements in the datastructure.
Definition: NearestNeighborsGNATNoThreadSafety.h:254
void rebuildDataStructure()
Rebuild the internal data structure.
Definition: NearestNeighborsGNATNoThreadSafety.h:166
Abstract representation of a container that can perform nearest neighbors queries.
Definition: NearestNeighbors.h:48
std::function< double(const _T &, const _T &)> DistanceFunction
The definition of a distance function.
Definition: NearestNeighbors.h:51
virtual void setDistanceFunction(const DistanceFunction &distFun)
Set the distance function to use.
Definition: NearestNeighbors.h:58
_T & sample(double r) const
Returns a piece of data from the PDF according to the input sampling value, which must be between 0 a...
Definition: PDF.h:132
Element * add(const _T &d, const double w)
Adds a piece of data with a given weight to the PDF. Returns a corresponding Element,...
Definition: PDF.h:97
void permute(unsigned int n)
Create a permutation of the numbers 0, ..., n - 1.
Definition: Permutation.h:58
Random number generation. An instance of this class cannot be used by multiple threads at once (membe...
Definition: RandomNumbers.h:58
int uniformInt(int lower_bound, int upper_bound)
Generate a random integer within given bounds: [lower_bound, upper_bound].
Definition: RandomNumbers.h:80
Main namespace. Contains everything in this library.
Definition: ConstrainedSpaceInformation.h:53