| findKNN {BiocNeighbors} | R Documentation |
Find the k-nearest neighbors for each point in a data set, using exact or approximate algorithms.
findKNN(..., BNINDEX=NULL, BNPARAM=NULL)
... |
Further arguments to pass to specific methods, including:
|
BNINDEX |
A BiocNeighborIndex object, or |
BNPARAM |
A BiocNeighborParam object, or |
The class of BNINDEX and BNPARAM will determine whether dispatch is performed to findKmknn or findAnnoy.
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.
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
findKmknn and findAnnoy for specific methods.
Y <- matrix(rnorm(100000), ncol=20) str(k.out <- findKNN(Y, k=10)) str(a.out <- findKNN(Y, k=10, BNPARAM=AnnoyParam())) k.dex <- buildKmknn(Y) str(k.out2 <- findKNN(Y, k=10, BNINDEX=k.dex, BNPARAM=NULL)) str(k.out3 <- findKNN(Y, k=10, BNINDEX=k.dex, BNPARAM=KmknnParam())) a.dex <- buildAnnoy(Y) str(a.out2 <- findKNN(Y, k=10, BNINDEX=a.dex, BNPARAM=NULL)) str(a.out3 <- findKNN(Y, k=10, BNINDEX=a.dex, BNPARAM=AnnoyParam()))