CoverTree {less} | R Documentation |
CoverTree - Nearest Neighbor Search
Description
Wrapper R6 Class of FNN::get.knnx function that can be used for LESSRegressor and LESSClassifier
Details
The cover tree is O(n) space data structure which allows us to answer queries in the same O(log(n)) time as kd tree given a fixed intrinsic dimensionality. Templated code from https://hunch.net/~jl/projects/cover_tree/cover_tree.html is used.
Value
R6 Class of CoverTree
Methods
Public methods
Method new()
Creates a new instance of R6 Class of CoverTree
Usage
CoverTree$new(X = NULL)
Arguments
X
An M x d data.frame or matrix, where each of the M rows is a point or a (column) vector (where d=1).
Examples
data(abalone) ct <- CoverTree$new(abalone[1:100,])
Method query()
Finds the p number of near neighbours for each point in an input/output dataset.
Usage
CoverTree$query(query_X = private$X, k = 1)
Arguments
query_X
A set of N x d points that will be queried against
X
. d, the number of columns, must be the same asX
. If missing, defaults toX
.k
The maximum number of nearest neighbours to compute (deafults to 1).
Returns
A list
of length 2 with elements:
nn.idx | A N x k integer matrix returning the near neighbour indices. |
nn.dists | A N x k matrix returning the near neighbour Euclidean distances |
Examples
res <- ct$query(abalone[1:3,], k=2) print(res)
Method clone()
The objects of this class are cloneable with this method.
Usage
CoverTree$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
See Also
Examples
## ------------------------------------------------
## Method `CoverTree$new`
## ------------------------------------------------
data(abalone)
ct <- CoverTree$new(abalone[1:100,])
## ------------------------------------------------
## Method `CoverTree$query`
## ------------------------------------------------
res <- ct$query(abalone[1:3,], k=2)
print(res)