Merge branch 'rattoma/dynare-smoother_fixes'

Ref. !1847
time-shift
Sébastien Villemot 2021-05-07 16:35:36 +02:00
commit 088fd64114
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
3 changed files with 16 additions and 10 deletions

View File

@ -211,10 +211,12 @@ while notsteady && t<smpl
P(:,:,t+1) = T*P(:,:,t)*L(:,:,t)' + QQ;
end
a(:,t+1) = T*atilde(:,t);
Pf = P(:,:,t);
Pf = P(:,:,t+1);
aK(1,:,t+1) = a(:,t+1);
for jnk=1:nk
Pf = T*Pf*T' + QQ;
if jnk>1
Pf = T*Pf*T' + QQ;
end
PK(jnk,:,:,t+jnk) = Pf;
if jnk>1
aK(jnk,:,t+jnk) = T*dynare_squeeze(aK(jnk-1,:,t+jnk-1));

View File

@ -1,5 +1,5 @@
function [alphahat,epsilonhat,etahat,a,P,aK,PK,decomp,V] = missing_DiffuseKalmanSmootherH3_Z(a_initial,T,Z,R,Q,H,Pinf1,Pstar1,Y,pp,mm,smpl,data_index,nk,kalman_tol,diffuse_kalman_tol,decomp_flag,state_uncertainty_flag)
% function [alphahat,epsilonhat,etahat,a1,P,aK,PK,d,decomp] = missing_DiffuseKalmanSmootherH3_Z(T,Z,R,Q,H,Pinf1,Pstar1,Y,pp,mm,smpl,data_index,nk,kalman_tol,decomp_flag,state_uncertainty_flag)
function [alphahat,epsilonhat,etahat,a,P1,aK,PK,decomp,V] = missing_DiffuseKalmanSmootherH3_Z(a_initial,T,Z,R,Q,H,Pinf1,Pstar1,Y,pp,mm,smpl,data_index,nk,kalman_tol,diffuse_kalman_tol,decomp_flag,state_uncertainty_flag)
% function [alphahat,epsilonhat,etahat,a1,P1,aK,PK,d,decomp] = missing_DiffuseKalmanSmootherH3_Z(T,Z,R,Q,H,Pinf1,Pstar1,Y,pp,mm,smpl,data_index,nk,kalman_tol,decomp_flag,state_uncertainty_flag)
% Computes the diffuse kalman smoother in the case of a singular var-cov matrix.
% Univariate treatment of multivariate time series.
%
@ -31,7 +31,7 @@ function [alphahat,epsilonhat,etahat,a,P,aK,PK,decomp,V] = missing_DiffuseKalman
% a: matrix of updated variables (a_{t|t})
% aK: 3D array of k step ahead filtered state variables (a_{t+k|t})
% (meaningless for periods 1:d)
% P: 3D array of one-step ahead forecast error variance
% P1: 3D array of one-step ahead forecast error variance
% matrices
% PK: 4D array of k-step ahead forecast error variance
% matrices (meaningless for periods 1:d)
@ -221,18 +221,21 @@ while notsteady && t<smpl
end
end
a1(:,t+1) = T*a(:,t); %transition according to (6.14) in DK (2012)
Pf = P(:,:,t);
P(:,:,t+1) = T*P(:,:,t)*T' + QQ; %transition according to (6.14) in DK (2012)
Pf = P(:,:,t+1);
aK(1,:,t+1) = a1(:,t+1);
for jnk=1:nk
Pf = T*Pf*T' + QQ;
if jnk>1
Pf = T*Pf*T' + QQ;
end
PK(jnk,:,:,t+jnk) = Pf;
if jnk>1
aK(jnk,:,t+jnk) = T*dynare_squeeze(aK(jnk-1,:,t+jnk-1));
end
end
P(:,:,t+1) = T*P(:,:,t)*T' + QQ; %transition according to (6.14) in DK (2012)
% notsteady = ~(max(max(abs(P(:,:,t+1)-P(:,:,t))))<kalman_tol);
end
P1(:,:,t+1) = P(:,:,t+1);
% $$$ P_s=tril(P(:,:,t))+tril(P(:,:,t),-1)';
% $$$ P1_s=tril(P1(:,:,t))+tril(P1(:,:,t),-1)';
% $$$ Fi_s = Fi(:,t);

View File

@ -34,8 +34,9 @@ function [oo_, yf]=store_smoother_results(M_,oo_,options_,bayestopt_,dataset_,da
% oo_.Smoother.Variance: one-step ahead forecast error variance (declaration order)
% oo_.Smoother.Constant: structure storing the constant term of the smoother
% oo_.Smoother.Trend: structure storing the trend term of the smoother
% oo_.FilteredVariablesKStepAhead: k-step ahead forecast error variance matrices (decision-rule order)
% oo_.FilteredVariablesShockDecomposition: shock decomposition of k-step ahead filtered variables (decision-rule order)
% oo_.FilteredVariablesKStepAhead: k-step ahead filtered variables (declaration order)
% oo_.FilteredVariablesKStepAheadVariances: k-step ahead forecast error variance matrices (declaration order)
% oo_.FilteredVariablesShockDecomposition: shock decomposition of k-step ahead filtered variables (declaration order)
% oo_.FilteredVariables: structure storing the filtered variables
% oo_.UpdatedVariables: structure storing the updated variables
% oo_.SmoothedShocks: structure storing the smoothed shocks