# Spectral clustering

An example of two connected graphs

In multivariate statistics and the clustering of data, spectral clustering techniques make use of the spectrum (eigenvalues) of the similarity matrix of the data to perform dimensionality reduction before clustering in fewer dimensions. The similarity matrix is provided as an input and consists of a quantitative assessment of the relative similarity of each pair of points in the dataset.

In application to image segmentation, spectral clustering is known as segmentation-based object categorization.

## Definitions

Given an enumerated set of data points, the similarity matrix may be defined as a symmetric matrix ${\displaystyle A}$, where ${\displaystyle A_{ij}\geq 0}$ represents a measure of the similarity between data points with indices ${\displaystyle i}$ and ${\displaystyle j}$. The general approach to spectral clustering is to use a standard clustering method (there are many such methods, k-means is discussed below) on relevant eigenvectors of a Laplacian matrix of ${\displaystyle A}$. There are many different ways to define a Laplacian which have different mathematical interpretations, and so the clustering will also have different interpretations. The eigenvectors that are relevant are the ones that correspond to smallest several eigenvalues of the Laplacian except for the smallest eigenvalue which will have a value of 0. For computational efficiency, these eigenvectors are often computed as the eigenvectors corresponding to the largest several eigenvalues of a function of the Laplacian.

Spectral clustering is well known to relate to partitioning of a mass-spring system, where each mass is associated with a data point and each spring stiffness corresponds to a weight of an edge describing a similarity of the two related data points. Specifically, the classical reference [1] explains that the eigenvalue problem describing transversal vibration modes of a mass-spring system is exactly the same as the eigenvalue problem for the graph Laplacian matrix defined as

${\displaystyle L:=D-A}$,

where ${\displaystyle D}$ is the diagonal matrix

${\displaystyle D_{ii}=\sum _{j}A_{ij}.}$

The masses that are tightly connected by the springs in the mass-spring system evidently move together from the equilibrium position in low-frequency vibration modes, so that the components of the eigenvectors corresponding to the smallest eigenvalues of the graph Laplacian can be used for meaningful clustering of the masses.

A popular related spectral clustering technique is the normalized cuts algorithm or Shi–Malik algorithm introduced by Jianbo Shi and Jitendra Malik,[2] commonly used for image segmentation. It partitions points into two sets ${\displaystyle (B_{1},B_{2})}$ based on the eigenvector ${\displaystyle v}$ corresponding to the second-smallest eigenvalue of the symmetric normalized Laplacian defined as

${\displaystyle L^{\text{norm}}:=I-D^{-1/2}AD^{-1/2}.}$

A mathematically equivalent algorithm [3] takes the eigenvector corresponding to the largest eigenvalue of the random walk normalized adjacency matrix ${\displaystyle P=D^{-1}A}$.

Knowing the eigenvectors, partitioning may be done in various ways, such as by computing the median ${\displaystyle m}$ of the components of the second smallest eigenvector ${\displaystyle v}$, and placing all points whose component in ${\displaystyle v}$ is greater than ${\displaystyle m}$ in ${\displaystyle B_{1}}$, and the rest in ${\displaystyle B_{2}}$. The algorithm can be used for hierarchical clustering by repeatedly partitioning the subsets in this fashion.

## Algorithms

If the similarity matrix ${\displaystyle A}$ has not already been explicitly constructed, the efficiency of spectral clustering may be improved if the solution to the corresponding eigenvalue problem is performed in a matrix-free fashion (without explicitly manipulating or even computing the similarity matrix), as in the Lanczos algorithm.

For large-sized graphs, the second eigenvalue of the (normalized) graph Laplacian matrix is often ill-conditioned, leading to slow convergence of iterative eigenvalue solvers. Preconditioning is a key technology accelerating the convergence, e.g., in the matrix-free LOBPCG method. Spectral clustering has been successfully applied on large graphs by first identifying their community structure, and then clustering communities.[4]

Spectral clustering is closely related to nonlinear dimensionality reduction, and dimension reduction techniques such as locally-linear embedding can be used to reduce errors from noise or outliers.[5]

Free software to implement spectral clustering is available in large open source projects like Scikit-learn [6] using LOBPCG with multigrid preconditioning,[7] or ARPACK, MLlib for pseudo-eigenvector clustering using the power iteration method,[8] and R.[9]

## Relationship with k-means

The kernel k-means problem is an extension of the k-means problem where the input data points are mapped non-linearly into a higher-dimensional feature space via a kernel function ${\displaystyle k(x_{i},x_{j})=\varphi ^{T}(x_{i})\varphi (x_{j})}$. The weighted kernel k-means problem further extends this problem by defining a weight ${\displaystyle w_{r}}$ for each cluster as the reciprocal of the number of elements in the cluster,

${\displaystyle \max _{\{C_{s}\}}\sum _{r=1}^{k}w_{r}\sum _{x_{i},x_{j}\in C_{r}}k(x_{i},x_{j}).}$

Suppose ${\displaystyle F}$ is a matrix of the normalizing coefficients for each point for each cluster ${\displaystyle F_{ij}=w_{r}}$ if ${\displaystyle i,j\in C_{r}}$ and zero otherwise. Suppose ${\displaystyle K}$ is the kernel matrix for all points. The weighted kernel k-means problem with n points and k clusters is given as,

${\displaystyle \max _{F}\operatorname {trace} (KF)}$

such that

${\displaystyle F=G_{n\times k}G_{k\times n}^{T}}$
${\displaystyle G^{T}G=I}$

such that ${\displaystyle \operatorname {rank} (G)=k}$. In addition, there are identity constrains on ${\displaystyle F}$ given by,

${\displaystyle F\cdot \mathbb {I} =\mathbb {I} }$

where ${\displaystyle \mathbb {I} }$ represents a vector of ones.

${\displaystyle F^{T}\mathbb {I} =\mathbb {I} }$

This problem can be recast as,

${\displaystyle \max _{G}\operatorname {trace} (G^{T}G).}$

This problem is equivalent to the spectral clustering problem when the identity constraints on ${\displaystyle F}$ are relaxed. In particular, the weighted kernel k-means problem can be reformulated as a spectral clustering (graph partitioning) problem and vice versa. The output of the algorithms are eigenvectors which do not satisfy the identity requirements for indicator variables defined by ${\displaystyle F}$. Hence, post-processing of the eigenvectors is required for the equivalence between the problems.[10] Transforming the spectral clustering problem into a weighted kernel k-means problem greatly reduces the computational burden.[11]

## Relationship to DBSCAN

Spectral clustering is also related to DBSCAN clustering, that finds density-connected components. Connected components correspond to optimal spectral clusters (no edges cut); and DBSCAN uses an asymmetric neighbor graph with edges removed when source points are not dense.[12] Thus, DBSCAN is a special case of spectral clustering, but one which allows more efficient algorithms (worst case ${\displaystyle O(n^{2})}$, in many practical cases much faster with indexes).

## Measures to compare clusterings

Ravi Kannan, Santosh Vempala and Adrian Vetta[13] proposed a bicriteria measure to define the quality of a given clustering. They said that a clustering was an (α, ε)-clustering if the conductance of each cluster (in the clustering) was at least α and the weight of the inter-cluster edges was at most ε fraction of the total weight of all the edges in the graph. They also look at two approximation algorithms in the same paper.

## Approximate Solutions

Spectral clustering is computationally expensive unless the graph is sparse and the similarity matrix can be efficiently constructed. If the similarity matrix is an RBF kernel matrix, spectral clustering is expensive. There are approximate algorithms for making spectral clustering more efficient: power method[14], Nystrom method[15], etc. However, recent research[16] pointed out the problems with spectral clustering with Nystrom method; in particular, the similarity matrix with Nystrom approximation is not elementwisely positive, which can be problematic.

## History

Spectral clustering has a long history.[17][18][19][20][21][2][22] Spectral clustering as a machine learning method was popularized by Shi & Malik[2] and Ng, Jordan, & Weiss.[22]

## References

1. ^ J. Demmel, [1], CS267: Notes for Lecture 23, April 9, 1999, Graph Partitioning, Part 2
2. ^ a b c Jianbo Shi and Jitendra Malik, "Normalized Cuts and Image Segmentation", IEEE Transactions on PAMI, Vol. 22, No. 8, Aug 2000.
3. ^ Marina Meilă & Jianbo Shi, "Learning Segmentation by Random Walks", Neural Information Processing Systems 13 (NIPS 2000), 2001, pp. 873–879.
4. ^ Zare, Habil; P. Shooshtari; A. Gupta; R. Brinkman (2010). "Data reduction for spectral clustering to analyze high throughput flow cytometry data". BMC Bioinformatics. 11: 403. doi:10.1186/1471-2105-11-403. PMC 2923634. PMID 20667133.
5. ^ Arias-Castro, E. and Chen, G. and Lerman, G. (2011), "Spectral clustering based on local linear approximations.", Electronic Journal of Statistics, 5: 1537–1587, arXiv:1001.1323, doi:10.1214/11-ejs651CS1 maint: multiple names: authors list (link)
6. ^ http://scikit-learn.org/stable/modules/clustering.html#spectral-clustering
7. ^ Knyazev, Andrew V. (2006). Multiscale Spectral Graph Partitioning and Image Segmentation. Workshop on Algorithms for Modern Massive Data Sets Stanford University and Yahoo! Research.
8. ^ http://spark.apache.org/docs/latest/mllib-clustering.html#power-iteration-clustering-pic
9. ^ https://cran.r-project.org/web/packages/kernlab
10. ^ Dhillon, I.S. and Guan, Y. and Kulis, B. (2004). "Kernel k-means: spectral clustering and normalized cuts". Proceedings of the tenth ACM SIGKDD international conference on Knowledge discovery and data mining. pp. 551–556.CS1 maint: multiple names: authors list (link)
11. ^ Dhillon, Inderjit; Yuqiang Guan; Brian Kulis (November 2007). "Weighted Graph Cuts without Eigenvectors: A Multilevel Approach". IEEE Transactions on Pattern Analysis and Machine Intelligence. 29 (11): 1944–1957. CiteSeerX 10.1.1.131.2635. doi:10.1109/tpami.2007.1115. PMID 17848776.
12. ^ Schubert, Erich; Hess, Sibylle; Morik, Katharina (2018). The Relationship of DBSCAN to Matrix Factorization and Spectral Clustering (PDF). LWDA. pp. 330–334.
13. ^ Kannan, Ravi; Vempala, Santosh; Vetta, Adrian (2004). "On Clusterings : Good, Bad and Spectral". Journal of the ACM. 51 (3): 497–515. doi:10.1145/990308.990313.
14. ^ Boutsidis, Christos (2015). "Spectral Clustering via the Power Method Provably" (PDF). International Conference on Machine Learning.
15. ^ Fowlkes, C (2004). "Spectral grouping using the Nystrom method". IEEE Transactions on Pattern Analysis and Machine Intelligence.
16. ^ S. Wang, A. Gittens, and M. W. Mahoney (2019). "Scalable Kernel K-Means Clustering with Nystrom Approximation: Relative-Error Bounds". Journal of Machine Learning Research. 20: 1–49. arXiv:1706.02803.CS1 maint: multiple names: authors list (link)
17. ^ Cheeger, Jeff (1969). "A lower bound for the smallest eigenvalue of the Laplacian". Proceedings of the Princeton Conference in Honor of Professor S. Bochner.
18. ^ William Donath and Alan Hoffman (1972). "Algorithms for partitioning of graphs and computer logic based on eigenvectors of connections matrices". IBM Technical Disclosure Bulletin.
19. ^ Fiedler, Miroslav (1973). "Algebraic connectivity of graphs". Czechoslovak Mathematical Journal.
20. ^ Stephen Guattery and Gary L. Miller (1995). "On the performance of spectral graph partitioning methods". Annual ACM-SIAM Symposium on Discrete Algorithms.
21. ^ Daniel A. Spielman and Shang-Hua Teng (1996). "Spectral Partitioning Works: Planar graphs and finite element meshes". Annual IEEE Symposium on Foundations of Computer Science.
22. ^ a b Ng, Andrew Y and Jordan, Michael I and Weiss, Yair (2002). "On spectral clustering: analysis and an algorithm" (PDF). Advances in Neural Information Processing Systems.CS1 maint: multiple names: authors list (link)