fixed issues relative to homotopy (type I) when the user wants to

continue after homotopy fails. Option stop_on_error is removed. Option
homotopy_force_continue is added.
time-shift
Michel Juillard 2012-05-17 17:05:50 +02:00
parent 6868e81b16
commit 1316bd9555
5 changed files with 60 additions and 24 deletions

View File

@ -80,7 +80,6 @@ else
end
options_.steadystate_partial = [];
options_.steadystate.nocheck = 0;
options_.steady.stop_on_error = 1;
% subset of the estimated deep parameters
options_.ParamSubSet = 'None';
@ -397,6 +396,7 @@ M_.endo_histval = [];
% homotopy
options_.homotopy_mode = 0;
options_.homotopy_steps = 1;
options_.homotopy_force_continue = 0;
% Simplex optimization routine (variation on Nelder Mead algorithm).
options_.simplex = [];

View File

@ -1,4 +1,4 @@
function homotopy1(values, step_nbr)
function [M,oo,info,last_values,ip,ix,ixd] = homotopy1(values, step_nbr, M, options, oo)
% function homotopy1(values, step_nbr)
%
% Implements homotopy (mode 1) for steady-state computation.
@ -16,9 +16,17 @@ function homotopy1(values, step_nbr)
% Column 3 can contain NaNs, in which case previous
% initialization of variable will be used as initial value.
% step_nbr: number of steps for homotopy
% M struct of model parameters
% options struct of options
% oo struct of outputs
%
% OUTPUTS
% none
% M struct of model parameters
% oo struct of outputs
% last_values last set of values fir which a solution was found
% ip index of parameters
% ix index of exogenous variables
% ixp index of exogenous deterministic variables
%
% SPECIAL REQUIREMENTS
% none
@ -40,8 +48,7 @@ function homotopy1(values, step_nbr)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
global M_ oo_ options_
last_values = [];
nv = size(values, 1);
ip = find(values(:,1) == 4); % Parameters
@ -56,11 +63,11 @@ end
% when initial value has not been given in homotopy_setup block
oldvalues = values(:,3);
ipn = find(values(:,1) == 4 & isnan(oldvalues));
oldvalues(ipn) = M_.params(values(ipn, 2));
oldvalues(ipn) = M.params(values(ipn, 2));
ixn = find(values(:,1) == 1 & isnan(oldvalues));
oldvalues(ixn) = oo_.exo_steady_state(values(ixn, 2));
oldvalues(ixn) = oo.exo_steady_state(values(ixn, 2));
ixdn = find(values(:,1) == 2 & isnan(oldvalues));
oldvalues(ixdn) = oo_.exo_det_steady_state(values(ixdn, 2));
oldvalues(ixdn) = oo.exo_det_steady_state(values(ixdn, 2));
points = zeros(nv, step_nbr+1);
for i = 1:nv
@ -73,16 +80,23 @@ end
for i=1:step_nbr+1
disp([ 'HOMOTOPY mode 1: computing step ' int2str(i-1) '/' int2str(step_nbr) '...' ])
M_.params(values(ip,2)) = points(ip,i);
oo_.exo_steady_state(values(ix,2)) = points(ix,i);
oo_.exo_det_steady_state(values(ixd,2)) = points(ixd,i);
old_params = M.params;
old_exo = oo.exo_steady_state;
old_exo_det = oo.exo_det_steady_state;
M.params(values(ip,2)) = points(ip,i);
oo.exo_steady_state(values(ix,2)) = points(ix,i);
oo.exo_det_steady_state(values(ixd,2)) = points(ixd,i);
[steady_state,M_.params,info] = steady_(M_,options_,oo_);
[steady_state,M.params,info] = steady_(M,options,oo);
if info(1) == 0
% if homotopy step is not successful, current values of steady
% state are not modified
oo_.steady_state = steady_state;
oo.steady_state = steady_state;
else
M.params = old_params;
oo.exo_steady_state = old_exo;
oo.exo_det_steady_state = old_exo_det;
last_values = points(:,i-1);
break
end
end

View File

@ -43,26 +43,48 @@ Sigma_e = M_.Sigma_e;
% Set M_.Sigma_e=0 (we compute the *deterministic* steady state)
M_.Sigma_e = zeros(size(Sigma_e));
info = 0;
switch options_.homotopy_mode
case 1
homotopy1(options_.homotopy_values, options_.homotopy_steps);
[M_,oo_,info,last_values,ip,ix,ixd] = homotopy1(options_.homotopy_values, options_.homotopy_steps,M_,options_,oo_);
case 2
homotopy2(options_.homotopy_values, options_.homotopy_steps);
case 3
homotopy3(options_.homotopy_values, options_.homotopy_steps);
end
if info(1)
hv = options_.homotopy_values;
disp(' ')
disp('WARNING: homotopy step was not comleted')
disp('The last values for which a solution was found are:')
for i=1:length(ip)
disp(sprintf('%12s %12.6f',M_.param_names(hv(ip(i),2),:), ...
last_values(ip(i))))
end
for i=1:length(ix)
disp(sprintf('%12s %12.6f',M_.exo_names(hv(ix(i),2),:), ...
last_values(ix(i))))
end
for i=1:length(ixd)
disp(sprintf('%12s %12.6f',M_.exo_det_names(hv(ixd(i),2),:), ...
last_values(ixd(i))))
end
if options_.homotopy_force_continue
disp('Option homotopy_continue is set, so I continue ...')
else
error('Homotopy step failed')
end
end
[steady_state,M_.params,info] = steady_(M_,options_,oo_);
if info(1) == 0
oo_.steady_state = steady_state;
disp_steady_state(M_,oo_);
elseif options_.steady.stop_on_error
print_info(info,options_.noprint);
else
disp(['Warning: steady state could not be computed but steady.stop_on_error ' ...
'== 0, so I continue'])
print_info(info,options_.noprint);
end
M_.Sigma_e = Sigma_e;

View File

@ -103,7 +103,7 @@ class ParsingDriver;
%token DEFAULT FIXED_POINT
%token FORECAST K_ORDER_SOLVER INSTRUMENTS PRIOR SHIFT MEAN STDEV VARIANCE MODE INTERVAL SHAPE DOMAINN
%token GAMMA_PDF GRAPH CONDITIONAL_VARIANCE_DECOMPOSITION NOCHECK STD
%token HISTVAL HOMOTOPY_SETUP HOMOTOPY_MODE HOMOTOPY_STEPS HP_FILTER HP_NGRID
%token HISTVAL HOMOTOPY_SETUP HOMOTOPY_MODE HOMOTOPY_STEPS HOMOTOPY_FORCE_CONTINUE HP_FILTER HP_NGRID
%token IDENTIFICATION INF_CONSTANT INITVAL INITVAL_FILE BOUNDS JSCALE INIT
%token <string_val> INT_NUMBER
%token <string_val> DATE_NUMBER
@ -130,7 +130,7 @@ class ParsingDriver;
%token UNIFORM_PDF UNIT_ROOT_VARS USE_DLL USEAUTOCORR GSA_SAMPLE_FILE
%token VALUES VAR VAREXO VAREXO_DET VAROBS PREDETERMINED_VARIABLES
%token WRITE_LATEX_DYNAMIC_MODEL WRITE_LATEX_STATIC_MODEL
%token XLS_SHEET XLS_RANGE STOP_ON_ERROR
%token XLS_SHEET XLS_RANGE
%left COMMA
%left EQUAL_EQUAL EXCLAMATION_EQUAL
%left LESS GREATER LESS_EQUAL GREATER_EQUAL
@ -833,10 +833,10 @@ steady_options_list : steady_options_list COMMA steady_options
steady_options : o_solve_algo
| o_homotopy_mode
| o_homotopy_steps
| o_homotopy_force_continue
| o_markowitz
| o_maxit
| o_nocheck
| o_stop_on_error
;
check : CHECK ';'
@ -2308,6 +2308,7 @@ o_max_dim_cova_group : MAX_DIM_COVA_GROUP EQUAL INT_NUMBER { driver.option_num("
o_homotopy_mode : HOMOTOPY_MODE EQUAL INT_NUMBER {driver.option_num("homotopy_mode",$3); };
o_homotopy_steps : HOMOTOPY_STEPS EQUAL INT_NUMBER {driver.option_num("homotopy_steps",$3); };
o_homotopy_force_continue: HOMOTOPY_FORCE_CONTINUE EQUAL INT_NUMBER { driver.option_num("homotopy_force_continue",$3); };
o_nocheck : NOCHECK {driver.option_num("steadystate.nocheck","1"); };
o_controlled_varexo : CONTROLLED_VAREXO EQUAL '(' symbol_list ')' { driver.option_symbol_list("controlled_varexo"); };
@ -2502,7 +2503,6 @@ o_median : MEDIAN { driver.option_num("ms.median","1"); }
o_regimes : REGIMES { driver.option_num("ms.regimes","1"); };
o_regime : REGIME EQUAL INT_NUMBER { driver.option_num("ms.regime",$3); };
o_data_obs_nbr : DATA_OBS_NBR EQUAL INT_NUMBER { driver.option_num("ms.forecast_data_obs",$3); };
o_stop_on_error: STOP_ON_ERROR EQUAL INT_NUMBER { driver.option_num("steady.stop_on_error",$3); };
o_discretionary_tol: DISCRETIONARY_TOL EQUAL non_negative_number { driver.option_num("discretionary_tol",$3); };
range : symbol ':' symbol

View File

@ -436,6 +436,7 @@ string eofbuff;
<DYNARE_STATEMENT>homotopy_mode {return token::HOMOTOPY_MODE; }
<DYNARE_STATEMENT>homotopy_steps {return token::HOMOTOPY_STEPS; }
<DYNARE_STATEMENT>homotopy_force_continue {return token::HOMOTOPY_FORCE_CONTINUE;}
<DYNARE_STATEMENT>nocheck {return token::NOCHECK; }
<DYNARE_STATEMENT>controlled_varexo {return token::CONTROLLED_VAREXO; }
@ -453,7 +454,6 @@ string eofbuff;
<DYNARE_STATEMENT>deflator {return token::DEFLATOR;}
<DYNARE_STATEMENT>growth_factor {return token::GROWTH_FACTOR;}
<DYNARE_STATEMENT>cova_compute {return token::COVA_COMPUTE;}
<DYNARE_STATEMENT>stop_on_error {return token::STOP_ON_ERROR;}
<DYNARE_STATEMENT>discretionary_tol {return token::DISCRETIONARY_TOL;}
<DYNARE_STATEMENT>[\$][^$]*[\$] {