cosnn: The k-nearest neighbours using the cosinus distance

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/cosnn.R

Description

The k-nearest neighbours using the cosinus distance.

Usage

1
cosnn(xnew, x, k = 5, index = FALSE, rann = FALSE)

Arguments

xnew

The new data whose k-nearest neighbours are to be found.

x

The data, a numeric matrix with unit vectors.

k

The number of nearest neighbours, set to 5 by default. It can also be a vector with many values.

index

If you want the indices of the closest observations set this equal to TRUE.

rann

If you have large scale datasets and want a faster k-NN search, you can use kd-trees implemented in the R package "RANN". In this case you must set this argument equal to TRUE.

Details

The shortest distances or the indices of the k-nearest neighbours using the cosinus distance are returned.

Value

A matrix with the shortest distance of each xnew from x, if index is FALSE, or the indices of the nearest neighbours of each xnew from x, if index is TRUE.

Author(s)

Michail Tsagris

R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.

References

Tsagris M. and Alenazi A. (2019). Comparison of discriminant analysis methods on the sphere. Communications in Statistics: Case Studies, Data Analysis and Applications, 5(4), 467–491.

See Also

dirknn, dirknn.tune

Examples

1
2
3
4
xnew <- rvmf(10, rnorm(3), 5)
x <- rvmf(50, rnorm(3), 5)
a <- cosnn(xnew, x, k = 5)
b <- cosnn(xnew, x, k = 5, index = TRUE)

Directional documentation built on Nov. 8, 2021, 1:07 a.m.