Title: | Extremely Fast Nearest Neighbor Search |
---|---|
Description: | Finds the k nearest neighbours for every point in a given dataset using Jose Luis' 'nanoflann' library. There is support for exact searches, fixed radius searches with 'kd' trees and two distances, the 'Euclidean' and 'Manhattan'. For more information see <https://github.com/jlblancoc/nanoflann>. Also, the 'nanoflann' library is exported and ready to be used via the linking to mechanism. |
Authors: | Manos Papadakis [aut, cre, cph], Jose Luis Blanco [aut, cph], Michail Tsagris [ctb] |
Maintainer: | Manos Papadakis <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.0.3 |
Built: | 2024-11-14 06:24:33 UTC |
Source: | CRAN |
Finds the k nearest neighbours for every point in a given dataset using Jose Luis' 'nanoflann' library. There is support for exact searches, fixed radius searches with 'kd' trees and two distances, the 'Euclidean' and 'Manhattan'. For more information see <https://github.com/jlblancoc/nanoflann>. Also, the 'nanoflann' library is exported and ready to be used via the linking to mechanism.
Package: | Rnanoflann |
Type: | Package |
Version: | 0.0.3 |
Date: | 2024-05-17 |
License: | GPL (>= 3) |
Authors: Manos Papadakis [aut, cre, cph], Jose Luis Blanco [aut, cph], Michail Tsagris [ctb]
Maintainer: Manos Papadakis <[email protected]>
Uses a kd-tree to find the k nearest neighbours for each point in a given dataset.
nn(data, points, k = nrow(data), method = "euclidean", search = "standard", eps = 0.0, square = FALSE, sorted = FALSE, radius = 0.0, trans = TRUE, leafs = 10L, p = 0.0, parallel = FALSE, cores = 0L)
nn(data, points, k = nrow(data), method = "euclidean", search = "standard", eps = 0.0, square = FALSE, sorted = FALSE, radius = 0.0, trans = TRUE, leafs = 10L, p = 0.0, parallel = FALSE, cores = 0L)
data |
A numerical matrix. The k nearest points will be extracted from this matrix. |
points |
A numerical matrix. The function will find the nearest neighbours of each row of this matrix. |
k |
The number of nearest neighbours to search for. |
method |
The type of distance.See details for the supported metrics. |
search |
The type of search. Apart from the "standard" there is the "radius" option. It searches only for neighbours within a specified radius of the point. If there are no neighbours then the value "indices" will contain 0 and distances will contain 1.340781e+154 for that point. |
eps |
The accuracy of the search. When this is equal to 0, the function will return the exact k neighbours. If higher values are supplied, the function will return k approximate neighbours. |
square |
If you choose "euclidean" as the method, then you can have the option to return the squared Euclidean distances by setting this argument to TRUE. Default is FALSE. |
sorted |
Should the distances be sorted? This works only when search = "radius". |
radius |
The radius of the search, when search = "radius". |
trans |
Should the return matrices be transposed? The default value is TRUE. |
p |
This is for the the Minkowski, the power of the metric. |
leafs |
Number of divided points. Default is 10. Large values mean that the tree will be built faster (since the tree will be smaller), but each query will be slower (since the linear search in the leaf is to be done over more points). Small values will build the tree much slower (there will be many tree nodes), but queries will be faster... up to some point, since the "tree-part" of the search (logarithmic complexity) still has a significant cost. |
parallel |
Should the computations take place in parallel? The default value is FALSE. |
cores |
Number of threads for parallel version. The default is 0 which means all the available threads. |
The target of this function is to calculate the distances between xnew and x without having to calculate the whole distance matrix of xnew and x. The latter does extra calculations, which can be avoided.
euclidean :
manhattan :
minimum :
maximum :
minkowski :
bhattacharyya :
hellinger :
kullback_leibler :
jensen_shannon :
canberra :
chi_square ^2 :
soergel :
sorensen :
cosine :
wave_hedges :
motyka :
harmonic_mean :
jeffries_matusita :
gower :
kulczynski :
itakura_saito :
A list with 2 fields.
indices |
A matrix with the indices of each nearest neighbour for each of the rows of the matrix "points". |
distances |
A matrix with the distances between each nearest neighbour and each of the rows of the matrix "points". |
x <- as.matrix(iris[1:140, 1:4]) xnew <- as.matrix(iris[141:150, 1:4]) nn(data = x, points = xnew, k = 10)
x <- as.matrix(iris[1:140, 1:4]) xnew <- as.matrix(iris[141:150, 1:4]) nn(data = x, points = xnew, k = 10)