annotate toolboxes/FullBNT-1.0.7/Kalman/learning_demo.m @ 0:cc4b1211e677 tip

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