diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index 36a42f80a..88fa04bfa 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -458,16 +458,17 @@ options_.prefilter = 0; options_.presample = 0; options_.prior_trunc = 1e-10; options_.smoother = 0; -options_.student_degrees_of_freedom = 3; options_.posterior_max_subsample_draws = 1200; options_.sub_draws = []; options_.use_mh_covariance_matrix = 0; options_.gradient_method = 2; %used by csminwel and newrat options_.gradient_epsilon = 1e-6; %used by csminwel and newrat options_.posterior_sampler_options = []; %extended set of options for individual posterior samplers -options_.posterior_sampling_method = 'random_walk_metropolis_hastings'; -options_.proposal_distribution = 'rand_multivariate_normal'; -options_.student_degrees_of_freedom = 3; +options_.posterior_sampler_options.posterior_sampling_method = 'random_walk_metropolis_hastings'; +options_.posterior_sampler_options.rwmh.proposal_distribution = 'rand_multivariate_normal'; +options_.posterior_sampler_options.rwmh.student_degrees_of_freedom = 3; +options_.posterior_sampler_options.tarb.proposal_distribution = 'rand_multivariate_normal'; +options_.posterior_sampler_options.tarb.student_degrees_of_freedom = 3; options_.trace_plot_ma = 200; options_.mh_autocorrelation_function_size = 30; options_.plot_priors = 1; diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index 194391eba..9363110f2 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -83,14 +83,14 @@ class ParsingDriver; #define yylex driver.lexer->lex } -%token AIM_SOLVER ANALYTIC_DERIVATION ANALYTIC_DERIVATION_MODE AR AUTOCORR TARB_MODE_COMPUTE -%token BAYESIAN_IRF BETA_PDF BLOCK USE_CALIBRATION USE_TARB TARB_NEW_BLOCK_PROBABILITY SILENT_OPTIMIZER +%token AIM_SOLVER ANALYTIC_DERIVATION ANALYTIC_DERIVATION_MODE AR AUTOCORR POSTERIOR_SAMPLING_METHOD +%token BAYESIAN_IRF BETA_PDF BLOCK USE_CALIBRATION SILENT_OPTIMIZER %token BVAR_DENSITY BVAR_FORECAST NODECOMPOSITION DR_DISPLAY_TOL HUGE_NUMBER %token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA TARB_OPTIM %token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN %token BVAR_REPLIC BYTECODE ALL_VALUES_REQUIRED PROPOSAL_DISTRIBUTION %token CALIB_SMOOTHER CHANGE_TYPE CHECK CONDITIONAL_FORECAST CONDITIONAL_FORECAST_PATHS CONF_SIG CONSTANT CONTROLLED_VAREXO CORR COVAR CUTOFF CYCLE_REDUCTION LOGARITHMIC_REDUCTION -%token CONSIDER_ALL_ENDOGENOUS CONSIDER_ONLY_OBSERVED STUDENT_DEGREES_OF_FREEDOM +%token CONSIDER_ALL_ENDOGENOUS CONSIDER_ONLY_OBSERVED %token DATAFILE FILE SERIES DOUBLING DR_CYCLE_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_MAXITER DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE CALIBRATION DIFFERENTIATE_FORWARD_VARS %token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT EXTENDED_PATH ENDOGENOUS_PRIOR %token FILENAME DIRNAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS LAST_OBS SET_TIME OSR_PARAMS_BOUNDS @@ -152,7 +152,7 @@ class ParsingDriver; %token GSIG2_LMDM Q_DIAG FLAT_PRIOR NCSK NSTD WEIBULL WEIBULL_PDF %token INDXPARR INDXOVR INDXAP APBAND INDXIMF IMFBAND INDXFORE FOREBAND INDXGFOREHAT INDXGIMFHAT %token INDXESTIMA INDXGDLS EQ_MS FILTER_COVARIANCE FILTER_DECOMPOSITION -%token EQ_CMS TLINDX TLNUMBER BANACT RESTRICTIONS +%token EQ_CMS TLINDX TLNUMBER BANACT RESTRICTIONS POSTERIOR_SAMPLER_OPTIONS %token OUTPUT_FILE_TAG DRAWS_NBR_BURN_IN_1 DRAWS_NBR_BURN_IN_2 HORIZON %token SBVAR TREND_VAR DEFLATOR GROWTH_FACTOR MS_IRF MS_VARIANCE_DECOMPOSITION %token MS_ESTIMATION MS_SIMULATION MS_COMPUTE_MDD MS_COMPUTE_PROBABILITIES MS_FORECAST @@ -1776,14 +1776,12 @@ estimation_options : o_datafile | o_distribution_approximation | o_dirname | o_huge_number - | o_use_tarb - | o_tarb_mode_compute - | o_tarb_new_block_probability | o_tarb_optim | o_silent_optimizer | o_proposal_distribution - | o_student_degrees_of_freedom | o_no_posterior_kernel_density + | o_posterior_sampling_method + | o_posterior_sampler_options ; list_optim_option : QUOTED_STRING COMMA QUOTED_STRING @@ -1806,6 +1804,16 @@ tarb_optim_options : list_tarb_optim_option | tarb_optim_options COMMA list_tarb_optim_option; ; +list_sampling_option : QUOTED_STRING COMMA QUOTED_STRING + { driver.sampling_options_string($1, $3); } + | QUOTED_STRING COMMA signed_number + { driver.sampling_options_num($1, $3); } + ; + +sampling_options : list_sampling_option + | sampling_options COMMA list_sampling_option; + ; + varobs : VAROBS { driver.check_varobs(); } varobs_list ';'; varobs_list : varobs_list symbol @@ -2702,6 +2710,8 @@ o_est_first_obs : FIRST_OBS EQUAL vec_int | FIRST_OBS EQUAL vec_int_number { driver.option_vec_int("first_obs", $3); } ; +o_posterior_sampling_method : POSTERIOR_SAMPLING_METHOD EQUAL QUOTED_STRING + { driver.option_str("posterior_sampler_options.posterior_sampling_method", $3); } ; o_first_obs : FIRST_OBS EQUAL INT_NUMBER { driver.option_num("first_obs", $3); }; o_data_first_obs : FIRST_OBS EQUAL date_expr { driver.option_date("firstobs", $3); } ; o_data_last_obs : LAST_OBS EQUAL date_expr { driver.option_date("lastobs", $3); } ; @@ -2759,11 +2769,11 @@ o_mh_drop : MH_DROP EQUAL non_negative_number { driver.option_num("mh_drop", $3) o_mh_jscale : MH_JSCALE EQUAL non_negative_number { driver.option_num("mh_jscale", $3); }; o_optim : OPTIM EQUAL '(' optim_options ')'; o_tarb_optim : TARB_OPTIM EQUAL '(' tarb_optim_options ')'; -o_proposal_distribution : PROPOSAL_DISTRIBUTION EQUAL symbol { driver.option_str("proposal_distribution", $3); }; +o_posterior_sampler_options : POSTERIOR_SAMPLER_OPTIONS EQUAL '(' sampling_options ')' ; +o_proposal_distribution : PROPOSAL_DISTRIBUTION EQUAL symbol { driver.option_str("posterior_sampler_options.posterior_sampling_method.proposal_distribution", $3); }; o_no_posterior_kernel_density : NO_POSTERIOR_KERNEL_DENSITY { driver.option_num("moments_posterior_density.indicator", "0"); } ; -o_student_degrees_of_freedom : STUDENT_DEGREES_OF_FREEDOM EQUAL INT_NUMBER { driver.option_num("student_degrees_of_freedom", $3); }; o_mh_init_scale : MH_INIT_SCALE EQUAL non_negative_number { driver.option_num("mh_init_scale", $3); }; o_mode_file : MODE_FILE EQUAL filename { driver.option_str("mode_file", $3); }; o_mode_compute : MODE_COMPUTE EQUAL INT_NUMBER { driver.option_num("mode_compute", $3); }; @@ -3022,9 +3032,6 @@ o_equations : EQUATIONS EQUAL vec_int | EQUATIONS EQUAL vec_int_number { driver.option_vec_int("ms.equations",$3); } ; -o_use_tarb : USE_TARB { driver.option_num("TaRB.use_TaRB", "1"); }; -o_tarb_mode_compute : TARB_MODE_COMPUTE EQUAL INT_NUMBER { driver.option_num("TaRB.mode_compute", $3); }; -o_tarb_new_block_probability : TARB_NEW_BLOCK_PROBABILITY EQUAL non_negative_number {driver.option_num("TaRB.new_block_probability",$3); }; o_silent_optimizer : SILENT_OPTIMIZER { driver.option_num("silent_optimizer", "1"); }; o_instruments : INSTRUMENTS EQUAL '(' symbol_list ')' {driver.option_symbol_list("instruments"); }; diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index 606744af0..957e240ed 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -391,7 +391,6 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 distribution_approximation {return token::DISTRIBUTION_APPROXIMATION;} proposal_distribution {return token::PROPOSAL_DISTRIBUTION;} no_posterior_kernel_density {return token::NO_POSTERIOR_KERNEL_DENSITY;} -student_degrees_of_freedom {return token::STUDENT_DEGREES_OF_FREEDOM;} alpha { yylval->string_val = new string(yytext); @@ -590,10 +589,9 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 outvars {return token::OUTVARS;} huge_number {return token::HUGE_NUMBER;} dr_display_tol {return token::DR_DISPLAY_TOL;} -use_tarb {return token::USE_TARB;} -tarb_mode_compute {return token::TARB_MODE_COMPUTE;} -tarb_new_block_probability {return token::TARB_NEW_BLOCK_PROBABILITY;} +posterior_sampling_method {return token::POSTERIOR_SAMPLING_METHOD;} tarb_optim {return token::TARB_OPTIM;} +posterior_sampler_options {return token::POSTERIOR_SAMPLER_OPTIONS;} silent_optimizer {return token::SILENT_OPTIMIZER;} lmmcp {return token::LMMCP;} occbin {return token::OCCBIN;} diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc index 467bf1147..3ea64b6f0 100644 --- a/preprocessor/ParsingDriver.cc +++ b/preprocessor/ParsingDriver.cc @@ -1693,6 +1693,35 @@ ParsingDriver::tarb_optim_options_num(string *name, string *value) delete value; } +void +ParsingDriver::sampling_options_helper(const string &name) +{ + if (options_list.string_options.find("posterior_sampler_options.sampling_opt") == + options_list.string_options.end()) + options_list.string_options["posterior_sampler_options.sampling_opt"] = ""; + else + options_list.string_options["posterior_sampler_options.sampling_opt"] += ","; + options_list.string_options["posterior_sampler_options.sampling_opt"] += "''" + name + "'',"; +} + +void +ParsingDriver::sampling_options_string(string *name, string *value) +{ + sampling_options_helper(*name); + options_list.string_options["posterior_sampler_options.sampling_opt"] += "''" + *value + "''"; + delete name; + delete value; +} + +void +ParsingDriver::sampling_options_num(string *name, string *value) +{ + sampling_options_helper(*name); + options_list.string_options["posterior_sampler_options.sampling_opt"] += *value; + delete name; + delete value; +} + void ParsingDriver::check_varobs() { diff --git a/preprocessor/ParsingDriver.hh b/preprocessor/ParsingDriver.hh index d3ad577cb..e51f2d357 100644 --- a/preprocessor/ParsingDriver.hh +++ b/preprocessor/ParsingDriver.hh @@ -99,6 +99,7 @@ private: //! Creates option "optim_opt" in OptionsList if it doesn't exist, else add a comma, and adds the option name void optim_options_helper(const string &name); void tarb_optim_options_helper(const string &name); + void sampling_options_helper(const string &name); //! Stores temporary symbol table SymbolList symbol_list; @@ -463,6 +464,10 @@ public: void tarb_optim_options_string(string *name, string *value); //! Adds a TaRB optimization option (numeric value) void tarb_optim_options_num(string *name, string *value); + //! Adds an sampling option (string value) + void sampling_options_string(string *name, string *value); + //! Adds an sampling option (numeric value) + void sampling_options_num(string *name, string *value); //! Check that no observed variable has yet be defined void check_varobs(); //! Add a new observed variable diff --git a/tests/estimation/MH_recover/fs2000_recover_tarb.mod b/tests/estimation/MH_recover/fs2000_recover_tarb.mod index 9c4fca92a..c2ce00f6d 100644 --- a/tests/estimation/MH_recover/fs2000_recover_tarb.mod +++ b/tests/estimation/MH_recover/fs2000_recover_tarb.mod @@ -1,14 +1,14 @@ -//Test mh_recover function for RW-MH when use_tarb was also used +//Test mh_recover function for RW-MH when posterior_sampling_method='tarb' is also used @#include "fs2000.common.inc" options_.MaxNumberOfBytes=10*11*8/2; -estimation(use_tarb,order=1, datafile='../fsdat_simul',nobs=192, loglinear, mh_replic=10, mh_nblocks=2, mh_jscale=0.8); +estimation(posterior_sampling_method='tarb',order=1, datafile='../fsdat_simul',nobs=192, loglinear, mh_replic=10, mh_nblocks=2, mh_jscale=0.8); copyfile([M_.dname filesep 'metropolis' filesep M_.dname '_mh1_blck1.mat'],[M_.dname '_mh1_blck1.mat']) copyfile([M_.dname filesep 'metropolis' filesep M_.dname '_mh2_blck2.mat'],[M_.dname '_mh2_blck2.mat']) delete([M_.dname filesep 'metropolis' filesep M_.dname '_mh2_blck2.mat']) -estimation(use_tarb,order=1, datafile='../fsdat_simul',mode_compute=0,mode_file=fs2000_recover_mode, nobs=192, loglinear, mh_replic=2000, mh_nblocks=2, mh_jscale=0.8,mh_recover); +estimation(posterior_sampling_method='tarb',order=1, datafile='../fsdat_simul',mode_compute=0,mode_file=fs2000_recover_mode, nobs=192, loglinear, mh_replic=2000, mh_nblocks=2, mh_jscale=0.8,mh_recover); %check first unaffected chain temp1=load([M_.dname '_mh1_blck1.mat']); @@ -32,4 +32,4 @@ temp2=load([M_.dname filesep 'metropolis' filesep M_.dname '_mh2_blck2.mat']); if max(max(abs(temp1.x2-temp2.x2)))>1e-10 error('Draws of affected chain''s affected files are not the same') -end \ No newline at end of file +end diff --git a/tests/estimation/TaRB/fs2000_tarb.mod b/tests/estimation/TaRB/fs2000_tarb.mod index 6586df195..4c7877ff1 100644 --- a/tests/estimation/TaRB/fs2000_tarb.mod +++ b/tests/estimation/TaRB/fs2000_tarb.mod @@ -17,7 +17,7 @@ */ /* - * Copyright (C) 2004-2010 Dynare Team + * Copyright (C) 2004-2016 Dynare Team * * This file is part of Dynare. * @@ -115,8 +115,7 @@ end; varobs gp_obs gy_obs; estimation(order=1, datafile='../fsdat_simul',nobs=192, loglinear, mh_replic=30, mh_nblocks=2, mh_jscale=0.5,mode_compute=4, -use_TaRB, -tarb_mode_compute=4, -tarb_new_block_probability=0.3, +posterior_sampling_method='tarb', +posterior_sampler_options=('tarb_mode_compute',4,'tarb_new_block_probability',0.3), silent_optimizer );