|
| | NnDescentIndex (std::size_t k, std::size_t maxIter=10, T delta=T{0.001}, std::uint64_t seed=0) |
| | Construct an index targeting k neighbors per node.
|
| | NnDescentIndex (const NnDescentIndex &)=delete |
| NnDescentIndex & | operator= (const NnDescentIndex &)=delete |
| | NnDescentIndex (NnDescentIndex &&)=default |
| | Defaulted move constructor; transfers the neighbor bank and scratch.
|
| NnDescentIndex & | operator= (NnDescentIndex &&)=default |
| | Defaulted move assignment; transfers the neighbor bank and scratch.
|
| | ~NnDescentIndex ()=default |
| void | build (const NDArray< T, 2 > &X, math::Pool pool) |
| | Build (or rebuild) the approximate kNN graph for X.
|
| const std::vector< std::vector< KnnEntry > > & | neighbors () const noexcept |
| | Per-node k -NN neighbor list, sorted ascending by squared distance.
|
| bool | isConnected () const |
| | Whether the undirected k-NN graph covers every node in a single connected component.
|
| std::size_t | k () const noexcept |
| | k specified at construction.
|
| std::size_t | lastIterations () const noexcept |
| | Number of join iterations actually executed during the most recent build.
|
template<class T>
class clustering::index::NnDescentIndex< T >
Approximate k -nearest-neighbor graph via the NN-Descent algorithm (Dong, Charikar, Li 2011) with random-projection-tree initialization.
Maintains a per-node bounded max-heap of k current-best neighbors. Each iteration performs a "local join": for every node u the step takes u 's current neighbors and the neighbors-of-neighbors as candidates, computing squared Euclidean distances and admitting any candidate that beats the heap's current worst. Convergence is reached when the fraction of updated slots falls below delta.
Initialization via one random-projection tree seeds each node with coarse neighbors from the same tree leaf. Dong 2011 shows RP-tree initialization typically cuts iteration count by half compared to uniform-random seeding on real workloads; defaults here follow that pattern.
- Warm start
- Rebuilding on the same (data pointer, @c n, @c d, @c k) tuple reuses the existing neighbor graph as warm state. The join loop runs without RP-tree re-initialization, so the second build converges measurably faster (typically in a single iteration). A different
k, a different input pointer, or a different shape forces a cold start (fresh bank + RP-tree init).
- Thread safety
- Not thread-safe: a single
NnDescentIndex instance must not be driven concurrently. The internal join step uses a Pool injection to parallelise across nodes per build; no nested pool dispatch.
- Template Parameters
-
| T | Element type; only float is currently supported. |
Definition at line 47 of file nn_descent.h.