Part1

Local Search (part 1)
Haim Kaplan and Uri Zwick
Algorithms in Action
Tel Aviv University
Last updated: March 2017
1
An example
2
Max Cut
Partition 𝐺 = (𝑉, 𝐸) into 2 parts 𝑆, 𝑉 βˆ– 𝑆 such that the
number of edges 𝑒, 𝑣 , 𝑒 ∈ 𝑆, 𝑣 ∈ 𝑉 βˆ– 𝑆 is maximized
𝑆
𝑆 =π‘‰βˆ–π‘†
3
Few comments
β€’ This problem is NP-hard, best
approximation guarantee is 0.878, NP-hard
to get more than 0.91
β€’ The analogous problem of finding a
minimum cut is easier (how ?)
4
The idea
Start with some cut and
try to improve it by making local changes
Stop when there is no local change that improves the cut
5
Local change
𝑆
𝑆
6
Local change
𝑆
𝑆
7
Local change
𝑆
𝑆
8
Local change
𝑆
𝑆
9
Local change
𝑆
𝑆
10
Local change
𝑆
𝑆
11
Local vs. global OPT
β€’ When we stop we have a cut that we cannot
improve by a local change (local opt)
β€’ This need not be the largest cut (global opt)
12
Local OPT
𝑆
𝑆
A
D
B
C
13
Global OPT
𝑆
𝑆
B
D
A
C
14
Analysis
There are two main parameters of interest:
β€’ Time: How long it takes to get to a local
optimum ?
β€’ Quality of the local optimum ?
15
Quality of local opt
𝑆 =π‘‰βˆ–π‘†
𝑆
v
Can this be the situation at a local optimum ?
16
Quality of local opt
𝑆 =π‘‰βˆ–π‘†
𝑆
v
βˆ€π‘£ 𝛾 𝑣 ≀ 𝛿(𝑣)
𝛿 𝑣 = #edges incident to v that cross the cut
𝛾 𝑣 = #edges incident to v that do not cross the cut
17
Quality of local opt
𝑆=π‘‰βˆ–π‘†
𝑆
v
𝛾 𝑣 ≀
𝑣
2
𝑒, 𝑣
𝑒, 𝑣 ∈ 𝑆 π‘œπ‘Ÿ 𝑒, 𝑣 ∈ 𝑆
𝛿 𝑣
𝑣
≀2
𝑒, 𝑣
𝑒 ∈ 𝑆, 𝑣 ∈ 𝑆
18
Quality of local opt
𝑆=π‘‰βˆ–π‘†
𝑆
v
𝛾 𝑣 ≀
𝑣
𝑒, 𝑣
𝑣
𝑒, 𝑣 ∈ 𝑆 π‘œπ‘Ÿ 𝑒, 𝑣 ∈ 𝑆
𝑂𝑃𝑇 |𝐸|
≀
≀
2
2
𝛿 𝑣
𝑒, 𝑣
≀
𝑒, 𝑣
𝑒 ∈ 𝑆, 𝑣 ∈ 𝑆
𝑒 ∈ 𝑆, 𝑣 ∈ 𝑆
19
Steps to local opt
𝑂( 𝐸 )
Each step the size of the cut increases by at least one
20
Weighted graphs
Partition 𝐺 = (𝑉, 𝐸) into 2 parts 𝑆, 𝑉 βˆ– 𝑆 such that the
βˆ‘π’˜ 𝑒, 𝑣 , 𝑒 ∈ 𝑉, 𝑣 ∈ 𝑉 βˆ– 𝑆 is maximized
𝑆
𝑆 =π‘‰βˆ–π‘†
21
Weighted graphs
Works the same:
Make a swap if it increases the weight of the cut
𝑂𝑃𝑇 π‘Š
≀
≀ 𝑀 𝑒, 𝑣 𝑒 ∈ 𝑆, 𝑣 ∈ 𝑆
2
2
π‘Š = βˆ‘π‘€(𝑒, 𝑣)
22
Hopfield networks
A neural network that is used as memory (Content
Addressable Memory)
Initialized with a noisy or incomplete pattern it converges to
the correct pattern
23
Memory cells (pixels) are nodes
in a weighted undirected graph
𝑠𝑖 ∈ {βˆ’1,1}
𝑠𝑖
𝑀𝑖𝑗
𝑠𝑗
24
Retrieving form memory
Initialize with a
tentative content
1
1
βˆ’1
-1
1
-1
1
25
Retrieving form memory
Each neuron 𝑖 in
turn checks if
βˆ‘π‘— 𝑀𝑖𝑗 𝑠𝑖 𝑠𝑗 > 0 ?
If so then 𝑠𝑖 flips
When no neuron
wants to flip we
found the content
1
1
βˆ’1
-1
1
-1
1
26
Retrieving form memory
Each neuron 𝑖 in
turn checks if
π΄βˆ’π΅ >0?
βˆ’1
-1
1
1
If so then 𝑠𝑖 flips
1
When a neuron flips
the value of the cut
increases  converges
to a local max cut
-1
1
27
Storing in memory
We want to
compute weights
such that the local
max cuts have a
specific form
Large (positive) weight
between cells in
different states, small
(negative) weight
between cells of the
same state
βˆ’1
-1
1
1
1
-1
1
28
Hebbian learning
Suppose we want to store π‘₯ = (π‘₯1 , π‘₯2 , … , π‘₯𝑛 )
Set 𝑀𝑖𝑗 = βˆ’π‘₯𝑖 π‘₯𝑗
29
Hebbian learning
1
1
βˆ’1
-1
1
βˆ’1
βˆ’1
1
-1
1
30
Storing in memory
The desired cut is
even the global max
1
βˆ’1
-1
1
1
βˆ’1
1
-1
1
31
Hebbian learning
Suppose we want π‘₯ = (π‘₯1 , π‘₯2 , … , π‘₯𝑛 ), 𝑦 = 𝑦1 , 𝑦2 , … , 𝑦𝑛 , and
𝑧 = (𝑧1 , 𝑧2 , … , 𝑧𝑛 ) to be local maxima
Set 𝑀𝑖𝑗 = βˆ’π‘₯𝑖 π‘₯𝑗 βˆ’π‘¦π‘– 𝑦𝑗 βˆ’π‘§π‘– 𝑧𝑗
Each neuron 𝑖 in turn checks if βˆ‘π‘— 𝑀𝑖𝑗 𝑠𝑖 𝑠𝑗 > 0 ?
Each neuron 𝑖 in turn checks if
βˆ‘π‘—(βˆ’π‘₯𝑖 π‘₯𝑗 βˆ’π‘¦π‘– 𝑦𝑗 βˆ’π‘§π‘– 𝑧𝑗 )𝑠𝑖 𝑠𝑗 > 0 ?
π‘₯ is stable iff for all 𝑖
(βˆ’π‘₯𝑖 π‘₯𝑗 βˆ’π‘¦π‘– 𝑦𝑗 βˆ’π‘§π‘– 𝑧𝑗 )π‘₯𝑖 π‘₯𝑗 ≀ 0 ?
𝑗
32
Hebbian learning
π‘₯ is stable iff for all 𝑖
(βˆ’π‘₯𝑖 π‘₯𝑗 βˆ’π‘¦π‘– 𝑦𝑗 βˆ’π‘§π‘– 𝑧𝑗 )π‘₯𝑖 π‘₯𝑗 ≀ 0
𝑗
βˆ’π‘₯𝑖2
π‘₯
2
βˆ’ 𝑦𝑖 π‘₯𝑖 π‘₯, 𝑦 βˆ’ 𝑧𝑖 π‘₯𝑖 π‘₯, 𝑧 ≀ 0
βˆ’π‘› βˆ’ 𝑦𝑖 π‘₯𝑖 π‘₯, 𝑦 βˆ’ 𝑧𝑖 π‘₯𝑖 π‘₯, 𝑧 ≀ 0
βˆ’π‘¦π‘– π‘₯𝑖 π‘₯, 𝑦 βˆ’ 𝑧𝑖 π‘₯𝑖 π‘₯, 𝑧 ≀ 𝑛
This will hold if we are not trying to store too many vectors or
if the vectors are nearly orthogonal…
33
Storage capacity:
Stochastic analysis
How may random βˆ’1/1 vectors can we store with high
probability ?
≀ 0.138𝑛
34
Back to max cut
35
Steps to local opt
We construct a example with a long running time
The example uses two kinds of vertices
36
Steps to local opt
𝑒2
𝑒3 𝑣
𝑒4
𝑒1
𝑀 𝑒3 > 𝑀 𝑒1 + 𝑀 𝑒2 + 𝑀 𝑒4
37
Steps to local opt
𝑒2
𝑒3 𝑣
𝑒4
𝑒1
𝑀 𝑒3 > 𝑀 𝑒1 + 𝑀 𝑒2 + 𝑀 𝑒4
38
Steps to local opt
𝑒2
𝑒3 𝑣
𝑒4
𝑒1
𝑀 𝑒3 > 𝑀 𝑒1 + 𝑀 𝑒2 + 𝑀 𝑒4
39
Steps to local opt
𝑒2
𝑒3 𝑣
𝑒4
𝑒3
𝑒1
𝑀 𝑒4 > 𝑀 𝑒2 , 𝑀 𝑒3 > 𝑀 𝑒1
𝑒2
𝑣
𝑒4
𝑀 𝑒3 > 𝑀 𝑒1 + 𝑀 𝑒2 + 𝑀 𝑒4
𝑒1
𝑀 𝑒2 + 𝑀 𝑒3 > 𝑀 𝑒1 + 𝑀 𝑒4
40
Steps to local opt
𝑒2
𝑒3 𝑣
𝑒4
𝑒3
𝑒1
𝑀 𝑒4 > 𝑀 𝑒2 , 𝑀 𝑒3 > 𝑀 𝑒1
𝑒2
𝑣
𝑒4
𝑀 𝑒3 > 𝑀 𝑒1 + 𝑀 𝑒2 + 𝑀 𝑒4
𝑒1
𝑀 𝑒2 + 𝑀 𝑒3 > 𝑀 𝑒1 + 𝑀 𝑒4
41
Steps to local opt
𝑒2
𝑒3 𝑣
𝑒4
𝑒3
𝑒1
𝑀 𝑒4 > 𝑀 𝑒2 , 𝑀 𝑒3 > 𝑀 𝑒1
𝑒2
𝑣
𝑒4
𝑀 𝑒3 > 𝑀 𝑒1 + 𝑀 𝑒2 + 𝑀 𝑒4
𝑒1
𝑀 𝑒2 + 𝑀 𝑒3 > 𝑀 𝑒1 + 𝑀 𝑒4
42
Steps to local opt
𝑒2
𝑒3 𝑣
𝑒4
𝑒3
𝑒1
𝑀 𝑒4 > 𝑀 𝑒2 , 𝑀 𝑒3 > 𝑀 𝑒1
𝑒2
𝑣
𝑒4
𝑀 𝑒3 > 𝑀 𝑒1 + 𝑀 𝑒2 + 𝑀 𝑒4
𝑒1
𝑀 𝑒2 + 𝑀 𝑒3 > 𝑀 𝑒1 + 𝑀 𝑒4
43
Steps to local opt
𝑒2
𝑒3 𝑣
𝑒4
𝑒3
𝑒1
𝑀 𝑒4 > 𝑀 𝑒2 , 𝑀 𝑒3 > 𝑀 𝑒1
𝑒2
𝑣
𝑒4
𝑀 𝑒3 > 𝑀 𝑒1 + 𝑀 𝑒2 + 𝑀 𝑒4
𝑒1
𝑀 𝑒2 + 𝑀 𝑒3 > 𝑀 𝑒1 + 𝑀 𝑒4
44
Steps to local opt
45
Steps to local opt
46
Steps to local opt
47
Steps to local opt
48
Steps to local opt
49
Steps to local opt
50
Steps to local opt
51
Steps to local opt
52
Steps to local opt
53
Steps to local opt
54
Steps to local opt
55
Steps to local opt
56
Steps to local opt
57
Steps to local opt
58
Steps to local opt
59
Steps to local opt
𝑣0
𝑣1
Moral: 2 flips of 𝑣0 caused 4 flips of 𝑣1
60
Steps to local opt
𝑣0
𝑣1
𝑣2
61
Steps to local opt
𝑣0
𝑣1
𝑣2
62
Steps to local opt
𝑣0
𝑣1
𝑣2
63
Steps to local opt
𝑣0
𝑣1
𝑣2
64
Steps to local opt
𝑣0
𝑣1
𝑣2
65
Steps to local opt
𝑣0
𝑣1
𝑣2
66
Steps to local opt
𝑣0
𝑣1
𝑣2
67
Steps to local opt
𝑣0
𝑣1
𝑣2
68
Steps to local opt
𝑣0
𝑣1
𝑣2
69
Steps to local opt
𝑣0
𝑣1
𝑣2
70
Steps to local opt
𝑣0
𝑣1
𝑣2
71
Steps to local opt
𝑣0
𝑣1
𝑣2
72
Steps to local opt
𝑣0
𝑣1
𝑣2
73
Steps to local opt
𝑣0
𝑣1
𝑣2
At this point 𝑣2 flipped 4 times and the circled gadget is in its
initial configuration
74
Steps to local opt
𝑣0
𝑣1
𝑣2
75
Steps to local opt
𝑣0
𝑣1
𝑣2
76
Steps to local opt
𝑣0
𝑣1
𝑣2
77
Steps to local opt
𝑣0
𝑣1
𝑣2
78
Steps to local opt
𝑣0
𝑣1
𝑣2
79
Steps to local opt
𝑣0
𝑣1
𝑣2
80
Steps to local opt
𝑣0
𝑣1
𝑣2
81
Steps to local opt
𝑣0
𝑣1
𝑣2
82
Steps to local opt
𝑣0
𝑣1
𝑣2
83
Steps to local opt
𝑣0
𝑣1
𝑣2
84
Steps to local opt
𝑣0
𝑣1
𝑣2
85
Steps to local opt
𝑣0
𝑣1
𝑣2
86
Steps to local opt
𝑣0
𝑣1
𝑣2
By induction we can make π‘£π‘˜ flip 2π‘˜+1 times
87
#Steps - Summary
β€’ Still 𝑂 π‘Š , π‘Š = βˆ‘π‘’βˆˆπΈ 𝑀 𝑒 , if all weights
are integers (pseudo polynomial)
β€’ We can prevent long running time if we
only do a move if it improves by at least
2πœ–π‘€(𝑆,𝑆)
𝑛
β€’ Then the # of moves is bounded by
𝑛
𝑂 log(π‘Š)
πœ–
88
Big improvement - analysis
𝑆
𝑆
v
βˆ€π‘£ 𝑀 Ξ“ 𝑣
≀𝑀 Ξ” 𝑣
2πœ–π‘€(𝑆, 𝑆)
+
𝑛
Ξ” 𝑣 = set of edges incident to v that cross the cut
Ξ“ 𝑣 = set of edges incident to v that do not cross the cut
Big improvement - analysis
𝑆=π‘‰βˆ–π‘†
𝑆
v
𝑀(Ξ“ 𝑣 ) ≀
𝑣
𝑀 Ξ” 𝑣
𝑣
2πœ–π‘€(𝑆, 𝑆)
+
𝑛
2𝑀 𝑒, 𝑣 𝑒, 𝑣 ∈ 𝑆 π‘œπ‘Ÿ 𝑒, 𝑣 ∈ 𝑆
≀ 2𝑀 𝑒, 𝑣 𝑒 ∈ 𝑆, 𝑣 ∈ 𝑆 + 2πœ–πΏ
90
Big improvement - analysis
𝑀 𝑒, 𝑣 𝑒, 𝑣 ∈ 𝑆 π‘œπ‘Ÿ 𝑒, 𝑣 ∈ 𝑆
≀ 𝑀 𝑒, 𝑣 𝑒 ∈ 𝑆, 𝑣 ∈ 𝑆 + πœ–πΏ
π‘Š βˆ’ 𝐿 ≀ 𝐿 + πœ–πΏ
π‘Š ≀ 2+πœ– 𝐿
1
1
𝑂𝑃𝑇 ≀
π‘Šβ‰€πΏ
2+πœ–
2+πœ–
Max-cut notes
β€’ The ½ approximation guarantee is not that
impressive: A random partition gives this
guarantee in expectation
β€’ Can also get ½ approximation
deterministically by inserting the vertices
one by one to the ``right’’ side of the cut
92
Max-cut notes
β€’ But still, our local search scheme gives in
practice larger cuts.
93