From 9a0c35a4b2a600753256a3886b11c2f474ad7f45 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer <jpfeifer@gmx.de> Date: Wed, 27 Nov 2024 11:54:51 +0100 Subject: [PATCH] occbin.DSGE_smoother.m: replace try-catch statement by error code Related to https://git.dynare.org/Dynare/dynare/-/merge_requests/2226#note_20318 --- matlab/+occbin/DSGE_smoother.m | 15 +++------------ matlab/kalman/DsgeSmoother.m | 5 +++-- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/matlab/+occbin/DSGE_smoother.m b/matlab/+occbin/DSGE_smoother.m index 76460bb07f..ebe3f36aa8 100644 --- a/matlab/+occbin/DSGE_smoother.m +++ b/matlab/+occbin/DSGE_smoother.m @@ -123,20 +123,11 @@ occbin_options.opts_simul = opts_simul; % this builds the opts_simul options fie occbin_options.opts_regime.binding_indicator = options_.occbin.smoother.init_binding_indicator; occbin_options.opts_regime.regime_history=options_.occbin.smoother.init_regime_history; -error_indicator=false; options_.noprint = true; -try - %blanket try-catch should be replaced be proper error handling, see https://git.dynare.org/Dynare/dynare/-/merge_requests/2226#note_20318 - [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T0,R0,P,PK,decomp,Trend,state_uncertainty,oo_,bayestopt_,alphahat0,state_uncertainty0] = DsgeSmoother(xparam1,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_,occbin_options);% T1=TT; -catch ME - error_indicator=true; - disp(ME.message) - for iter = 1:numel(ME.stack) - ME.stack(iter) - end - end -if error_indicator || isempty(alphahat0) +[alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T0,R0,P,PK,decomp,Trend,state_uncertainty,oo_,bayestopt_,alphahat0,state_uncertainty0,~,error_indicator] = DsgeSmoother(xparam1,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_,occbin_options);% T1=TT; + +if error_indicator(1) || isempty(alphahat0) if ~options_.occbin.smoother.linear_smoother || nargin~=12 %make sure linear smoother results are set before using them options_.occbin.smoother.status=false; [~,etahat,~,~,~,~,~,~,~,~,~,~,~,~,~,~,alphahat0] = ... diff --git a/matlab/kalman/DsgeSmoother.m b/matlab/kalman/DsgeSmoother.m index c8a8b8b2f7..364a80dfe9 100644 --- a/matlab/kalman/DsgeSmoother.m +++ b/matlab/kalman/DsgeSmoother.m @@ -1,5 +1,5 @@ -function [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T,R,P,PK,decomp,trend_addition,state_uncertainty,oo_,bayestopt_,alphahat0,state_uncertainty0,d] = DsgeSmoother(xparam1,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_,varargin) -% [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T,R,P,PK,decomp,trend_addition,state_uncertainty,oo_,bayestopt_,alphahat0,state_uncertainty0,d] = DsgeSmoother(xparam1,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_,varargin) +function [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T,R,P,PK,decomp,trend_addition,state_uncertainty,oo_,bayestopt_,alphahat0,state_uncertainty0,d,info] = DsgeSmoother(xparam1,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_,varargin) +% [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T,R,P,PK,decomp,trend_addition,state_uncertainty,oo_,bayestopt_,alphahat0,state_uncertainty0,d,info] = DsgeSmoother(xparam1,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_,varargin) % Estimation of the smoothed variables and innovations. % % INPUTS @@ -41,6 +41,7 @@ function [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T,R,P,PK,de % the smoothed state for the initial % period from the PKF % o d [integer] number of diffuse periods +% o info [1 by 4 double] error code and penalty % Notes: % m: number of endogenous variables (M_.endo_nbr) -- GitLab