From 576bb48062e81ddfc0d391fd017b19f697d01f8e Mon Sep 17 00:00:00 2001
From: Johannes Pfeifer <jpfeifer@gmx.de>
Date: Wed, 25 May 2022 14:15:29 +0200
Subject: [PATCH] dsge_likelihood.m: distinguish PKF problems with singularity
 in other KFs

(cherry picked from commit cf548b467d10b163b7132b645cd011995faccc62)
---
 matlab/dsge_likelihood.m   | 6 ++++++
 matlab/get_error_message.m | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/matlab/dsge_likelihood.m b/matlab/dsge_likelihood.m
index ae9babbc24..233a4a4cea 100644
--- a/matlab/dsge_likelihood.m
+++ b/matlab/dsge_likelihood.m
@@ -708,6 +708,12 @@ if ((kalman_algo==1) || (kalman_algo==3))% Multivariate Kalman Filter
                                                            DynareOptions.rescale_prediction_error_covariance, ...
                                                            DynareOptions.presample, ...
                                                            T,Q,R,H,Z,mm,pp,rr,Zflag,diffuse_periods, occbin_);
+            if occbin_.status && isinf(LIK)
+                fval = Inf;
+                info(1) = 320;
+                exit_flag = 0;
+                return
+            end
         end
     end
     if analytic_derivation
diff --git a/matlab/get_error_message.m b/matlab/get_error_message.m
index f59cac2842..1013184d69 100644
--- a/matlab/get_error_message.m
+++ b/matlab/get_error_message.m
@@ -188,6 +188,8 @@ switch info(1)
         message = 'Occbin: Simulation did not converge, increase maxit or check_ahead_periods.';        
     case 312
         message = 'Occbin: Constraint(s) are binding at the end of the sample.';        
+    case 320
+        message = 'Piecewise linear Kalman filter: There was a problem in obtaining the likelihood.';        
     otherwise
         message = 'This case shouldn''t happen. Contact the authors of Dynare';
 end
\ No newline at end of file
-- 
GitLab