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