From c4a9f93d40abd4747a1101116729400452dfe9a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Tue, 4 Feb 2020 17:48:37 +0100 Subject: [PATCH] =?UTF-8?q?Do=20not=20allow=20the=20estimation=20of=20a=20?= =?UTF-8?q?parameter=20that=20appears=20in=20=E2=80=9Cplanner=5Fdiscount?= =?UTF-8?q?=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ref. dynare#1173 --- src/ComputingTasks.cc | 21 ++++++++++++++++++++- src/ComputingTasks.hh | 6 ++++-- src/NumericalInitialization.cc | 6 +++++- src/ParsingDriver.cc | 4 ++-- src/Statement.hh | 5 ++++- 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/ComputingTasks.cc b/src/ComputingTasks.cc index 955d5bbb..3e97a23f 100644 --- a/src/ComputingTasks.cc +++ b/src/ComputingTasks.cc @@ -34,6 +34,7 @@ using namespace std; #pragma GCC diagnostic pop #include +#include SteadyStatement::SteadyStatement(OptionsList options_list_arg) : options_list{move(options_list_arg)} @@ -1134,8 +1135,10 @@ DiscretionaryPolicyStatement::writeJsonOutput(ostream &output) const output << "}"; } -EstimationStatement::EstimationStatement(SymbolList symbol_list_arg, +EstimationStatement::EstimationStatement(const SymbolTable &symbol_table_arg, + SymbolList symbol_list_arg, OptionsList options_list_arg) : + symbol_table{symbol_table_arg}, symbol_list{move(symbol_list_arg)}, options_list{move(options_list_arg)} { @@ -1212,6 +1215,22 @@ EstimationStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli exit(EXIT_FAILURE); } + /* Check that we are not trying to estimate a parameter appearing in the + planner discount factor (see dynare#1173) */ + vector estimated_params_in_planner_discount; + set_intersection(mod_file_struct.estimated_parameters.begin(), + mod_file_struct.estimated_parameters.end(), + mod_file_struct.parameters_in_planner_discount.begin(), + mod_file_struct.parameters_in_planner_discount.end(), + back_inserter(estimated_params_in_planner_discount)); + if (!estimated_params_in_planner_discount.empty()) + { + cerr << "ERROR: It is not possible to estimate a parameter (" + << symbol_table.getName(estimated_params_in_planner_discount[0]) + << ") that appears in the discount factor of the planner (i.e. in the 'planner_discount' option)." << endl; + exit(EXIT_FAILURE); + } + try { symbol_list.checkPass(warnings, { SymbolType::endogenous }); diff --git a/src/ComputingTasks.hh b/src/ComputingTasks.hh index 09d2fef8..53c6a96e 100644 --- a/src/ComputingTasks.hh +++ b/src/ComputingTasks.hh @@ -1,5 +1,5 @@ /* - * Copyright © 2003-2019 Dynare Team + * Copyright © 2003-2020 Dynare Team * * This file is part of Dynare. * @@ -314,10 +314,12 @@ public: class EstimationStatement : public Statement { private: + const SymbolTable &symbol_table; const SymbolList symbol_list; const OptionsList options_list; public: - EstimationStatement(SymbolList symbol_list_arg, + EstimationStatement(const SymbolTable &symbol_table_arg, + SymbolList symbol_list_arg, OptionsList options_list_arg); void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) override; void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const override; diff --git a/src/NumericalInitialization.cc b/src/NumericalInitialization.cc index 3f7446c3..12eeb420 100644 --- a/src/NumericalInitialization.cc +++ b/src/NumericalInitialization.cc @@ -1,5 +1,5 @@ /* - * Copyright © 2003-2019 Dynare Team + * Copyright © 2003-2020 Dynare Team * * This file is part of Dynare. * @@ -39,6 +39,10 @@ InitParamStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolid { if (symbol_table.getName(symb_id) == "dsge_prior_weight") mod_file_struct.dsge_prior_weight_initialized = true; + + // Needed for the workaround discussed in dynare#1173 + if (symbol_table.getName(symb_id) == "optimal_policy_discount_factor") + param_value->collectVariables(SymbolType::parameter, mod_file_struct.parameters_in_planner_discount); } void diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc index 1207f43b..316e7939 100644 --- a/src/ParsingDriver.cc +++ b/src/ParsingDriver.cc @@ -1,5 +1,5 @@ /* - * Copyright © 2003-2019 Dynare Team + * Copyright © 2003-2020 Dynare Team * * This file is part of Dynare. * @@ -1931,7 +1931,7 @@ ParsingDriver::set_corr_options(const string &name1, const string &name2, const void ParsingDriver::run_estimation() { - mod_file->addStatement(make_unique(symbol_list, options_list)); + mod_file->addStatement(make_unique(mod_file->symbol_table, symbol_list, options_list)); symbol_list.clear(); options_list.clear(); } diff --git a/src/Statement.hh b/src/Statement.hh index 908260b9..efc293cf 100644 --- a/src/Statement.hh +++ b/src/Statement.hh @@ -1,5 +1,5 @@ /* - * Copyright © 2006-2019 Dynare Team + * Copyright © 2006-2020 Dynare Team * * This file is part of Dynare. * @@ -134,6 +134,9 @@ public: /* Whether any of shock_decomposition, realtime_shock_decomposition and initial_condition_decomposition has the “with_epilogue” option */ bool with_epilogue_option{false}; + /* Lists symbol IDs of parameters that appear in a “planner_discount” option. + See dynare#1173 for more details. */ + set parameters_in_planner_discount; }; class Statement