clustering_notes
clustering_notes
Notes
Matteo Lugli
1
1 Intuition
Spectral clustering algorithms all rely on some simple steps:
2. Compute the adjacency matrix and the degree matrix of that graph;
5. Take the first k eigenvectors (from the smallest corresponding eigenvalue) except for
the first one, where k is the dimension of the new space;
6. The eigenvectors are going to be the features of the elements of the new space, so they
become the columns of a new matrix P ;
But why do we use the Laplacian matrix? Why do we compute the eigenvectors
of such matrix?
2 Example
nodes 1 2 3 4 5 6
1 3 -1 -1 0 -1 0
2 -1 2 -1 0 0 0
3 -1 -1 3 -1 0 0
4 0 0 -1 3 -1 -1
5 0 0 0 -1 3 -1
6 0 0 0 -1 -1 2
2
Above you can see an example graph and the corresponding Laplacian. If you notice,
the sum of all of the rows is always zero. You can easily verify that one possible eigenvector
is [1, 1, . . . , 1] with the corresponding eigenvalue being λ = 0. Also remember that all of the
eigenvectors are always real and orthogonal.
The min-max theorem (read Wikipedia page) says that finding the smallest eigenvalue
is the same as solving the following equation:
xt M x
λ2 = min (1)
xt x
Let’s see if plugging the Laplacian in that equation produces something usefull that can
relate to our clustering problem:
n
X n
X
xT Lx = Li,j xi xj = (Di,j − Ai,j )xi xj (2)
i,j=1 i,j=1
X X
= Dii x2i − 2xi xj (3)
i i,j∈E
Going from 2 to 3 is not trivial: you need to consider that D is a diagonal matrix, so when
you successfully select an element that is ̸= from zero in matrix D it means that i and j
are the same. For the second part you need to consider that the in matrix A you find a 1
if node i and node j are connected. So we can replace the original loop with a loop that
iterates on the edges. The matrix is symmetrical so we encounter the product xi xj twice
through the loop.
X X
= Dii x2i − 2xi xj
i i,j∈E
X
= x2i + x2j − 2xi xj (4)
i,j∈E
X
= (xi − xj )2 (5)
i,j∈E
Let’s recall that x is a vector that ”selects” some of the elements and place them in cluster
A, the other ones will be placed in cluster B. Let’s re-write the full problem and make some
considerations:
2
P
i,j∈E (xi − xj )
λ2 = min P 2 (6)
i xi
3
3 Summary
We learned that finding the eigenvector corresponding to the smallest eigenvalue is the same
as solving this: X
argminy∈[−1,1]n f (y) = (yi − yj )2 = y t Ly (7)
i,j∈E
which looks really similar to the clustering problem that we want to solve. This particular
formulation is obtained because we used the Laplacian matrix!