diff --git a/matlab/nonlinear-filters/online_auxiliary_filter.m b/matlab/nonlinear-filters/online_auxiliary_filter.m index 7495d4bc66c5d5d1602419d193c4f2e8ac0f0e23..62634eeccfde2fb97d64799d91b46e7335f1a8c9 100644 --- a/matlab/nonlinear-filters/online_auxiliary_filter.m +++ b/matlab/nonlinear-filters/online_auxiliary_filter.m @@ -143,9 +143,9 @@ for t=1:sample_size ghxx = ReducedForm.ghxx; ghuu = ReducedForm.ghuu; ghxu = ReducedForm.ghxu; - ghs2 = ReducedForm.ghs2; - if (order == 3) + if (order==3) % Set local state space model (third order approximation). + ghs2 = ReducedForm.ghs2; ghxxx = ReducedForm.ghxxx; ghuuu = ReducedForm.ghuuu; ghxxu = ReducedForm.ghxxu; @@ -171,7 +171,7 @@ for t=1:sample_size else if pruning yhat_ = bsxfun(@minus,StateVectors_(:,i),state_variables_steady_state_); - if order == 2 + if order <= 2 tmp = local_state_space_iteration_2(yhat, zeros(number_of_structural_innovations, 1), ghx, ghu, constant, ghxx, ghuu, ghxu, yhat_, steadystate, options_.threads.local_state_space_iteration_2); elseif order == 3 tmp = local_state_space_iteration_3(yhat_, zeros(number_of_structural_innovations, 1), ghx, ghu, ghxx, ghuu, ghxu, ghs2, ghxxx, ghuuu, ghxxu, ghxuu, ghxss, ghuss, steadystate, options_.threads.local_state_space_iteration_3, pruning); @@ -179,7 +179,7 @@ for t=1:sample_size error('Pruning is not available for orders > 3'); end else - if order == 2 + if order <= 2 tmp = local_state_space_iteration_2(yhat, zeros(number_of_structural_innovations, 1), ghx, ghu, constant, ghxx, ghuu, ghxu, options_.threads.local_state_space_iteration_2); elseif order == 3 tmp = local_state_space_iteration_3(yhat, zeros(number_of_structural_innovations, 1), ghx, ghu, ghxx, ghuu, ghxu, ghs2, ghxxx, ghuuu, ghxxu, ghxuu, ghxss, ghuss, steadystate, options_.threads.local_state_space_iteration_3, pruning); @@ -192,6 +192,8 @@ for t=1:sample_size % Replace Gaussian density with a Student density with 3 degrees of freedom for fat tails. z = sum(PredictionError.*(ReducedForm.H\PredictionError), 1) ; tau_tilde(i) = weights(i).*(tpdf(z, 3*ones(size(z)))+1e-99) ; + else + tau_tilde(i) = 0 ; end end % particles selection @@ -232,9 +234,9 @@ for t=1:sample_size ghxx = ReducedForm.ghxx; ghuu = ReducedForm.ghuu; ghxu = ReducedForm.ghxu; - ghs2 = ReducedForm.ghs2; if (order == 3) % Set local state space model (third order approximation). + ghs2 = ReducedForm.ghs2; ghxxx = ReducedForm.ghxxx; ghuuu = ReducedForm.ghuuu; ghxxu = ReducedForm.ghxxu; @@ -267,7 +269,7 @@ for t=1:sample_size else if pruning yhat_ = bsxfun(@minus,StateVectors_(:,i), state_variables_steady_state_); - if order == 2 + if order <= 2 [tmp, tmp_] = local_state_space_iteration_2(yhat, epsilon, ghx, ghu, constant, ghxx, ghuu, ghxu, yhat_, steadystate, options_.threads.local_state_space_iteration_2); elseif order == 3 [tmp, tmp_] = local_state_space_iteration_3(yhat_, epsilon, ghx, ghu, ghxx, ghuu, ghxu, ghs2, ghxxx, ghuuu, ghxxu, ghxuu, ghxss, ghuss, steadystate, options_.threads.local_state_space_iteration_3, pruning); @@ -276,7 +278,7 @@ for t=1:sample_size end StateVectors_(:,i) = tmp_(mf0_,:); else - if order == 2 + if order <= 2 tmp = local_state_space_iteration_2(yhat, epsilon, ghx, ghu, constant, ghxx, ghuu, ghxu, options_.threads.local_state_space_iteration_2); elseif order == 3 tmp = local_state_space_iteration_3(yhat, epsilon, ghx, ghu, ghxx, ghuu, ghxu, ghs2, ghxxx, ghuuu, ghxxu, ghxuu, ghxss, ghuss, steadystate, options_.threads.local_state_space_iteration_3, pruning); diff --git a/matlab/nonlinear-filters/solve_model_for_online_filter.m b/matlab/nonlinear-filters/solve_model_for_online_filter.m index f4a3e6af56071c39b618d23dc8aa0fa22fb66fc7..c7aa6785a9f0e4a0744778de618777d3b1e7016e 100644 --- a/matlab/nonlinear-filters/solve_model_for_online_filter.m +++ b/matlab/nonlinear-filters/solve_model_for_online_filter.m @@ -125,8 +125,8 @@ M_.H = H; %------------------------------------------------------------------------------ warning('off', 'MATLAB:nearlySingularMatrix') -[~, ~, ~, info, oo_.dr, M_.params] = ... - dynare_resolve(M_, options_, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state, 'restrict'); +[oo_.dr, info, M_.params] = ... + resol(0,M_, options_, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state); warning('on', 'MATLAB:nearlySingularMatrix') if info(1)~=0 @@ -174,6 +174,7 @@ if nargout>4 ReducedForm.ghuu = zeros(size(restrict_variables_idx,1),n_shocks^2); ReducedForm.ghxu = zeros(size(restrict_variables_idx,1),n_states*n_shocks); ReducedForm.constant = ReducedForm.steadystate; +% ReducedForm.ghs2 = dr.ghs2(restrict_variables_idx,:); end ReducedForm.state_variables_steady_state = dr.ys(dr.order_var(state_variables_idx)); ReducedForm.Q = Q;