| find_knn | R Documentation |
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.
find_knn(featureMatrix, k = 50, n_trees = 50, seed = 42)
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 |
seed |
Random seed for neighbor search, default: 42. |
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.
# Imagine we have 30 cells and 100 features:
fmat <- matrix(rnorm(3000), ncol=30)
nn <- find_knn(fmat,k=15)
# nn$idx has 30 rows and 15 columns.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.