rpf_knn_query | R Documentation |
Run queries against a "forest" of Random Projection Trees (Dasgupta and Freund, 2008), to return nearest neighbors taken from the reference data used to build the forest.
rpf_knn_query(
query,
reference,
forest,
k,
cache = TRUE,
n_threads = 0,
verbose = FALSE,
obs = "R"
)
query |
Matrix of |
reference |
Matrix of |
forest |
A random partition forest, created by |
k |
Number of nearest neighbors to return. You are unlikely to get good
results if you choose a value substantially larger than the value of
|
cache |
if |
n_threads |
Number of threads to use. Note that the parallelism in the
search is done over the observations in |
verbose |
If |
obs |
set to |
the approximate nearest neighbor graph as 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.
k
neighbors per observation are not guaranteed to be found. Missing data
is represented with an index of 0
and a distance of NA
.
Dasgupta, S., & Freund, Y. (2008, May). Random projection trees and low dimensional manifolds. In Proceedings of the fortieth annual ACM symposium on Theory of computing (pp. 537-546). \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1145/1374376.1374452")}.
rpf_build()
# Build a forest of 10 trees from the odd rows
iris_odd <- iris[seq_len(nrow(iris)) %% 2 == 1, ]
iris_odd_forest <- rpf_build(iris_odd, n_trees = 10)
iris_even <- iris[seq_len(nrow(iris)) %% 2 == 0, ]
iris_even_nn <- rpf_knn_query(
query = iris_even, reference = iris_odd,
forest = iris_odd_forest, k = 15
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.