Kalmanfilter_HW

```Kalman filter model of adaptation
Let us simulate an experiment in which we impose a perturbation on a movement, we reverse the
perturbation for a few trials, and then impose an ‘error-clamp’.
The target is at 90 deg, we generate a motor command u, and the experimenter imposes a 30 deg
perturbation on our movement. After a few hundred trials, the rotation is reversed to -30 deg, and
then an error-clamp is imposed on our movements.
We assume that the learner makes the following assumptions:
1. There is a perturbation that is affecting my movements. That perturbation is driven by something that
has multiple timescales. The perturbation is a sum of these hidden states.
2. The hidden states change from trial to trial. Some change slowly, others change fast.
3. The states that change fast have larger noise than states that change slow.
u
r1
h
r2
( n  1)
x
(n)
 Ax
y
(n)
c x
T
(n)
 bu  ε x
(n)
 εy
(n)
εx
N  0 ,Q 
εy
N  0 ,
2

y
The perturbations that
are produced by the
experimenter:
Initial conditions
 r1 
 
x  r2
 
 h 
0 
 
b 0
 
 1 
 0.995

A
0

 0
 0.01

Q
0

 0
0
0.8
0
0

0

0 
0
1
0
 9
2
c  1
1
1
T
x
0

0

0 
P
(0 )
1 0 
0 
 
 0
 
 t 
 100

 0

 0
r
0
200
0
0

0

0 
(n )
 0

 30

  30
 0 , y  yˆ

n  1,
, 300
n  301,
, 500
n  501,
, 520
n  600 (erro r clam p )
Using the Kalman filter approach, simulate the learner’s performance using the initial conditions
given in the last slide.
Plot u as a function of trial number.
Plot y as a function of trial number.
Plot the first and second element of the x vector (fast and slow states). Also plot the sum of these
two states. Note the spontaneous recovery following start of error-clamp trials.
t = 90 target is at 90deg
u = t - d xˆ
(n)
T
yˆ(n) = cT xˆ
d = éê 1 1 0 ùú
ë
û
T
(n n-1)
(n n-1)
y (n) = u(n) + r (n) + e y
xˆ
(n n)
= xˆ
k =
(n n-1)
P
(n)
P
xˆ
(n n)
cT P
(n n-1)
(
c
c + s y2
)
= I - ck(n)T P
(n+1 n)
= Axˆ
(n+1 n)
= AP
P
(
+k(n) y (n) - yˆ (n)
(n n-1)
(
e y ∼ N 0,s y2
(n n-1)
(n n)
+bu(n)
(n n)
AT +Q
)
)
95
u
x1  x2
(n)
20
x1
90
10
85
x2
80
0
75
10
70
65
0
100
200
300
400
500
600
700
200
300
400
500
600
700
120
(n)
yˆ
100
80
60
40
0
100
0
100
200
300
400
500
600
700
```