KDTree {less} | R Documentation |
KDTree - Nearest Neighbor Search
Description
Wrapper R6 Class of RANN::nn2 function that can be used for LESSRegressor and LESSClassifier
Value
R6 Class of KDTree
Methods
Public methods
Method new()
Creates a new instance of R6 Class of KDTree
Usage
KDTree$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) kdt <- KDTree$new(abalone[1:100,])
Method query()
Finds the p number of near neighbours for each point in an input/output dataset. The advantage of the kd-tree is that it runs in O(M log M) time.
Usage
KDTree$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 <- kdt$query(abalone[1:3,], k=2) print(res)
Method clone()
The objects of this class are cloneable with this method.
Usage
KDTree$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
See Also
Examples
## ------------------------------------------------
## Method `KDTree$new`
## ------------------------------------------------
data(abalone)
kdt <- KDTree$new(abalone[1:100,])
## ------------------------------------------------
## Method `KDTree$query`
## ------------------------------------------------
res <- kdt$query(abalone[1:3,], k=2)
print(res)
[Package less version 0.1.0 Index]