From 636cd1bae6cb12b5d4bc7f7a1ccfae00eea612f0 Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Sun, 22 Jan 2012 18:59:19 +0100 Subject: [PATCH] calling always multivariate Kalman filter first, even if univariate diffuse Kalman filter was used before --- matlab/dsge_likelihood.m | 13 +++++++------ matlab/dsge_likelihood_hh.m | 24 +++++++++++++----------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/matlab/dsge_likelihood.m b/matlab/dsge_likelihood.m index 68574b40d..fbb2d1eab 100644 --- a/matlab/dsge_likelihood.m +++ b/matlab/dsge_likelihood.m @@ -359,6 +359,7 @@ end diffuse_periods = 0; correlated_errors_have_been_checked = 0; +singular_diffuse_filter = 0; switch DynareOptions.lik_init case 1% Standard initialization with the steady state of the state equation. if kalman_algo~=2 @@ -407,17 +408,17 @@ switch DynareOptions.lik_init diffuse_periods = length(tmp); if isinf(dLIK) % Go to univariate diffuse filter if singularity problem. - kalman_algo = 4; + singular_diffuse_filter = 1; end end - if (kalman_algo==4) + if singular_diffuse_filter || (kalman_algo==4) % Univariate Diffuse Kalman Filter if isequal(H,0) - H = zeros(nobs,1); + H1 = zeros(nobs,1); mmm = mm; 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; else Z = [Z, eye(pp)]; @@ -426,7 +427,7 @@ switch DynareOptions.lik_init R = blkdiag(R,eye(pp)); Pstar = blkdiag(Pstar,H); Pinf = blckdiag(Pinf,zeros(pp)); - H = zeros(nobs,1); + H1 = zeros(nobs,1); mmm = mm+pp; end end @@ -439,7 +440,7 @@ switch DynareOptions.lik_init Y, 1, size(Y,2), ... zeros(mmm,1), Pinf, Pstar, ... kalman_tol, riccati_tol, DynareOptions.presample, ... - T,R,Q,H,Z,mmm,pp,rr); + T,R,Q,H1,Z,mmm,pp,rr); diffuse_periods = length(tmp); end case 4% Start from the solution of the Riccati equation. diff --git a/matlab/dsge_likelihood_hh.m b/matlab/dsge_likelihood_hh.m index 9d91a44b9..ff8c6d383 100644 --- a/matlab/dsge_likelihood_hh.m +++ b/matlab/dsge_likelihood_hh.m @@ -255,6 +255,7 @@ end diffuse_periods = 0; correlated_errors_have_been_checked = 0; +singular_diffuse_filter = 0; switch DynareOptions.lik_init case 1% Standard initialization with the steady state of the state equation. if kalman_algo~=2 @@ -303,18 +304,17 @@ switch DynareOptions.lik_init diffuse_periods = length(dlik); if isinf(dLIK) % Go to univariate diffuse filter if singularity problem. - kalman_algo = 4; - singularity_flag = 1; + singular_diffuse_filter end end - if (kalman_algo==4) + if singular_diffuse_filter || (kalman_algo==4) % Univariate Diffuse Kalman Filter if isequal(H,0) - H = zeros(nobs,1); + H1 = zeros(nobs,1); mmm = mm; 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; else Z = [Z, eye(pp)]; @@ -323,18 +323,20 @@ switch DynareOptions.lik_init R = blkdiag(R,eye(pp)); Pstar = blkdiag(Pstar,H); Pinf = blckdiag(Pinf,zeros(pp)); - H = zeros(nobs,1); + H1 = zeros(nobs,1); mmm = mm+pp; end end % no need to test again for correlation elements correlated_errors_have_been_checked = 1; - [dLIK,dlik,a,Pstar] = univariate_kalman_filter_d(DynareDataset.missing.aindex,DynareDataset.missing.number_of_observations,DynareDataset.missing.no_more_missing_observations, ... - Y, 1, size(Y,2), ... - zeros(mmm,1), Pinf, Pstar, ... - kalman_tol, riccati_tol, DynareOptions.presample, ... - T,R,Q,H,Z,mmm,pp,rr); + [dLIK,dlik,a,Pstar] = univariate_kalman_filter_d(DynareDataset.missing.aindex,... + DynareDataset.missing.number_of_observations,... + DynareDataset.missing.no_more_missing_observations, ... + Y, 1, size(Y,2), ... + zeros(mmm,1), Pinf, Pstar, ... + kalman_tol, riccati_tol, DynareOptions.presample, ... + T,R,Q,H1,Z,mmm,pp,rr); diffuse_periods = length(dlik); end case 4% Start from the solution of the Riccati equation.