IVF: improve error handling

unit-tests
Johannes Pfeifer 2022-11-23 16:46:40 +01:00
parent 80f6799c38
commit 26fbc6c56d
2 changed files with 47 additions and 21 deletions

View File

@ -175,13 +175,20 @@ if isequal(options_.mode_compute,0) && isempty(options_.mode_file) && ~options_.
if options_.order==1 && ~options_.particle.status
if options_.smoother
if options_.occbin.smoother.status && options_.occbin.smoother.inversion_filter
[~, ~, ~, ~, ~, ~, ~, ~, ~, ~, oo_, atT, innov] = occbin.IVF_posterior(xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,prior_bounds(bayestopt_,options_.prior_trunc),oo_);
updated_variables = atT*nan;
measurement_error=[];
ys = oo_.dr.ys;
trend_coeff = zeros(length(options_.varobs_id),1);
bayestopt_.mf = bayestopt_.smoother_var_list(bayestopt_.smoother_mf);
[oo_]=store_smoother_results(M_,oo_,options_,bayestopt_,dataset_,dataset_info,atT,innov,measurement_error,updated_variables,ys,trend_coeff);
[~, info, ~, ~, ~, ~, ~, ~, ~, ~, oo_, atT, innov] = occbin.IVF_posterior(xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,prior_bounds(bayestopt_,options_.prior_trunc),oo_);
if ismember(info(1),[303,304,306])
fprintf('\nIVF: smoother did not succeed. No results will be written to oo_.\n')
else
updated_variables = atT*nan;
measurement_error=[];
ys = oo_.dr.ys;
trend_coeff = zeros(length(options_.varobs_id),1);
bayestopt_.mf = bayestopt_.smoother_var_list(bayestopt_.smoother_mf);
options_nk=options_.nk;
options_.nk=[]; %unset options_.nk and reset it later
[oo_]=store_smoother_results(M_,oo_,options_,bayestopt_,dataset_,dataset_info,atT,innov,measurement_error,updated_variables,ys,trend_coeff);
options_.nk=options_nk;
end
else
if options_.occbin.smoother.status
[atT,innov,measurement_error,updated_variables,ys,trend_coeff,aK,T,R,P,PK,decomp,Trend,state_uncertainty,M_,oo_,bayestopt_] = occbin.DSGE_smoother(xparam1,gend,transpose(data),data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_,dataset_,dataset_info);
@ -593,13 +600,20 @@ if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.psha
|| ~options_.smoother ) && ~options_.partial_information % to be fixed
%% ML estimation, or posterior mode without Metropolis-Hastings or Metropolis without Bayesian smoothed variables
if options_.occbin.smoother.status && options_.occbin.smoother.inversion_filter
[~, ~, ~, ~, ~, ~, ~, ~, ~, ~, oo_, atT, innov] = occbin.IVF_posterior(xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,prior_bounds(bayestopt_,options_.prior_trunc),oo_);
updated_variables = atT*nan;
measurement_error=[];
ys = oo_.dr.ys;
trend_coeff = zeros(length(options_.varobs_id),1);
bayestopt_.mf = bayestopt_.smoother_var_list(bayestopt_.smoother_mf);
[oo_, yf]=store_smoother_results(M_,oo_,options_,bayestopt_,dataset_,dataset_info,atT,innov,measurement_error,updated_variables,ys,trend_coeff);
[~, info, ~, ~, ~, ~, ~, ~, ~, ~, oo_, atT, innov] = occbin.IVF_posterior(xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,prior_bounds(bayestopt_,options_.prior_trunc),oo_);
if ismember(info(1),[303,304,306])
fprintf('\nIVF: smoother did not succeed. No results will be written to oo_.\n')
else
updated_variables = atT*nan;
measurement_error=[];
ys = oo_.dr.ys;
trend_coeff = zeros(length(options_.varobs_id),1);
bayestopt_.mf = bayestopt_.smoother_var_list(bayestopt_.smoother_mf);
options_nk=options_.nk;
options_.nk=[]; %unset options_.nk and reset it later
[oo_, yf]=store_smoother_results(M_,oo_,options_,bayestopt_,dataset_,dataset_info,atT,innov,measurement_error,updated_variables,ys,trend_coeff);
options_.nk=options_nk;
end
else
if options_.occbin.smoother.status
[atT,innov,measurement_error,updated_variables,ys,trend_coeff,aK,T,R,P,PK,decomp,Trend,state_uncertainty,M_,oo_,bayestopt_] = occbin.DSGE_smoother(xparam1,dataset_.nobs,transpose(dataset_.data),dataset_info.missing.aindex,dataset_info.missing.state,M_,oo_,options_,bayestopt_,estim_params_,dataset_,dataset_info);

View File

@ -105,12 +105,17 @@ end
if options_.occbin.smoother.status
if options_.occbin.smoother.inversion_filter
[~, ~, ~, ~, ~, ~, ~, ~, ~, ~, oo_, atT, innov] = occbin.IVF_posterior(parameters,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,prior_bounds(bayestopt_,options_.prior_trunc),oo_);
updated_variables = atT*nan;
measurement_error=[];
ys = oo_.dr.ys;
trend_coeff = zeros(length(options_.varobs_id),1);
bayestopt_.mf = bayestopt_.smoother_var_list(bayestopt_.smoother_mf);
[~, info, ~, ~, ~, ~, ~, ~, ~, ~, oo_, atT, innov] = occbin.IVF_posterior(parameters,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,prior_bounds(bayestopt_,options_.prior_trunc),oo_);
if ismember(info(1),[303,304,306])
oo_.occbin.smoother.error_flag=1;
else
oo_.occbin.smoother.error_flag=0;
updated_variables = atT*nan;
measurement_error=[];
ys = oo_.dr.ys;
trend_coeff = zeros(length(options_.varobs_id),1);
bayestopt_.mf = bayestopt_.smoother_var_list(bayestopt_.smoother_mf);
end
else
[atT,innov,measurement_error,updated_variables,ys,trend_coeff,aK,T,R,P,PK,decomp,Trend,state_uncertainty,M_,oo_,bayestopt_] = ...
occbin.DSGE_smoother(parameters,dataset_.nobs,transpose(dataset_.data),dataset_info.missing.aindex,dataset_info.missing.state,M_,oo_,options_,bayestopt_,estim_params_,dataset_,dataset_info);
@ -124,7 +129,14 @@ if ~(options_.occbin.smoother.status && options_.occbin.smoother.inversion_filte
[oo_]=store_smoother_results(M_,oo_,options_,bayestopt_,dataset_,dataset_info,atT,innov,measurement_error,updated_variables,ys,trend_coeff,aK,P,PK,decomp,Trend,state_uncertainty);
end
else
[oo_]=store_smoother_results(M_,oo_,options_,bayestopt_,dataset_,dataset_info,atT,innov,measurement_error,updated_variables,ys,trend_coeff);
if ~oo_.occbin.smoother.error_flag
options_nk=options_.nk;
options_.nk=[]; %unset options_.nk and reset it later
[oo_]=store_smoother_results(M_,oo_,options_,bayestopt_,dataset_,dataset_info,atT,innov,measurement_error,updated_variables,ys,trend_coeff);
options_.nk=options_nk;
else
fprintf('\nIVF: smoother did not succeed. No results will be written to oo_.\n')
end
end
if nargout>4
Smoothed_variables_declaration_order_deviation_form=atT(oo_.dr.inv_order_var(bayestopt_.smoother_var_list),:);