| 1 |
% Test optimizers |
| 2 |
% |
| 3 |
% Copyright © 2020-2021 Dynare Team |
| 4 |
% |
| 5 |
% This file is part of Dynare. |
| 6 |
% |
| 7 |
% Dynare is free software: you can redistribute it and/or modify |
| 8 |
% it under the terms of the GNU General Public License as published by |
| 9 |
% the Free Software Foundation, either version 3 of the License, or |
| 10 |
% (at your option) any later version. |
| 11 |
% |
| 12 |
% Dynare is distributed in the hope that it will be useful, |
| 13 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
% GNU General Public License for more details. |
| 16 |
% |
| 17 |
% You should have received a copy of the GNU General Public License |
| 18 |
% along with Dynare. If not, see <https://www.gnu.org/licenses/>. |
| 19 |
% ========================================================================= |
| 20 |
% TO DO |
| 21 |
% [ ] fix optimizers 11 and 12; |
| 22 |
% note that 12 and 102 require GADS_Toolbox which is not available on servers, but need to be tested locally |
| 23 |
|
| 24 |
% Define testscenario |
| 25 |
@#define orderApp = 2 |
| 26 |
|
| 27 |
% Note that we will set the numerical optimization tolerance levels very large to speed up the testsuite |
| 28 |
|
| 29 |
@#include "RBC_MoM_common.inc" |
| 30 |
|
| 31 |
shocks; |
| 32 |
var u_a; stderr 0.0072; |
| 33 |
end; |
| 34 |
|
| 35 |
varobs c iv n; |
| 36 |
|
| 37 |
%-------------------------------------------------------------------------- |
| 38 |
% Method of Moments Estimation |
| 39 |
%-------------------------------------------------------------------------- |
| 40 |
matched_moments; |
| 41 |
c; |
| 42 |
n; |
| 43 |
iv; |
| 44 |
c*c; |
| 45 |
c*iv; |
| 46 |
iv*n; |
| 47 |
iv*iv; |
| 48 |
n*c; |
| 49 |
n*n; |
| 50 |
c*c(-1); |
| 51 |
n*n(-1); |
| 52 |
iv*iv(-1); |
| 53 |
end; |
| 54 |
|
| 55 |
% reduce options to speed up testsuite |
| 56 |
options_.newrat.maxiter = 10; |
| 57 |
options_.newrat.tolerance.f = 1e-2; |
| 58 |
options_.newrat.tolerance.f_analytic = 1e-2; |
| 59 |
|
| 60 |
options_.mh_jscale = 0.6; |
| 61 |
options_.gmhmaxlik.iterations=1; |
| 62 |
options_.gmhmaxlik.number=2000; |
| 63 |
options_.gmhmaxlik.nclimb=2000; |
| 64 |
options_.gmhmaxlik.nscale=2000; |
| 65 |
options_.gmhmaxlik.target=0.5; |
| 66 |
|
| 67 |
options_.solveopt.MaxIter=300; |
| 68 |
options_.solveopt.LBGradientStep=1e-3; |
| 69 |
options_.solveopt.TolFun = 1e-3; |
| 70 |
options_.solveopt.TolX = 1e-3; |
| 71 |
options_.solveopt.TolXConstraint=1e-3; |
| 72 |
|
| 73 |
|
| 74 |
@#for estimParams in [0, 1, 2] |
| 75 |
@#if estimParams == 0 |
| 76 |
estimated_params(overwrite); |
| 77 |
%DELTA, 0.025; |
| 78 |
%BETTA, 0.984; |
| 79 |
%B, 0.5; |
| 80 |
%ETAc, 2; |
| 81 |
ALFA, 0.667; |
| 82 |
RHOA, 0.979; |
| 83 |
stderr u_a, 0.0072; |
| 84 |
end; |
| 85 |
@#define OPTIMIZERS = [1, 2, 3, 4, 5, 7, 8, 9, 10, 13, 101] |
| 86 |
@#endif |
| 87 |
|
| 88 |
@#if estimParams == 1 |
| 89 |
estimated_params(overwrite); |
| 90 |
%DELTA, , 0, 1; |
| 91 |
%BETTA, , 0, 1; |
| 92 |
%B, , 0, 1; |
| 93 |
%ETAc, , 0, 10; |
| 94 |
ALFA, , 0, 1; |
| 95 |
RHOA, , 0, 1; |
| 96 |
stderr u_a, , 0, 1; |
| 97 |
end; |
| 98 |
@#define OPTIMIZERS = [1, 2, 3, 4, 7, 8, 9, 10, 13, 101] |
| 99 |
@#endif |
| 100 |
|
| 101 |
@#if estimParams == 2 |
| 102 |
estimated_params(overwrite); |
| 103 |
%DELTA, 0.025, 0, 1, normal_pdf, 0.02, 0.5; |
| 104 |
%BETTA, 0.98, 0, 1, beta_pdf, 0.90, 0.25; |
| 105 |
%B, 0.45, 0, 1, normal_pdf, 0.40, 0.5; |
| 106 |
%ETAl, 1, 0, 10, normal_pdf, 0.25, 0.0.1; |
| 107 |
%ETAc, 1.8, 0, 10, normal_pdf, 1.80, 0.5; |
| 108 |
ALFA, 0.65, 0, 1, normal_pdf, 0.60, 0.5; |
| 109 |
RHOA, 0.95, 0, 1, normal_pdf, 0.90, 0.5; |
| 110 |
stderr u_a, 0.01, 0, 1, normal_pdf, 0.01, 0.5; |
| 111 |
%THETA, 3.48, 0, 10, normal_pdf, 0.25, 0.0.1; |
| 112 |
end; |
| 113 |
@#define OPTIMIZERS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 101] |
| 114 |
@#endif |
| 115 |
|
| 116 |
estimated_params_init(use_calibration); |
| 117 |
end; |
| 118 |
|
| 119 |
@#for optimizer in OPTIMIZERS |
| 120 |
|
| 121 |
@#if estimParams == 2 && optimizer == 13 |
| 122 |
%skip due to buggy behavior in Octave |
| 123 |
if ~isoctave |
| 124 |
@#endif |
| 125 |
|
| 126 |
method_of_moments( |
| 127 |
mom_method = GMM % method of moments method; possible values: GMM|SMM |
| 128 |
, datafile = 'RBC_Andreasen_Data_2.mat' % name of filename with data |
| 129 |
, order = @{orderApp} % order of Taylor approximation in perturbation |
| 130 |
, weighting_matrix = ['OPTIMAL'] % weighting matrix in moments distance objective function; possible values: OPTIMAL|IDENTITY_MATRIX|DIAGONAL|filename. Size of cell determines stages in iterated estimation, e.g. two state with ['DIAGONAL','OPTIMAL'] |
| 131 |
, nograph % do not create graphs (which implies that they are not saved to the disk nor displayed) |
| 132 |
, mode_compute = @{optimizer} % specifies the optimizer for minimization of moments distance |
| 133 |
@#if optimizer == 102 |
| 134 |
, optim = ('TolFun' , 1D-3 % termination tolerance on the function value, a positive scalar |
| 135 |
,'MaxIter' , 300 % maximum number of iterations allowed, a positive integer |
| 136 |
,'MaxFunEvals' , 1D3 % maximum number of function evaluations allowed, a positive integer |
| 137 |
) |
| 138 |
@#else |
| 139 |
, optim = ('TolFun' , 1D-3 % termination tolerance on the function value, a positive scalar |
| 140 |
,'TolX' , 1e-3 % termination tolerance on x, a positive scalar |
| 141 |
,'MaxIter' , 300 % maximum number of iterations allowed, a positive integer |
| 142 |
,'MaxFunEvals' , 1D3 % maximum number of function evaluations allowed, a positive integer |
| 143 |
) |
| 144 |
@#endif |
| 145 |
, silent_optimizer % run minimization of moments distance silently without displaying results or saving files in between |
| 146 |
); |
| 147 |
|
| 148 |
@#if estimParams == 2 && optimizer == 13 |
| 149 |
%skip due to buggy behavior in Octave |
| 150 |
end |
| 151 |
@#endif |
| 152 |
@#endfor |
| 153 |
@#endfor |
| 154 |
|
| 155 |
|
| 156 |
|