particle filter dynare

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

particle filter dynare

Postby HouseC » Wed Oct 19, 2016 11:56 am

Dears,

I search the internet and realized that Dynare could use particle filter when using Bayesian estimation. Is there any example code to show how to call it. I understand that the we need to set "order =2" within the options of estimation. But how about the rest of model?

Best,
House
HouseC
 
Posts: 41
Joined: Fri Apr 19, 2013 3:36 am

Re: particle filter dynare

Postby jpfeifer » Wed Oct 19, 2016 3:10 pm

------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: particle filter dynare

Postby HouseC » Sat Oct 22, 2016 5:59 pm

jpfeifer wrote:The current test files are at https://github.com/DynareTeam/dynare/tree/master/tests/particle

Dear Johannes,
Many thanks for the link. While I trying to run the linear_model.mod file. It seems that the datafile "linear_model_data" is missing. Is it possible to share this datafile so that the code could be runned.
Besides, dynare 4.4.3 fails to understand "filter_algorithm=sis" when estimation command tries to call it, could you please suggest which version of dynare could be useful?

Best,
House
HouseC
 
Posts: 41
Joined: Fri Apr 19, 2013 3:36 am

Re: particle filter dynare

Postby jpfeifer » Sat Oct 22, 2016 6:05 pm

1. You need to use the unstable version.
2. The
Code: Select all
linear_model_data.mat
is generated by first running https://github.com/DynareTeam/dynare/blob/master/tests/particle/linear_model.mod
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: particle filter dynare

Postby HouseC » Sat Oct 22, 2016 6:26 pm

jpfeifer wrote:1. You need to use the unstable version.
2. The
Code: Select all
linear_model_data.mat
is generated by first running https://github.com/DynareTeam/dynare/blob/master/tests/particle/linear_model.mod


Thanks for patient reply. The first question is silly.
When I use the unstable version of 20160802 and choose either 0 or 6 for mode-finder, the error message appears:
Error using print_info (line 110)
Likelihood is not a number (NaN) or a complex number
Error in print_info (line 110)
error('Likelihood is not a number (NaN) or a complex number');
Error in initial_estimation_checks (line 142)
print_info(info, DynareOptions.noprint, DynareOptions)
Error in dynare_estimation_1 (line 159)
oo_ =
initial_estimation_checks(objective_function,xparam1,dataset_,dataset_info,M_,estim_params_,options_,bayestopt_,bounds,oo_);
Error in dynare_estimation (line 105)
dynare_estimation_1(var_list,dname);
Error in linear_model (line 182)
oo_recursive_=dynare_estimation(var_list_);
Error in dynare (line 223)
evalin('base',fname) ;


Should I try the most updated version of Dynare? Or it's a bug to fix?
HouseC
 
Posts: 41
Joined: Fri Apr 19, 2013 3:36 am

Re: particle filter dynare

Postby jpfeifer » Mon Oct 24, 2016 9:22 am

The
Code: Select all
linear_model.mod

file seems to be very outdated. I will try to look into it.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: particle filter dynare

Postby HouseC » Mon Oct 24, 2016 1:21 pm

jpfeifer wrote:The
Code: Select all
linear_model.mod

file seems to be very outdated. I will try to look into it.

Thanks. Please keep me updated.
HouseC
 
Posts: 41
Joined: Fri Apr 19, 2013 3:36 am

Re: particle filter dynare

Postby jpfeifer » Mon Oct 24, 2016 2:06 pm

Attached is a working version of the model.
Attachments
linear_model.mod
Updated version compatible with unstable version of October 2016
(1.16 KiB) Downloaded 87 times
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: particle filter dynare

Postby HouseC » Tue Oct 25, 2016 2:16 pm

jpfeifer wrote:Attached is a working version of the model.


Dear Johannes,

Thanks for the code. It works.
Yet I try to understand the code structure and hope to hear your comments.
1. on prior distribution. In the specified estimated_params; All parameters are not specified the distribution, is it proper to do that?
Code: Select all
estimated_params;
a1,  .50;
a2,  .00;
a3,  .70;
a4,  .40;
b1,  .90;
b2,  .00;
b3,  .80;
c1,  .95;
stderr u, .05;
stderr v, .05;
stderr y, 0.01;
stderr z, 0.01;
end;


2. on the option choice. I understands that they are to do with particle filter. Is there any user manual to deal with these options? I just to understand the meaning of each options behind.
Code: Select all
options_.particle.status = 1;
options_.particle.initialization = 1;
options_.particle.pruning = 0;
options_.particle.number_of_particles = 20000;
particle.resampling.status.systematic = 1;
options_.particle.resampling.neff_threshold = .1;

options_.gstep(1) = 1e-4;
options_.gstep(2) = .1;

options_.mode_check_neighbourhood_size = 0.05;

set_dynare_threads('local_state_space_iteration_2',3);


Best,
House
HouseC
 
Posts: 41
Joined: Fri Apr 19, 2013 3:36 am

Re: particle filter dynare

Postby jpfeifer » Tue Oct 25, 2016 5:54 pm

1. The first part just means we are doing maximum likelihood instead of Bayesian estimation. That can easily be changed.
2. Please have a look at the manual of the unstable version where most of the options should be (implicitly) defined. The
Code: Select all
gstep
sets the gradient step size for numerical gradients and should usually not be altered.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: particle filter dynare

Postby HouseC » Wed Oct 26, 2016 1:16 am

jpfeifer wrote:1. The first part just means we are doing maximum likelihood instead of Bayesian estimation. That can easily be changed.
2. Please have a look at the manual of the unstable version where most of the options should be (implicitly) defined. The
Code: Select all
gstep
sets the gradient step size for numerical gradients and should usually not be altered.


1. I change your shared code in the block of estimated_params; by specifying the distribution AND keep other commands unchanged. In this case, I guess we are doing bayesian estimation.
Code: Select all
estimated_params;

a1, , , , normal_pdf, 0.5, 0.05;
a2, , , , normal_pdf, 0.0, 0.05;
a3, , , ,normal_pdf, 0.7, 0.05;
a4, , , ,normal_pdf, 0.4, 0.05;

b1, , , , normal_pdf, 0.9, 0.05;
b2, , , ,normal_pdf, 0.0, 0.05;
b3, , , ,normal_pdf, 0.8, 0.05;
c1, , , , normal_pdf, 0.95, 0.05;

stderr u, , , , gamma_pdf, 0.05, 0.05;
stderr v, , , , gamma_pdf, 0.05, 0.05;
stderr y, , , ,gamma_pdf, 0.05, 0.05;
stderr z, , , ,gamma_pdf, 0.05, 0.05;
end;


Running this mode file results in the following error message:
Error using chol
Matrix must be positive definite.
Error in sequential_importance_particle_filter (line 74)
StateVectorVarianceSquareRoot =
chol(ReducedForm.StateVectorVariance)';%reduced_rank_cholesky(ReducedForm.StateVectorVariance)';
Error in non_linear_dsge_likelihood (line 333)
LIK =
feval(DynareOptions.particle.algorithm,ReducedForm,Y,start,DynareOptions.particle,DynareOptions.threads);
Error in cmaes (line 948)
fitness.raw(k) = feval(fitfun, arxvalid(:,k), varargin{:});
Error in dynare_minimize_objective (line 361)
[x, fval, COUNTEVAL, STOPFLAG, OUT, BESTEVER] =
cmaes(func2str(objective_function),start_par_value,H0,cmaesOptions,varargin{:});
Error in dynare_estimation_1 (line 199)
[xparam1, fval, exitflag, hh, options_, Scale, new_rat_hess_info] =
dynare_minimize_objective(objective_function,xparam1,options_.mode_compute,options_,[bounds.lb
bounds.ub],bayestopt_.name,bayestopt_,hh,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
Error in dynare_estimation (line 105)
dynare_estimation_1(var_list,dname);
Error in linear_model (line 185)
oo_recursive_=dynare_estimation(var_list_);
Error in dynare (line 223)
evalin('base',fname) ;


I checked the user manual and it says "mode_compute=9" call an evolutionary algorithm for difficult non-linear non-convex optimization and "mode_compute=6" uses a Monte-Carlo based optimization routine. In this case, it seems using "mode_compute=6" is still acceptable. Then I change the estimation options and use
Code: Select all
mode_compute=6
instead of
Code: Select all
mode_compute=9
. The modified mod file could be called without error message. But the system is ineffective and updated the mode after several hours. Is it proper to modify the code in this way?

2. I search the user manual for unstable version using key words "options" and "particle". It seems that the manual mentions these key words in the estimation command. Yet, it does not mention "options_.particle". Yet I guess the following matlab file helps to understand why we need to specify the options. http://www.dynare.org/dynare-matlab-m2html/matlab/global_initialization.html
HouseC
 
Posts: 41
Joined: Fri Apr 19, 2013 3:36 am

Re: particle filter dynare

Postby jpfeifer » Wed Oct 26, 2016 6:06 pm

1. Yes, using a non-uniform prior is fine and running a different mode-finder is also OK.
2. In the manual to the unstable version you will see the estimation options for the particle filter after
Code: Select all
number_of_particles = INTEGER

What the interface does is setting the respective fields of
Code: Select all
options_.particle

As you found out, these are initialized in
Code: Select all
global_initialization.m

Only some of these options are accessible via the estimation interface, because they are not intended for basic users to change. Instead of setting options via the interface, you can always directly set the options before the command if you know the name of these
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: particle filter dynare

Postby HouseC » Fri Oct 28, 2016 5:41 am

jpfeifer wrote:1. Yes, using a non-uniform prior is fine and running a different mode-finder is also OK.
2. In the manual to the unstable version you will see the estimation options for the particle filter after
Code: Select all
number_of_particles = INTEGER

What the interface does is setting the respective fields of
Code: Select all
options_.particle

As you found out, these are initialized in
Code: Select all
global_initialization.m

Only some of these options are accessible via the estimation interface, because they are not intended for basic users to change. Instead of setting options via the interface, you can always directly set the options before the command if you know the name of these


Dear Johannes,
Sorry for late reply and thanks for your comments.
I try to run the linear model with bayesian estimation. However, my labtop cannot find the mode after days of searching. It seems that running particle filter is extremely time-inefficient and demands lots of computational power.

Best,
House
HouseC
 
Posts: 41
Joined: Fri Apr 19, 2013 3:36 am

Re: particle filter dynare

Postby jpfeifer » Fri Oct 28, 2016 4:57 pm

Yes, indeed the particle filter is computationally expensive. That is why we rely on the Kalman filter for linear models.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: particle filter dynare

Postby shengan28 » Sat Oct 29, 2016 9:13 pm

Where is this user manual for the unstable version. Specifically for the particle filter syntax?
shengan28
 
Posts: 13
Joined: Mon Jul 20, 2015 11:24 pm

Next

Return to Dynare help

Who is online

Users browsing this forum: No registered users and 9 guests