Builds the kNN graph directly by iterative local join. Want the kNN graph of
the data itself (UMAP, clustering)? $extract_knn() hands back the
converged graph without any search, far cheaper than $query_self(). It
reads the post-pruning graph, so leave diversify_prob at 0 if extraction
is the point.
References
Dong W, Charikar M, Li K (2011). Efficient k-nearest neighbor graph construction for generic similarity measures. Proceedings of the 20th International Conference on World Wide Web, 577-586. doi:10.1145/1963405.1963487
Super class
AnnIndex -> NNDescentIndex
Active bindings
ef_searchInteger or
NULL. Beam width at query time.k_graphInteger. Degree of the built graph. Read-only.
Methods
Inherited methods
NNDescentIndex$new()
Build the index.
Usage
NNDescentIndex$new(
data,
metric = c("euclidean", "sqeuclidean", "cosine", "manhattan"),
k_graph = 15L,
delta = 0.001,
diversify_prob = 0,
max_iter = NULL,
max_candidates = NULL,
n_trees = NULL,
ef_search = NULL,
seed = 42L,
precision = c("float", "double"),
.verbose = FALSE
)Arguments
dataNumeric matrix or data.frame. Samples x features. An index pointer is also accepted;
load_ann_index()uses that path.metricString. One of
c("euclidean", "sqeuclidean", "cosine", "manhattan").k_graphInteger. Neighbours per node in the graph being built.
deltaNumeric. Convergence threshold: descent stops once the fraction of updated edges falls below it.
diversify_probNumeric between 0 and 1. Probability of pruning an occluded edge after descent.
0disables pruning.max_iterInteger or
NULL. Iteration cap.NULLusesmax(round(log2(n)), 5).max_candidatesInteger or
NULL. Neighbours sampled per node per local join.NULLusesmin(k_graph, 60).n_treesInteger or
NULL. Random projection trees for the seed graph.NULLusesmin(5 + round(sqrt(n) / 20), 64).ef_searchInteger or
NULL. Beam width at query time.NULLusesclamp(2 * k, 50, 200). Can be changed after the build.seedInteger. Fixes the seed graph and the sampling.
precisionString.
"float"stores the data as f32,"double"as f64..verboseBoolean. Print build progress from Rust.
NNDescentIndex$extract_knn()
The converged kNN graph over the indexed data, read straight off the index. No search involved.
Examples
x <- generate_clustered_data(1000L, 16L)$data
idx <- NNDescentIndex$new(x, k_graph = 15L)
knn <- idx$extract_knn()
