Search for approximate nearest neighbors between cells in the reduced dimensions (e.g. PCA), and return the k nearest neighbors (knn) for each cell. Optionally, we can find neighbors between two separate sets of cells by utilizing both data and query.
Arguments
- data
cell x dims matrix for reference dataset
- query
cell x dims matrix for query dataset (optional)
- k
number of neighbors to calculate
- metric
distance metric to use
- verbose
whether to print progress information during search
- threads
Number of threads to use. Note that result is non-deterministic if threads > 1
- ef
ef parameter for
RcppHNSW::hnsw_search()
. Increase for slower search but improved accuracy- n_trees
Number of trees during index build time. More trees gives higher accuracy
- search_k
Number of nodes to inspect during the query, or -1 for default value. Higher number gives higher accuracy
Value
Named list of two matrices of dimension (cells x k):
idx
: Neighbor indices, whereidx[c, n]
is the index of the nth nearest neighbor to cellc
.dist
: Neighbor distances, wheredist[c, n]
is the distance between cellc
and its nth nearest neighbor.
If no query is given, nearest neighbors are found by mapping the data matrix to itself,
likely including self-neighbors (i.e. idx[c,1] == c
for most cells).