Harmonize output of local_state_space_iteration_k and local_state_space_iteration_2
local_state_space_iteration_k has all endogenous variables as its output, while
local_state_space_iteration_2 has only
restrict_var_list (i.e. drops static variables that are not observed). Nevertheless in pretty much all particle filters we have code like
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 PredictionError = bsxfun(@minus,Y(:,t),tmp(mf1,:));
mf1 is the position of the observables in
restrict_var_list. Consequently, the use of
k_order_solver will generally return wrong result as we are reading out the wrong variables. There are two ways of fixing this:
- Change indexing for reading out to
restrict_var_list(mf1)in various subfunctions
- Make the output of
local_state_space_iteration_2consistent to output only
I would prefer option 2 as it makes the code faster and we do not need to introduce additional case distinctions that make the code hard to parse.
local_state_space_iteration_2 is about 60 times faster than
local_state_space_iteration_k at the same
order=2, see https://git.dynare.org/Dynare/dynare/-/blob/master/tests/particle/local_state_space_iteration_k_test.mod so any changes should keep this in mind.