Learn R Programming

FuzzySpec (version 1.0.0)

rNN.dist: Compute r-Nearest Neighbours from a Distance Matrix

Description

Given a symmetric distance matrix, returns the indices of the \(r\) nearest neighbours for each observation.

Usage

rNN.dist(D, r)

Value

An \(n \times r\) integer matrix, where row \(i\) contains the indices of the r nearest neighbours of observation \(i\).

Arguments

D

An \(n \times n\) numeric (symmetric) distance matrix.

r

Integer indicating the number of nearest neighbours to extract for each observation.

Details

For each row \(i\) of D, the function orders the distances \(D[i, \cdot]\), excludes the self-distance, and returns the indices of the first r smallest distances. This provides the indices of the r nearest neighbours of observation \(i\).

References

Ghashti, J. S., Hare, W., and J. R. J. Thompson (2025). Variable-weighted adjacency constructions for fuzzy spectral clustering. Submitted.

See Also

make.adjacency, gen.fuzzy, plot.fuzzy, find.radius, compute.sigma, compute.SNN, fuzzy.spectral.clustering

Examples

Run this code
set.seed(1)
X <- matrix(rnorm(20), nrow = 5)
D <- as.matrix(dist(X))
rNN.dist(D, r = 2)  # find 2 nearest neighbours for each row

Run the code above in your browser using DataLab