1function optimize_prior(DynareOptions, ModelInfo, DynareResults, BayesInfo, EstimationInfo) 2 3% This routine computes the mode of the prior density using an optimization algorithm. 4 5% Copyright (C) 2015-2017 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 <http://www.gnu.org/licenses/>. 21 22% Initialize to the prior mean 23DynareResults.dr = set_state_space(DynareResults.dr,ModelInfo,DynareOptions); 24xparam1 = BayesInfo.p1; 25 26% Pertubation of the initial condition. 27look_for_admissible_initial_condition = 1; scale = 1.0; iter = 0; 28while look_for_admissible_initial_condition 29 xinit = xparam1+scale*randn(size(xparam1)); 30 if all(xinit(:)>BayesInfo.p3) && all(xinit(:)<BayesInfo.p4) 31 ModelInfo = set_all_parameters(xinit,EstimationInfo,ModelInfo); 32 [dr,INFO,ModelInfo,DynareOptions,DynareResults] = resol(0,ModelInfo,DynareOptions,DynareResults); 33 if ~INFO(1) 34 look_for_admissible_initial_condition = 0; 35 end 36 else 37 if iter == 2000 38 scale = scale/1.1; 39 iter = 0; 40 else 41 iter = iter+1; 42 end 43 end 44end 45 46% Maximization of the prior density 47[xparams, lpd, hessian_mat] = ... 48 maximize_prior_density(xinit, BayesInfo.pshape, ... 49 BayesInfo.p6, ... 50 BayesInfo.p7, ... 51 BayesInfo.p3, ... 52 BayesInfo.p4,DynareOptions,ModelInfo,BayesInfo,EstimationInfo,DynareResults); 53 54% Display the results. 55skipline(2) 56disp('------------------') 57disp('PRIOR OPTIMIZATION') 58disp('------------------') 59skipline() 60for i = 1:length(xparams) 61 disp(['deep parameter ' int2str(i) ': ' get_the_name(i,0,ModelInfo,EstimationInfo,DynareOptions) '.']) 62 disp([' Initial condition ....... ' num2str(xinit(i)) '.']) 63 disp([' Prior mode .............. ' num2str(BayesInfo.p5(i)) '.']) 64 disp([' Optimized prior mode .... ' num2str(xparams(i)) '.']) 65 skipline() 66end 67skipline()