Skip to content
Snippets Groups Projects
Commit 62b0129a authored by Johannes Pfeifer's avatar Johannes Pfeifer
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
parent 1ce40d4d
Branches
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.
%
......@@ -212,8 +212,18 @@ while notsteady && t<=last %loop over t
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
% do nothing as a_{t,i+1}=a_{t,i} and P_{t,i+1}=P_{t,i}, see
% p. 157, DK (2012)
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
......
......@@ -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.
%
......@@ -155,8 +155,14 @@ while newRank && (t<=last)
a = a+Kstar*(prediction_error/Fstar);
Pstar = Pstar-Kstar*(Kstar'/Fstar);
else
% do nothing as a_{t,i+1}=a_{t,i} and P_{t,i+1}=P_{t,i}, see
% p. 157, DK (2012)
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment