Exercise Sheet 4 - Machine Learning Lab

Universität Freiburg
Lehrstuhl für Maschinelles Lernen und natürlichsprachliche Systeme
Machine Learning (SS2013)
Prof. Dr. Volker Sperschneider, Manuel Blum
Exercise Sheet 4
Exercise 4.1: Hopfield Networks
(a) Can the vector (1, 0, −1, 0, 1) be stored in a 5-neuron Hopfield network? If so, what
are the weights for a network with that vector stored in it? If not, why not?
(b) Consider the Hopfield network given below. Write down the corresponding weight
matrix, such that weight wij is in column i and row j. Write down the threshold
vector θ, such that element θi is the bias of neuron i.
-2
2
0
-2
3
-2
-6
1
3
-10
5
2
5
11
4
0
1
-5
5
0
(c) Find one or more stable states of the given network.
(d) Consider the weight matrix w and the threshold vector θ. Starting with the given
state z0 , compute the state flow of the corresponding Hopfield network to the stable
state using asynchronous updates.
0
1
0
0 −4
 1
0
−4
3
4

 0 −4 0 −7 −6

w=
 0
3 −7 0 −4

−4 4 −6 −4 0
−2 −4 −2 3 −6

−2
−4

−2

,
3

−6
0

−5
 0 
 
 2 
 
θ =  ,
 1 
 
 0 
0


−1
−1
 
−1
 
z0 =  
−1
 
 1 
1


(e) Starting in the (same) state z0 , compute the state flow using synchronous updates.
Exercise 4.2: Stable states of a Hopfield network
Show that stable states of a Hopfield net are exactly the local minima of the energy
function. Remember that
E(z(i ← −1)) − E(z(i ← +1)) = 2neti (z)
E(z(i ← +1)) − E(z(i ← −1)) = −2neti (z)
Exercise 4.3: Hebb learning
(a) Compute the weight matrix for a Hopfield network with the two vectors (1, −1, 1, −1, 1, 1)
and (1, 1, 1, −1, −1, −1) stored in it.
(b) Confirm that both these vectors are stable states of the network.
Exercise 4.4: Markov chains
From one weekend to the next, there is a large fluctuation between the main discount
supermarkets Ladi, Didl und Puls. In average 30% of the Ladi customers buy at Didl
the next week. 10% switch from Didl to Ladi and 40% to Puls. From Puls, 20%
switch to Ladi. The remaining customers stick to their current discounter. Assuming
that customers are uniformly distributed at the beginning, what is the distribution of
customers after one week? How are the customers distributed after 10 weeks?
Exercise 4.5: Programming Assignment
Download the files hopfield.py and usps40.mat from the course website. It contains
skeleton python code for learning Hopfield networks and a training set of 40 handwritten
digits. To run the code you will need Numpy, Scipy and Pygame.
(a) Implement the method getActivation(state, weights). Given a state vector
and a weight vector, this function should return the bipolar activation of a single
neuron.
(b) Implement the method getStableStates(weights, m). Given a weight matrix,
this function should return m stable states of the Hopfield network. Compute stable
states by initializing the network with random states and let it run until convergence.
(c) Implement the method correlation(data), that computes the correlation matrix
of the given data.
(d) Implement the method HopfieldLearning(data), that trains the Hopfield network
using the methods implemented in the previous exercises. Choose a suitable learning
rate and number of optimization steps.
(e) Test your algorithm with different training patterns. Add noise and observe to which
stable states the network converges. Draw new patterns and observe the results.