Skip to content
Snippets Groups Projects
Verified Commit 9528c35d authored by Johannes Pfeifer's avatar Johannes Pfeifer Committed by Sébastien Villemot
Browse files

:bug: univariate_kalman_filter: discard pathological parameter draws that...

:bug: univariate_kalman_filter: discard pathological parameter draws that result in negative variance

Logic was faulty as not bigger than tolerance does not imply being 0

(cherry picked from commit 62b0129a)
parent ab77f5ee
No related branches found
No related tags found
No related merge requests found
......@@ -84,7 +84,7 @@ function [LIK, lik,a,P] = univariate_kalman_filter(data_index,number_of_observat
% Second Edition, Ch. 6.4 + 7.2.5
% Copyright © 2004-2021 Dynare Team
% Copyright © 2004-2024 Dynare Team
%
% This file is part of Dynare.
%
......@@ -211,11 +211,21 @@ while notsteady && t<=last %loop over t
end
a = a + Ki*prediction_error; %filtering according to (6.13) in DK (2012)
P = P - PZ*Ki'; %filtering according to (6.13) in DK (2012)
else
if Fi<0
%pathological numerical case where variance is negative
if analytic_derivation
LIK={NaN,DLIK,Hess};
else
LIK = NaN;
end
return
else
% do nothing as a_{t,i+1}=a_{t,i} and P_{t,i+1}=P_{t,i}, see
% p. 157, DK (2012)
end
end
end
if analytic_derivation
if analytic_derivation==2
[Da,DP,D2a,D2P] = univariate_computeDstate(k,a,P,T,Da,DP,DT,DOm,notsteady,D2a,D2P,D2T,D2Om);
......
......@@ -87,7 +87,7 @@ function [dLIK, dlikk, a, Pstar, llik] = univariate_kalman_filter_d(data_index,
% Series Analysis by State Space Methods", Oxford University Press,
% Second Edition, Ch. 5, 6.4 + 7.2.5
% Copyright © 2004-2021 Dynare Team
% Copyright © 2004-2024 Dynare Team
%
% This file is part of Dynare.
%
......@@ -154,11 +154,17 @@ while newRank && (t<=last)
dlikk(s) = dlikk(s) + llik(s,d_index(i));
a = a+Kstar*(prediction_error/Fstar);
Pstar = Pstar-Kstar*(Kstar'/Fstar);
else
if Fstar<0 || Finf<0
%pathological numerical case where variance is negative
dLIK = NaN;
return
else
% do nothing as a_{t,i+1}=a_{t,i} and P_{t,i+1}=P_{t,i}, see
% p. 157, DK (2012)
end
end
end
if newRank
oldRank = rank(Z*Pinf*Z',diffuse_kalman_tol);
else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment