From 0402c56ee70bba5b1b3e027e7f71fc45250cba63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 27 Jan 2021 15:41:24 +0100 Subject: [PATCH] Compatibility fix for MATLAB R2014a when estimating with empty estim_params MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The tests kalman_filter_smoother/fs2000_smoother_only.mod and kalman_filter_smoother/fs2000_smoother_only_ns.mod would fail under MATLAB R2014a. They both run the estimation command without having declared an estim_params block. Their execution would fail in check_bounds_and_definiteness_estimation, at the point where we check if initial values are below the lower bound. The problem is that xparam1 would be of size 0×1, while bounds.lb would be empty (0×0), and the comparison fails on older MATLABs. The fix consists in ensuring that xparam1 remains of size 0×0 in that case. --- matlab/dsge_likelihood.m | 9 +++++++-- matlab/dsge_var_likelihood.m | 11 ++++++++--- matlab/non_linear_dsge_likelihood.m | 9 +++++++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/matlab/dsge_likelihood.m b/matlab/dsge_likelihood.m index 62d5ff570..8ff23126c 100644 --- a/matlab/dsge_likelihood.m +++ b/matlab/dsge_likelihood.m @@ -115,7 +115,7 @@ function [fval,info,exit_flag,DLIK,Hess,SteadyState,trend_coeff,Model,DynareOpti %! @end deftypefn %@eod: -% Copyright (C) 2004-2020 Dynare Team +% Copyright (C) 2004-2021 Dynare Team % % This file is part of Dynare. % @@ -148,7 +148,12 @@ end Hess = []; % Ensure that xparam1 is a column vector. -xparam1 = xparam1(:); +% (Don't do the transformation if xparam1 is empty, otherwise it would become a +% 0×1 matrix, which create issues with older MATLABs when comparing with [] in +% check_bounds_and_definiteness_estimation) +if ~isempty(xparam1) + xparam1 = xparam1(:); +end if DynareOptions.estimation_dll [fval,exit_flag,SteadyState,trend_coeff,info,params,H,Q] ... diff --git a/matlab/dsge_var_likelihood.m b/matlab/dsge_var_likelihood.m index 596136ce8..c1b490819 100644 --- a/matlab/dsge_var_likelihood.m +++ b/matlab/dsge_var_likelihood.m @@ -37,7 +37,7 @@ function [fval,info,exit_flag,grad,hess,SteadyState,trend_coeff,PHI_tilde,SIGMA_ % SPECIAL REQUIREMENTS % None. -% Copyright (C) 2006-2018 Dynare Team +% Copyright (C) 2006-2021 Dynare Team % % This file is part of Dynare. % @@ -69,7 +69,12 @@ prior = []; trend_coeff=[]; % Ensure that xparam1 is a column vector. -xparam1 = xparam1(:); +% (Don't do the transformation if xparam1 is empty, otherwise it would become a +% 0×1 matrix, which create issues with older MATLABs when comparing with [] in +% check_bounds_and_definiteness_estimation) +if ~isempty(xparam1) + xparam1 = xparam1(:); +end % Initialization of of the index for parameter dsge_prior_weight in Model.params. if isempty(dsge_prior_weight_idx) @@ -317,4 +322,4 @@ if (nargout==11) prior.ArtificialSampleSize = fix(dsge_prior_weight*NumberOfObservations); prior.DF = prior.ArtificialSampleSize - NumberOfParameters - NumberOfObservedVariables; prior.iGXX_star = iGXX; -end \ No newline at end of file +end diff --git a/matlab/non_linear_dsge_likelihood.m b/matlab/non_linear_dsge_likelihood.m index b5a9ff76f..7f34ab2d3 100644 --- a/matlab/non_linear_dsge_likelihood.m +++ b/matlab/non_linear_dsge_likelihood.m @@ -26,7 +26,7 @@ function [fval,info,exit_flag,DLIK,Hess,ys,trend_coeff,Model,DynareOptions,Bayes % - BayesInfo [struct] See INPUTS section. % - DynareResults [struct] Updated DynareResults structure described in INPUTS section. -% Copyright (C) 2010-2019 Dynare Team +% Copyright (C) 2010-2021 Dynare Team % % This file is part of Dynare. % @@ -52,7 +52,12 @@ DLIK = []; Hess = []; % Ensure that xparam1 is a column vector. -xparam1 = xparam1(:); +% (Don't do the transformation if xparam1 is empty, otherwise it would become a +% 0×1 matrix, which create issues with older MATLABs when comparing with [] in +% check_bounds_and_definiteness_estimation) +if ~isempty(xparam1) + xparam1 = xparam1(:); +end % Issue an error if loglinear option is used. if DynareOptions.loglinear