rnnd_query {rnndescent} | R Documentation |
Query an index for approximate nearest neighbors
Description
Takes a nearest neighbor index produced by rnnd_build()
and uses it to
find the nearest neighbors of a query set of observations, using a
back-tracking search with the search size determined by the method of
Iwasaki and Miyazaki (2018). For further control over the search effort, the
total number of distance calculations can also be bounded, similar to the
method of Harwood and Drummond (2016).
Usage
rnnd_query(
index,
query,
k = 30,
epsilon = 0.1,
max_search_fraction = 1,
init = NULL,
n_threads = 0,
verbose = FALSE,
obs = "R"
)
Arguments
index |
A nearest neighbor index produced by |
query |
Matrix of |
k |
Number of nearest neighbors to return. |
epsilon |
Controls trade-off between accuracy and search cost, as
described by Iwasaki and Miyazaki (2018). Setting |
max_search_fraction |
Maximum fraction of the reference data to search.
This is a value between 0 (search none of the reference data) and 1 (search
all of the data if necessary). This works in conjunction with |
init |
An optional matrix of |
n_threads |
Number of threads to use. |
verbose |
If |
obs |
set to |
Value
the approximate nearest neighbor index, a list containing:
-
idx
an n by k matrix containing the nearest neighbor indices. -
dist
an n by k matrix containing the nearest neighbor distances.
References
Harwood, B., & Drummond, T. (2016). Fanng: Fast approximate nearest neighbour graphs. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (pp. 5713-5722).
Iwasaki, M., & Miyazaki, D. (2018). Optimization of indexing based on k-nearest neighbor graph for proximity search in high-dimensional data. arXiv preprint arXiv:1810.07355. https://arxiv.org/abs/1810.07355
See Also
Examples
iris_even <- iris[seq_len(nrow(iris)) %% 2 == 0, ]
iris_odd <- iris[seq_len(nrow(iris)) %% 2 == 1, ]
iris_even_index <- rnnd_build(iris_even, k = 4)
iris_odd_nbrs <- rnnd_query(index = iris_even_index, query = iris_odd, k = 4)