Implements RcppAnnoy's approximate nearest neighbor search
(much faster than precise neighbors).
Random search is made reproducible using set.seed(seed).
Hint: If you pass find_knn's output directly to uwot::umap via the
nn_method argument, make sure to set umap's argument n_sgd_threads
to <=1 to ensure the UMAP embedding is reproducible.
Usage
find_knn(featureMatrix, k = 50, n_trees = 50, seed = 42)
Value
List with two slots:
idx A NxK matrix (N cells, K neighbors) containing the integer
indexes of the approximate nearest neighbors in featureMatrix.
Each cell is considered to be its own nearest neighbor, next to
K-1 other neighbors.
dist A NxK matrix containing the distances of the nearest neighbors.
Inspired by uwot::umap's return value when setting ret_nn=TRUE.
Arguments
featureMatrix
Numeric matrix with features in rows, cells in columns.
Rows could be normalized genes or latent dimensions such as principal
components.
k
Number of neighbors to find.
n_trees
RccpAnnoy builds a forest of n_trees trees.
More trees gives higher precision when querying. Default: 50.