Lecture 22 Energy-Based Models - Hopfield Network
Lecture 22 Energy-Based Models - Hopfield Network
-- Hopfield Network
Hao Dong
Peking University
1
Contents
2
• Discrete Hopfield Neural Networks
• Introduction
• How to use
• How to train
• Thinking
• Continuous Hopfield Neural Networks
3
• Before
• What about …
4
Consider this network
+1 𝑖𝑓 𝑥 ≥ 0
𝑓 𝑥 =$
−1 𝑖𝑓 𝑥 < 0
+1 𝑖𝑓 𝑥 ≥ 0
𝑓 𝑥 =$
−1 𝑖𝑓 𝑥 < 0
+1 𝑖𝑓 𝑥 ≥ 0
𝑓 𝑥 =$
−1 𝑖𝑓 𝑥 < 0
• If the sign of the field opposes its own sign, it “flips” to match the
sign of the field.
• “Flips” of a neuron may cause other neurons to “flip”!
8
Example
9
Example
10
Example
11
Hopfield Net
• If the sign of the field opposes its own sign, it “flips” to match the field
• Which will change the field at other nodes
• Which may then flip
• Which may cause other neurons to flip
• And so on…
• Will this continue forever?
12
Hopfield Net
+1 𝑖𝑓 𝑥 ≥ 0
𝑓 𝑥 =$
−1 𝑖𝑓 𝑥 < 0
• Let 𝑦!( be the output of the i-th neuron before it responds to the current field
• Let 𝑦!) be the output of the i-th neuron before it responds to the current field
+1 𝑖𝑓 𝑥 ≥ 0
𝑓 𝑥 =$ 𝑦! = 𝑓(. 𝑤"! 𝑦" + 𝑏! )
−1 𝑖𝑓 𝑥 < 0
"#!
14
Hopfield Net
+1 𝑖𝑓 𝑥 ≥ 0
𝑓 𝑥 =$ 𝑦! = 𝑓(. 𝑤"! 𝑦" + 𝑏! )
−1 𝑖𝑓 𝑥 < 0
"#!
15
Globally
• E is bounded:
• 𝐸($) = − ∑$,&'$ 𝑤$& − ∑$ 𝑏$
• The minimum variation of E in a ”flip” is:
• Δ𝐸 ($) = min 2| ∑&'$ 𝑤&$ 𝑦& + 𝑏$ |
$,{+! ,$,!…#}
18
Spin Glass
21
Contents
22
Hopfield Network
+1 𝑖𝑓 𝑥 ≥ 0
𝑓 𝑥 =$
−1 𝑖𝑓 𝑥 < 0
• The network will evolve until it arrives at a local minimum in the energy contour
23
Content-addressable memory
25
Real-world Examples
http://staff.itee.uq.edu.au/janetw/cmc/chapters/Hopfield 26
Computation
28
Evolution
• If we use tanh for activation
• Still not global minimum, why?
• Local minimum still exists
29
Contents
30
Issues to be solved
31
How to store a specific pattern?
32
Method1: Hebbian Learning
• We want:
• 𝑓 ∑"#! 𝑤"! 𝑦" = 𝑦! ∀𝑖
• Hebbian Learning:
• 𝑤"! = 𝑦" 𝑦!
%
• E = − ∑!,"#! 𝑤!" 𝑦! 𝑦" = − 𝑁(𝑁 − 1)
(
33
Method1: Hebbian Learning
• Note:
• If we store P, we will also store –P
• For K patterns:
• 𝑦$ = 𝑦%$ , 𝑦($ , … , 𝑦&$ , 𝑘 = 1, … , 𝐾
%
• 𝑤!" = ∑$ 𝑦!$ 𝑦"$
&
• Each pattern is stable
34
Method1: Hebbian Learning - How many patterns can we store?
35
Method1: Hebbian Learning - Example: 4-bit pattern
36
Method1: Hebbian Learning - Parasitic Patterns
37
Method2: Geometric approach
38
Method2: Geometric approach
39
Method2: Geometric approach
%
• 𝐸 = − 𝑦 ) 𝑊𝑦 − 𝑏) 𝑦
(
• This must be maximally low for target patterns
• Also must be maximally high for all other patterns
41
Method3: Optimization
• Intuitively:
42
Method3: Optimization
• So gradient descent:
• 𝑊 = 𝑊 + 𝛼(∑.∈0! yy ) − ∑.∉0" 𝑦𝑦 ) )
43
Method3: Optimization
• 𝑊 = 𝑊 + 𝛼(∑.∈0! yy ) − ∑.∉0" 𝑦𝑦 ) )
44
Method3: Optimization
• Initialize W
• Repeat until convergence or limitation:
• Sample target pattern
• Randomly initialize the network and let it evolve
• Update weights
45
Method3: Optimization
• Initialize W
• Repeat until convergence or limitation:
• Sample target pattern
• Initialize the network with target pattern and let it evolve
• Update weights
46
Method3: Optimization
• 𝑊 = 𝑊 + 𝛼(∑.∈0! yy ) − ∑.∉0" ,.345667. 𝑦𝑦 ) )
• Initialize W
• Repeat until convergence or limitation:
• Sample target pattern
• Initialize the network with target pattern and let it evolve a
few steps
• Update weights
47
Contents
48
Thinking
• The capacity of Hopfield Network
• How many patterns can be stored?
• Orthogonal <N; Non-orthogonal?
49
Thinking
• Something bad happens:
• The results are not perfect…
50
Thinking
• Something bad happens:
• The results are not perfect…
• Because of the local minima
51
Thinking – Stochastic Hopfield Net
• Something bad happens:
• The results are not perfect…
53
Contents
54
Continuous Hopfield Neural Network
• Energy function :
• Issues:
• Design the energy function for specific problems
• The variable of the problem and the neuron of the CHNN
55
Reference
• CMU 11-785 Lec17, 18
Thanks
57