From d331cf5a7a59ece00ab23bb2048c4e7c04fea643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Hermes=29?= Date: Sat, 5 Mar 2016 15:55:22 +0100 Subject: [PATCH] Fixed extended path. - Removed call to make_ex_, - Fill oo_.exo_simul in extended path routine, - Do not update oo_.exo_simul after the call to the extended path routine, - Cosmetic change. (cherry picked from commit 4791649524cc7876fc25d04a925f58a546a3a67d) --- matlab/ep/extended_path.m | 81 ++----------------------------- matlab/ep/extended_path_core.m | 88 ++++++++++++++++++++++++++++++++++ preprocessor/ComputingTasks.cc | 3 +- 3 files changed, 93 insertions(+), 79 deletions(-) create mode 100644 matlab/ep/extended_path_core.m diff --git a/matlab/ep/extended_path.m b/matlab/ep/extended_path.m index 3fc811add..d43766321 100644 --- a/matlab/ep/extended_path.m +++ b/matlab/ep/extended_path.m @@ -138,7 +138,6 @@ switch ep.innovation_distribution error(['extended_path:: ' ep.innovation_distribution ' distribution for the structural innovations is not (yet) implemented!']) end - % Set waitbar (graphic or text mode) hh = dyn_waitbar(0,'Please wait. Extended Path simulations...'); set(hh,'Name','EP simulations.'); @@ -182,6 +181,8 @@ oo_.ep.failures.periods = []; oo_.ep.failures.previous_period = cell(0); oo_.ep.failures.shocks = cell(0); +oo_.exo_simul = shocks; + % Initializes some variables. t = 1; tsimul = 1; @@ -189,7 +190,7 @@ for k = 1:replic_nbr results{k} = zeros(endo_nbr,sample_size+1); results{k}(:,1) = initial_conditions; end -make_ex_; +%make_ex_; exo_simul_ = zeros(maximum_lag+sample_size+maximum_lead,exo_nbr); exo_simul_(1:size(oo_.exo_simul,1),1:size(oo_.exo_simul,2)) = oo_.exo_simul; % Main loop. @@ -265,78 +266,4 @@ else end end - assignin('base', 'Simulated_time_series', ts); - - -function [y, info_convergence] = extended_path_core(periods,endo_nbr,exo_nbr,positive_var_indx, ... - exo_simul,init,initial_conditions,... - maximum_lag,maximum_lead,steady_state, ... - verbosity,bytecode_flag,order,M,pfm,algo,solve_algo,stack_solve_algo,... - olmmcp,options,oo) - -ep = options.ep; -if init% Compute first order solution (Perturbation)... - endo_simul = simult_(initial_conditions,oo.dr,exo_simul(2:end,:),1); -else - endo_simul = [initial_conditions repmat(steady_state,1,periods+1)]; -end -oo.endo_simul = endo_simul; -oo_.endo_simul = endo_simul; -% Solve a perfect foresight model. -% Keep a copy of endo_simul_1 -if verbosity - save ep_test_1 endo_simul exo_simul -end -if bytecode_flag && ~ep.stochastic.order - [flag,tmp] = bytecode('dynamic',endo_simul,exo_simul, M_.params, endo_simul, periods); -else - flag = 1; -end -if flag - if order == 0 - options.periods = periods; - options.block = pfm.block; - oo.endo_simul = endo_simul; - oo.exo_simul = exo_simul; - oo.steady_state = steady_state; - options.bytecode = bytecode_flag; - options.lmmcp = olmmcp; - options.solve_algo = solve_algo; - options.stack_solve_algo = stack_solve_algo; - [tmp,flag] = perfect_foresight_solver_core(M,options,oo); - if ~flag && ~options.no_homotopy - exo_orig = oo.exo_simul; - endo_simul = repmat(steady_state,1,periods+1); - for i = 1:10 - weight = i/10; - oo.endo_simul = [weight*initial_conditions + (1-weight)*steady_state ... - endo_simul]; - oo.exo_simul = repmat((1-weight)*oo.exo_steady_state', ... - size(oo.exo_simul,1),1) + weight*exo_orig; - [tmp,flag] = perfect_foresight_solver_core(M,options,oo); - disp([i,flag]) - if ~flag - break - end - endo_simul = tmp.endo_simul; - end - end - info_convergence = flag; - else - switch(algo) - case 0 - [flag,endo_simul] = ... - solve_stochastic_perfect_foresight_model(endo_simul,exo_simul,pfm,ep.stochastic.quadrature.nodes,ep.stochastic.order); - case 1 - [flag,endo_simul] = ... - solve_stochastic_perfect_foresight_model_1(endo_simul,exo_simul,options_,pfm,ep.stochastic.order); - end - tmp.endo_simul = endo_simul; - info_convergence = ~flag; - end -end -if info_convergence - y = tmp.endo_simul(:,2); -else - y = NaN(size(endo_nbr,1)); -end + assignin('base', 'Simulated_time_series', ts); \ No newline at end of file diff --git a/matlab/ep/extended_path_core.m b/matlab/ep/extended_path_core.m new file mode 100644 index 000000000..b3c83b486 --- /dev/null +++ b/matlab/ep/extended_path_core.m @@ -0,0 +1,88 @@ +function [y, info_convergence] = extended_path_core(periods,endo_nbr,exo_nbr,positive_var_indx, ... + exo_simul,init,initial_conditions,... + maximum_lag,maximum_lead,steady_state, ... + verbosity,bytecode_flag,order,M,pfm,algo,solve_algo,stack_solve_algo,... + olmmcp,options,oo) + +% Copyright (C) 2016 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see . + +ep = options.ep; +if init% Compute first order solution (Perturbation)... + endo_simul = simult_(initial_conditions,oo.dr,exo_simul(2:end,:),1); +else + endo_simul = [initial_conditions repmat(steady_state,1,periods+1)]; +end +oo.endo_simul = endo_simul; +% Solve a perfect foresight model. +% Keep a copy of endo_simul_1 +if verbosity + save ep_test_1 endo_simul exo_simul +end +if bytecode_flag && ~ep.stochastic.order + [flag,tmp] = bytecode('dynamic',endo_simul,exo_simul, M_.params, endo_simul, periods); +else + flag = 1; +end +if flag + if order == 0 + options.periods = periods; + options.block = pfm.block; + oo.endo_simul = endo_simul; + oo.exo_simul = exo_simul; + oo.steady_state = steady_state; + options.bytecode = bytecode_flag; + options.lmmcp = olmmcp; + options.solve_algo = solve_algo; + options.stack_solve_algo = stack_solve_algo; + [tmp,flag] = perfect_foresight_solver_core(M,options,oo); + if ~flag && ~options.no_homotopy + exo_orig = oo.exo_simul; + endo_simul = repmat(steady_state,1,periods+1); + for i = 1:10 + weight = i/10; + oo.endo_simul = [weight*initial_conditions + (1-weight)*steady_state ... + endo_simul]; + oo.exo_simul = repmat((1-weight)*oo.exo_steady_state', ... + size(oo.exo_simul,1),1) + weight*exo_orig; + [tmp,flag] = perfect_foresight_solver_core(M,options,oo); + disp([i,flag]) + if ~flag + break + end + endo_simul = tmp.endo_simul; + end + end + info_convergence = flag; + else + switch(algo) + case 0 + [flag,endo_simul] = ... + solve_stochastic_perfect_foresight_model(endo_simul,exo_simul,pfm,ep.stochastic.quadrature.nodes,ep.stochastic.order); + case 1 + [flag,endo_simul] = ... + solve_stochastic_perfect_foresight_model_1(endo_simul,exo_simul,options_,pfm,ep.stochastic.order); + end + tmp.endo_simul = endo_simul; + info_convergence = ~flag; + end +end +if info_convergence + y = tmp.endo_simul(:,2); +else + y = NaN(size(endo_nbr,1)); +end diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index 5649c67cc..325d6f057 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -3166,8 +3166,7 @@ ExtendedPathStatement::writeOutput(ostream &output, const string &basename, bool output << "options_." << it->first << " = " << it->second << ";" << endl; output << "extended_path([], " << options_list.num_options.find("periods")->second - << ");" << endl - << "oo_.exo_simul = oo_.ep.shocks;" << endl; + << ");" << endl; } ModelDiagnosticsStatement::ModelDiagnosticsStatement()