Debian Codegraph @

tests/estimation/MH_recover/fs2000_slice_recover.mod

raw
1 // See fs2000.mod in the examples/ directory for details on the model
2
3 var m P c e W R k d n l gy_obs gp_obs y dA;
4 varexo e_a e_m;
5
6 parameters alp bet gam mst rho psi del;
7
8 alp = 0.33;
9 bet = 0.99;
10 gam = 0.003;
11 mst = 1.011;
12 rho = 0.7;
13 psi = 0.787;
14 del = 0.02;
15
16 model;
17 dA = exp(gam+e_a);
18 log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m;
19 -P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0;
20 W = l/n;
21 -(psi/(1-psi))*(c*P/(1-n))+l/n = 0;
22 R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W;
23 1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0;
24 c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1);
25 P*c = m;
26 m-1+d = l;
27 e = exp(e_a);
28 y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a));
29 gy_obs = dA*y/y(-1);
30 gp_obs = (P/P(-1))*m(-1)/dA;
31 end;
32
33 steady_state_model;
34 dA = exp(gam);
35 gst = 1/dA;
36 m = mst;
37 khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1));
38 xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1);
39 nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp );
40 n = xist/(nust+xist);
41 P = xist + nust;
42 k = khst*n;
43
44 l = psi*mst*n/( (1-psi)*(1-n) );
45 c = mst/P;
46 d = l - mst + 1;
47 y = k^alp*n^(1-alp)*gst^alp;
48 R = mst/bet;
49 W = l/n;
50 ist = y-c;
51 q = 1 - d;
52
53 e = 1;
54
55 gp_obs = m/dA;
56 gy_obs = dA;
57 end;
58
59 shocks;
60 var e_a; stderr 0.014;
61 var e_m; stderr 0.005;
62 end;
63
64 steady;
65
66 check;
67
68 estimated_params;
69 alp, beta_pdf, 0.356, 0.02;
70 bet, beta_pdf, 0.993, 0.002;
71 gam, normal_pdf, 0.0085, 0.003;
72 mst, normal_pdf, 1.0002, 0.007;
73 rho, beta_pdf, 0.129, 0.05;
74 psi, beta_pdf, 0.65, 0.05;
75 del, beta_pdf, 0.01, 0.005;
76 stderr e_a, inv_gamma_pdf, 0.035449, inf;
77 stderr e_m, inv_gamma_pdf, 0.008862, inf;
78 end;
79
80 varobs gp_obs gy_obs;
81 if ~isoctave
82
83 estimation(order=1,datafile='../fsdat_simul',nobs=192,silent_optimizer,loglinear,mh_replic=50,mh_nblocks=1,mh_drop=0.2,
84 posterior_sampling_method='slice',
85 posterior_sampler_options=('save_tmp_file',1)
86 );
87
88
89 copyfile([M_.dname filesep 'metropolis' filesep M_.dname '_mh1_blck1.mat'],[M_.dname '_mh1_blck1.mat'])
90 delete([M_.dname filesep 'metropolis' filesep M_.dname '_mh1_blck1.mat'])
91 copyfile([M_.fname '_mh_tmp_blck1.mat'],[M_.dname filesep 'metropolis' filesep M_.dname '_mh_tmp_blck1.mat'])
92
93 estimation(order=1,datafile='../fsdat_simul',nobs=192,silent_optimizer,loglinear,mh_replic=50,mh_nblocks=1,mh_drop=0.2,
94 posterior_sampling_method='slice',
95 posterior_sampler_options=('save_tmp_file',1)
96 ,mh_recover);
97
98 %check first unaffected chain
99 temp1=load([M_.dname '_mh1_blck1.mat']);
100 temp2=load([M_.dname filesep 'metropolis' filesep M_.dname '_mh1_blck1.mat']);
101
102 if max(max(abs(temp1.x2./temp2.x2-1)))>5e-3
103 max(max(abs(temp1.x2./temp2.x2-1)))
104 temp1.x2
105 temp2.x2
106 error('Draws of unaffected chain are not the same')
107 end
108
109 if max(max(abs(temp1.feval_this_chain-temp2.feval_this_chain)))>1e-6
110 temp1.feval_this_chain
111 temp2.feval_this_chain
112 error('feval_this_chain are not the same')
113 end
114
115 if max(max(abs(temp1.logpo2-temp2.logpo2)))>1e-3
116 temp1.logpo2
117 temp2.logpo2
118 error('logpo2 is not the same')
119 end
120
121 if max(max(abs(temp1.accepted_draws_this_file-temp2.accepted_draws_this_file)))>1e-6
122 temp1.accepted_draws_this_file
123 temp2.accepted_draws_this_file
124 error('accepted_draws_this_file are not the same')
125 end
126
127 if max(max(abs(temp1.accepted_draws_this_chain-temp2.accepted_draws_this_chain)))>1e-6
128 temp1.accepted_draws_this_chain
129 temp2.accepted_draws_this_chain
130 error('accepted_draws_this_chain are not the same')
131 end
132 end