Debian Codegraph @

tests/estimation/method_of_moments/CET/cet_interface.mod

raw
1 % -------------------------------------------------------------------------
2 % Functionality testing of interface for IRF matching
3 % -------------------------------------------------------------------------
4
5 % Copyright © 2023 Dynare Team
6 %
7 % This file is part of Dynare.
8 %
9 % Dynare is free software: you can redistribute it and/or modify
10 % it under the terms of the GNU General Public License as published by
11 % the Free Software Foundation, either version 3 of the License, or
12 % (at your option) any later version.
13 %
14 % Dynare is distributed in the hope that it will be useful,
15 % but WITHOUT ANY WARRANTY; without even the implied warranty of
16 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 % GNU General Public License for more details.
18 %
19 % You should have received a copy of the GNU General Public License
20 % along with Dynare. If not, see <https://www.gnu.org/licenses/>.
21
22 @#include "cet_model.inc"
23 xx = [23,24,25];
24 ww = [51,52];
25
26 matched_irfs(overwrite);
27 var GDPAGG; varexo epsR_eps; periods 5; values 7; weights 25;
28 var GDPAGG; varexo mupsi_eps; periods 1,2; values 17,18; weights 37,38;
29 var RAGG; varexo muz_eps; periods 3:5; values (xx);
30 var ukAGG; varexo mupsi_eps; periods 1:2; values 30; weights (ww);
31
32 varexo epsR_eps;
33 var wAGG;
34 periods 1, 13:15, 2:12;
35 values 2, (xx), 15;
36 weights 3, (xx), 4;
37 end;
38
39 method_of_moments(mom_method = irf_matching
40 , cova_compute=0
41 , irf_matching_file = cet_irf_matching_file
42 , mcmc_jumping_covariance = prior_variance
43 , mh_jscale = 0.5
44 , mh_nblocks = 1
45 , mh_replic=1000
46 , mode_compute = 0
47 , mode_file = cet_original_mode
48 , plot_priors = 0
49 , posterior_sampling_method = 'independent_metropolis_hastings'
50 );
51
52
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 %% CHECKS ON INTERFACE AND TRANSFORMATIONS %%
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 verbatim;
57
58 % check on matched_irfs
59 matched_irfs = [
60 {'GDPAGG'} {'epsR_eps'} {[ {[5] [ 7] [25]} ]};
61 {'GDPAGG'} {'mupsi_eps'} {[ {[1] [17] [37]};
62 {[2] [18] [38]} ]};
63 {'RAGG'} {'muz_eps'} {[ {[3 4 5] [23 24 25] [1]} ]};
64 {'ukAGG'} {'mupsi_eps'} {[ {[1 2] [30] [51 52]} ]};
65 {'wAGG'} {'epsR_eps'} {[ {[1] [2] [3]};
66 {[13:15] [23 24 25] [23 24 25]};
67 {[2:12] [15] [4]}; ]};
68 ];
69 if ~isequal(M_.matched_irfs,matched_irfs)
70 error('Something wrong with the transformation of the matched_irfs block!')
71 else
72 fprintf('matched_irfs transformation was successful!\n\n')
73 end
74
75 % check on data_moments
76 data_moments = [7 2 15 15 15 15 15 15 15 15 15 15 15 23 24 25 23 24 25 17 18 30 30]';
77 if ~isequal(oo_.mom.data_moments,data_moments)
78 error('Something wrong with the creation of data_moments!')
79 else
80 fprintf('creation of data_moments was successful!\n\n')
81 end
82
83 % check on weighting matrix
84 weighting_mat = sparse(size(data_moments,1));
85 weighting_mat(1,1) = 25;
86 weighting_mat(2,2) = 3;
87 weighting_mat(3,3) = 4;
88 weighting_mat(4,4) = 4;
89 weighting_mat(5,5) = 4;
90 weighting_mat(6,6) = 4;
91 weighting_mat(7,7) = 4;
92 weighting_mat(8,8) = 4;
93 weighting_mat(9,9) = 4;
94 weighting_mat(10,10) = 4;
95 weighting_mat(11,11) = 4;
96 weighting_mat(12,12) = 4;
97 weighting_mat(13,13) = 4;
98 weighting_mat(14,14) = 23;
99 weighting_mat(15,15) = 24;
100 weighting_mat(16,16) = 25;
101 weighting_mat(17,17) = 1;
102 weighting_mat(18,18) = 1;
103 weighting_mat(19,19) = 1;
104 weighting_mat(20,20) = 37;
105 weighting_mat(21,21) = 38;
106 weighting_mat(22,22) = 51;
107 weighting_mat(23,23) = 52;
108 if ~isequal(oo_.mom.weighting_info.W,weighting_mat)
109 error('Something wrong with the creation of weighting_info.W!')
110 else
111 fprintf('creation of weighting_info.W was successful!\n\n')
112 end
113
114 end;//verbatim
115
116
117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118 %% SIMPLIFIED EXAMPLE TO TEST INTERFACE ON WEIGHTING MATRIX %%
119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120
121 matched_irfs(overwrite);
122 var GDPAGG; varexo epsR_eps; periods 1 3; values 11 13; weights 111 222;
123 var RAGG; varexo muz_eps; periods 2 4; values 22 24; weights 333 444;
124 end;
125
126 matched_irfs_weights(overwrite);
127 RAGG(2), muz_eps, GDPAGG(1), epsR_eps, 555;
128 GDPAGG(1), epsR_eps, RAGG(4), muz_eps, 666;
129 RAGG(2), muz_eps, GDPAGG(3), epsR_eps, 777;
130 GDPAGG(3), epsR_eps, RAGG(4), muz_eps, 888;
131 GDPAGG(1), epsR_eps, RAGG(1), muz_eps, 999;
132 end;
133
134 verbatim;
135 % check on matched_irfs_weights
136 matched_irfs_weights = [
137 {'GDPAGG'} {[1]} {'epsR_eps'} {'RAGG' } {[1]} {'muz_eps' } {[999]};
138 {'GDPAGG'} {[1]} {'epsR_eps'} {'RAGG' } {[4]} {'muz_eps' } {[666]};
139 {'GDPAGG'} {[3]} {'epsR_eps'} {'RAGG' } {[4]} {'muz_eps' } {[888]};
140 {'RAGG' } {[2]} {'muz_eps' } {'GDPAGG'} {[1]} {'epsR_eps'} {[555]};
141 {'RAGG' } {[2]} {'muz_eps' } {'GDPAGG'} {[3]} {'epsR_eps'} {[777]};
142 ];
143 if ~isequal(M_.matched_irfs_weights,matched_irfs_weights)
144 error('Something wrong with the transformation of the matched_irfs_weights block!')
145 else
146 fprintf('matched_irfs_weights transformation was successful!\n\n')
147 end
148
149 % test transformation function
150 [data_moments, W, irfIndex] = mom.matched_irfs_blocks(M_.matched_irfs, M_.matched_irfs_weights, options_mom_.varobs_id, length(options_mom_.varobs_id), M_.exo_nbr, M_.endo_names, M_.exo_names);
151
152 if ~isequal(data_moments, [11 13 22 24]')
153 error('Something wrong with the creation of data_moments in simple example!');
154 else
155 fprintf('simple example: creation of data_moments was successful!\n\n');
156 end
157
158 if ~isequal(irfIndex, [1 3 58 60]')
159 error('Something wrong with the creation of irfIndex in simple example!');
160 else
161 fprintf('simple example: creation of irfIndex was successful!\n\n')
162 end
163
164 W0 = eye(4);
165 W0(1,1) = 111; % (GDPAGG(1) epsR_eps) x (GDPAGG(1) epsR_eps)
166 W0(2,2) = 222; % (GDPAGG(3) epsR_eps) x (GDPAGG(3) epsR_eps)
167 W0(3,3) = 333; % (RAGG(2) muz_eps) x (RAGG(2) muz_eps)
168 W0(4,4) = 444; % (RAGG(4) muz_eps) x (RAGG(4) muz_eps)
169 W0(1,3) = 555; % (GDPAGG(1) epsR_eps) x (RAGG(2) muz_eps)
170 W0(3,1) = 555; % (RAGG(2) muz_eps) x (GDPAGG(1) epsR_eps)
171 W0(1,4) = 666; % (GDPAGG(1) epsR_eps) x (RAGG(4) muz_eps)
172 W0(4,1) = 666; % (RAGG(4) muz_eps) x (GDPAGG(1) epsR_eps)
173 W0(2,3) = 777; % (GDPAGG(3) epsR_eps) x (RAGG(2) muz_eps)
174 W0(3,2) = 777; % (RAGG(2) muz_eps) x (GDPAGG(3) epsR_eps)
175 W0(2,4) = 888; % (GDPAGG(3) epsR_eps) x (RAGG(4) muz_eps)
176 W0(4,2) = 888; % (RAGG(4) muz_eps) x (GDPAGG(3) epsR_eps)
177
178 if ~isequal(W, W0)
179 error('Something wrong with the creation of W in simple example!')
180 else
181 fprintf('simple example: creation of W was successful!\n\n')
182 end
183 end;