Merge pull request #441 from JohannesPfeifer/mode_check

Bugfix for mode_check and display of parameters out of bounds
time-shift
Sébastien Villemot 2013-08-12 03:31:50 -07:00
commit b4f8532bea
3 changed files with 56 additions and 18 deletions

View File

@ -513,6 +513,24 @@ if ~options_.mh_posterior_mode_estimation && options_.cova_compute
disp('=> posterior variance of the estimated parameters are not positive.') disp('=> posterior variance of the estimated parameters are not positive.')
disp('You should try to change the initial values of the parameters using') disp('You should try to change the initial values of the parameters using')
disp('the estimated_params_init block, or use another optimization routine.') disp('the estimated_params_init block, or use another optimization routine.')
params_at_bound=find(xparam1==ub | xparam1==lb);
if ~isempty(params_at_bound)
for ii=1:length(params_at_bound)
params_at_bound_name{ii,1}=get_the_name(ii,0,M_,estim_params_,options_);
end
disp_string=[params_at_bound_name{1,:}];
for ii=2:size(params_at_bound_name,1)
disp_string=[disp_string,', ',params_at_bound_name{ii,:}];
end
fprintf('\nThe following parameters are at the prior bound: %s\n', disp_string)
fprintf('Some potential solutions are:\n')
fprintf(' - Check your model for mistakes.\n')
fprintf(' - Check whether model and data are consistent (correct observation equation).\n')
fprintf(' - Shut off prior_trunc.\n')
fprintf(' - Use a different mode_compute like 6 or 9.\n')
fprintf(' - Check whether the parameters estimated are identified.\n')
fprintf(' - Increase the informativeness of the prior.\n')
end
warning('The results below are most likely wrong!'); warning('The results below are most likely wrong!');
end end
end end
@ -578,11 +596,14 @@ if (any(bayestopt_.pshape >0 ) && options_.mh_replic) || ...
bounds(:,2)=min(bounds(:,2),ub); bounds(:,2)=min(bounds(:,2),ub);
bayestopt_.lb = bounds(:,1); bayestopt_.lb = bounds(:,1);
bayestopt_.ub = bounds(:,2); bayestopt_.ub = bounds(:,2);
if any(xparam1 < bounds(:,1)) || any(xparam1 > bounds(:,2)) outside_bound_pars=find(xparam1 < bounds(:,1) | xparam1 > bounds(:,2));
outside_bound_vars=bayestopt_.name([find(xparam1 < bounds(:,1)); find(xparam1 > bounds(:,2))],:); if ~isempty(outside_bound_pars)
disp_string=[outside_bound_vars{1,:}]; for ii=1:length(outside_bound_pars)
for ii=2:size(outside_bound_vars,1) outside_bound_par_names{ii,1}=get_the_name(ii,0,M_,estim_params_,options_);
disp_string=[disp_string,', ',outside_bound_vars{ii,:}]; end
disp_string=[outside_bound_par_names{1,:}];
for ii=2:size(outside_bound_par_names,1)
disp_string=[disp_string,', ',outside_bound_par_names{ii,:}];
end end
error(['Mode value(s) of ', disp_string ,' are outside parameter bounds. Potentially, you should set prior_trunc=0.']) error(['Mode value(s) of ', disp_string ,' are outside parameter bounds. Potentially, you should set prior_trunc=0.'])
end end

View File

@ -146,11 +146,14 @@ if ~isempty(estim_params_)
end end
% Test if initial values of the estimated parameters are all between % Test if initial values of the estimated parameters are all between
% the prior lower and upper bounds. % the prior lower and upper bounds.
if any(xparam1 < bounds(:,1)) || any(xparam1 > bounds(:,2)) outside_bound_pars=find(xparam1 < bounds(:,1) | xparam1 > bounds(:,2));
outside_bound_vars=bayestopt_.name([find(xparam1 < bounds(:,1)); find(xparam1 > bounds(:,2))],:); if ~isempty(outside_bound_pars)
disp_string=[outside_bound_vars{1,:}]; for ii=1:length(outside_bound_pars)
for ii=2:size(outside_bound_vars,1) outside_bound_par_names{ii,1}=get_the_name(ii,0,M_,estim_params_,options_);
disp_string=[disp_string,', ',outside_bound_vars{ii,:}]; end
disp_string=[outside_bound_par_names{1,:}];
for ii=2:size(outside_bound_par_names,1)
disp_string=[disp_string,', ',outside_bound_par_names{ii,:}];
end end
error(['Initial value(s) of ', disp_string ,' are outside parameter bounds. Potentially, you should set prior_trunc=0. If you used the mode_file-option, check whether your mode-file is consistent with the priors.']) error(['Initial value(s) of ', disp_string ,' are outside parameter bounds. Potentially, you should set prior_trunc=0. If you used the mode_file-option, check whether your mode-file is consistent with the priors.'])
end end

View File

@ -109,15 +109,24 @@ for plt = 1:nbplt,
end end
end end
xx = x; xx = x;
l1 = max(BayesInfo.lb(kk),(1-sign(x(kk))*ll)*x(kk)); m1 = 0; l1 = max(BayesInfo.lb(kk),(1-sign(x(kk))*ll)*x(kk)); m1 = 0; %lower bound
l2 = min(BayesInfo.ub(kk),(1+sign(x(kk))*ll)*x(kk)); l2 = min(BayesInfo.ub(kk),(1+sign(x(kk))*ll)*x(kk)); %upper bound
if DynareOptions.mode_check.symmetric_plots, binding_lower_bound=0;
if l2<(1+ll)*x(kk) binding_upper_bound=0;
l1 = x(kk) - (l2-x(kk)); if isequal(x(kk),BayesInfo.lb(kk))
binding_lower_bound=1;
bound_value=BayesInfo.lb(kk);
elseif isequal(x(kk),BayesInfo.ub(kk))
binding_upper_bound=1;
bound_value=BayesInfo.ub(kk);
end
if DynareOptions.mode_check.symmetric_plots && ~binding_lower_bound && ~binding_upper_bound
if l2<(1+ll)*x(kk) %test whether upper bound is too small due to prior binding
l1 = x(kk) - (l2-x(kk)); %adjust lower bound to become closer
m1 = 1; m1 = 1;
end end
if ~m1 && (l1>(1-ll)*x(kk)) && (x(kk)+(x(kk)-l1)<BayesInfo.ub(kk)) if ~m1 && (l1>(1-ll)*x(kk)) && (x(kk)+(x(kk)-l1)<BayesInfo.ub(kk)) % if lower bound was truncated and using difference from lower bound does not violate upper bound
l2 = x(kk) + (x(kk)-l1); l2 = x(kk) + (x(kk)-l1); %set upper bound to same distance as lower bound
end end
end end
z1 = l1:((x(kk)-l1)/(DynareOptions.mode_check.number_of_points/2)):x(kk); z1 = l1:((x(kk)-l1)/(DynareOptions.mode_check.number_of_points/2)):x(kk);
@ -149,8 +158,13 @@ for plt = 1:nbplt,
yNaN = yl(1)*ones(size(NaN_index)); yNaN = yl(1)*ones(size(NaN_index));
plot(zNaN,yNaN,'o','MarkerEdgeColor','r','MarkerFaceColor','r','MarkerSize',6); plot(zNaN,yNaN,'o','MarkerEdgeColor','r','MarkerFaceColor','r','MarkerSize',6);
title(name,'interpreter','none') title(name,'interpreter','none')
hold off
axis tight axis tight
if binding_lower_bound || binding_upper_bound
xl=get(gca,'xlim');
plot( [bound_value bound_value], yl, 'r--', 'LineWidth', 1)
xlim([xl(1)-0.5*binding_lower_bound*(xl(2)-xl(1)) xl(2)+0.5*binding_upper_bound*(xl(2)-xl(1))])
end
hold off
drawnow drawnow
end end
if DynareOptions.mode_check.nolik==0, if DynareOptions.mode_check.nolik==0,