Debian Codegraph @

tests/kalman_filter_smoother/algoH1.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
32 stderr z, normal_pdf, 0, 0.1;
33 end;
34
35 varobs dw dx dy z;
36
37 estimation(datafile=data_algo,first_obs=1000,silent_optimizer,nobs=200,mh_replic=0,filtered_vars,smoothed_state_uncertainty);
38
39 //checking smoother consistency
40 X = oo_.SmoothedVariables;
41 S = [X.z X.dw X.dx X.dy X.dc1 X.dc2];
42 X = oo_.SmoothedShocks;
43 E = [X.e_w X.e_x X.e_y X.e_z];
44 A = oo_.dr.ghx;
45 B = oo_.dr.ghu;
46 err = zeros(6,200);
47 for t=2:200;
48 err(:,t) = S(t,:)'-A*S(t-1,:)'-B*E(t,:)';
49 end;
50 if max(max(abs(err))) > 1e-10;
51 error('Test fails');
52 end;
53
54 d=load('data_algo');
55 dat = [d.dw d.dx d.dy d.z];
56 X = oo_.SmoothedMeasurementErrors;
57 ME = [X.dw X.dx X.dy X.z];
58 if max(max(abs(dat(1000:1199,:)-S(:,[2:4 1])-ME))) > 1e-10;
59 error('Test fails');
60 end;