From 13d79cb4382ade3b74a4509fdd8ddad3d273ffaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 20 Dec 2019 11:21:13 +0100 Subject: [PATCH] Allow k order approximation in SIP filter. --- src/sequential_importance_particle_filter.m | 26 ++++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/sequential_importance_particle_filter.m b/src/sequential_importance_particle_filter.m index 72a789ccd..526ee825f 100644 --- a/src/sequential_importance_particle_filter.m +++ b/src/sequential_importance_particle_filter.m @@ -1,4 +1,4 @@ -function [LIK,lik] = sequential_importance_particle_filter(ReducedForm,Y,start,ParticleOptions,ThreadsOptions) +function [LIK,lik] = sequential_importance_particle_filter(ReducedForm,Y,start,ParticleOptions,ThreadsOptions, DynareOptions, Model) % Evaluates the likelihood of a nonlinear model with a particle filter (optionally with resampling). @@ -49,14 +49,18 @@ if isempty(init_flag) init_flag = 1; end -% Set local state space model (first order approximation). -ghx = ReducedForm.ghx; -ghu = ReducedForm.ghu; +if ReducedForm.use_k_order_solver + dr = ReducedForm.dr; +else + % Set local state space model (first order approximation). + ghx = ReducedForm.ghx; + ghu = ReducedForm.ghu; -% Set local state space model (second order approximation). -ghxx = ReducedForm.ghxx; -ghuu = ReducedForm.ghuu; -ghxu = ReducedForm.ghxu; + % Set local state space model (second order approximation). + ghxx = ReducedForm.ghxx; + ghuu = ReducedForm.ghuu; + ghxu = ReducedForm.ghxu; +end % Get covariance matrices. Q = ReducedForm.Q; % Covariance matrix of the structural innovations. @@ -101,7 +105,11 @@ for t=1:sample_size yhat_ = bsxfun(@minus,StateVectors_,state_variables_steady_state); [tmp, tmp_] = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,yhat_,steadystate,ThreadsOptions.local_state_space_iteration_2); else - tmp = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,ThreadsOptions.local_state_space_iteration_2); + if ReducedForm.use_k_order_solver + tmp = local_state_space_iteration_k(yhat, epsilon, dr, Model, DynareOptions); + else + tmp = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,ThreadsOptions.local_state_space_iteration_2); + end end %PredictedObservedMean = tmp(mf1,:)*transpose(weights); PredictionError = bsxfun(@minus,Y(:,t),tmp(mf1,:));