The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....


Class: none
Declaration: procedure FindNearestNeighbors (k: integer; InMat: TMatrix; FirstObj, LastObj: integer; DatVec: TVector; KNNList: TMatrix; CalcDist: TCalcDistFunc);

This routine calculates the k nearest neighbors of the vector DatVec in the matrix InMat. The rows are considered to be objects, the columns are the variables. The user has to ensure that both the x-dimension of InMat and the length of DatVec are equal to each other. The result is returned as an ordered list in the matrix KNNList (size 2 x k), the first row specifying the nearest neighbor. The first column of KNNList holds the indices into the data matrix InMat, the second column holds the distances to these neighbors. The parameters FirstObj and LastObj define the index of the first and the last object of matrix Inmat to be included in the kNN search.

The function pointer CalcDist may be used to perform a user defined calculation of the distances between the elements of the data matrix and the data vector (see TCalcDistFunc  for more details). If CalcDist is set to nil the Euclidean distance is calculated by default.

Hint: Note that the maximum number of nearest neighbors k is restricted to 100. This can be easily adapted by changing the corresponding constant MAXK in the sources.

Last Update: 2015-Mar-26