Beruflich Dokumente
Kultur Dokumente
www.cs.ucl.ac.uk/staff/T.Fletcher/
1 Introduction
This document explains how to use Barber’s Deterministic Latent Tables [1]
& [2] to learn the parameters in a Hopfield Network. The document con-
cludes with Matlab code showing an implementation of the learning method
detailed here.
In order to make the maths appear less cluttered, superscript indices such
as the t in vt relate to time. Vectors are represented by bold font, and an
element in a vector or array by subscript indices, so vti is the ith element of
vector v at time t.
1
where ft = f(vt+1 , vt , ht , θh ). Hence the derivatives can be calculated by
deterministic propagation of errors.
at = Wvt + Aht
V
X H
X
ati = Wij vjt + Aij htj (3.2)
j=1 j=1
Differentiating the log likelihood shown in (2.4) with respect to the observ-
able parameters θv ∈ {W, A}:
T −1
dL X
1 − σ (2vit+1 − 1)ati (2vit+1 − 1)vjt
=
dWij
t=1
T −1
dL X
1 − σ (2vit+1 − 1)ati (2vit+1 − 1)htj
= (3.5)
dAij
t=1
2
Differentiating the log likelihood with respect to the latent parameters θh ∈
{C, B} one first needs to calculate:
T −1
∂L X
A 1 − σ (2vt+1 − 1)at (2vt+1 − 1)
t =
∂h t=1
T −1 X
V
∂L X
Aij 1 − σ (2vit+1 − 1)ati (2vit+1 − 1)
t = (3.6)
∂hj
t=1 i=1
dht
dθh then needs to be calculated for each parameter:
and
dht ∂ft ∂ft dht−1
= +
dB ∂B ∂ht−1 dB
dht−1
t−1 t−1 t−1
= 2σ (1 − σ ) h +B (3.8)
dB
T −1
dht−1
dL X t+1 t
t+1 t−1 t−1 t−1
= A 1 − σ (2v − 1)a (2v −1)2σ (1−σ ) h +B
dB dB
t=1
(3.10)
3
4 Matlab Code
4.1 Initialise a Network
4
4.2 Learn Parameters
% Sum over t
for t = 1:T−1
at = W*v(:,t) + A*h(:,t);
dLdW = dLdW + (1−sig((2*v(:,t+1)−1).*at)).*(2*v(:,t+1)−1)*v(:,t)';
dLdA = dLdA + (1−sig((2*v(:,t+1)−1).*at)).*(2*v(:,t+1)−1)*h(:,t)';
if t>1
sm = sig(B*h(:,t−1)+C*v(:,t−1));
dLdC = dLdC + (A'*((1−sig((2*v(:,t+1)−1).*at)).*(2*v(:,t+1)−1))...
.*(2*sm.*(1−sm)))*v(:,t−1)';
sA=A'*((1−sig((2*v(:,t+1)−1).*at)).*(2*v(:,t+1)−1));
for i=1:H
for j=1:H
for m=1:H
sumr=0;
for r=1:H
sumr=sumr+B(m,r)*dhmdB old(r,i,j);
end %r
if m==i
sumr=sumr+h(j,t−1);
end %if
dhmdB(m,i,j) = 2*sm(m).*(1−sm(m))*sumr;
end %m
dLdB(i,j)=dLdB(i,j)+sA(m)*dhmdB(m,i,j);
end %j
5
end %i
dhmdB old=dhmdB;
end %if
LL = LL + sum(log(sig((2*v(:,t+1)−1).*at)));
end %t
% Update parameters
A = A + eta*dLdA;
B = B + eta*dLdB;
C = C + eta*dLdC;
W = W + eta*dLdW;
end %loop
% Sigma function
function s = sig(x)
s = 1./(1+exp(−x));
6
4.3 Reconstruct Network
7
References
[1] D. Barber, “Dynamic Bayesian Networks with Deterministic Tables,” in
Advances in Neural Information Processing Systems (NIPS), 2003.