From 8513c59c9ed06f07c7645dc12357139dacf513e5 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 6 Nov 2013 10:36:58 +0100 Subject: [PATCH 1/3] preprocessor: add use_calibration option for estimated_params_init block. closes #447, closes #512 --- ComputingTasks.cc | 9 +++++++-- ComputingTasks.hh | 4 +++- DynareBison.yy | 7 +++++-- DynareFlex.ll | 2 +- ParsingDriver.cc | 4 ++-- ParsingDriver.hh | 2 +- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 9434b315..ec201921 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -581,15 +581,20 @@ EstimatedParamsStatement::writeOutput(ostream &output, const string &basename) c } EstimatedParamsInitStatement::EstimatedParamsInitStatement(const vector &estim_params_list_arg, - const SymbolTable &symbol_table_arg) : + const SymbolTable &symbol_table_arg, + const bool use_calibration_arg) : estim_params_list(estim_params_list_arg), - symbol_table(symbol_table_arg) + symbol_table(symbol_table_arg), + use_calibration(use_calibration_arg) { } void EstimatedParamsInitStatement::writeOutput(ostream &output, const string &basename) const { + if (use_calibration) + output << "options_.use_calibration_initialization = 1;" << endl; + vector::const_iterator it; for (it = estim_params_list.begin(); it != estim_params_list.end(); it++) diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 59c6a264..156a3421 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -290,9 +290,11 @@ class EstimatedParamsInitStatement : public Statement private: const vector estim_params_list; const SymbolTable &symbol_table; + const bool use_calibration; public: EstimatedParamsInitStatement(const vector &estim_params_list_arg, - const SymbolTable &symbol_table_arg); + const SymbolTable &symbol_table_arg, + const bool use_calibration_arg); virtual void writeOutput(ostream &output, const string &basename) const; }; diff --git a/DynareBison.yy b/DynareBison.yy index 77b82e25..f50b09ff 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -90,7 +90,7 @@ class ParsingDriver; %} %token AIM_SOLVER ANALYTIC_DERIVATION AR AUTOCORR -%token BAYESIAN_IRF BETA_PDF BLOCK +%token BAYESIAN_IRF BETA_PDF BLOCK USE_CALIBRATION %token BVAR_DENSITY BVAR_FORECAST %token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA %token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN @@ -1141,7 +1141,10 @@ estimated_elem3 : expression_or_empty COMMA expression_or_empty ; estimated_params_init : ESTIMATED_PARAMS_INIT ';' estimated_init_list END ';' - { driver.estimated_params_init(); }; + { driver.estimated_params_init(); } + | ESTIMATED_PARAMS_INIT '(' USE_CALIBRATION ')' ';' estimated_init_list END ';' + { driver.estimated_params_init(true); } + ; estimated_init_list : estimated_init_list estimated_init_elem { driver.add_estimated_params_element(); } diff --git a/DynareFlex.ll b/DynareFlex.ll index 9e073081..b53719bc 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -395,7 +395,7 @@ string eofbuff; return token::CNUM; } banact {return token::BANACT;} - +use_calibration {return token::USE_CALIBRATION;} output_file_tag {return token::OUTPUT_FILE_TAG;} file_tag {return token::FILE_TAG;}; no_create_init {return token::NO_CREATE_INIT;}; diff --git a/ParsingDriver.cc b/ParsingDriver.cc index 911ac6d1..55bf7aed 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -1209,9 +1209,9 @@ ParsingDriver::estimated_params() } void -ParsingDriver::estimated_params_init() +ParsingDriver::estimated_params_init(bool use_calibration) { - mod_file->addStatement(new EstimatedParamsInitStatement(estim_params_list, mod_file->symbol_table)); + mod_file->addStatement(new EstimatedParamsInitStatement(estim_params_list, mod_file->symbol_table, use_calibration)); estim_params_list.clear(); } diff --git a/ParsingDriver.hh b/ParsingDriver.hh index 8b9b21e9..8466deb0 100644 --- a/ParsingDriver.hh +++ b/ParsingDriver.hh @@ -391,7 +391,7 @@ public: //! Writes estimated params command void estimated_params(); //! Writes estimated params init command - void estimated_params_init(); + void estimated_params_init(bool use_calibration = false); //! Writes estimated params bound command void estimated_params_bounds(); //! Adds a declaration for a user-defined external function From f964d06e223eca0e0ec9cb4c1189ee272902fab3 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 13 Nov 2013 11:29:27 +0100 Subject: [PATCH 2/3] saves variables if they exist at end of dynare run. closes #517 --- ModFile.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ModFile.cc b/ModFile.cc index 1abb76ce..1a1b7e3e 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -703,7 +703,15 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool no_log, b if (block && !byte_code) mOutputFile << "rmpath " << basename << ";" << endl; - mOutputFile << "save('" << basename << "_results.mat', 'oo_', 'M_', 'options_');" << endl; + mOutputFile << "save('" << basename << "_results.mat', 'oo_', 'M_', 'options_');" << endl + << "if exist('estim_params_', 'var') == 1" << endl + << " save('" << basename << "_results.mat', 'estim_params_', '-append');" << endl << "end" << endl + << "if exist('bayestopt_', 'var') == 1" << endl + << " save('" << basename << "_results.mat', 'bayestopt_', '-append');" << endl << "end" << endl + << "if exist('dataset_', 'var') == 1" << endl + << " save('" << basename << "_results.mat', 'dataset_', '-append');" << endl << "end" << endl + << "if exist('estimation_info', 'var') == 1" << endl + << " save('" << basename << "_results.mat', 'estimation_info', '-append');" << endl << "end" << endl; config_file.writeEndParallel(mOutputFile); From eabad03581b56972fe6748ba00b3459ba2c89f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 13 Nov 2013 14:34:46 +0100 Subject: [PATCH 3/3] Preprocessor interface for irf_plot_threshold Closes #498 --- DynareBison.yy | 5 ++++- DynareFlex.ll | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/DynareBison.yy b/DynareBison.yy index f50b09ff..7b047031 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -107,7 +107,7 @@ class ParsingDriver; %token IDENTIFICATION INF_CONSTANT INITVAL INITVAL_FILE BOUNDS JSCALE INIT %token INT_NUMBER %token DATE_NUMBER -%token INV_GAMMA_PDF INV_GAMMA1_PDF INV_GAMMA2_PDF IRF IRF_SHOCKS +%token INV_GAMMA_PDF INV_GAMMA1_PDF INV_GAMMA2_PDF IRF IRF_SHOCKS IRF_PLOT_THRESHOLD %token KALMAN_ALGO KALMAN_TOL SUBSAMPLES OPTIONS TOLF %token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_IDENT_FILES LOAD_MH_FILE LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR LYAPUNOV %token LYAPUNOV_FIXED_POINT_TOL LYAPUNOV_DOUBLING_TOL LYAPUNOV_SQUARE_ROOT_SOLVER_TOL LOG_DEFLATOR LOG_TREND_VAR LOG_GROWTH_FACTOR MARKOWITZ MARGINAL_DENSITY MAX MAXIT @@ -991,6 +991,7 @@ stoch_simul_primary_options : o_dr_algo | o_dr_cycle_reduction_tol | o_dr_logarithmic_reduction_tol | o_dr_logarithmic_reduction_maxiter + | o_irf_plot_threshold ; stoch_simul_options : stoch_simul_primary_options @@ -1562,6 +1563,7 @@ estimation_options : o_datafile | o_taper_steps | o_geweke_interval | o_mcmc_jumping_covariance + | o_irf_plot_threshold ; list_optim_option : QUOTED_STRING COMMA QUOTED_STRING @@ -2689,6 +2691,7 @@ o_mcmc_jumping_covariance : MCMC_JUMPING_COVARIANCE EQUAL HESSIAN | MCMC_JUMPING_COVARIANCE EQUAL filename { driver.option_str("MCMC_jumping_covariance", $3); } ; +o_irf_plot_threshold : IRF_PLOT_THRESHOLD EQUAL non_negative_number { driver.option_num("impulse_responses.plot_threshold", $3); }; range : symbol ':' symbol { diff --git a/DynareFlex.ll b/DynareFlex.ll index b53719bc..c58ca30a 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -567,6 +567,7 @@ string eofbuff; mh_recover {return token::MH_RECOVER;} planner_discount {return token::PLANNER_DISCOUNT;} calibration {return token::CALIBRATION;} +irf_plot_threshold {return token::IRF_PLOT_THRESHOLD;} equation {return token::EQUATION;} exclusion {return token::EXCLUSION;}