Commit 0b0c9398 authored by MichelJuillard's avatar MichelJuillard

fixing bug with smoother with univariate filters

parent 9d91625c
......@@ -525,6 +525,11 @@ if ((kalman_algo==1) || (kalman_algo==3))% Multivariate Kalman Filter
T,Q,R,H,Z,mm,pp,rr,Zflag,diffuse_periods);
end
if isinf(LIK)
if kalman_algo == 1
kalman_algo = 2;
else
kalman_algo = 4;
end
singularity_flag = 1;
else
if DynareOptions.lik_init==3
......
......@@ -165,7 +165,7 @@ if kalman_algo == 1 || kalman_algo == 3
Z,R1,Q,H,Pinf,Pstar, ...
data1,nobs,np,smpl,data_index, ...
options_.nk,kalman_tol,options_.filter_decomposition);
if isequal(alphahat,0)
if isinf(alphahat)
if kalman_algo == 1
kalman_algo = 2;
elseif kalman_algo == 3
......
......@@ -117,8 +117,12 @@ if isequal(options_.mode_compute,0) && isempty(options_.mode_file) && options_.m
end
for i=bayestopt_.smoother_saved_var_list'
i1 = dr.order_var(bayestopt_.smoother_var_list(i));
eval(['oo_.SmoothedVariables.' deblank(M_.endo_names(i1,:)) ' = atT(i,:)'';']);
eval(['oo_.FilteredVariables.' deblank(M_.endo_names(i1,:)) ' = squeeze(aK(1,i,:));']);
eval(['oo_.SmoothedVariables.' deblank(M_.endo_names(i1,:)) ...
' = atT(i,:)'';']);
if options_.nk > 0
eval(['oo_.FilteredVariables.' deblank(M_.endo_names(i1,:)) ...
' = squeeze(aK(1,i,:));']);
end
eval(['oo_.UpdatedVariables.' deblank(M_.endo_names(i1,:)) ' = updated_variables(i,:)'';']);
end
for i=1:M_.exo_nbr
......@@ -828,8 +832,12 @@ if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.psha
end
for i=bayestopt_.smoother_saved_var_list'
i1 = dr.order_var(bayestopt_.smoother_var_list(i));
eval(['oo_.SmoothedVariables.' deblank(M_.endo_names(i1,:)) ' = atT(i,:)'';']);
eval(['oo_.FilteredVariables.' deblank(M_.endo_names(i1,:)) ' = squeeze(aK(1,i,:));']);
eval(['oo_.SmoothedVariables.' deblank(M_.endo_names(i1,:)) ' = ' ...
'atT(i,:)'';']);
if options_.nk > 0
eval(['oo_.FilteredVariables.' deblank(M_.endo_names(i1,:)) ...
' = squeeze(aK(1,i,:));']);
end
eval(['oo_.UpdatedVariables.' deblank(M_.endo_names(i1,:)) ...
' = updated_variables(i,:)'';']);
end
......
......@@ -106,12 +106,14 @@ while rank(Pinf(:,:,t+1),crit1) && t<smpl
if rcond(Finf) < kalman_tol
if ~all(abs(Finf(:)) < kalman_tol)
% The univariate diffuse kalman filter should be used.
alphahat = Inf;
return
else
Fstar(:,:,t) = ZZ*Pstar(:,:,t)*ZZ' + H(di,di);
if rcond(Fstar(:,:,t)) < kalman_tol
if ~all(abs(Fstar(:,:,t))<kalman_tol)
% The univariate diffuse kalman filter should be used.
alphahat = Inf;
return
else
a(:,:,t+1) = T*a(:,:,t);
......@@ -167,6 +169,7 @@ while notsteady && t<smpl
v(di,t) = Y(di,t) - ZZ*a(:,t);
F = ZZ*P(:,:,t)*ZZ' + H(di,di);
if rcond(F) < kalman_tol
alphahat = Inf;
return
end
iF(di,di,t) = inv(F);
......
......@@ -34,8 +34,7 @@ end;
varobs dw dx dy z;
//estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0);
estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,mode_compute=0,mode_file=algoH1_mode);
estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0);
//checking smoother consistency
X = oo_.SmoothedVariables;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment