buildVptree {BiocNeighbors} | R Documentation

## Build a VP tree

### Description

Build a vantage point tree in preparation for a nearest-neighbors search.

### Usage

    buildVptree(X, transposed=FALSE, distance=c("Euclidean", "Manhattan"))

### Arguments

`X` | A numeric matrix where rows correspond to data points and columns correspond to variables (i.e., dimensions).
`transposed` | Logical scalar indicating whether `X` is transposed, i.e., rows are variables and columns are data points.
`distance` | String specifying the type of distance to use.

### Details

This function is automatically called by `findVptree` and related functions. However, it can be called directly by the user to save time if multiple queries are to be performed to the same `X`.

### Value

A VptreeIndex object containing:

- `data`, a numeric matrix with points in the columns and dimensions in the rows, i.e., transposed relative to the input. Points have also been reordered to improve data locality during the nearest-neighbor search.

- `nodes`, a list containing four vectors of equal length describing the structure of the VP tree. Each parallel element specifies a node.

  - The first integer vector specifies the column index of `data` of the current node.

  - The second integer vector specifies the column index of the left child of the current node,

  - The third integer vector specifies the column index of the right child of the current node.

  - The fourth numeric vector specifies the radius of the current node.

  All indices here are zero-based, with child values set to -1 for leaf nodes.

- `order`, an integer vector specifying how rows in `X` have been reordered in columns of `data`.

- `NAMES`, a character vector or `NULL` equal to `rownames(X)`.

- `distance`, a string specifying the distance metric used.

### Author(s)

Aaron Lun

### See Also

See `VptreeIndex` for details on the output class.

See `findVptree` and `queryVptree` for dependent functions.

### Examples

    Y <- matrix(rnorm(100000), ncol=20)
    out <- buildVptree(Y)
    out

[Package BiocNeighbors version 1.2.0 Index]