Algorithms for Graph Visualization

21
Steven Chaplick · Lehrstuhl f¨ ur Informatik I · Universit¨ at W¨ urzburg (based on slides from Martin N¨ ollenburg and Robert G¨ orke, KIT) Lecture #2 Summer Semester 2019 Algorithms for Graph Visualization Two Heuristics: Force-Directed Method & Multi-dimensional Scaling Refs: [GD: AVG, Ch. 10] and [DG: M&M, Ch. 4]

Transcript of Algorithms for Graph Visualization

Page 1: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

(based on slides from Martin Nollenburg and Robert Gorke, KIT)

Lecture #2

Summer Semester 2019

Algorithms for Graph Visualization

Two Heuristics:Force-Directed Method & Multi-dimensional Scaling

Refs: [GD: AVG, Ch. 10] and [DG: M&M, Ch. 4]

Page 2: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

How will we do it?

Ideas? Criteria?

Given a graph G = (V , E ),find a

”nice“ drawing Γ , where

• vertices are points and• edges are straight lines

Physical Analogy: attractive vs. repulsive forces.

Case 1: vertices u, v adjacent Case 2: u and v non-adjacent

frepu v u v

• similar edge lengths• greater distances on

non-adjacent vertices

fspring

Page 3: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

Part I – Force Based Methods

Page 4: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

An iterative approach

Endlayout

SpringEmbedder(G = (V , E ), p = (pv )v∈V , ε > 0, K ∈ N)

t ← 1while t < K and maxv∈V ‖Fv (t)‖ > ε do

foreach v ∈ V doFv (t)←∑

u:uv /∈E frep(pu, pv ) +∑

u:uv∈E fspring(pu, pv )

foreach v ∈ V dopv ← pv + δ · Fv (t)

t ← t + 1

return p

Initial Layout thresholditerations

Page 5: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

Analysis

Advantages Disadvantages

+ very easy

+ surprisingly good fornot too large graphs

– possibly unstable

– ends too soon /stuck in a local minimum.

Timing

In each iteration, we calculate all values of– frep– fspring

O( ) timeO( ) time

– Fv and pv : O(|V |2) time

|E ||V |2

Page 6: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

Force Directed Spring-Embedder by Eades (1984)

Distance

frep(pu, pv ) =crep

‖pv − pu‖· −−→pupv

fspring

l

Force

fspring(pu, pv ) = cspring log‖pv − pu‖

l· −−→pvpu

Unit-vectorfrom pv to pu

Spring constant (e.g. 2.0)

‘natural’ spring length

Repulsion constant (e.g. 1.0)

frep

pu

llv

tou

pu

shv

away

Page 7: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

Forces of Fruchterman & Reingold (1991)

pu

llv

tou

Distance

frep(pu, pv ) =l2

‖pu − pv‖· −−→pupv

fspring = frep + fattr

l

fattr(pu, pv ) =

Force

‖pu − pv‖2

l· −−→pvpu

for edges uv

for all vertex pairs u, vpu

shv

away

‘natural’ spring length

Page 8: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

Speeding up “convergence” – Via Grids

v

[Fruchterman & Reingold (1991)]

Page 9: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

Speeding up – by adaptive displacement δv (t)

SpringEmbedder(G = (V , E ), p = (pv )v∈V , ε > 0, K ∈ N)

t ← 1while t < K and maxv∈V ‖Fv (t)‖ > ε do

foreach v ∈ V doFv (t)←

∑u:uv /∈E frep(pu, pv ) +

∑u:uv∈E fspring(pu, pv )

foreach v ∈ V dopv ← pv + δ · Fv (t)

t ← t + 1

return p

Reminder. . .

δv (t)

Page 10: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

Speeding up – by adaptive displacement δv (t)

Fv (t − 1)

Fv (t)

αv (t)

⇒ larger δv (t)

(Frick, Ludwig, Mehldau 1995)

Page 11: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

Speeding up – by adaptive displacement δv (t)

Fv (t − 1)

Fv (t)

αv (t)

⇒ smaller δv (t)

(Frick, Ludwig, Mehldau 1995)

Page 12: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

Speeding up – by adaptive displacement δv (t)

Fv (t − 1)

Fv (t)αv (t)

F ′v (t)

⇒ smaller δv (t)

(Frick, Ludwig, Mehldau 1995)

Page 13: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

Quad-Tree

R17

R18

QTR0

R1 R2 R3 R4

R5R12

R13

R16

R17 R18

Page 14: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

Calculating repulsive forces (Barnes-Hut 1986)

R0

R1 R2 R3 R4

R5R12

R13

R16

R17 R18

QT

u

σR16

frep(Ri , pu) := |Ri | · frep(σRi , pu)

frep(pu) :=∑

Ri∈Rufrep(Ri , pu)

where Ru = all children of nodes on the R0-u-path in QT

u

σR4

Page 15: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

Part II – Multidimensional Scaling

Page 16: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

Idea: measure and “match” the dissimilarity

Let V = {1, . . . , n} be a lot of objects.

Let D ∈ Rn×n Matrix, where di j ∼ dissimilarty between obj. i , j .

Goal: find x1, . . . , xn ∈ R2, so that

‖xi − xj‖ ≈ di j for all i , j ∈ V

For our drawing, how do we define the dissimilarity between twoobjects, i.e., two vertices?

Answer: The distance between vertices,i.e., the length of a shortest path between them.

Page 17: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

Classic Scaling

Let D(2) = (d2i j)1≤i ,j≤n (note: not D × D).

Compute Matrix B = (bi j) ∈ Rn×n of pseudo products.

Let v1, . . . , vn ∈ Rn be the eigenvectorsof the eigenvalues λ1 ≥ · · · ≥ λn ∈ R of B.

Let X = [x1, . . . , xn]T = [√λ1v1,

√λ2v2].

The minimum strain (X ) = ‖B − X XT‖2 =∑

(bi j − xTi xj)

2.

Good: Find a solution with optimal strain.Bad: numerical inconsistency, dimension reduction degeneracy.

B := −1

2JnD(2)Jn, where Jn = In − 1

n (1n1Tn ),

In = identity matrix1Tn = (1, 1, . . . , 1)

(row & column means of B are zero.)

(project to “largest”eigenvectors)

Page 18: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

Distance Scaling

Definition of strain: set bi j → di j and xTi xj → ‖xi − xj‖:

(unweighted) stress(X ) =∑i ,j

(di j − ‖xi − xj‖)2

(weighted) stress(X ) =∑i ,j

wi j(di j − ‖xi − xj‖)2

where wi j ≥ 0, e.g., wi j = dqij . In graph drawing often q = −2.

Page 19: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

Examples: Classical and Distance Scaling

(a) classical scaling (b) q = 2 (c) q = 0

(d) q = −1 (e) q = −2 (f) q = −4

Page 20: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

Example (a) Classical Scaling

Page 21: Algorithms for Graph Visualization

Steven Chaplick · Lehrstuhl fur Informatik I · Universitat Wurzburg

Example (e) Distance Scaling with q = −2