queryNeighbors {BiocNeighbors} | R Documentation

## Query all neighbors

### Description

Find all neighbors in one data set that are in range of each point in another query data set.

### Usage

    queryNeighbors(X, query, threshold, ..., BNINDEX, BNPARAM)

### Arguments

`X` | A numeric data matrix where rows are points and columns are dimensions. This can be missing if `BNINDEX` is supplied.
`query` | A numeric query matrix where rows are points and columns are dimensions.
`threshold` | A numeric scalar or vector specifying the maximum distance for considering neighbors.
`...` | Further arguments to pass to specific methods. This is guaranteed to include `subset`, `get.index`, `get.distance` `BPPARAM` and `raw.index`. See `?"queryNeighbors-functions"` for more details.
`BNINDEX` | A BiocNeighborIndex object containing precomputed index information. This can be missing if `X` and `BNPARAM` is supplied, see Details.
`BNPARAM` | A BiocNeighborParam object specifying the algorithm to use. This can be missing if `BNINDEX` is supplied, see Details.

### Details

The class of `BNINDEX` and `BNPARAM` will determine dispatch to specific methods. 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()`.

### Value

A list is returned containing `index`, a list of integer vectors specifying the identities of the neighbors of each point; and `distance`, a list of numeric vectors containing the distances to those neighbors. See `?"queryNeighbors-functions"` for more details.

### Author(s)

Aaron Lun

### See Also

`rangeQueryKmknn` and `rangeQueryVptree` for specific methods.

### Examples

    Y <- matrix(rnorm(100000), ncol=20)
    Z <- matrix(rnorm(10000), ncol=20)
    k.out <- queryNeighbors(Y, Z, threshold=3)
    v.out <- queryNeighbors(Y, Z, threshold=3, BNPARAM=VptreeParam())

    k.dex <- buildKmknn(Y)
    k.out2 <- queryNeighbors(Y,Z,  threshold=3, BNINDEX=k.dex)
    k.out3 <- queryNeighbors(Y,Z,  threshold=3, BNINDEX=k.dex, BNPARAM=KmknnParam())

    v.dex <- buildVptree(Y)
    v.out2 <- queryNeighbors(Y,Z,  threshold=3, BNINDEX=v.dex)
    v.out3 <- queryNeighbors(Y,Z,  threshold=3, BNINDEX=v.dex, BNPARAM=VptreeParam())

[Package BiocNeighbors version 1.12.0 Index]