Debian Codegraph @

tests/kalman_filter_smoother/algo1.mod

raw
1 var z dw dx dy dc1 dc2;
2 varexo e_w e_x e_y e_z;
3
4 parameters rho_w rho_x rho_y rho_z a1 a2 a3 b c;
5
6 model(linear);
7 dw = rho_w*dw(-1)+a1*(dc1(-1))+e_w;
8 dx = rho_x*dx(-1)+a2*(dc1(-1))+e_x;
9 dy = rho_y*dy(-1)+a3*(dc2(-1))+e_y;
10 z = rho_z*z(-1)+dw-dx+e_z;
11 dc1 = dc1(-1)+dx-b*dy-c*dw;
12 dc2 = dc2(-1)+dx-b*dy;
13 end;
14
15 estimated_params;
16 rho_w, normal_pdf, 0.5,0.2;
17 rho_x, normal_pdf, 0.5,0.2;
18 rho_y, normal_pdf, 0.5,0.2;
19 rho_z, normal_pdf, 0.8,0.2;
20
21 a1, normal_pdf, 0.1,0.2;
22 a2, normal_pdf, -0.1,0.2;
23 a3, normal_pdf, 0.1,0.2;
24 b , normal_pdf, 1,0.2;
25 c , normal_pdf, 1,0.2;
26
27 stderr e_w, uniform_pdf,,, 0.01, 0.1;
28 stderr e_x, uniform_pdf,,, 0.01, 0.1;
29 stderr e_y, uniform_pdf,,, 0.01, 0.1;
30 stderr e_z, uniform_pdf,,, 0.01, 0.1;
31 end;
32
33 varobs dw dx dy z;
34
35 estimation(datafile=data_algo,silent_optimizer,first_obs=1000,nobs=200,mh_replic=0,filtered_vars,smoothed_state_uncertainty);
36
37 //checking smoother consistency
38 X = oo_.SmoothedVariables;
39 S = [X.z X.dw X.dx X.dy X.dc1 X.dc2];
40 X = oo_.SmoothedShocks;
41 E = [X.e_w X.e_x X.e_y X.e_z];
42 A = oo_.dr.ghx;
43 B = oo_.dr.ghu;
44 err = zeros(6,200);
45 for t=2:200;
46 err(:,t) = S(t,:)'-A*S(t-1,:)'-B*E(t,:)';
47 end;
48 if max(max(abs(err))) > 1e-10;
49 error('Test fails')
50 end;
51
52 d=load('data_algo');
53 dat = [d.dw d.dx d.dy d.z];
54 if max(max(abs(dat(1000:1199,:)-S(:,[2:4 1])))) > 1e-10;
55 error('Test fails');
56 end;