k nearest neighbor search with custom distance function.

find_knn(data, k, ..., query = NULL, distance = c("euclidean",
  "cosine", "rankcor"), sym = TRUE)

Arguments

data

Data matrix

k

Number of nearest neighbors

...

Unused. All parameters to the right of the ... have to be specified by name (e.g. find_knn(data, k, distance = 'cosine'))

query

Query matrix. In knn and knn_asym, query and data are identical

distance

Distance metric to use. Allowed measures: Euclidean distance (default), cosine distance (\(1-corr(c_1, c_2)\)) or rank correlation distance (\(1-corr(rank(c_1), rank(c_2))\))

sym

Return a symmetric matrix (as long as query is NULL)?

Value

A list with the entries:

index

A \(nrow(data) \times k\) integer matrix containing the indices of the k nearest neighbors for each cell.

dist

A \(nrow(data) \times k\) double matrix containing the distances to the k nearest neighbors for each cell.

dist_mat

A dgCMatrix if sym == TRUE, else a dsCMatrix (\(nrow(query) \times nrow(data)\)). Any zero in the matrix (except for the diagonal) indicates that the cells in the corresponding pair are close neighbors.