nearest_neighbors function

Compute Nearest Neighbors

Compute Nearest Neighbors

Computes the nearest neighbor distances and indices of a sample using the infinite norm.

nearest_neighbors(data, k)

Arguments

  • data: Matrix of sample observations, each row is an observation.
  • k: Neighborhood order.

Returns

List of distances and indices of the k-nearest neighbors of each point in data.

Details

Nearest neighbors are computed using the brute-force method.

Examples

X <- cbind(1:10) nearest_neighbors(X,3) set.seed(123) X <- cbind(runif(100),runif(100)) plot(X,pch=20) points(X[3,1],X[3,2],col='blue',pch=19, cex=1.5) nn <- nearest_neighbors(X,5) a = X[nn$nn_inds[3,-1],1] b = X[nn$nn_inds[3,-1],2] points(a,b,col='red',pch=19, cex=1.5)
  • Maintainer: Isaac Michaud
  • License: GPL-3
  • Last published: 2018-08-02

Useful links