From a36cf301183c85b74438ba8c5cd8442024ea138d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= <stephane.adjemian@univ-lemans.fr> Date: Mon, 12 Dec 2011 11:34:27 +0100 Subject: [PATCH] Make options_.dynatol specific to x/f by adding dynatol.x and dynatol.f. By default dynatol.x=dynatol.f= old default value of dynatol. --- matlab/ep/extended_path.m | 4 ++-- matlab/ep/homotopic_steps.m | 4 ++-- matlab/evaluate_steady_state.m | 2 +- matlab/global_initialization.m | 3 ++- matlab/model_diagnostics.m | 2 +- matlab/partial_information/PCL_resol.m | 2 +- matlab/perfect_foresight_simulation.m | 2 +- matlab/resid.m | 2 +- matlab/sim1.m | 2 +- matlab/simk.m | 2 +- mex/sources/bytecode/bytecode.cc | 3 ++- mex/sources/bytecode/testing/simulate_debug.m | 2 +- tests/block_bytecode/ireland.mod | 4 ++-- tests/run_test_matlab.m | 4 ++-- tests/run_test_octave.m | 4 ++-- 15 files changed, 22 insertions(+), 20 deletions(-) diff --git a/matlab/ep/extended_path.m b/matlab/ep/extended_path.m index f85dd4c148..1cab219ab7 100644 --- a/matlab/ep/extended_path.m +++ b/matlab/ep/extended_path.m @@ -152,7 +152,7 @@ while (t<sample_size) end end % Test if periods is big enough. - if ~increase_periods && max(max(abs(tmp(idx,end-options_.ep.lp:end)./tmp(idx,end-options_.ep.lp-1:end-1)-1)))<options_.dynatol + if ~increase_periods && max(max(abs(tmp(idx,end-options_.ep.lp:end)./tmp(idx,end-options_.ep.lp-1:end-1)-1)))<options_.dynatol.x break else options_.periods = options_.periods + options_.ep.step; @@ -183,7 +183,7 @@ while (t<sample_size) info.time = info.time+ctime; if info.convergence maxdiff = max(max(abs(tmp(:,2:options_.ep.fp)-tmp_old(:,2:options_.ep.fp)))); - if maxdiff<options_.dynatol + if maxdiff<options_.dynatol.x options_.periods = options_.ep.periods; options_.minimal_solving_period = options_.periods; oo_.exo_simul = oo_.exo_simul(1:(options_.periods+2),:); diff --git a/matlab/ep/homotopic_steps.m b/matlab/ep/homotopic_steps.m index c36dc73047..814f01ffa5 100644 --- a/matlab/ep/homotopic_steps.m +++ b/matlab/ep/homotopic_steps.m @@ -64,7 +64,7 @@ if homotopy_1 weight = weight-step_length; step_length=step_length/10; weight = weight+step_length; - if 10*step_length<options_.dynatol + if 10*step_length<options_.dynatol.x homotopy_1 = 0; homotopy_2 = 0; break @@ -153,7 +153,7 @@ if homotopy_2 disp('I am reducing the step length!') end step_length=step_length/10; - if 10*step_length<options_.dynatol + if 10*step_length<options_.dynatol.x homotopy_1 = 0; homotopy_2 = 0; break diff --git a/matlab/evaluate_steady_state.m b/matlab/evaluate_steady_state.m index 0035f438db..2eb829a464 100644 --- a/matlab/evaluate_steady_state.m +++ b/matlab/evaluate_steady_state.m @@ -74,7 +74,7 @@ function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadysta info(2) = check; % to be improved return; end - if max(abs(residuals)) > options.dynatol + if max(abs(residuals)) > options.dynatol.f info(1) = 19; info(2) = residuals'*residuals; return diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index eda5909fb1..460a25710f 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -38,7 +38,8 @@ options_.console_mode = 0; options_.terminal_condition = 0; options_.rplottype = 0; options_.smpl = 0; -options_.dynatol = 0.00001; +options_.dynatol.f = 1e-5; +options_.dynatol.x = 1e-5; options_.maxit_ = 10; options_.slowc = 1; options_.timing = 0; diff --git a/matlab/model_diagnostics.m b/matlab/model_diagnostics.m index bb58d7cdeb..6fd14494fc 100644 --- a/matlab/model_diagnostics.m +++ b/matlab/model_diagnostics.m @@ -98,7 +98,7 @@ else if options_.linear == 0 % nonlinear models if max(abs(feval(fh,dr.ys,[oo_.exo_steady_state; ... - oo_.exo_det_steady_state], M_.params))) > options_.dynatol + oo_.exo_det_steady_state], M_.params))) > options_.dynatol.f [ys,check1] = dynare_solve(fh,dr.ys,1,... [oo_.exo_steady_state; ... oo_.exo_det_steady_state], ... diff --git a/matlab/partial_information/PCL_resol.m b/matlab/partial_information/PCL_resol.m index 4c3ac93b14..96028e2ea8 100644 --- a/matlab/partial_information/PCL_resol.m +++ b/matlab/partial_information/PCL_resol.m @@ -89,7 +89,7 @@ else if options_.linear == 0 % nonlinear models if max(abs(feval(fh,dr.ys,[oo_.exo_steady_state; ... - oo_.exo_det_steady_state], M_.params))) > options_.dynatol + oo_.exo_det_steady_state], M_.params))) > options_.dynatol.f [dr.ys,check1] = dynare_solve(fh,dr.ys,options_.jacobian_flag,... [oo_.exo_steady_state; ... oo_.exo_det_steady_state], M_.params); diff --git a/matlab/perfect_foresight_simulation.m b/matlab/perfect_foresight_simulation.m index 2b2b4c4a3e..2e95573aca 100644 --- a/matlab/perfect_foresight_simulation.m +++ b/matlab/perfect_foresight_simulation.m @@ -159,7 +159,7 @@ for iter = 1:options_.maxit_ last_line = iter; break end - if err < options_.dynatol + if err < options_.dynatol.f stop = 1; info.time = etime(clock,h1); info.error = err; diff --git a/matlab/resid.m b/matlab/resid.m index 91273bb838..75148e3586 100644 --- a/matlab/resid.m +++ b/matlab/resid.m @@ -101,7 +101,7 @@ if nargout == 0 disp('Residuals of the static equations:') disp(' ') for i=1:M_.orig_endo_nbr - if abs(z(i)) < options_.dynatol/100 + if abs(z(i)) < options_.dynatol.f/100 tmp = 0; else tmp = z(i); diff --git a/matlab/sim1.m b/matlab/sim1.m index c18b9acc81..b8e27bc4ed 100644 --- a/matlab/sim1.m +++ b/matlab/sim1.m @@ -102,7 +102,7 @@ for iter = 1:options_.maxit_ disp([num2str(iter) ' - err = ' num2str(err)]) ; disp([' Time of iteration :' num2str(etime(clock,h2))]) ; - if err < options_.dynatol + if err < options_.dynatol.f stop = 1 ; fprintf('\n') ; disp([' Total time of simulation :' num2str(etime(clock,h1))]) ; diff --git a/matlab/simk.m b/matlab/simk.m index b890e88025..d800016946 100644 --- a/matlab/simk.m +++ b/matlab/simk.m @@ -318,7 +318,7 @@ for iter = 1:options_.maxit_ if options_.timing disp ([' Back substitution : ' num2str(hbacsup)]) ; end - if err < options_.dynatol + if err < options_.dynatol.f h1 = etime(clock,h1) ; fprintf ('\n') ; disp ([' Total time of simulation : ' num2str(h1)]) ; diff --git a/mex/sources/bytecode/bytecode.cc b/mex/sources/bytecode/bytecode.cc index 6f240dd555..a022d7d0b4 100644 --- a/mex/sources/bytecode/bytecode.cc +++ b/mex/sources/bytecode/bytecode.cc @@ -302,7 +302,8 @@ main(int nrhs, const char *prhs[]) else { solve_algo = stack_solve_algo; - solve_tolf = *(mxGetPr(mxGetFieldByNumber(options_, 0, mxGetFieldNumber(options_, "dynatol")))); + mxArray *dynatol = mxGetFieldByNumber(options_, 0, mxGetFieldNumber(options_, "dynatol")); + solve_tolf= *mxGetPr((mxGetFieldByNumber(dynatol, 0, mxGetFieldNumber(dynatol, "f")))); } mxArray *mxa = mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "fname")); diff --git a/mex/sources/bytecode/testing/simulate_debug.m b/mex/sources/bytecode/testing/simulate_debug.m index a220b484f2..396a558e05 100644 --- a/mex/sources/bytecode/testing/simulate_debug.m +++ b/mex/sources/bytecode/testing/simulate_debug.m @@ -7,7 +7,7 @@ end; fprintf(fid,'%d\n',options_.maxit_); fprintf(fid,'%6.20f\n',options_.slowc); fprintf(fid,'%6.20f\n',options_.markowitz); -fprintf(fid,'%6.20f\n',options_.dynatol); +fprintf(fid,'%6.20f\n',options_.dynatol.f); fprintf(fid,'%d\n',options_.minimal_solving_periods); fclose(fid); diff --git a/tests/block_bytecode/ireland.mod b/tests/block_bytecode/ireland.mod index 3c81fdab37..b36f2452cc 100644 --- a/tests/block_bytecode/ireland.mod +++ b/tests/block_bytecode/ireland.mod @@ -59,12 +59,12 @@ k=k+0.000001; end; -options_.dynatol=1e-12; +options_.dynatol.f=1e-12; options_.maxit_=5; options_.slowc=1; steady(solve_algo=2); -options_.dynatol=4e-5; +options_.dynatol.f=4e-5; shocks; var e; diff --git a/tests/run_test_matlab.m b/tests/run_test_matlab.m index 116a4cdaf6..48cd788f02 100644 --- a/tests/run_test_matlab.m +++ b/tests/run_test_matlab.m @@ -119,7 +119,7 @@ for blockFlag = 0:1 % Test against the reference simulation path load('test.mat','y_ref'); diff = oo_.endo_simul - y_ref; - if(abs(diff) > options_.dynatol) + if(abs(diff) > options_.dynatol.x) failedBlock{size(failedBlock,2)+1} = ['block_bytecode/run_ls2003.m(' num2str(blockFlag) ', ' num2str(bytecodeFlag) ', ' num2str(solve_algos(i)) ', ' num2str(default_stack_solve_algo) ')']; exception = MException('ERROR: simulation path differs from the reference path'); printMakeCheckMatlabErrMsg(['block_bytecode/run_ls2003.m(' num2str(blockFlag) ', ' num2str(bytecodeFlag) ', ' num2str(solve_algos(i)) ', ' num2str(default_stack_solve_algo) ')'], exception); @@ -145,7 +145,7 @@ for blockFlag = 0:1 % Test against the reference simulation path load('test.mat','y_ref'); diff = oo_.endo_simul - y_ref; - if(abs(diff) > options_.dynatol) + if(abs(diff) > options_.dynatol.x) failedBlock{size(failedBlock,2)+1} = ['block_bytecode/run_ls2003.m(' num2str(blockFlag) ', ' num2str(bytecodeFlag) ', ' num2str(default_solve_algo) ', ' num2str(stack_solve_algos(i)) ')']; exception = MException('ERROR: simulation path difers from the reference path'); printMakeCheckMatlabErrMsg(['block_bytecode/run_ls2003.m(' num2str(blockFlag) ', ' num2str(bytecodeFlag) ', ' num2str(default_solve_algo) ', ' num2str(stack_solve_algos(i)) ')'], exception); diff --git a/tests/run_test_octave.m b/tests/run_test_octave.m index 2574cc90c1..082edf664e 100644 --- a/tests/run_test_octave.m +++ b/tests/run_test_octave.m @@ -113,7 +113,7 @@ for blockFlag = 0:1 ## Test against the reference simulation path load('test.mat','y_ref'); diff = oo_.endo_simul - y_ref; - if(abs(diff) > options_.dynatol) + if(abs(diff) > options_.dynatol.x) failedBlock{size(failedBlock,2)+1} = ['block_bytecode/run_ls2003.m(' num2str(blockFlag) ', ' num2str(bytecodeFlag) ', ' num2str(solve_algos(i)) ', ' num2str(default_stack_solve_algo) ')']; differr.message = ["ERROR: simulation path differs from the reference path" ]; printMakeCheckOctaveErrMsg(['block_bytecode/run_ls2003.m(' num2str(blockFlag) ', ' num2str(bytecodeFlag) ', ' num2str(solve_algos(i)) ', ' num2str(default_stack_solve_algo) ')'], differr); @@ -137,7 +137,7 @@ for blockFlag = 0:1 ## Test against the reference simulation path load('test.mat','y_ref'); diff = oo_.endo_simul - y_ref; - if(abs(diff) > options_.dynatol) + if(abs(diff) > options_.dynatol.x) failedBlock{size(failedBlock,2)+1} = ['block_bytecode/run_ls2003.m(' num2str(blockFlag) ', ' num2str(bytecodeFlag) ', ' num2str(default_solve_algo) ', ' num2str(stack_solve_algos(i)) ')']; differr.message = ["ERROR: simulation path differs from the reference path" ]; printMakeCheckOctaveErrMsg(['block_bytecode/run_ls2003.m(' num2str(blockFlag) ', ' num2str(bytecodeFlag) ', ' num2str(default_solve_algo) ', ' num2str(stack_solve_algos(i)) ')'], differr); -- GitLab