findNeighbors {BiocNeighbors} | R Documentation |
Find all neighbors within a given distance for each point in a data set, using exact or approximate algorithms.
findNeighbors(X, threshold, subset=NULL, get.index=TRUE, get.distance=TRUE, BPPARAM=SerialParam(), ..., BNINDEX, BNPARAM)
X |
A numeric data matrix where rows are points and columns are dimensions. |
threshold |
A numeric scalar or vector specifying the maximum distance for considering neighbors. |
subset |
A vector specifying the subset of points in |
get.index |
A logical scalar indicating whether to return row indices of the neighbors. |
get.distance |
A logical scalar indicating whether to return distances to neighbors. |
BPPARAM |
A BiocParallelParam class for parallelization. |
... |
Further arguments to pass to specific methods. |
BNINDEX |
A BiocNeighborIndex object containing precomputed index information.
This can be missing if |
BNPARAM |
A BiocNeighborParam object specifying the algorithm to use.
This can be missing if |
The class of BNINDEX
and BNPARAM
will determine the dispatch to specific functions.
Only one of these arguments needs to be defined to resolve dispatch.
However, if both are defined, they cannot specify different algorithms.
If BNINDEX
is supplied, X
does not need to be specified.
In fact, any value of X
will be ignored as all necessary information for the search is already present in BNINDEX
.
Similarly, any parameters in BNPARAM
will be ignored.
If both BNINDEX
and BNPARAM
are missing, the function will default to the KMKNN algorithm by setting BNPARAM=KmknnParam()
.
A list is returned containing:
index
, if get.index=TRUE
.
This is an integer matrix where each row corresponds to a point (denoted here as i) in X
.
The row for i contains the row indices of X
that are the nearest neighbors to point i, sorted by increasing distance from i.
distance
, if get.distance=TRUE
.
This is a numeric matrix where each row corresponds to a point (as above) and contains the sorted distances of the neighbors from i.
If subset
is not NULL
, each row of the above matrices refers to a point in the subset, in the same order as supplied in subset
.
Aaron Lun
rangeFindKmknn
and rangeFindVptree
for specific methods.
Y <- matrix(rnorm(100000), ncol=20) k.out <- findNeighbors(Y, threshold=1) a.out <- findNeighbors(Y, threshold=1, BNPARAM=VptreeParam()) k.dex <- buildKmknn(Y) k.out2 <- findNeighbors(Y, threshold=1, BNINDEX=k.dex) k.out3 <- findNeighbors(Y, threshold=1, BNINDEX=k.dex, BNPARAM=KmknnParam()) v.dex <- buildVptree(Y) v.out2 <- findNeighbors(Y, threshold=1, BNINDEX=v.dex) v.out3 <- findNeighbors(Y, threshold=1, BNINDEX=v.dex, BNPARAM=VptreeParam())