From 115b16236bf83b2e4e7f01a69ca56104665b6c0a Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Fri, 17 May 2013 23:54:17 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20bug=20in=20dsge=5Flikelihood=20for=20univ?= =?UTF-8?q?ariate=5Fkalman=5Ffilter=20=C3=BF=C3=BF=C3=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lines 399-418 set the measurement covariance matrix and save it to H1. If it is diagonal, it is not recomputed again as correlated_errors_have_been_checked is 0. In that case, lines 654-675 are not entered and univariate_kalman_filter tries to use the old H, but it was named H1 before, leading to a crash. Changing the name of the matrix H in lines 654-682 to H1 assures that univariate_kalman_filter uses the correctly updated matrix of the ~correlated_errors_have_been_checked and the previously computed H1 in the other cases. --- matlab/dsge_likelihood.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/matlab/dsge_likelihood.m b/matlab/dsge_likelihood.m index b7b8d38cf..8b5337ece 100644 --- a/matlab/dsge_likelihood.m +++ b/matlab/dsge_likelihood.m @@ -653,14 +653,14 @@ if (kalman_algo==2) || (kalman_algo==4) % resetting measurement error covariance matrix when necessary % if ~correlated_errors_have_been_checked if isequal(H,0) - H = zeros(pp,1); + H1 = zeros(pp,1); mmm = mm; if analytic_derivation, DH = zeros(pp,length(xparam1)); end else if all(all(abs(H-diag(diag(H)))<1e-14))% ie, the covariance matrix is diagonal... - H = diag(H); + H1 = diag(H); mmm = mm; clear tmp if analytic_derivation, @@ -676,7 +676,7 @@ if (kalman_algo==2) || (kalman_algo==4) R = blkdiag(R,eye(pp)); Pstar = blkdiag(Pstar,H); Pinf = blckdiag(Pinf,zeros(pp)); - H = zeros(pp,1); + H1 = zeros(pp,1); mmm = mm+pp; end end @@ -690,7 +690,7 @@ if (kalman_algo==2) || (kalman_algo==4) DynareOptions.kalman_tol, ... DynareOptions.riccati_tol, ... DynareOptions.presample, ... - T,Q,R,H,Z,mmm,pp,rr,Zflag,diffuse_periods,analytic_deriv_info{:}); + T,Q,R,H1,Z,mmm,pp,rr,Zflag,diffuse_periods,analytic_deriv_info{:}); if analytic_derivation, LIK1=LIK; LIK=LIK1{1};