Spectral Clustering Through Courant–Fischer
From Lloyd’s algorithm to graph Laplacians and random walks
Contents
These notes develop -means and spectral clustering from an optimization viewpoint. After proving the descent and finite termination of Lloyd's algorithm, we formulate a balanced graph-partitioning problem, derive its spectral relaxation, and show how the resulting Fiedler vector is related to the eigenmodes of a random walk on a similarity graph.
These notes grew out of Prof. Alexis Drouot's MATH 480 course at the University of Washington, Seattle (Winter 2025). I have reorganized and expanded my course notes and have done my best to ensure correctness, but errors may remain.
1K-means clustering
Let be the data and let be the desired number of clusters. K-means seeks centers around which the data cluster.
1.1Lloyd's algorithm
Fix a deterministic rule for breaking ties between equally close centers. Choose initial centers , often as distinct points sampled from .
For , repeat the following steps.
- Given , assign every data point to a nearest center. If is the assigned label of , then Define the corresponding sets of indices by . Thus .
- Assuming each is nonempty, replace each center by the mean of its assigned observations:
- Stop if ; otherwise continue.
The displayed update requires every to be nonempty. In an implementation, empty clusters need an explicit rule, such as retaining the old center or reinitializing it in a way that does not increase the objective. For the theoretical discussion below, we assume that all clusters remain nonempty.
1.2Objective and descent
Define the -means objective
It is often convenient to introduce an assignment and the joint objective
For fixed , a nearest-center assignment minimizes over ; for fixed , the cluster means minimize over .
Lemma 1.1 (The sample mean minimizes squared distance). Let and . Then is the unique solution of
Proof. Let . Expanding gives
The final two terms do not depend on , and the first is nonnegative with equality exactly when .Theorem 1.2 (Monotonicity and finite termination). Assume that ties are broken deterministically and all clusters remain nonempty. The iterates of Lloyd's algorithm satisfy Moreover, equality forces . Consequently the algorithm reaches a fixed point after finitely many iterations.
Proof. Let denote the nearest-center assignment associated with . The sample-mean lemma, applied separately to every nonempty cluster, gives
Reassigning each point to a nearest new center can only improve the joint objective, so This proves monotonicity. If , then equality holds in the first inequality above. By uniqueness of the sample mean, every old center already equals the mean of its assigned cluster, and hence .There are only finitely many assignments, at most , and each assignment with nonempty clusters determines a unique tuple of cluster means. After the first update, every center tuple produced by the algorithm is therefore one of finitely many such tuples. Between two distinct center tuples the objective decreases strictly. Hence no nonfixed center tuple can repeat, and the algorithm must reach a fixed point after finitely many iterations.
Remark 1.3. The fixed point need not be a global minimizer of . K-means is sensitive to initialization, so multiple restarts or -means++ initialization are often used in practice.
2Spectral clustering
K-means can perform poorly when clusters are nonconvex, as in the familiar “two moons” example. Spectral clustering instead encodes the data as a weighted graph: nearby, similar points receive a large edge weight and should preferably receive the same label.
2.1A balanced two-cluster problem
Suppose is even and we seek two clusters of equal size. Assign labels
The balance condition is .
With an -neighborhood graph, a natural disagreement energy is
It penalizes nearby points given opposite labels. Because the sum runs over ordered pairs , every undirected edge is counted twice.
More generally, choose a nonnegative, nonincreasing similarity function , so that close points receive large weights. The indicator above corresponds to
Relax to . The constraint retains the scale of the discrete labels and excludes the trivial vector . The relaxed problem is
The relaxed vector embeds the data points on the real line. A two-way partition can be obtained by thresholding at zero. If an exactly balanced partition is required, assign the smallest coordinates to one cluster and the largest to the other.
2.2Graph Laplacian form
Define the symmetric weight matrix and degree matrix by
The unnormalized graph Laplacian is .
Lemma 2.1 (Dirichlet energy). For every ,
Proof. Using ,
In particular, is positive semidefinite because its quadratic form is a sum of nonnegative terms. Also , since .
2.3The Courant–Fischer theorem
For a real symmetric matrix and , define the Rayleigh quotient
Theorem 2.2 (Courant–Fischer). Let the eigenvalues of be ordered as . For ,
Proof. Because is symmetric, it has an orthonormal eigenbasis , with . If , then
a weighted average of the eigenvalues.Take . Every nonzero satisfies , and equality is attained at . Hence the max–min is at least .
Conversely, let be any -dimensional subspace and set , whose dimension is . The dimension formula gives
For a nonzero , . Thus for every , proving the max–min formula. The min–max formula follows by the same argument with the roles of the top and bottom eigenspaces reversed.2.4Solution of the spectral relaxation
Theorem 2.3 (Fiedler-vector solution). Let the eigenvalues of be counted with multiplicity. If the weighted graph is connected, then is simple and an associated unit eigenvector is Every solution of (M) has the form where is a unit eigenvector in the eigenspace of the second-smallest eigenvalue . The minimum value is .
Proof. Choose an orthonormal eigenbasis of with . The balance constraint implies
and the norm constraint gives Therefore Equality holds exactly when lies in the -eigenspace and has norm .Remark 2.4. If the graph has connected components, then the nullspace of has dimension . A nonconstant vector in that nullspace can be orthogonal to , so the relaxed minimum is zero and components can be separated without cutting a positive-weight edge. The connectedness assumption is what makes the first nonconstant mode the usual Fiedler vector.
3Probabilistic interpretation
For a general weighted graph with degree matrix , the associated random walk has transition matrix , provided every degree is positive. This matrix is row-stochastic, although it need not be symmetric even when is symmetric.
To make the spectral relation especially transparent, we now consider the special case of a symmetric, nonnegative, row-stochastic transition matrix , so for every . It may be viewed as the transition matrix of a random walk on the data graph, with .
For the column probability vector
the usual row-transition convention gives
where the second equality uses symmetry. Symmetry and stochasticity imply that the uniform distribution is stationary.
Lemma 3.1 (Spectrum of a symmetric stochastic matrix). Assume the graph of is connected. Order the eigenvalues as Then is a unit eigenvector for , and the eigenvalue is simple.
Proof. Since , the number is an eigenvalue. For any , symmetry, nonnegativity, and yield
Thus every eigenvalue lies in .If , choose an index for which (replacing by if needed). Then
Equality forces every neighbor of with positive transition probability to have the same value . Connectivity propagates this equality to all vertices, so is proportional to . Hence the eigenspace for is one-dimensional. A real symmetric matrix is orthogonally diagonalizable, so algebraic and geometric multiplicities agree and .Let be an orthonormal eigenbasis of . The spectral decomposition gives
Consider the Laplacian-form matrix . The matrices and have the same eigenvectors, and an eigenvalue of corresponds to the eigenvalue of . The second-smallest eigenvector of is therefore a second-largest eigenvector of .
If is normalized so that , take
Then
Thus the spectral-clustering coordinate is the nonconstant eigenmode associated with the second-largest eigenvalue of the transition matrix. When the nontrivial spectrum is nonnegative, this is also the slowest-decaying nonconstant mode.
Remark 3.2 (Periodicity). Connectedness alone does not ensure that converges: for example, a random walk on a bipartite graph can have eigenvalue . If the chain is also aperiodic, then
and A common fix is the lazy walk . It preserves the eigenvectors and transforms each eigenvalue into . In particular, for the lazy walk the second-largest eigenvalue corresponds to the slowest-decaying nonconstant mode.