From 2fe73fafdc4886053f6871daedfecbe8e7fe8d1c Mon Sep 17 00:00:00 2001
From: Johannes Pfeifer <jpfeifer@gmx.de>
Date: Sun, 2 Oct 2016 12:56:28 +0200
Subject: [PATCH] Implement and document
 keep_kalman_algo_if_singularity_is_detected option

---
 doc/dynare.texi          | 9 +++++++++
 matlab/dsge_likelihood.m | 6 ++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/doc/dynare.texi b/doc/dynare.texi
index 23ddc0de2..ce6e3ab0a 100644
--- a/doc/dynare.texi
+++ b/doc/dynare.texi
@@ -6020,6 +6020,15 @@ the option is equal to @code{0}, Dynare will not automatically change
 the filter, but rather use a penalty value for the likelihood when
 such a singularity is encountered. Default: @code{1}.
 
+@item keep_kalman_algo_if_singularity_is_detected
+@anchor{keep_kalman_algo_if_singularity_is_detected}
+With the default @ref{use_univariate_filters_if_singularity_is_detected}=1, Dynare will switch 
+to the univariate Kalman filter when it encounters a singular forecast error variance
+matrix during Kalman filtering. Upon encountering such a singularity for the first time, all subsequent
+parameter draws and computations will automatically rely on univariate filter, i.e. Dynare will never try 
+the multivariate filter again. Use the @code{keep_kalman_algo_if_singularity_is_detected} option to have the 
+@code{use_univariate_filters_if_singularity_is_detected} only affect the behavior for the current draw/computation.
+
 @item qz_zero_threshold = @var{DOUBLE}
 @xref{qz_zero_threshold}.
 
diff --git a/matlab/dsge_likelihood.m b/matlab/dsge_likelihood.m
index 2d3406ed5..3da705c9a 100644
--- a/matlab/dsge_likelihood.m
+++ b/matlab/dsge_likelihood.m
@@ -894,8 +894,10 @@ if imag(fval)~=0
     return
 end
 
-% Update DynareOptions.kalman_algo.
-DynareOptions.kalman_algo = kalman_algo;
+if ~DynareOptions.kalman.keep_kalman_algo_if_singularity_is_detected
+    % Update DynareOptions.kalman_algo.
+    DynareOptions.kalman_algo = kalman_algo;
+end
 
 if analytic_derivation==0 && nargout>3,
     lik=lik(start:end,:);
-- 
GitLab