From 6ea053e47d4542b02bc75e14c1d008c639d2340b Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Thu, 13 Jan 2011 11:38:12 +0100 Subject: [PATCH] correcting bugs in diffuse Kalman smoother --- matlab/DiffuseKalmanSmoother1_Z.m | 5 ++- matlab/DiffuseKalmanSmoother3.m | 56 +++++++++------------------- matlab/DiffuseKalmanSmootherH1_Z.m | 59 +++++++++++++++++++++--------- 3 files changed, 61 insertions(+), 59 deletions(-) diff --git a/matlab/DiffuseKalmanSmoother1_Z.m b/matlab/DiffuseKalmanSmoother1_Z.m index 854d9b446..35fc69b30 100644 --- a/matlab/DiffuseKalmanSmoother1_Z.m +++ b/matlab/DiffuseKalmanSmoother1_Z.m @@ -101,7 +101,7 @@ while rank(Pinf(:,:,t+1),kalman_tol) && (tcrit); - % if newRank==0, id = i; end, - if ~isempty(options_.diffuse_d), - newRank = (icccrit)==0; - if newRank & (any(diag(P0(mf,mf))>crit)==0 & rank(P0,crit1)==0); - disp('WARNING!! Change in OPTIONS_.DIFFUSE_D in univariate DKF') - options_.diffuse_d = icc; - newRank=0; - end - else - %newRank = any(diag(P0(mf,mf))>crit); - newRank = (any(diag(P0(mf,mf))>crit) | rank(P0,crit1)); - if newRank==0, - options_.diffuse_d = icc; - end - end, - % if newRank==0, - % options_.diffuse_d=i; %this is buggy - % end - % end new terminiation criteria by M. Ratto elseif Fstar(i,t) > crit %% Note that : (1) rank(Pinf)=0 implies that Finf = 0, (2) outside this loop (when for some i and t the condition %% rank(Pinf)=0 is satisfied we have P = Pstar and F = Fstar and (3) Finf = 0 does not imply that @@ -170,13 +141,20 @@ while newRank & t < smpl for jnk=2:nk aK(jnk,:,t+jnk) = T*dynare_squeeze(aK(jnk-1,:,t+jnk-1)); end + if newRank + oldRank = rank(P0,crit); + else + oldRank = 0; + end Pstar(:,:,t+1) = T*Pstar(:,:,t)*transpose(T)+ QQ; Pinf(:,:,t+1) = T*Pinf(:,:,t)*transpose(T); P0 = Pinf(:,:,t+1); - if newRank, - %newRank = any(diag(P0(mf,mf))>crit); + if newRank newRank = rank(P0,crit1); end + if oldRank ~= newRank + disp('univariate_diffuse_kalman_filter:: T does influence the rank of Pinf!') + end end diff --git a/matlab/DiffuseKalmanSmootherH1_Z.m b/matlab/DiffuseKalmanSmootherH1_Z.m index 63c4f6c8e..7f60c7e4c 100644 --- a/matlab/DiffuseKalmanSmootherH1_Z.m +++ b/matlab/DiffuseKalmanSmootherH1_Z.m @@ -97,25 +97,48 @@ t = 0; while rank(Pinf(:,:,t+1),crit1) & t