comparison toolboxes/FullBNT-1.0.7/Kalman/learning_demo.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 % Make a point move in the 2D plane
2 % State = (x y xdot ydot). We only observe (x y).
3 % Generate data from this process, and try to learn the dynamics back.
4
5 % X(t+1) = F X(t) + noise(Q)
6 % Y(t) = H X(t) + noise(R)
7
8 ss = 4; % state size
9 os = 2; % observation size
10 F = [1 0 1 0; 0 1 0 1; 0 0 1 0; 0 0 0 1];
11 H = [1 0 0 0; 0 1 0 0];
12 Q = 0.1*eye(ss);
13 R = 1*eye(os);
14 initx = [10 10 1 0]';
15 initV = 10*eye(ss);
16
17 seed = 1;
18 rand('state', seed);
19 randn('state', seed);
20 T = 100;
21 [x,y] = sample_lds(F, H, Q, R, initx, T);
22
23 % Initializing the params to sensible values is crucial.
24 % Here, we use the true values for everything except F and H,
25 % which we initialize randomly (bad idea!)
26 % Lack of identifiability means the learned params. are often far from the true ones.
27 % All that EM guarantees is that the likelihood will increase.
28 F1 = randn(ss,ss);
29 H1 = randn(os,ss);
30 Q1 = Q;
31 R1 = R;
32 initx1 = initx;
33 initV1 = initV;
34 max_iter = 10;
35 [F2, H2, Q2, R2, initx2, initV2, LL] = learn_kalman(y, F1, H1, Q1, R1, initx1, initV1, max_iter);
36