Learn R Programming

meanShiftR (version 0.50)

knn_meanShift: K-d tree based k nearest neighbor search

Description

knn_meanShift performs a search for the k nearest neighbors of a single point, where nearest is determined by the Mahalanobis distance. This search is performed through a k-d tree.

Usage

knn_meanShift(points, trainData, k = min(5, NROW(trainData)), weight,
  leafSize = 40, maxDist = Inf)

Arguments

points

n vectors stored in an n by p matrix. k nearest neighbors are found for each vector.

trainData

A matrix or vector of potential nearest neighbors.

k

A scalar indicating the number neighbors to find.

weight

A scalar or vector of length equal to the number of columns of trainData. This value is used as the diagonal elements for the inverse covariance matrix of the Mahalanobis distance.

leafSize

A scalar used to specify the number of points to store in the leaf nodes.

maxDist

A vector specifying the maximum value of the Mahalanobis that will be considered.

Value

A list is returned containing two items: neighbors, an n by k matrix of k indexes for each of the n vectors in points, corresponding to the nearest neighbors in trainData. value, a matrix of scalars containing the k distances between the neighbors found in trainData and points.

Examples

Run this code
# NOT RUN {
x <- matrix(runif(20),10,2)
neighbors <- knn_meanShift(c(0,0),x)
# }

Run the code above in your browser using DataLab