find_knn {cellpypes}R Documentation

Find approximate k-nearest neighbors

Description

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)

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.

seed

Random seed for neighbor search, default: 42.

Value

List with two slots:

Inspired by uwot::umap's return value when setting ret_nn=TRUE.

Examples

  # 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.

[Package cellpypes version 0.3.0 Index]