| findKNN | R Documentation |
Find the k-nearest neighbors of each point in a dataset.
findKNN(
X,
k,
get.index = TRUE,
get.distance = TRUE,
num.threads = 1,
subset = NULL,
...,
BNPARAM = NULL
)
X |
A numeric matrix where rows correspond to data points and columns correspond to variables (i.e., dimensions).
Alternatively, a prebuilt BiocNeighborIndex object from |
k |
A positive integer scalar specifying the number of nearest neighbors to retrieve. Alternatively, an integer vector of length equal to the number of points in All |
get.index |
A logical scalar indicating whether the indices of the nearest neighbors should be recorded.
Setting this to Alternatively, if |
get.distance |
A logical scalar indicating whether distances to the nearest neighbors should be recorded.
Setting this to Alternatively, if |
num.threads |
Integer scalar specifying the number of threads to use for the search. |
subset |
An integer, logical or character vector specifying the indices of points in |
... |
Further arguments to pass to |
BNPARAM |
A BiocNeighborParam object specifying how the index should be constructed.
If |
If multiple queries are to be performed to the same X, it may be beneficial to build the index from X with buildIndex.
The resulting pointer object can be supplied as X to multiple findKNN calls, avoiding the need to repeat index construction in each call.
List containing index (if get.index is not FALSE) and distance (if get.distance is not FALSE).
If get.index=TRUE or "normal" and k is an integer scalar,
index is an integer matrix with k columns where each row corresponds to a point (denoted here as i) in X.
The i-th row contains the indices of points in X that are the nearest neighbors to point i, sorted by increasing distance from i.
i will not be included in its own set of nearest neighbors.
If get.index=FALSE or "transposed" and k is an integer scalar,
index is as described above but transposed, i.e., the i-th column contains the indices of neighboring points in X.
If get.distance=TRUE or "normal" and k is an integer scalar,
distance is a numeric matrix of the same dimensions as index.
The i-th row contains the distances of neighboring points in X to the point i, sorted in increasing order.
If get.distance=FALSE or "transposed" and k is an integer scalar,
distance is as described above but transposed, i.e., the i-th column contains the distances to neighboring points in X.
If get.index is not FALSE and k is an integer vector,
index is a list of integer vectors where each vector corresponds to a point (denoted here as i) in X.
The i-th vector has length k[i] and contains the indices of points in X that are the nearest neighbors to point i, sorted by increasing distance from i.
If get.distance is not FALSE and k is an integer vector,
distance is a list of numeric vectors of the same lengths as those in index.
The i-th vector contains the distances of neighboring points in X to the point i, sorted in increasing order.
Aaron Lun
buildIndex, to build an index ahead of time.
findDistance, to efficiently obtain the distance to the k-th nearest neighbor.
Y <- matrix(rnorm(100000), ncol=20)
out <- findKNN(Y, k=8)
head(out$index)
head(out$distance)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.