From 1e2fb88d326bed478ba9f69e37fc89db628457c6 Mon Sep 17 00:00:00 2001
From: Johannes Pfeifer <jpfeifer@gmx.de>
Date: Wed, 23 Nov 2022 15:37:12 +0100
Subject: [PATCH] IVF: fix error handling for smoother

---
 matlab/+occbin/IVF_posterior.m | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/matlab/+occbin/IVF_posterior.m b/matlab/+occbin/IVF_posterior.m
index 5959d8ba13..2783e2b1c4 100644
--- a/matlab/+occbin/IVF_posterior.m
+++ b/matlab/+occbin/IVF_posterior.m
@@ -106,7 +106,14 @@ filtered_errs_init = zeros(sample_length,sum(err_index));
 if info(1)
     fval = Inf;
     exit_flag = 0;
+    atT=NaN(size(stateval(:,DynareResults.dr.order_var)'));
+    innov=NaN(Model.exo_nbr,sample_length);
     return
+else
+    atT = stateval(:,DynareResults.dr.order_var)';
+    innov = zeros(Model.exo_nbr,sample_length);
+    innov(diag(Model.Sigma_e)~=0,:)=filtered_errs';
+    updated_variables = atT*nan;
 end
 nobs=size(filtered_errs,1);
 
@@ -185,10 +192,7 @@ end
 % remember that the likelihood has already been multiplied by -1
 % hence, posterior is -1 times the log of the prior
 fval = like+prior;
-atT = stateval(:,DynareResults.dr.order_var)';
-innov = zeros(Model.exo_nbr,sample_length);
-innov(diag(Model.Sigma_e)~=0,:)=filtered_errs';
-updated_variables = atT*nan;
+
 BayesInfo.mf = BayesInfo.smoother_var_list(BayesInfo.smoother_mf);
 
 
-- 
GitLab