diff --git a/matlab/initial_estimation_checks.m b/matlab/initial_estimation_checks.m index 45189b0b18aac5da90e219d662bcd1fb4fc965f4..73637948c9ddb68e9e3019ccfce31317b2842cdf 100644 --- a/matlab/initial_estimation_checks.m +++ b/matlab/initial_estimation_checks.m @@ -75,7 +75,12 @@ test_for_deep_parameters_calibration(Model); % Evaluate the likelihood. ana_deriv = DynareOptions.analytic_derivation; DynareOptions.analytic_derivation=0; -[fval,junk1,junk2,a,b,c,d] = feval(objective_function,xparam1,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults); +if ~isequal(DynareOptions.mode_compute,11) + [fval,junk1,junk2,a,b,c,d] = feval(objective_function,xparam1,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults); +else + b=0; + fval = 0; +end DynareOptions.analytic_derivation=ana_deriv; if DynareOptions.dsge_var || strcmp(func2str(objective_function),'non_linear_dsge_likelihood') @@ -106,4 +111,6 @@ if any(abs(DynareResults.steady_state(BayesInfo.mfys))>1e-9) && (DynareOptions.p error('You should change something in your mod file...') end -disp(['Initial value of the log posterior (or likelihood): ' num2str(-fval)]); +if ~isequal(DynareOptions.mode_compute,11) + disp(['Initial value of the log posterior (or likelihood): ' num2str(-fval)]); +end diff --git a/matlab/particle/online_auxiliary_filter.m b/matlab/particle/online_auxiliary_filter.m index 4a8243a2df7391658b5f8630c6ca22369c194df1..1edcb66b9f7750a1745a2bba40493d95cce6e2ab 100644 --- a/matlab/particle/online_auxiliary_filter.m +++ b/matlab/particle/online_auxiliary_filter.m @@ -85,8 +85,8 @@ small_a = sqrt(1-h_square) ; % Initialization of parameter particles xparam = zeros(number_of_parameters,number_of_particles) ; -stderr = sqrt(bsxfun(@power,bounds(:,2)+bounds(:,1),2)/12)/100 ; -stderr = sqrt(bsxfun(@power,bounds(:,2)+bounds(:,1),2)/12)/50 ; +%stderr = sqrt(bsxfun(@power,bounds(:,2)+bounds(:,1),2)/12)/100 ; +stderr = sqrt(bsxfun(@power,bounds(:,2)+bounds(:,1),2)/12)/10 ; i = 1 ; while i<=number_of_particles %candidate = start_param + .001*liu_west_chol_sigma_bar*randn(number_of_parameters,1) ; @@ -110,7 +110,10 @@ std_xparam = zeros(number_of_parameters,sample_size) ; lb95_xparam = zeros(number_of_parameters,sample_size) ; ub95_xparam = zeros(number_of_parameters,sample_size) ; -%% The Online filter +disp(0) +disp(start_param) + + %% The Online filter for t=1:sample_size disp(t) % Moments of parameters particles distribution diff --git a/matlab/particle/solve_model_for_online_filter.m b/matlab/particle/solve_model_for_online_filter.m index a9cefe4074195ebd81372bae489b1ab6d31ee9fa..31fb7f7e69960c27c4a2cb5173a0290385ac9349 100644 --- a/matlab/particle/solve_model_for_online_filter.m +++ b/matlab/particle/solve_model_for_online_filter.m @@ -307,11 +307,18 @@ end ReducedForm.ghx = dr.ghx(restrict_variables_idx,:); ReducedForm.ghu = dr.ghu(restrict_variables_idx,:); -ReducedForm.ghxx = dr.ghxx(restrict_variables_idx,:); -ReducedForm.ghuu = dr.ghuu(restrict_variables_idx,:); -ReducedForm.ghxu = dr.ghxu(restrict_variables_idx,:); ReducedForm.steadystate = dr.ys(dr.order_var(restrict_variables_idx)); -ReducedForm.constant = ReducedForm.steadystate + .5*dr.ghs2(restrict_variables_idx); +if DynareOptions.order>1 + ReducedForm.ghxx = dr.ghxx(restrict_variables_idx,:); + ReducedForm.ghuu = dr.ghuu(restrict_variables_idx,:); + ReducedForm.ghxu = dr.ghxu(restrict_variables_idx,:); + ReducedForm.constant = ReducedForm.steadystate + .5*dr.ghs2(restrict_variables_idx); +else + ReducedForm.ghxx = zeros(size(restrict_variables_idx,1),size(dr.kstate,2)); + ReducedForm.ghuu = zeros(size(restrict_variables_idx,1),size(dr.ghu,2)); + ReducedForm.ghxu = zeros(size(restrict_variables_idx,1),size(dr.ghx,2)); + ReducedForm.constant = ReducedForm.steadystate ; +end ReducedForm.state_variables_steady_state = dr.ys(dr.order_var(state_variables_idx)); ReducedForm.Q = Q; ReducedForm.H = H; diff --git a/tests/particle/dsge_base2.mod b/tests/particle/dsge_base2.mod index 9ebb71fef310c6edb064dd3c0463f34b46a451e2..448072aa385fc5016c0a90535a0fabf680df9744 100644 --- a/tests/particle/dsge_base2.mod +++ b/tests/particle/dsge_base2.mod @@ -35,26 +35,39 @@ steady; //disp(oo_.mean) ; estimated_params; -alp, uniform_pdf,,, 0.0001, 0.5; +alp, uniform_pdf,,, 0.0001, 0.99; bet, uniform_pdf,,, 0.0001, 0.99; tet, uniform_pdf,,, 0.0001, 1; tau, uniform_pdf,,, 0.0001, 100; delt, uniform_pdf,,, 0.0001, 0.05; -rho, uniform_pdf,,, 0.8, 0.99; +rho, uniform_pdf,,, 0.0001, 0.99; stderr e_a, uniform_pdf,,, 0.00001, 0.1; stderr y, uniform_pdf,,, 0.00001, 0.1; stderr l, uniform_pdf,,, 0.00001, 0.1; stderr i, uniform_pdf,,, 0.00001, 0.1; end; +//estimated_params_init; +//alp, 0.4; +//bet, 0.99; +//tet, 0.357 ; +//tau, 50; +//delt, 0.02; +//rho, 0.95 ; +//stderr e_a, .035; +//stderr y, .0175;//.00158; +//stderr l, .00312;//.0011; +//stderr i, .00465;//.000866; +//end; + estimated_params_init; alp, 0.4; -bet, 0.97; -tet, 0.357 ; -tau, 50; -delt, 0.02; -rho, 0.9 ; -stderr e_a, .035; +bet, 0.98; +tet, 0.3; +tau, 30; +delt, 0.01; +rho, 0.85; +stderr e_a, .03; stderr y, .0175;//.00158; stderr l, .00312;//.0011; stderr i, .00465;//.000866; @@ -68,20 +81,20 @@ varobs y l i ; options_.particle.status = 1; options_.particle.initialization = 1; options_.particle.pruning = 0; -options_.particle.number_of_particles = 1000 ; +options_.particle.number_of_particles = 5000 ; options_.particle.resampling.status = 'systematic'; -//options_.particle.resampling.method1 = 'traditional' ; +options_.particle.resampling.method1 = 'traditional' ; //options_.particle.resampling.method1 = 'residual' ; -options_.particle.resampling.method1 = 'smooth' ; +//options_.particle.resampling.method1 = 'smooth' ; -options_.particle.reampling.method2 = 'kitagawa' ; -//options_.particle.resampling.method2 = 'stratified' ; +options_.particle.reampling.method2 = 'kitagawa' ;//'stratified' ; -options_.particle.resampling.number_of_partitions = 1; options_.particle.resampling.neff_threshold = .5; +options_.mode_check.neighbourhood_size = .2 ; +options_.mode_check.number_of_points = 250; -set_dynare_threads('local_state_space_iteration_2',3); +//set_dynare_threads('local_state_space_iteration_2',3); options_.particle.algorithm = 'sequential_importance_particle_filter'; //options_.particle.algorithm = 'auxiliary_particle_filter'; @@ -94,14 +107,14 @@ options_.particle.IS_approximation_method = 'cubature' ; //options_.particle.IS_approximation_method = 'unscented' ; //options_.particle.approximation_method = 'quadrature' ; -options_.particle.approximation_method = 'cubature' ; +//options_.particle.approximation_method = 'cubature' ; //options_.particle.approximation_method = 'unscented' ; //options_.particle.approximation_method = 'MonteCarlo' ; -//options_.mh_posterior_mode_estimation=1 ; +options_.mh_posterior_mode_estimation=0 ; // online -options_.particle.liu_west_delta = 0.9 ; +options_.particle.liu_west_delta = 0.99 ; options_.mode_check_node_number = 250 ; -estimation(datafile=data_risky_perturb2,nograph,order=2,nobs=100,mh_replic=0,mode_compute=7,mode_check); +estimation(datafile=data_risky_perturb3,order=1,nograph,nobs=100,mh_replic=0,mode_compute=11);