Skip to content
Snippets Groups Projects
Commit c3a9f0b9 authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Added new routine to compute the max. abs. error associated to a path (perfect...

Added new routine to compute the max. abs. error associated to a path (perfect foresight models). Use this routine to compute (and report) the true max. abs. error when sim1 (stack_algo==0) is used with option endogenous_terminal_period.
parent 3fbeba66
No related branches found
No related tags found
No related merge requests found
function err = evaluate_max_dynamic_residual(model_dynamic, Y, exogenous_variables, params, steady_state, periods, ny, max_lag, lead_lag_incidence)
% Copyright (C) 2013 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 <http://www.gnu.org/licenses/>.
i_rows = 1:ny;
i_cols = find(lead_lag_incidence');
err = 0;
for it = (max_lag+1):(max_lag+periods)
d = model_dynamic(Y(i_cols), exogenous_variables, params, steady_state, it);
i_rows = i_rows + ny;
i_cols = i_cols + ny;
r = max(abs(d));
if r>err
err = r;
end
end
\ No newline at end of file
......@@ -72,6 +72,7 @@ i_upd = ny+(1:periods*ny);
Y = endo_simul(:);
skipline()
disp (['-----------------------------------------------------']) ;
fprintf('MODEL SIMULATION:\n');
......@@ -146,6 +147,10 @@ for iter = 1:options_.simul.maxit
end
if endogenous_terminal_period
err = evaluate_max_dynamic_residual(model_dynamic, Y, oo_.exo_simul, params, steady_state, periods, ny, max_lag, lead_lag_incidence);
end
if stop
if any(isnan(res)) || any(isinf(res)) || any(isnan(Y)) || any(isinf(Y))
......@@ -156,13 +161,14 @@ if stop
oo_.endo_simul = reshape(Y,ny,periods+2);
skipline();
fprintf('\nSimulation terminated after %d iterations.\n',iter);
fprintf('Total time of simulation : %10.3f\n',etime(clock,h1));
fprintf('Total time of simulation: %16.13f\n',etime(clock,h1));
error('Simulation terminated with NaN or Inf in the residuals or endogenous variables. There is most likely something wrong with your model.');
else
skipline();
fprintf('\nSimulation concluded successfully after %d iterations.\n',iter);
fprintf('Total time of simulation : %10.3f\n',etime(clock,h1));
fprintf('Convergency obtained.\n');
fprintf('Total time of simulation: %16.13f\n',etime(clock,h1));
fprintf('Max. Abs. Error : %16.13f\n',err);
fprintf('Convergency obtained!\n');
oo_.deterministic_simulation.status = 1;% Convergency obtained.
oo_.deterministic_simulation.error = err;
oo_.deterministic_simulation.iterations = iter;
......@@ -172,12 +178,12 @@ if stop
elseif ~stop
skipline();
fprintf('\nSimulation terminated after %d iterations.\n',iter);
fprintf('Total time of simulation : %10.3f\n',etime(clock,h1));
fprintf('Total time of simulation: %16.13f\n',etime(clock,h1));
fprintf('Max. Abs. Error : %16.13f\n',err);
fprintf('WARNING : maximum number of iterations is reached (modify options_.simul.maxit).\n') ;
oo_.deterministic_simulation.status = 0;% more iterations are needed.
oo_.deterministic_simulation.error = err;
oo_.deterministic_simulation.periods = vperiods(1:iter);
%oo_.deterministic_simulation.errors = c/abs(err)
oo_.deterministic_simulation.iterations = options_.simul.maxit;
end
disp (['-----------------------------------------------------']) ;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment