Learn R Programming

FuzzySpec (version 1.0.0)

compute.SNN: Shared-Nearest-Neighbours (SNN) Similarity from a Similarity Matrix

Description

Builds a Shared-Nearest-Neighbours (SNN) similarity matrix from an input similarity matrix similarity. For each pair of observations, the SNN score is the fraction of shared indices among their top-\(r\) neighbour lists.

Usage

compute.SNN(similarity, r)

Value

An \(n \times n\) symmetric numeric matrix SNN.S with entries in \([0,1]\).

Arguments

similarity

An \(n \times n\) numeric similarity matrix. The diagonal is assumed to correspond to self-similarity and is ignored when forming neighbour lists.

r

Integer value number of nearest neighbours per observation used to compute SNN overlap.

Details

For each observation \(i\), the function forms its neighbour set by ordering similarity[i, ] in decreasing order, dropping i itself, and retaining the first \(r\) indices. For a pair \((i, j)\), the SNN similarity is $$\mathrm{SNN}(i,j) = \frac{|N_r(i) \cap N_r(j)|}{r},$$ i.e., the size of the intersection of their neighbour sets divided by \(r\). The result is symmetric with ones on the diagonal.

References

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

Jarvis, R. A., and A. E. Patrick (1973). Clustering using a similarity measure based on shared near neighbors. IEEE Transactions on Computers, 22(11), 1025-1034.

See Also

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

Examples

Run this code
set.seed(1)
X <- matrix(rnorm(50), nrow = 10)
D <- as.matrix(dist(X))
r <- 3
S <- exp(-D^2)
SNN <- compute.SNN(S, r)
head(SNN, 5)

# inspect average SNN similarity to nearest neighbour
rowMeans(SNN - diag(diag(SNN)))

Run the code above in your browser using DataLab