Graph Partitioning and Spectral Methods

44
Graph Partitioning II: Spectral Methods Class Algorithmic Methods of Data Mining Program M. Sc. Data Science University Sapienza University of Rome Semester Fall 2015 Lecturer Carlos Castillo http://chato.cl/ Sources: Evimaria Terzi: “Clustering: graph cuts and spectral graph partitioning” [link] Daniel A. Spielman: “The Laplacian” [ link] Jure Leskovec: “Defining the graph laplacian” [ link]

Transcript of Graph Partitioning and Spectral Methods

Page 1: Graph Partitioning and Spectral Methods

Graph Partitioning II: Spectral Methods

Class Algorithmic Methods of Data MiningProgram M. Sc. Data ScienceUniversity Sapienza University of RomeSemester Fall 2015Lecturer Carlos Castillo http://chato.cl/

Sources:● Evimaria Terzi: “Clustering: graph cuts and spectral graph

partitioning” [link]● Daniel A. Spielman: “The Laplacian” [link]● Jure Leskovec: “Defining the graph laplacian” [link]

Page 2: Graph Partitioning and Spectral Methods

2

Graph projections

Page 3: Graph Partitioning and Spectral Methods

3

Graphs are nice, but ...

● They describe only local relationships● We would like to understand a global structure● Our objective is transforming a graph into a

more familiar object: a cloud of points in Rk

R1

Page 4: Graph Partitioning and Spectral Methods

4

Graphs are nice, but ...

● They describe only local relationships● We would like to understand a global structure● Our objective is transforming a graph into a

more familiar object: a cloud of points in Rk

R1

Distances should be somehow preserved

Page 5: Graph Partitioning and Spectral Methods

5

Simple 3D graph projection

● Start a BFS from a random node, that has x=1, and nodes visited have ascending x

● Start a BFS from another random node, which has y=1, and nodes visited have ascending y

● Start a BFS from yet another node, which has z=1, and nodes visited have ascending z

● Project node n to position (xn, yn, zn)

How do you think this works in practice?

Page 6: Graph Partitioning and Spectral Methods

6

Eigenvectors of adjacency matrix

Page 7: Graph Partitioning and Spectral Methods

7

Adjacency matrix of G=(V,E)

● Matrix of size |V| x |V| such that:

● What is Ax? Think of x as a set of labels/values:

https://www.youtube.com/watch?v=YuKsZstrua4

Ax is a vector whose ith coordinate contains the sum of the x

j who are

in-neighbors of i

Page 8: Graph Partitioning and Spectral Methods

8

Properties of adjacency matrix

● How many non-zeros are in every row of A?

https://www.youtube.com/watch?v=YuKsZstrua4

Page 9: Graph Partitioning and Spectral Methods

9

Understanding the adjacency matrix

What is Ax? Think of x as a set of labels/values:

https://www.youtube.com/watch?v=YuKsZstrua4

Ax is a vector whose ith coordinate contains the sum of the x

j who are in-neighbors of i

Page 10: Graph Partitioning and Spectral Methods

10

Spectral graph theory

● The study of the eigenvalues and eigenvectors of a graph matrix– Adjacency matrix

– Laplacian matrix (next)

● Suppose graph is d-regular (every node has degree d), what is the value of:

Page 11: Graph Partitioning and Spectral Methods

11

An easy eigenvector of A

● Suppose graph is d-regular, i.e. all nodes have degree d:

● So [1, 1, …, 1]T is an eigenvector of eigenvalue d

Page 12: Graph Partitioning and Spectral Methods

12

Disconnected graphs

● Suppose graph is disconnected (still regular)

● Then matrix has block structure:

S S'

Page 13: Graph Partitioning and Spectral Methods

13

Disconnected graphs

● Suppose graph is disconnected (still regular)

S S'

Page 14: Graph Partitioning and Spectral Methods

14

Disconnected graphs

● Suppose graph is disconnected (still regular)

S S'

Page 15: Graph Partitioning and Spectral Methods

15

Disconnected graphs

● Suppose graph is disconnected (still regular)

● What happens if there are more than 2 connected components?

S S'

Page 16: Graph Partitioning and Spectral Methods

16

In general

Disconnected graph Almost disconnected graph

Small “eigengap”

Page 17: Graph Partitioning and Spectral Methods

17

Graph Laplacian

Page 18: Graph Partitioning and Spectral Methods

18

Adjacency matrix

3

2

1

4

5

6

Page 19: Graph Partitioning and Spectral Methods

19

Degree matrix

3

2

1

4

5

6

Page 20: Graph Partitioning and Spectral Methods

20

Laplacian matrix

3

2

1

4

5

6

Page 21: Graph Partitioning and Spectral Methods

21

Laplacian matrix L = D - A

● Symmetric● Eigenvalues non-negative and real● Eigenvectors real and orthogonal

Page 22: Graph Partitioning and Spectral Methods

22

Constant vector is eigenvector of L

● The constant vector x=[1,1,...,1]T is again an eigenvector, but this time has eigenvalue 0

Page 23: Graph Partitioning and Spectral Methods

23

If the graph is disconnected

● If there are two connected components, the same argument as for the adjacency matrix applies, and

● In general, the multiplicity of eigenvalue 0 is the number of connected components

Page 24: Graph Partitioning and Spectral Methods

24

xTLx

Page 25: Graph Partitioning and Spectral Methods

25

Important property of xTLx

Think of this quantity as the “stress” produced by the assignment of node labels x

Page 26: Graph Partitioning and Spectral Methods

26

xTLx and graph cuts

● Suppose (S, S') is a cut of graph G● Set

0

01

1

1

Page 27: Graph Partitioning and Spectral Methods

27

For symmetric matrices

● Important fact for symmetric matrices

https://en.wikipedia.org/wiki/Rayleigh_quotient

Page 28: Graph Partitioning and Spectral Methods

28

Second eigenvector

● Orthogonal to the first one:● Normal:

Page 29: Graph Partitioning and Spectral Methods

29

What does this mean?

0

Nodes should be placed at both sides of 0 because

Page 30: Graph Partitioning and Spectral Methods

30

Example Graph 1

1

2

3

4

8

5

7

6

Page 31: Graph Partitioning and Spectral Methods

31

Example Graph 1

1

2

3

4

8

5

7

6

Page 32: Graph Partitioning and Spectral Methods

32

Example Graph 1, projected

1

2

3

4

8

5

7

6

0 0.247 0.383-0.383 -0.247

Page 33: Graph Partitioning and Spectral Methods

33

Example Graph 1, communities

1

2

3

4

8

5

7

6

0 0.247 0.383-0.383 -0.247

S S'

Page 34: Graph Partitioning and Spectral Methods

34

Example Graph 2

1

2

3

4

8

5

7

6

Page 35: Graph Partitioning and Spectral Methods

35

Example Graph 3

1

2

3

4

8

5

7

6

Page 36: Graph Partitioning and Spectral Methods

36

Example Graph 3, projected

0-0.057-0.246-0.210

-0.364 0.5510.139

1

2

3

4

8

5

7

6

Page 37: Graph Partitioning and Spectral Methods

37

Example Graph 3, projectedhow to partition?

12

3

4

8

5

7

6

0-0.057-0.246-0.210

-0.364 0.5510.139

Page 38: Graph Partitioning and Spectral Methods

38

Example Graph 3, projected

12

3

4

8

5

7

6

0-0.057-0.246-0.210

-0.364 0.5510.139

S S'

Page 39: Graph Partitioning and Spectral Methods

39

A more complex graph

https://www.youtube.com/watch?v=jpTjj5PmcMM

Page 40: Graph Partitioning and Spectral Methods

40

A graph with 4 “communities”

https://www.youtube.com/watch?v=jpTjj5PmcMM

Page 41: Graph Partitioning and Spectral Methods

41

Other eigenvectors

Second eigenvector Third eigenvector

Value in second eigenvector

Val

ue in

thi

rd e

igen

vect

or

Page 42: Graph Partitioning and Spectral Methods

42

Other eigenvectors

Second eigenvector Third eigenvector

Value in second eigenvector

Val

ue in

thi

rd e

igen

vect

or

Page 43: Graph Partitioning and Spectral Methods

43

Interesting application: image segmentation [Shi & Malik 2000]

Transform into grid graph with edge weights proportional to pixel similarity

Page 44: Graph Partitioning and Spectral Methods

44

Lots of examples, including one of embedding streets in Rome

http://www.cs.yale.edu/homes/spielman/sgta/SpectTut.pdf