diff --git a/tests/pruning/AnSchorfheide_pruned_state_space.mod b/tests/pruning/AnSchorfheide_pruned_state_space.mod index 9afd133b8..4858f7318 100644 --- a/tests/pruning/AnSchorfheide_pruned_state_space.mod +++ b/tests/pruning/AnSchorfheide_pruned_state_space.mod @@ -143,51 +143,51 @@ for iorder = 1:3 error('Something wrong with pruned_state_space.m compared to Andreasen et al 2018 Toolbox v2 at order %d.',iorder); end end -skipline(); -fprintf('Note that at third order, there is an error in the computation of Var_z in Andreasen et al (2018)''s toolbox, @wmutschl is in contact to clarify this.\n'); -fprintf('EXAMPLE:\n') -fprintf(' Consider Var[kron(kron(xf,xf),xf)] = E[kron(kron(kron(kron(kron(xf,xf),xf),xf),xf),xf)] - E[kron(kron(xf,xf),xf)]*E[kron(kron(xf,xf),xf)].''\n'); -fprintf(' Now note that xf=hx*xf(-1)+hu*u is Gaussian, that is E[kron(kron(xf,xf),xf)]=0, and Var[kron(kron(xf,xf),xf)] are the sixth-order product moments\n'); -fprintf(' which can be computed using the prodmom.m function by providing E[xf*xf''] as covariance matrix.\n'); -fprintf(' In order to replicate this you have to change UnconditionalMoments_3rd_Lyap.m to also output Var_z.\n') - -dynare_nx = M_.nspred; -dynare_E_xf2 = pruned_state_space.order_3.Var_z(1:dynare_nx,1:dynare_nx); -dynare_E_xf6 = pruned_state_space.order_3.Var_z((end-dynare_nx^3+1):end,(end-dynare_nx^3+1):end); -dynare_E_xf6 = dynare_E_xf6(:); - -Andreasen_nx = M_.nspred+M_.exo_nbr; -Andreasen_E_xf2 = outAndreasenetal.order_3.Var_z(1:Andreasen_nx,1:Andreasen_nx); -Andreasen_E_xf6 = outAndreasenetal.order_3.Var_z((end-Andreasen_nx^3+1):end,(end-Andreasen_nx^3+1):end); -Andreasen_E_xf6 = Andreasen_E_xf6(:); - -fprintf('Second-order product moments of xf and u are the same:\n') -norm_E_xf2 = norm(dynare_E_xf2-Andreasen_E_xf2(1:M_.nspred,1:M_.nspred),Inf) -norm_E_uu = norm(M_.Sigma_e-Andreasen_E_xf2(M_.nspred+(1:M_.exo_nbr),M_.nspred+(1:M_.exo_nbr)),Inf) - -% Compute unique sixth-order product moments of xf, i.e. unique(E[kron(kron(kron(kron(kron(xf,xf),xf),xf),xf),xf)],'stable') -dynare_nx6 = dynare_nx*(dynare_nx+1)/2*(dynare_nx+2)/3*(dynare_nx+3)/4*(dynare_nx+4)/5*(dynare_nx+5)/6; -dynare_Q6Px = Q6_plication(dynare_nx); -dynare_COMBOS6 = flipud(allVL1(dynare_nx, 6)); %all possible (unique) combinations of powers that sum up to six -dynare_true_E_xf6 = zeros(dynare_nx6,1); %only unique entries -for j6 = 1:size(dynare_COMBOS6,1) - dynare_true_E_xf6(j6) = prodmom(dynare_E_xf2, 1:dynare_nx, dynare_COMBOS6(j6,:)); -end -dynare_true_E_xf6 = dynare_Q6Px*dynare_true_E_xf6; %add duplicate entries -norm_dynare_E_xf6 = norm(dynare_true_E_xf6 - dynare_E_xf6, Inf); - -Andreasen_nx6 = Andreasen_nx*(Andreasen_nx+1)/2*(Andreasen_nx+2)/3*(Andreasen_nx+3)/4*(Andreasen_nx+4)/5*(Andreasen_nx+5)/6; -Andreasen_Q6Px = Q6_plication(Andreasen_nx); -Andreasen_COMBOS6 = flipud(allVL1(Andreasen_nx, 6)); %all possible (unique) combinations of powers that sum up to six -Andreasen_true_E_xf6 = zeros(Andreasen_nx6,1); %only unique entries -for j6 = 1:size(Andreasen_COMBOS6,1) - Andreasen_true_E_xf6(j6) = prodmom(Andreasen_E_xf2, 1:Andreasen_nx, Andreasen_COMBOS6(j6,:)); -end -Andreasen_true_E_xf6 = Andreasen_Q6Px*Andreasen_true_E_xf6; %add duplicate entries -norm_Andreasen_E_xf6 = norm(Andreasen_true_E_xf6 - Andreasen_E_xf6, Inf); - -fprintf('Sixth-order product moments of xf and u are not the same!\n'); -fprintf(' Dynare maximum absolute deviations of sixth-order product moments of xf: %d\n',norm_dynare_E_xf6) -fprintf(' Andreasen et al maximum absolute deviations of sixth-order product moments of xf: %d\n',norm_Andreasen_E_xf6) -skipline(); -fprintf('Note that the standard deviations are set quite high to make the numerical differences more apparent.\n'); +% skipline(); +% fprintf('Note that at third order, there is an error in the computation of Var_z in Andreasen et al (2018)''s toolbox, @wmutschl is in contact to clarify this.\n'); +% fprintf('EXAMPLE:\n') +% fprintf(' Consider Var[kron(kron(xf,xf),xf)] = E[kron(kron(kron(kron(kron(xf,xf),xf),xf),xf),xf)] - E[kron(kron(xf,xf),xf)]*E[kron(kron(xf,xf),xf)].''\n'); +% fprintf(' Now note that xf=hx*xf(-1)+hu*u is Gaussian, that is E[kron(kron(xf,xf),xf)]=0, and Var[kron(kron(xf,xf),xf)] are the sixth-order product moments\n'); +% fprintf(' which can be computed using the prodmom.m function by providing E[xf*xf''] as covariance matrix.\n'); +% fprintf(' In order to replicate this you have to change UnconditionalMoments_3rd_Lyap.m to also output Var_z.\n') +% +% dynare_nx = M_.nspred; +% dynare_E_xf2 = pruned_state_space.order_3.Var_z(1:dynare_nx,1:dynare_nx); +% dynare_E_xf6 = pruned_state_space.order_3.Var_z((end-dynare_nx^3+1):end,(end-dynare_nx^3+1):end); +% dynare_E_xf6 = dynare_E_xf6(:); +% +% Andreasen_nx = M_.nspred+M_.exo_nbr; +% Andreasen_E_xf2 = outAndreasenetal.order_3.Var_z(1:Andreasen_nx,1:Andreasen_nx); +% Andreasen_E_xf6 = outAndreasenetal.order_3.Var_z((end-Andreasen_nx^3+1):end,(end-Andreasen_nx^3+1):end); +% Andreasen_E_xf6 = Andreasen_E_xf6(:); +% +% fprintf('Second-order product moments of xf and u are the same:\n') +% norm_E_xf2 = norm(dynare_E_xf2-Andreasen_E_xf2(1:M_.nspred,1:M_.nspred),Inf) +% norm_E_uu = norm(M_.Sigma_e-Andreasen_E_xf2(M_.nspred+(1:M_.exo_nbr),M_.nspred+(1:M_.exo_nbr)),Inf) +% +% % Compute unique sixth-order product moments of xf, i.e. unique(E[kron(kron(kron(kron(kron(xf,xf),xf),xf),xf),xf)],'stable') +% dynare_nx6 = dynare_nx*(dynare_nx+1)/2*(dynare_nx+2)/3*(dynare_nx+3)/4*(dynare_nx+4)/5*(dynare_nx+5)/6; +% dynare_Q6Px = Q6_plication(dynare_nx); +% dynare_COMBOS6 = flipud(allVL1(dynare_nx, 6)); %all possible (unique) combinations of powers that sum up to six +% dynare_true_E_xf6 = zeros(dynare_nx6,1); %only unique entries +% for j6 = 1:size(dynare_COMBOS6,1) +% dynare_true_E_xf6(j6) = prodmom(dynare_E_xf2, 1:dynare_nx, dynare_COMBOS6(j6,:)); +% end +% dynare_true_E_xf6 = dynare_Q6Px*dynare_true_E_xf6; %add duplicate entries +% norm_dynare_E_xf6 = norm(dynare_true_E_xf6 - dynare_E_xf6, Inf); +% +% Andreasen_nx6 = Andreasen_nx*(Andreasen_nx+1)/2*(Andreasen_nx+2)/3*(Andreasen_nx+3)/4*(Andreasen_nx+4)/5*(Andreasen_nx+5)/6; +% Andreasen_Q6Px = Q6_plication(Andreasen_nx); +% Andreasen_COMBOS6 = flipud(allVL1(Andreasen_nx, 6)); %all possible (unique) combinations of powers that sum up to six +% Andreasen_true_E_xf6 = zeros(Andreasen_nx6,1); %only unique entries +% for j6 = 1:size(Andreasen_COMBOS6,1) +% Andreasen_true_E_xf6(j6) = prodmom(Andreasen_E_xf2, 1:Andreasen_nx, Andreasen_COMBOS6(j6,:)); +% end +% Andreasen_true_E_xf6 = Andreasen_Q6Px*Andreasen_true_E_xf6; %add duplicate entries +% norm_Andreasen_E_xf6 = norm(Andreasen_true_E_xf6 - Andreasen_E_xf6, Inf); +% +% fprintf('Sixth-order product moments of xf and u are not the same!\n'); +% fprintf(' Dynare maximum absolute deviations of sixth-order product moments of xf: %d\n',norm_dynare_E_xf6) +% fprintf(' Andreasen et al maximum absolute deviations of sixth-order product moments of xf: %d\n',norm_Andreasen_E_xf6) +% skipline(); +% fprintf('Note that the standard deviations are set quite high to make the numerical differences more apparent.\n');