graphclust.cluster.fuzzy_neighborhood_similarity#

graphclust.cluster.fuzzy_neighborhood_similarity(X, k=6, r_max=3, alpha=0.2)[source]#

Transitive fuzzy neighborhood similarity (Vathy-Fogarassy, Kiss and Abonyi 2007).

With \(A_i^{(r)}\) the \(r\)-order neighborhood of sample \(i\) (its \(k\) nearest neighbors and itself for \(r=1\); the union of the neighborhoods of all members of \(A_i^{(r-1)}\) otherwise), the similarity is the first-order filtered sequence of Jaccard indices

\[s_{ij}^{(r)} = (1-\alpha)\,s_{ij}^{(r-1)} + \alpha\, \frac{|A_i^{(r)}\cap A_j^{(r)}|}{|A_i^{(r)}\cup A_j^{(r)}|}, \qquad s_{ij}^{(0)}=0,\; r=1,\dots,r_{\max}.\]

For \(r_{\max}=1,\ \alpha=1\) it is the Jaccard index of the neighbor sets, \(m_{ij}/(2(k+1)-m_{ij})\), a fuzzification of the Jarvis–Patrick threshold; the same quantity later became the edge weight of PhenoGraph-type community detection. The result is a dense symmetric matrix with ones on the diagonal; \(1-\mathbf{S}\) is a dissimilarity usable by hierarchical clustering, MDS or VAT.

Examples

>>> import numpy as np
>>> S = fuzzy_neighborhood_similarity(np.random.default_rng(0).normal(size=(40, 2)), k=5)
>>> S.shape, bool(np.allclose(S, S.T))
((40, 40), True)