From fb8d9258d06d8e71bed0ee2d75905a9312995cf1 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 28 Mar 2018 18:46:15 +0200 Subject: [PATCH] add pac_model statement --- src/ComputingTasks.cc | 115 ++++++++++++++++++++++++- src/ComputingTasks.hh | 26 +++++- src/DataTree.cc | 7 +- src/DataTree.hh | 6 +- src/DynamicModel.cc | 90 ++++++++++++++++++-- src/DynamicModel.hh | 12 ++- src/DynareBison.yy | 40 +++++---- src/DynareFlex.ll | 8 +- src/ExprNode.cc | 194 +++++++++++++++++++++++------------------- src/ExprNode.hh | 56 +++++++----- src/ModFile.cc | 78 ++++++++++++----- src/ParsingDriver.cc | 92 ++++++++------------ src/ParsingDriver.hh | 16 ++-- src/Statement.hh | 2 + 14 files changed, 502 insertions(+), 240 deletions(-) diff --git a/src/ComputingTasks.cc b/src/ComputingTasks.cc index d8911f63..27f422ae 100644 --- a/src/ComputingTasks.cc +++ b/src/ComputingTasks.cc @@ -258,6 +258,114 @@ PriorPosteriorFunctionStatement::writeJsonOutput(ostream &output) const output << "}"; } +PacModelStatement::PacModelStatement(const string &name_arg, + const string &var_name_arg, + const string &discount_arg, + const string &growth_arg, + const map &undiff_arg, + const SymbolTable &symbol_table_arg) : + name(name_arg), + var_name(var_name_arg), + discount(discount_arg), + growth(growth_arg), + undiff(undiff_arg), + symbol_table(symbol_table_arg) +{ +} + +void +PacModelStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) +{ + mod_file_struct.pac_params.insert(symbol_table.getID(discount)); + if (!growth.empty()) + mod_file_struct.pac_params.insert(symbol_table.getID(growth)); +} + +void +PacModelStatement::fillUndiffedLHS(vector &lhs_arg) +{ + lhs = lhs_arg; +} + +void +PacModelStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const +{ + output << "M_.pac." << name << ".var_model_name = '" << var_name << "';" << endl + << "M_.pac." << name << ".discount_index = " << symbol_table.getTypeSpecificID(discount) + 1 << ";" << endl; + + if (!growth.empty()) + { + output << "M_.pac." << name << ".growth_index = " << symbol_table.getTypeSpecificID(growth) + 1 << ";" << endl + << "M_.pac." << name << ".growth_type = "; + switch(symbol_table.getType(growth)) + { + case eEndogenous: + output << "'endogenous';" << endl; + break; + case eExogenous: + output << "'exogenous';" << endl; + break; + case eParameter: + output << "'parameter';" << endl; + break; + default: + cerr << "pac_model: error encountered in growth type" << endl; + exit(EXIT_FAILURE); + } + } + + output << "M_.pac." << name << ".lhs = ["; + for (vector::const_iterator it = lhs.begin(); it !=lhs.end(); it++) + { + if (it != lhs.begin()) + output << " "; + output << *it + 1; + } + output << "];" << endl; + +} + +void +PacModelStatement::writeJsonOutput(ostream &output) const +{ + output << "{\"statementName\": \"pac_model\"," + << "\"model_name\": \"" << name << "\"," + << "\"var_model_name\": \"" << var_name << "\"," + << "\"discount_index\": " << symbol_table.getTypeSpecificID(discount) + 1; + + if (!growth.empty()) + { + output << "," + << "\"growth_index\": " << symbol_table.getTypeSpecificID(growth) + 1 << "," + << "\"growth_type\": "; + switch(symbol_table.getType(growth)) + { + case eEndogenous: + output << "\"endogenous\"" << endl; + break; + case eExogenous: + output << "\"exogenous\"" << endl; + break; + case eParameter: + output << "\"parameter\"" << endl; + break; + default: + cerr << "pac_model: error encountered in growth type" << endl; + exit(EXIT_FAILURE); + } + } + output << "}"; +} + +void +PacModelStatement::getPacModelInfoForPacExpectation(pair > > > > &pac_model_info) const +{ + int growth_symb_id = -1; + if (!growth.empty()) + growth_symb_id = symbol_table.getID(growth); + pac_model_info = make_pair(name, make_pair(var_name, make_pair(discount, make_pair(growth_symb_id, undiff)))); +} + VarModelStatement::VarModelStatement(const SymbolList &symbol_list_arg, const OptionsList &options_list_arg, const string &name_arg, @@ -280,14 +388,13 @@ VarModelStatement::getVarModelInfoForVarExpectation(map &var_model_eqtags) const +VarModelStatement::getVarModelEqTags(map > &var_model_eqtags) const { if (!symbol_list.empty()) return; - OptionsList::vec_str_options_t::const_iterator it1 = - options_list.vector_str_options.find("var.eqtags"); - var_model_eqtags = it1->second; + OptionsList::vec_str_options_t::const_iterator it = options_list.vector_str_options.find("var.eqtags"); + var_model_eqtags[name] = it->second; } void diff --git a/src/ComputingTasks.hh b/src/ComputingTasks.hh index 360432d4..b0d5584a 100644 --- a/src/ComputingTasks.hh +++ b/src/ComputingTasks.hh @@ -119,6 +119,30 @@ public: virtual void writeJsonOutput(ostream &output) const; }; +class PacModelStatement : public Statement +{ +private: + const string &name; + const string &var_name; + const string &discount; + const string &growth; + const map undiff; + const SymbolTable &symbol_table; + vector lhs; +public: + PacModelStatement(const string &name_arg, + const string &var_name_arg, + const string &discount_arg, + const string &growth_arg, + const map &undiff_arg, + const SymbolTable &symbol_table_arg); + virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; + virtual void writeJsonOutput(ostream &output) const; + void fillUndiffedLHS(vector &lhs); + void getPacModelInfoForPacExpectation(pair > > > > &pac_model_info) const; +}; + class VarModelStatement : public Statement { private: @@ -136,7 +160,7 @@ public: const string &name_arg, const SymbolTable &symbol_table_arg); void getVarModelInfoForVarExpectation(map > &var_model_info) const; - void getVarModelEqTags(vector &var_model_eqtags) const; + void getVarModelEqTags(map > &var_model_eqtags) const; void fillVarModelInfoFromEquations(vector &eqnumber_arg, vector &lhs_arg, vector > > &rhs_arg, vector &nonstationary_arg, diff --git a/src/DataTree.cc b/src/DataTree.cc index 217a3137..f193d0da 100644 --- a/src/DataTree.cc +++ b/src/DataTree.cc @@ -515,14 +515,13 @@ DataTree::AddVarExpectation(const int symb_id, const int forecast_horizon, const } expr_t -DataTree::AddPacExpectation(const string &model_name, const string &var_model_name, const int discount_id, const int growth_id) +DataTree::AddPacExpectation(const string &model_name) { - pac_expectation_node_map_t::iterator it = - pac_expectation_node_map.find(make_pair(model_name, make_pair(var_model_name, make_pair(discount_id, growth_id)))); + pac_expectation_node_map_t::iterator it = pac_expectation_node_map.find(model_name); if (it != pac_expectation_node_map.end()) return it->second; - return new PacExpectationNode(*this, model_name, var_model_name, discount_id, growth_id); + return new PacExpectationNode(*this, model_name); } expr_t diff --git a/src/DataTree.hh b/src/DataTree.hh index d302063e..00ddd32e 100644 --- a/src/DataTree.hh +++ b/src/DataTree.hh @@ -81,8 +81,8 @@ protected: typedef map >, VarExpectationNode *> var_expectation_node_map_t; var_expectation_node_map_t var_expectation_node_map; - // (model_name, (discount, growth)) -> PacExpectationNode - typedef map > >, PacExpectationNode *> pac_expectation_node_map_t; + // model_name -> PacExpectationNode + typedef map pac_expectation_node_map_t; pac_expectation_node_map_t pac_expectation_node_map; // ((arguments, deriv_idx), symb_id) -> FirstDerivExternalFunctionNode @@ -231,7 +231,7 @@ public: //! Adds "var_expectation(arg1, arg2, model_name=arg3)" to model tree expr_t AddVarExpectation(const int symb_id, const int forecast_horizon, const string &model_name); //! Adds pac_expectation command to model tree - expr_t AddPacExpectation(const string &model_name, const string &var_model_name, const int discount_id, const int growth_id); + expr_t AddPacExpectation(const string &model_name); //! Adds a model local variable with its value void AddLocalVariable(int symb_id, expr_t value) throw (LocalVariableException); //! Adds an external function node diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index 34efdb78..92ebad6f 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -3418,6 +3418,85 @@ DynamicModel::addEquationsForVar(map > &var_model_ cout << "Accounting for var_model lags not in model block: added " << count << " auxiliary variables and equations." << endl; } +int +DynamicModel::get_undiff_max_lag(vector &eqnumber, vector &lhs) +{ + int max_lag = 0; + for (vector::const_iterator it = eqnumber.begin(); + it != eqnumber.end(); it++) + { + int max_lag_tmp = dynamic_cast(equations[*it])->get_arg2()->PacMaxLag(lhs); + if (max_lag_tmp > max_lag) + max_lag = max_lag_tmp; + } + return max_lag; +} + +void +DynamicModel::undiff_lhs_for_pac(vector &lhs, vector &diff, vector &orig_diff_var, + vector &eqnumber, map &undiff, map &undiff_table) +{ + if (undiff.empty()) + return; + + for (map::const_iterator it = undiff.begin(); + it != undiff.end(); it++) + { + int eqn = -1; + string eqtag (it->first); + for (vector > >::const_iterator iteqtag = + equation_tags.begin(); iteqtag != equation_tags.end(); iteqtag++) + if (iteqtag->second.first == "name" + && iteqtag->second.second == eqtag) + { + eqn = iteqtag->first; + break; + } + + if (eqn == -1) + { + cerr << "ERROR: equation tag '" << eqtag << "' not found" << endl; + exit(EXIT_FAILURE); + } + + int i = 0; + bool found = false; + for (vector::const_iterator it1 = eqnumber.begin(); + it1 != eqnumber.end(); it1++) + if (eqn == i) + { + found = true; + break; + } + else + i++; + + if (!found) + { + cerr << "ERROR: equation not found in VAR"; + exit(EXIT_FAILURE); + } + + if (diff.at(eqnumber[i]) != true) + { + cerr << "ERROR: the variable on the LHS of equation #" << eqn << " (VAR equation #" << eqnumber[i] + << " with equation tag '" << eqtag + << "') does not have the diff operator applied to it yet you are trying to undiff it." << endl; + exit(EXIT_FAILURE); + } + + for (int j = it->second; j > 0; j--) + if (undiff_table.find(lhs.at(eqnumber.at(i))) == undiff_table.end()) + { + cerr << "You are undiffing the LHS of equation #" << eqn << " " + << it->second << " times but it has only been diffed " << j - 1 << " time(s)" << endl; + exit(EXIT_FAILURE); + } + else + lhs.at(eqnumber.at(i)) = undiff_table.at(lhs.at(eqnumber.at(i))); + } +} + void DynamicModel::walkPacParameters() { @@ -3436,10 +3515,11 @@ void DynamicModel::fillPacExpectationVarInfo(string &var_model_name, vector &lhs, int max_lag, - vector &nonstationary) + vector &nonstationary, + int growth_symb_id) { for (size_t i = 0; i < equations.size(); i++) - equations[i]->fillPacExpectationVarInfo(var_model_name, lhs, max_lag, nonstationary, i); + equations[i]->fillPacExpectationVarInfo(var_model_name, lhs, max_lag, nonstationary, growth_symb_id, i); } void @@ -5030,7 +5110,7 @@ DynamicModel::substituteAdl() } void -DynamicModel::substituteDiff(StaticModel &static_model) +DynamicModel::substituteDiff(StaticModel &static_model, map &undiff_table) { // Find diff Nodes diff_table_t diff_table; @@ -5046,13 +5126,13 @@ DynamicModel::substituteDiff(StaticModel &static_model) ExprNode::subst_table_t diff_subst_table; for (map::iterator it = local_variables_table.begin(); it != local_variables_table.end(); it++) - it->second = it->second->substituteDiff(static_model, diff_table, diff_subst_table, neweqs); + it->second = it->second->substituteDiff(static_model, diff_table, diff_subst_table, neweqs, undiff_table); // Substitute in equations for (int i = 0; i < (int) equations.size(); i++) { BinaryOpNode *substeq = dynamic_cast(equations[i]-> - substituteDiff(static_model, diff_table, diff_subst_table, neweqs)); + substituteDiff(static_model, diff_table, diff_subst_table, neweqs, undiff_table)); assert(substeq != NULL); equations[i] = substeq; } diff --git a/src/DynamicModel.hh b/src/DynamicModel.hh index 7ff8475f..7a8c7d57 100644 --- a/src/DynamicModel.hh +++ b/src/DynamicModel.hh @@ -307,7 +307,11 @@ public: void fillPacExpectationVarInfo(string &var_model_name, vector &lhs, int max_lag, - vector &nonstationary); + vector &nonstationary, + int growth_symb_id); + //! Get the max lag for the PAC VAR + int get_undiff_max_lag(vector &eqnumber, vector &lhs); + //! Substitutes pac_expectation operator void substitutePacExpectation(); @@ -399,7 +403,11 @@ public: void substituteAdl(); //! Substitutes diff operator - void substituteDiff(StaticModel &static_model); + void substituteDiff(StaticModel &static_model, map &undiff_table); + + //! Table to undiff LHS variables for pac vector z + void undiff_lhs_for_pac(vector &lhs, vector &diff, vector &orig_diff_var, + vector &eqnumber, map &undiff, map &undiff_table); //! Adds contents of diff_aux_equations to the back of aux_equations void combineDiffAuxEquations(); diff --git a/src/DynareBison.yy b/src/DynareBison.yy index 2ce25fea..f81e286f 100644 --- a/src/DynareBison.yy +++ b/src/DynareBison.yy @@ -132,7 +132,7 @@ class ParsingDriver; %token UNIFORM_PDF UNIT_ROOT_VARS USE_DLL USEAUTOCORR GSA_SAMPLE_FILE USE_UNIVARIATE_FILTERS_IF_SINGULARITY_IS_DETECTED %token VALUES VAR VAREXO VAREXO_DET VAROBS VAREXOBS PREDETERMINED_VARIABLES VAR_EXPECTATION PLOT_SHOCK_DECOMPOSITION MODEL_LOCAL_VARIABLE %token WRITE_LATEX_DYNAMIC_MODEL WRITE_LATEX_STATIC_MODEL WRITE_LATEX_ORIGINAL_MODEL CROSSEQUATIONS COVARIANCE WRITE_LATEX_STEADY_STATE_MODEL -%token XLS_SHEET XLS_RANGE LMMCP OCCBIN BANDPASS_FILTER COLORMAP VAR_MODEL QOQ YOY AOA PAC_EXPECTATION +%token XLS_SHEET XLS_RANGE LMMCP OCCBIN BANDPASS_FILTER COLORMAP VAR_MODEL PAC_MODEL QOQ YOY AOA UNDIFF PAC_EXPECTATION %left COMMA %left EQUAL_EQUAL EXCLAMATION_EQUAL %left LESS GREATER LESS_EQUAL GREATER_EQUAL @@ -233,6 +233,7 @@ statement : parameters | set_time | data | var_model + | pac_model | restrictions | prior | prior_eq @@ -383,6 +384,20 @@ var_model_options : o_var_name | o_var_eq_tags ; +pac_model : PAC_MODEL '(' pac_model_options_list ')' ';' { driver.pac_model(); } ; + +pac_model_options_list : pac_model_options_list COMMA pac_model_options + | pac_model_options + ; + +pac_model_options : o_pac_name + | o_pac_var_name + | o_pac_discount + | o_pac_growth + | UNDIFF '(' QUOTED_STRING COMMA INT_NUMBER ')' + { driver.pac_model_undiff($3, $5); } + ; + restrictions : RESTRICTIONS '(' symbol ')' ';' { driver.begin_VAR_restrictions(); } restrictions_list END ';' { driver.end_VAR_restrictions($3); } ; @@ -914,8 +929,8 @@ hand_side : '(' hand_side ')' { $$ = driver.add_var_expectation($3, new string("1"), $7); } | VAR_EXPECTATION '(' symbol COMMA INT_NUMBER COMMA MODEL_NAME EQUAL NAME ')' { $$ = driver.add_var_expectation($3, $5, $9); } - | PAC_EXPECTATION '(' pac_expectation_options_list ')' - { $$ = driver.add_pac_expectation(); } + | PAC_EXPECTATION '(' symbol ')' + { $$ = driver.add_pac_expectation($3); } | MINUS hand_side %prec UMINUS { $$ = driver.add_uminus($2); } | PLUS hand_side @@ -974,21 +989,6 @@ hand_side : '(' hand_side ')' { $$ = driver.add_steady_state($3); } ; - -pac_expectation_options_list : pac_expectation_options_list COMMA pac_expectation_options - | pac_expectation_options - ; - -pac_expectation_options : VAR_MODEL_NAME EQUAL NAME - { driver.add_pac_expectation_var_model_name($3); } - | MODEL_NAME EQUAL NAME - { driver.add_pac_expectation_model_name($3); } - | DISCOUNT EQUAL symbol - { driver.add_pac_expectation_discount($3); } - | GROWTH EQUAL symbol - { driver.add_pac_expectation_growth($3); } - ; - comma_hand_side : hand_side { driver.add_external_function_arg($1); } | comma_hand_side COMMA hand_side @@ -3203,6 +3203,10 @@ o_simul_seed : SIMUL_SEED EQUAL INT_NUMBER { driver.error("'simul_seed' option i o_qz_criterium : QZ_CRITERIUM EQUAL non_negative_number { driver.option_num("qz_criterium", $3); }; o_qz_zero_threshold : QZ_ZERO_THRESHOLD EQUAL non_negative_number { driver.option_num("qz_zero_threshold", $3); }; o_file : FILE EQUAL filename { driver.option_str("file", $3); }; +o_pac_name : MODEL_NAME EQUAL symbol { driver.option_str("pac.model_name", $3); }; +o_pac_var_name : VAR_MODEL_NAME EQUAL symbol { driver.option_str("pac.var_model_name", $3); }; +o_pac_discount : DISCOUNT EQUAL symbol { driver.option_str("pac.discount", $3); }; +o_pac_growth : GROWTH EQUAL symbol { driver.option_str("pac.growth", $3); }; o_var_name : MODEL_NAME EQUAL symbol { driver.option_str("var.model_name", $3); }; o_var_order : ORDER EQUAL INT_NUMBER { driver.option_num("var.order", $3); }; o_series : SERIES EQUAL symbol { driver.option_str("series", $3); }; diff --git a/src/DynareFlex.ll b/src/DynareFlex.ll index 39dd7836..4df5aa30 100644 --- a/src/DynareFlex.ll +++ b/src/DynareFlex.ll @@ -140,6 +140,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 simul {BEGIN DYNARE_STATEMENT; return token::SIMUL;} stoch_simul {BEGIN DYNARE_STATEMENT; return token::STOCH_SIMUL;} var_model {BEGIN DYNARE_STATEMENT; return token::VAR_MODEL;} +pac_model {BEGIN DYNARE_STATEMENT; return token::PAC_MODEL;} dsample {BEGIN DYNARE_STATEMENT; return token::DSAMPLE;} Sigma_e {BEGIN DYNARE_STATEMENT; sigma_e = 1; return token::SIGMA_E;} planner_objective {BEGIN DYNARE_STATEMENT; return token::PLANNER_OBJECTIVE;} @@ -322,6 +323,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 kalman_algo {return token::KALMAN_ALGO;} fast_kalman_filter {return token::FAST_KALMAN_FILTER;} kalman_tol {return token::KALMAN_TOL;} +undiff {return token::UNDIFF;} diffuse_kalman_tol {return token::DIFFUSE_KALMAN_TOL;} forecast {return token::FORECAST;} smoother {return token::SMOOTHER;} @@ -342,7 +344,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 optim {return token::OPTIM;} periods {return token::PERIODS;} model_name {return token::MODEL_NAME;} -var_model_name {return token::VAR_MODEL_NAME;} +var_model_name {return token::VAR_MODEL_NAME;} endogenous_terminal_period {return token::ENDOGENOUS_TERMINAL_PERIOD;} sub_draws {return token::SUB_DRAWS;} minimal_solving_periods {return token::MINIMAL_SOLVING_PERIODS;} @@ -626,6 +628,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 log_deflator {return token::LOG_DEFLATOR;} growth_factor {return token::GROWTH_FACTOR;} log_growth_factor {return token::LOG_GROWTH_FACTOR;} +growth {return token::GROWTH;} cova_compute {return token::COVA_COMPUTE;} discretionary_tol {return token::DISCRETIONARY_TOL;} analytic_derivation {return token::ANALYTIC_DERIVATION;} @@ -678,7 +681,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 } /* Inside a Dynare block */ -growth {return token::GROWTH;} var {return token::VAR;} stderr {return token::STDERR;} values {return token::VALUES;} @@ -825,7 +827,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 expectation {return token::EXPECTATION;} var_expectation {return token::VAR_EXPECTATION;} pac_expectation {return token::PAC_EXPECTATION;} -discount {return token::DISCOUNT;} +discount {return token::DISCOUNT;} varobs {return token::VAROBS;} varexobs {return token::VAREXOBS;} full {return token::FULL;} diff --git a/src/ExprNode.cc b/src/ExprNode.cc index f2340b65..3ba356eb 100644 --- a/src/ExprNode.cc +++ b/src/ExprNode.cc @@ -457,6 +457,12 @@ NumConstNode::maxLag() const return 0; } +int +NumConstNode::PacMaxLag(vector &lhs) const +{ + return 0; +} + expr_t NumConstNode::decreaseLeadsLags(int n) const { @@ -511,7 +517,7 @@ NumConstNode::findDiffNodes(DataTree &static_datatree, diff_table_t &diff_table) } expr_t -NumConstNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs) const +NumConstNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs, map &undiff_table) const { return const_cast(this); } @@ -600,7 +606,7 @@ NumConstNode::addParamInfoToPac(pair &lhs_arg, set &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int equation_number_arg) +NumConstNode::fillPacExpectationVarInfo(string &model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg) { } @@ -1324,6 +1330,12 @@ VariableNode::maxLag() const } } +int +VariableNode::PacMaxLag(vector &lhs) const +{ + return -lag; +} + expr_t VariableNode::substituteAdl() const { @@ -1336,7 +1348,7 @@ VariableNode::findDiffNodes(DataTree &static_datatree, diff_table_t &diff_table) } expr_t -VariableNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs) const +VariableNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs, map &undiff_table) const { return const_cast(this); } @@ -1702,7 +1714,7 @@ VariableNode::addParamInfoToPac(pair &lhs_arg, set &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int equation_number_arg) +VariableNode::fillPacExpectationVarInfo(string &model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg) { } @@ -2841,6 +2853,13 @@ UnaryOpNode::maxLag() const return arg->maxLag(); } +int +UnaryOpNode::PacMaxLag(vector &lhs) const +{ + //This will never be an oDiff node + return arg->PacMaxLag(lhs); +} + expr_t UnaryOpNode::substituteAdl() const { @@ -2906,11 +2925,12 @@ UnaryOpNode::findDiffNodes(DataTree &static_datatree, diff_table_t &diff_table) } expr_t -UnaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs) const +UnaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, + vector &neweqs, map &undiff_table) const { if (op_code != oDiff) { - expr_t argsubst = arg->substituteDiff(static_datatree, diff_table, subst_table, neweqs); + expr_t argsubst = arg->substituteDiff(static_datatree, diff_table, subst_table, neweqs, undiff_table); return buildSimilarUnaryOpNode(argsubst, datatree); } @@ -2928,7 +2948,7 @@ UnaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, rit != it->second.rend(); rit++) { expr_t argsubst = dynamic_cast(rit->second)-> - get_arg()->substituteDiff(static_datatree, diff_table, subst_table, neweqs); + get_arg()->substituteDiff(static_datatree, diff_table, subst_table, neweqs, undiff_table); int symb_id; VariableNode *vn = dynamic_cast(argsubst); if (rit == it->second.rbegin()) @@ -2946,6 +2966,7 @@ UnaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, datatree.AddMinus(argsubst, argsubst->decreaseLeadsLags(1))))); subst_table[rit->second] = dynamic_cast(last_aux_var); + undiff_table[symb_id] = vn->get_symb_id(); } else { @@ -2966,7 +2987,6 @@ UnaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, symb_id = datatree.symbol_table.addDiffAuxiliaryVar(new_aux_var->idx, new_aux_var, vn->get_symb_id(), i - 1); - new_aux_var = datatree.AddVariable(symb_id, 0); neweqs.push_back(dynamic_cast(datatree.AddEqual(new_aux_var, last_aux_var->decreaseLeadsLags(1)))); @@ -3171,9 +3191,9 @@ UnaryOpNode::addParamInfoToPac(pair &lhs_arg, set &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int equation_number_arg) +UnaryOpNode::fillPacExpectationVarInfo(string &model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg) { - arg->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, equation_number_arg); + arg->fillPacExpectationVarInfo(model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, growth_symb_id_arg, equation_number_arg); } bool @@ -4477,6 +4497,12 @@ BinaryOpNode::maxLag() const return max(arg1->maxLag(), arg2->maxLag()); } +int +BinaryOpNode::PacMaxLag(vector &lhs) const +{ + return max(arg1->PacMaxLag(lhs), arg2->PacMaxLag(lhs)); +} + expr_t BinaryOpNode::decreaseLeadsLags(int n) const { @@ -4621,10 +4647,10 @@ BinaryOpNode::findDiffNodes(DataTree &static_datatree, diff_table_t &diff_table) } expr_t -BinaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs) const +BinaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs, map &undiff_table) const { - expr_t arg1subst = arg1->substituteDiff(static_datatree, diff_table, subst_table, neweqs); - expr_t arg2subst = arg2->substituteDiff(static_datatree, diff_table, subst_table, neweqs); + expr_t arg1subst = arg1->substituteDiff(static_datatree, diff_table, subst_table, neweqs, undiff_table); + expr_t arg2subst = arg2->substituteDiff(static_datatree, diff_table, subst_table, neweqs, undiff_table); return buildSimilarBinaryOpNode(arg1subst, arg2subst, datatree); } @@ -4800,10 +4826,10 @@ BinaryOpNode::addParamInfoToPac(pair &lhs_arg, set &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int equation_number_arg) +BinaryOpNode::fillPacExpectationVarInfo(string &model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg) { - arg1->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, equation_number_arg); - arg2->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, equation_number_arg); + arg1->fillPacExpectationVarInfo(model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, growth_symb_id_arg, equation_number_arg); + arg2->fillPacExpectationVarInfo(model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, growth_symb_id_arg, equation_number_arg); } bool @@ -5397,6 +5423,12 @@ TrinaryOpNode::maxLag() const return max(arg1->maxLag(), max(arg2->maxLag(), arg3->maxLag())); } +int +TrinaryOpNode::PacMaxLag(vector &lhs) const +{ + return max(arg1->PacMaxLag(lhs), max(arg2->PacMaxLag(lhs), arg3->PacMaxLag(lhs))); +} + expr_t TrinaryOpNode::decreaseLeadsLags(int n) const { @@ -5492,11 +5524,11 @@ TrinaryOpNode::findDiffNodes(DataTree &static_datatree, diff_table_t &diff_table } expr_t -TrinaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs) const +TrinaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs, map &undiff_table) const { - expr_t arg1subst = arg1->substituteDiff(static_datatree, diff_table, subst_table, neweqs); - expr_t arg2subst = arg2->substituteDiff(static_datatree, diff_table, subst_table, neweqs); - expr_t arg3subst = arg3->substituteDiff(static_datatree, diff_table, subst_table, neweqs); + expr_t arg1subst = arg1->substituteDiff(static_datatree, diff_table, subst_table, neweqs, undiff_table); + expr_t arg2subst = arg2->substituteDiff(static_datatree, diff_table, subst_table, neweqs, undiff_table); + expr_t arg3subst = arg3->substituteDiff(static_datatree, diff_table, subst_table, neweqs, undiff_table); return buildSimilarTrinaryOpNode(arg1subst, arg2subst, arg3subst, datatree); } @@ -5606,11 +5638,11 @@ TrinaryOpNode::addParamInfoToPac(pair &lhs_arg, set &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int equation_number_arg) +TrinaryOpNode::fillPacExpectationVarInfo(string &model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg) { - arg1->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, equation_number_arg); - arg2->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, equation_number_arg); - arg3->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, equation_number_arg); + arg1->fillPacExpectationVarInfo(model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, growth_symb_id_arg, equation_number_arg); + arg2->fillPacExpectationVarInfo(model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, growth_symb_id_arg, equation_number_arg); + arg3->fillPacExpectationVarInfo(model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, growth_symb_id_arg, equation_number_arg); } bool @@ -5789,6 +5821,16 @@ AbstractExternalFunctionNode::maxLag() const return val; } +int +AbstractExternalFunctionNode::PacMaxLag(vector &lhs) const +{ + int val = 0; + for (vector::const_iterator it = arguments.begin(); + it != arguments.end(); it++) + val = max(val, (*it)->PacMaxLag(lhs)); + return val; +} + expr_t AbstractExternalFunctionNode::decreaseLeadsLags(int n) const { @@ -5869,11 +5911,11 @@ AbstractExternalFunctionNode::findDiffNodes(DataTree &static_datatree, diff_tabl } expr_t -AbstractExternalFunctionNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs) const +AbstractExternalFunctionNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs, map &undiff_table) const { vector arguments_subst; for (vector::const_iterator it = arguments.begin(); it != arguments.end(); it++) - arguments_subst.push_back((*it)->substituteDiff(static_datatree, diff_table, subst_table, neweqs)); + arguments_subst.push_back((*it)->substituteDiff(static_datatree, diff_table, subst_table, neweqs, undiff_table)); return buildSimilarExternalFunctionNode(arguments_subst, datatree); } @@ -6011,10 +6053,10 @@ AbstractExternalFunctionNode::addParamInfoToPac(pair &lhs_arg, set &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int equation_number_arg) +AbstractExternalFunctionNode::fillPacExpectationVarInfo(string &model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg) { for (vector::const_iterator it = arguments.begin(); it != arguments.end(); it++) - (*it)->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, equation_number_arg); + (*it)->fillPacExpectationVarInfo(model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, growth_symb_id_arg, equation_number_arg); } bool @@ -7280,6 +7322,12 @@ VarExpectationNode::maxLag() const return 0; } +int +VarExpectationNode::PacMaxLag(vector &lhs) const +{ + return 0; +} + expr_t VarExpectationNode::decreaseLeadsLags(int n) const { @@ -7403,7 +7451,7 @@ VarExpectationNode::findDiffNodes(DataTree &static_datatree, diff_table_t &diff_ } expr_t -VarExpectationNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs) const +VarExpectationNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs, map &undiff_table) const { return const_cast(this); } @@ -7503,7 +7551,7 @@ VarExpectationNode::addParamInfoToPac(pair &lhs_arg, set &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int equation_number_arg) +VarExpectationNode::fillPacExpectationVarInfo(string &model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg) { } @@ -7528,19 +7576,11 @@ VarExpectationNode::writeJsonOutput(ostream &output, } PacExpectationNode::PacExpectationNode(DataTree &datatree_arg, - const string &model_name_arg, - const string &var_model_name_arg, - const int discount_symb_id_arg, - const int growth_symb_id_arg) : + const string &model_name_arg) : ExprNode(datatree_arg), - model_name(model_name_arg), - var_model_name(var_model_name_arg), - discount_symb_id(discount_symb_id_arg), - growth_symb_id(growth_symb_id_arg), - stationary_vars_present(false), - nonstationary_vars_present(false) + model_name(model_name_arg) { - datatree.pac_expectation_node_map[make_pair(model_name, make_pair(var_model_name, make_pair(discount_symb_id, growth_symb_id)))] = this; + datatree.pac_expectation_node_map[model_name] = this; } void @@ -7568,13 +7608,13 @@ PacExpectationNode::computeTemporaryTerms(map &reference_count, expr_t PacExpectationNode::toStatic(DataTree &static_datatree) const { - return static_datatree.AddPacExpectation(string(model_name), string(var_model_name), discount_symb_id, growth_symb_id); + return static_datatree.AddPacExpectation(string(model_name)); } expr_t PacExpectationNode::cloneDynamic(DataTree &dynamic_datatree) const { - return dynamic_datatree.AddPacExpectation(string(model_name), string(var_model_name), discount_symb_id, growth_symb_id); + return dynamic_datatree.AddPacExpectation(string(model_name)); } void @@ -7586,47 +7626,19 @@ PacExpectationNode::writeOutput(ostream &output, ExprNodeOutputType output_type, if (IS_LATEX(output_type)) { - output << "PAC_EXPECTATION" << LEFT_PAR(output_type) << model_name << ", " - << var_model_name << ", " << discount_symb_id; - if (growth_symb_id >= 0) - output << ", " << growth_symb_id; - output << RIGHT_PAR(output_type); + output << "PAC_EXPECTATION" << LEFT_PAR(output_type) << model_name << RIGHT_PAR(output_type); return; } - output <<"M_.pac_expectation." << model_name << ".var_model_name = '" << var_model_name << "';" << endl - << "M_.pac_expectation." << model_name << ".discount_index = " - << datatree.symbol_table.getTypeSpecificID(discount_symb_id) + 1 << ";" << endl - << "M_.pac_expectation." << model_name << ".equation_number = " << equation_number + 1 << ";" << endl - << "M_.pac_expectation." << model_name << ".lhs_var = " + output << "M_.pac." << model_name << ".lhs_var = " << datatree.symbol_table.getTypeSpecificID(lhs_pac_var.first) + 1 << ";" << endl - << "M_.pac_expectation." << model_name << ".lhs_lag = " << lhs_pac_var.second << ";" << endl; + << "M_.pac." << model_name << ".lhs_lag = " << lhs_pac_var.second << ";" << endl; if (growth_symb_id >= 0) - { - output << "M_.pac_expectation." << model_name << ".growth_neutrality_param_index = " - << datatree.symbol_table.getTypeSpecificID(growth_param_index) + 1 << ";" << endl - << "M_.pac_expectation." << model_name << ".growth_index = " - << datatree.symbol_table.getTypeSpecificID(growth_symb_id) + 1 << ";" << endl - << "M_.pac_expectation." << model_name << ".growth_type = "; - switch(datatree.symbol_table.getType(growth_symb_id)) - { - case eEndogenous: - output << "'endogenous';" << endl; - break; - case eExogenous: - output << "'exogenous';" << endl; - break; - case eParameter: - output << "'parameter';" << endl; - break; - default: - cerr << "pac_expectation: error encountered in growth type" << endl; - exit(EXIT_FAILURE); - } - } + output << "M_.pac." << model_name << ".growth_neutrality_param_index = " + << datatree.symbol_table.getTypeSpecificID(growth_param_index) + 1 << ";" << endl; - output << "M_.pac_expectation." << model_name << ".equation_params = ["; + output << "M_.pac." << model_name << ".equation_params = ["; for (set > >::const_iterator it = params_and_vals.begin(); it != params_and_vals.end(); it++) { @@ -7635,7 +7647,7 @@ PacExpectationNode::writeOutput(ostream &output, ExprNodeOutputType output_type, output << datatree.symbol_table.getTypeSpecificID(it->first) + 1; } output << "];" << endl - << "M_.pac_expectation." << model_name << ".equation_vars = ["; + << "M_.pac." << model_name << ".equation_vars = ["; for (set > >::const_iterator it = params_and_vals.begin(); it != params_and_vals.end(); it++) { @@ -7644,7 +7656,7 @@ PacExpectationNode::writeOutput(ostream &output, ExprNodeOutputType output_type, output << datatree.symbol_table.getTypeSpecificID(it->second.first) + 1; } output << "];" << endl - << "M_.pac_expectation." << model_name << ".equation_var_lags = ["; + << "M_.pac." << model_name << ".equation_var_lags = ["; for (set > >::const_iterator it = params_and_vals.begin(); it != params_and_vals.end(); it++) { @@ -7653,7 +7665,7 @@ PacExpectationNode::writeOutput(ostream &output, ExprNodeOutputType output_type, output << it->second.second; } output << "];" << endl - << "M_.pac_expectation." << model_name << ".h0_param_indices = ["; + << "M_.pac." << model_name << ".h0_param_indices = ["; for (vector::const_iterator it = h0_indices.begin(); it != h0_indices.end(); it++) { @@ -7662,7 +7674,7 @@ PacExpectationNode::writeOutput(ostream &output, ExprNodeOutputType output_type, output << datatree.symbol_table.getTypeSpecificID(*it) + 1; } output << "];" << endl - << "M_.pac_expectation." << model_name << ".h1_param_indices = ["; + << "M_.pac." << model_name << ".h1_param_indices = ["; for (vector::const_iterator it = h1_indices.begin(); it != h1_indices.end(); it++) { @@ -7709,6 +7721,12 @@ PacExpectationNode::maxLag() const return 0; } +int +PacExpectationNode::PacMaxLag(vector &lhs) const +{ + return 0; +} + expr_t PacExpectationNode::decreaseLeadsLags(int n) const { @@ -7831,7 +7849,7 @@ PacExpectationNode::findDiffNodes(DataTree &static_datatree, diff_table_t &diff_ } expr_t -PacExpectationNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs) const +PacExpectationNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs, map &undiff_table) const { return const_cast(this); } @@ -7925,11 +7943,8 @@ PacExpectationNode::writeJsonOutput(ostream &output, const bool isdynamic) const { output << "pac_expectation(" - << ", model_name = " << model_name - << ", " << discount_symb_id; - if (growth_symb_id >= 0) - output << ", " << growth_symb_id; - output << ")"; + << "model_name = " << model_name + << ")"; } void @@ -7959,13 +7974,14 @@ PacExpectationNode::addParamInfoToPac(pair &lhs_arg, set &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int equation_number_arg) +PacExpectationNode::fillPacExpectationVarInfo(string &model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg) { - if (var_model_name != var_model_name_arg) + if (model_name != model_name_arg) return; lhs = lhs_arg; max_lag = max_lag_arg; + growth_symb_id = growth_symb_id_arg; equation_number = equation_number_arg; for (vector::const_iterator it = nonstationary_arg.begin(); diff --git a/src/ExprNode.hh b/src/ExprNode.hh index 46326535..6de78059 100644 --- a/src/ExprNode.hh +++ b/src/ExprNode.hh @@ -349,6 +349,10 @@ class ExprNode /*! A negative value means that the expression contains only leaded variables */ virtual int maxLag() const = 0; + //! Get Max lag of var associated with Pac model + //! Takes account of undiffed LHS variables in calculating the max lag + virtual int PacMaxLag(vector &lhs) const = 0; + //! Returns a new expression where all the leads/lags have been shifted backwards by the same amount /*! Only acts on endogenous, exogenous, exogenous det @@ -476,7 +480,7 @@ class ExprNode //! Substitute diff operator virtual void findDiffNodes(DataTree &static_datatree, diff_table_t &diff_table) const = 0; - virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs) const = 0; + virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs, map &undiff_table) const = 0; //! Substitute pac_expectation operator virtual expr_t substitutePacExpectation(map &subst_table) = 0; @@ -506,7 +510,7 @@ class ExprNode virtual void addParamInfoToPac(pair &lhs_arg, set > > ¶ms_and_vals_arg) = 0; //! Fills var_model info for pac_expectation node - virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int equation_number_arg) = 0; + virtual void fillPacExpectationVarInfo(string &model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg) = 0; //! Fills map virtual void getEndosAndMaxLags(map &model_endos_and_lags) const = 0; @@ -555,6 +559,7 @@ public: virtual int maxExoLag() const; virtual int maxLead() const; virtual int maxLag() const; + virtual int PacMaxLag(vector &lhs) const; virtual expr_t decreaseLeadsLags(int n) const; virtual expr_t substituteEndoLeadGreaterThanTwo(subst_table_t &subst_table, vector &neweqs, bool deterministic_model) const; virtual expr_t substituteEndoLagGreaterThanTwo(subst_table_t &subst_table, vector &neweqs) const; @@ -563,7 +568,7 @@ public: virtual expr_t substituteExpectation(subst_table_t &subst_table, vector &neweqs, bool partial_information_model) const; virtual expr_t substituteAdl() const; virtual void findDiffNodes(DataTree &static_datatree, diff_table_t &diff_table) const; - virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs) const; + virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs, map &undiff_table) const; virtual expr_t substitutePacExpectation(map &subst_table); virtual expr_t decreaseLeadsLagsPredeterminedVariables() const; virtual expr_t differentiateForwardVars(const vector &subset, subst_table_t &subst_table, vector &neweqs) const; @@ -580,7 +585,7 @@ public: virtual void setVarExpectationIndex(map > &var_model_info); virtual void walkPacParameters(bool &pac_encountered, pair &lhs, set > > ¶ms_and_vals) const; virtual void addParamInfoToPac(pair &lhs_arg, set > > ¶ms_and_vals_arg); - virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int equation_number_arg); + virtual void fillPacExpectationVarInfo(string &model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg); virtual bool isVarModelReferenced(const string &model_info_name) const; virtual void getEndosAndMaxLags(map &model_endos_and_lags) const; virtual expr_t substituteStaticAuxiliaryVariable() const; @@ -638,6 +643,7 @@ public: virtual int maxExoLag() const; virtual int maxLead() const; virtual int maxLag() const; + virtual int PacMaxLag(vector &lhs) const; virtual expr_t decreaseLeadsLags(int n) const; virtual expr_t substituteEndoLeadGreaterThanTwo(subst_table_t &subst_table, vector &neweqs, bool deterministic_model) const; virtual expr_t substituteEndoLagGreaterThanTwo(subst_table_t &subst_table, vector &neweqs) const; @@ -646,7 +652,7 @@ public: virtual expr_t substituteExpectation(subst_table_t &subst_table, vector &neweqs, bool partial_information_model) const; virtual expr_t substituteAdl() const; virtual void findDiffNodes(DataTree &static_datatree, diff_table_t &diff_table) const; - virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs) const; + virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs, map &undiff_table) const; virtual expr_t substitutePacExpectation(map &subst_table); virtual expr_t decreaseLeadsLagsPredeterminedVariables() const; virtual expr_t differentiateForwardVars(const vector &subset, subst_table_t &subst_table, vector &neweqs) const; @@ -663,7 +669,7 @@ public: virtual void setVarExpectationIndex(map > &var_model_info); virtual void walkPacParameters(bool &pac_encountered, pair &lhs, set > > ¶ms_and_vals) const; virtual void addParamInfoToPac(pair &lhs_arg, set > > ¶ms_and_vals_arg); - virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int equation_number_arg); + virtual void fillPacExpectationVarInfo(string &model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg); virtual bool isVarModelReferenced(const string &model_info_name) const; virtual void getEndosAndMaxLags(map &model_endos_and_lags) const; //! Substitute auxiliary variables by their expression in static model @@ -741,6 +747,7 @@ public: virtual int maxExoLag() const; virtual int maxLead() const; virtual int maxLag() const; + virtual int PacMaxLag(vector &lhs) const; virtual expr_t decreaseLeadsLags(int n) const; virtual expr_t substituteEndoLeadGreaterThanTwo(subst_table_t &subst_table, vector &neweqs, bool deterministic_model) const; //! Creates another UnaryOpNode with the same opcode, but with a possibly different datatree and argument @@ -751,7 +758,7 @@ public: virtual expr_t substituteExpectation(subst_table_t &subst_table, vector &neweqs, bool partial_information_model) const; virtual expr_t substituteAdl() const; virtual void findDiffNodes(DataTree &static_datatree, diff_table_t &diff_table) const; - virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs) const; + virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs, map &undiff_table) const; virtual expr_t substitutePacExpectation(map &subst_table); virtual expr_t decreaseLeadsLagsPredeterminedVariables() const; virtual expr_t differentiateForwardVars(const vector &subset, subst_table_t &subst_table, vector &neweqs) const; @@ -768,7 +775,7 @@ public: virtual void setVarExpectationIndex(map > &var_model_info); virtual void walkPacParameters(bool &pac_encountered, pair &lhs, set > > ¶ms_and_vals) const; virtual void addParamInfoToPac(pair &lhs_arg, set > > ¶ms_and_vals_arg); - virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int equation_number_arg); + virtual void fillPacExpectationVarInfo(string &model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg); virtual bool isVarModelReferenced(const string &model_info_name) const; virtual void getEndosAndMaxLags(map &model_endos_and_lags) const; //! Substitute auxiliary variables by their expression in static model @@ -862,6 +869,7 @@ public: virtual int maxExoLag() const; virtual int maxLead() const; virtual int maxLag() const; + virtual int PacMaxLag(vector &lhs) const; virtual expr_t decreaseLeadsLags(int n) const; virtual expr_t substituteEndoLeadGreaterThanTwo(subst_table_t &subst_table, vector &neweqs, bool deterministic_model) const; //! Creates another BinaryOpNode with the same opcode, but with a possibly different datatree and arguments @@ -872,7 +880,7 @@ public: virtual expr_t substituteExpectation(subst_table_t &subst_table, vector &neweqs, bool partial_information_model) const; virtual expr_t substituteAdl() const; virtual void findDiffNodes(DataTree &static_datatree, diff_table_t &diff_table) const; - virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs) const; + virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs, map &undiff_table) const; virtual expr_t substitutePacExpectation(map &subst_table); virtual expr_t decreaseLeadsLagsPredeterminedVariables() const; virtual expr_t differentiateForwardVars(const vector &subset, subst_table_t &subst_table, vector &neweqs) const; @@ -895,7 +903,7 @@ public: virtual void setVarExpectationIndex(map > &var_model_info); virtual void walkPacParameters(bool &pac_encountered, pair &lhs, set > > ¶ms_and_vals) const; virtual void addParamInfoToPac(pair &lhs_arg, set > > ¶ms_and_vals_arg); - virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int equation_number_arg); + virtual void fillPacExpectationVarInfo(string &model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg); virtual bool isVarModelReferenced(const string &model_info_name) const; virtual void getEndosAndMaxLags(map &model_endos_and_lags) const; //! Substitute auxiliary variables by their expression in static model @@ -960,6 +968,7 @@ public: virtual int maxExoLag() const; virtual int maxLead() const; virtual int maxLag() const; + virtual int PacMaxLag(vector &lhs) const; virtual expr_t decreaseLeadsLags(int n) const; virtual expr_t substituteEndoLeadGreaterThanTwo(subst_table_t &subst_table, vector &neweqs, bool deterministic_model) const; //! Creates another TrinaryOpNode with the same opcode, but with a possibly different datatree and arguments @@ -970,7 +979,7 @@ public: virtual expr_t substituteExpectation(subst_table_t &subst_table, vector &neweqs, bool partial_information_model) const; virtual expr_t substituteAdl() const; virtual void findDiffNodes(DataTree &static_datatree, diff_table_t &diff_table) const; - virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs) const; + virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs, map &undiff_table) const; virtual expr_t substitutePacExpectation(map &subst_table); virtual expr_t decreaseLeadsLagsPredeterminedVariables() const; virtual expr_t differentiateForwardVars(const vector &subset, subst_table_t &subst_table, vector &neweqs) const; @@ -987,7 +996,7 @@ public: virtual void setVarExpectationIndex(map > &var_model_info); virtual void walkPacParameters(bool &pac_encountered, pair &lhs, set > > ¶ms_and_vals) const; virtual void addParamInfoToPac(pair &lhs_arg, set > > ¶ms_and_vals_arg); - virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int equation_number_arg); + virtual void fillPacExpectationVarInfo(string &model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg); virtual bool isVarModelReferenced(const string &model_info_name) const; virtual void getEndosAndMaxLags(map &model_endos_and_lags) const; //! Substitute auxiliary variables by their expression in static model @@ -1060,6 +1069,7 @@ public: virtual int maxExoLag() const; virtual int maxLead() const; virtual int maxLag() const; + virtual int PacMaxLag(vector &lhs) const; virtual expr_t decreaseLeadsLags(int n) const; virtual expr_t substituteEndoLeadGreaterThanTwo(subst_table_t &subst_table, vector &neweqs, bool deterministic_model) const; virtual expr_t substituteEndoLagGreaterThanTwo(subst_table_t &subst_table, vector &neweqs) const; @@ -1068,7 +1078,7 @@ public: virtual expr_t substituteExpectation(subst_table_t &subst_table, vector &neweqs, bool partial_information_model) const; virtual expr_t substituteAdl() const; virtual void findDiffNodes(DataTree &static_datatree, diff_table_t &diff_table) const; - virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs) const; + virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs, map &undiff_table) const; virtual expr_t substitutePacExpectation(map &subst_table); virtual expr_t buildSimilarExternalFunctionNode(vector &alt_args, DataTree &alt_datatree) const = 0; virtual expr_t decreaseLeadsLagsPredeterminedVariables() const; @@ -1087,7 +1097,7 @@ public: virtual void setVarExpectationIndex(map > &var_model_info); virtual void walkPacParameters(bool &pac_encountered, pair &lhs, set > > ¶ms_and_vals) const; virtual void addParamInfoToPac(pair &lhs_arg, set > > ¶ms_and_vals_arg); - virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int equation_number_arg); + virtual void fillPacExpectationVarInfo(string &model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg); virtual bool isVarModelReferenced(const string &model_info_name) const; virtual void getEndosAndMaxLags(map &model_endos_and_lags) const; //! Substitute auxiliary variables by their expression in static model @@ -1243,6 +1253,7 @@ public: virtual int maxExoLag() const; virtual int maxLead() const; virtual int maxLag() const; + virtual int PacMaxLag(vector &lhs) const; virtual expr_t decreaseLeadsLags(int n) const; virtual void prepareForDerivation(); virtual expr_t computeDerivative(int deriv_id); @@ -1257,7 +1268,7 @@ public: virtual expr_t substituteExpectation(subst_table_t &subst_table, vector &neweqs, bool partial_information_model) const; virtual expr_t substituteAdl() const; virtual void findDiffNodes(DataTree &static_datatree, diff_table_t &diff_table) const; - virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs) const; + virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs, map &undiff_table) const; virtual expr_t substitutePacExpectation(map &subst_table); virtual pair normalizeEquation(int symb_id_endo, vector > > &List_of_Op_RHS) const; virtual void compile(ostream &CompileCode, unsigned int &instruction_number, @@ -1280,7 +1291,7 @@ public: virtual void setVarExpectationIndex(map > &var_model_info); virtual void walkPacParameters(bool &pac_encountered, pair &lhs, set > > ¶ms_and_vals) const; virtual void addParamInfoToPac(pair &lhs_arg, set > > ¶ms_and_vals_arg); - virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int equation_number_arg); + virtual void fillPacExpectationVarInfo(string &model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg); virtual bool isVarModelReferenced(const string &model_info_name) const; virtual void getEndosAndMaxLags(map &model_endos_and_lags) const; virtual expr_t substituteStaticAuxiliaryVariable() const; @@ -1290,8 +1301,9 @@ public: class PacExpectationNode : public ExprNode { private: - const string model_name, var_model_name; - const int discount_symb_id, growth_symb_id; + const string model_name; + string var_model_name; + int growth_symb_id; bool stationary_vars_present, nonstationary_vars_present; vector lhs; pair lhs_pac_var; @@ -1300,8 +1312,7 @@ private: int growth_param_index, equation_number; set > > params_and_vals; public: - PacExpectationNode(DataTree &datatree_arg, const string &model_name, const string &var_model_name, - const int discount_arg, const int growth_arg); + PacExpectationNode(DataTree &datatree_arg, const string &model_name); virtual void computeTemporaryTerms(map > &reference_count, map &temp_terms_map, bool is_matlab, NodeTreeReference tr) const; @@ -1320,6 +1331,7 @@ public: virtual int maxExoLag() const; virtual int maxLead() const; virtual int maxLag() const; + virtual int PacMaxLag(vector &lhs) const; virtual expr_t decreaseLeadsLags(int n) const; virtual void prepareForDerivation(); virtual expr_t computeDerivative(int deriv_id); @@ -1334,7 +1346,7 @@ public: virtual expr_t substituteExpectation(subst_table_t &subst_table, vector &neweqs, bool partial_information_model) const; virtual expr_t substituteAdl() const; virtual void findDiffNodes(DataTree &static_datatree, diff_table_t &diff_table) const; - virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs) const; + virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector &neweqs, map &undiff_table) const; virtual expr_t substitutePacExpectation(map &subst_table); virtual pair normalizeEquation(int symb_id_endo, vector > > &List_of_Op_RHS) const; virtual void compile(ostream &CompileCode, unsigned int &instruction_number, @@ -1357,7 +1369,7 @@ public: virtual void setVarExpectationIndex(map > &var_model_info); virtual void walkPacParameters(bool &pac_encountered, pair &lhs, set > > ¶ms_and_vals) const; virtual void addParamInfoToPac(pair &lhs_arg, set > > ¶ms_and_vals_arg); - virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int equation_number_arg); + virtual void fillPacExpectationVarInfo(string &model_name_arg, vector &lhs_arg, int max_lag_arg, vector &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg); virtual bool isVarModelReferenced(const string &model_info_name) const; virtual void getEndosAndMaxLags(map &model_endos_and_lags) const; virtual expr_t substituteStaticAuxiliaryVariable() const; diff --git a/src/ModFile.cc b/src/ModFile.cc index 042f19ce..402a8ab1 100644 --- a/src/ModFile.cc +++ b/src/ModFile.cc @@ -324,7 +324,11 @@ ModFile::checkPass(bool nostrict, bool stochastic) } // Check if some exogenous is not used in the model block, Issue #841 - set unusedExo = dynamic_model.findUnusedExogenous(); + set unusedExo0 = dynamic_model.findUnusedExogenous(); + set unusedExo; + set_difference(unusedExo0.begin(), unusedExo0.end(), + mod_file_struct.pac_params.begin(), mod_file_struct.pac_params.end(), + inserter(unusedExo, unusedExo.begin())); if (unusedExo.size() > 0) { ostringstream unused_exos; @@ -363,39 +367,67 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, const } // Create auxiliary variable and equations for Diff operator - dynamic_model.substituteDiff(diff_static_model); + map undiff_table; + dynamic_model.substituteDiff(diff_static_model, undiff_table); // Var Model map > var_model_info_var_expectation; + map > var_model_eq_tags; + map, pair, vector > >, pair >, vector > > > var_model_info_pac_expectation; for (vector::const_iterator it = statements.begin(); it != statements.end(); it++) { VarModelStatement *vms = dynamic_cast(*it); if (vms != NULL) { + string var_model_name; + vms->getVarModelName(var_model_name); + vms->getVarModelEqTags(var_model_eq_tags); vms->getVarModelInfoForVarExpectation(var_model_info_var_expectation); - - vector var_model_eqtags; - vms->getVarModelEqTags(var_model_eqtags); - if (!var_model_eqtags.empty()) - { - int max_lag = 0; - vector eqnumber, lhs, orig_diff_var; - vector > > rhs; - vector nonstationary, diff; - dynamic_model.getVarModelVariablesFromEqTags(var_model_eqtags, - eqnumber, lhs, rhs, nonstationary); - original_model.getVarMaxLagAndLhsDiffAndInfo(eqnumber, diff, orig_diff_var, max_lag); - vms->fillVarModelInfoFromEquations(eqnumber, lhs, rhs, nonstationary, - diff, orig_diff_var, max_lag); - string var_model_name; - vms->getVarModelName(var_model_name); - dynamic_model.walkPacParameters(); - dynamic_model.fillPacExpectationVarInfo(var_model_name, lhs, max_lag, nonstationary); - dynamic_model.substitutePacExpectation(); - } + int max_lag = 0; + vector eqnumber, lhs, orig_diff_var; + vector > > rhs; + vector nonstationary, diff; + vector eqtags = var_model_eq_tags[var_model_name]; + dynamic_model.getVarModelVariablesFromEqTags(eqtags, + eqnumber, lhs, rhs, nonstationary); + original_model.getVarMaxLagAndLhsDiffAndInfo(eqnumber, diff, orig_diff_var, max_lag); + vms->fillVarModelInfoFromEquations(eqnumber, lhs, rhs, nonstationary, + diff, orig_diff_var, max_lag); + var_model_info_pac_expectation[var_model_name] = + make_pair(make_pair(lhs, make_pair(diff, orig_diff_var)), make_pair(make_pair(max_lag, nonstationary), eqnumber)); } - } + + PacModelStatement *pms = dynamic_cast(*it); + if (pms != NULL) + { + pair > > > > pac_model_info_pac_expectation; + pms->getPacModelInfoForPacExpectation(pac_model_info_pac_expectation); + string pac_model_name = pac_model_info_pac_expectation.first; + string var_model_name = pac_model_info_pac_expectation.second.first; + vector eqtags = var_model_eq_tags[var_model_name]; + if (!eqtags.empty()) + { + vector lhs = var_model_info_pac_expectation[var_model_name].first.first; + map undiff = pac_model_info_pac_expectation.second.second.second.second; + int max_lag = var_model_info_pac_expectation[var_model_name].second.first.first; + vector nonstationary = var_model_info_pac_expectation[var_model_name].second.first.second; + if (!undiff.empty()) + { + vector diff = var_model_info_pac_expectation[var_model_name].first.second.first; + vector orig_diff_var = var_model_info_pac_expectation[var_model_name].first.second.second; + vector eqnumber = var_model_info_pac_expectation[var_model_name].second.second; + dynamic_model.undiff_lhs_for_pac(lhs, diff, orig_diff_var, eqnumber, undiff, undiff_table); + max_lag = dynamic_model.get_undiff_max_lag(eqnumber, lhs); + } + pms->fillUndiffedLHS(lhs); + dynamic_model.walkPacParameters(); + int growth_symb_id = pac_model_info_pac_expectation.second.second.second.first; + dynamic_model.fillPacExpectationVarInfo(pac_model_name, lhs, max_lag, nonstationary, growth_symb_id); + dynamic_model.substitutePacExpectation(); + } + } + } if (!var_model_info_var_expectation.empty()) { diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc index 6845ed6f..a6e6bf3b 100644 --- a/src/ParsingDriver.cc +++ b/src/ParsingDriver.cc @@ -2813,73 +2813,51 @@ ParsingDriver::add_var_expectation(string *arg1, string *arg2, string *arg3) } expr_t -ParsingDriver::add_pac_expectation() +ParsingDriver::add_pac_expectation(string *var_model_name) { - if (pac_expectation_model_name.empty()) - error("pac_expectation: you must pass the model_name option"); - - if (pac_expectation_var_model_name.empty()) - error("pac_expectation: you must pass the var_model_name option"); - - if (pac_expectation_discount.empty()) - error("pac_expectation: you must pass the discount option"); - - int pac_expectation_discount_id = - mod_file->symbol_table.getID(pac_expectation_discount); - - int pac_expectation_growth_id = -1; - if (!pac_expectation_growth.empty()) - pac_expectation_growth_id = mod_file->symbol_table.getID(pac_expectation_growth); - - expr_t pac_exp_node = data_tree->AddPacExpectation(pac_expectation_model_name, - pac_expectation_var_model_name, - pac_expectation_discount_id, - pac_expectation_growth_id); - - pac_expectation_model_name = pac_expectation_discount = pac_expectation_growth = ""; - + expr_t pac_exp_node = data_tree->AddPacExpectation(*var_model_name); + delete var_model_name; return pac_exp_node; } void -ParsingDriver::add_pac_expectation_model_name(string *arg) +ParsingDriver::pac_model() { - if (!pac_expectation_model_name.empty()) - error("pac_expectation: you can only pass the model_name option once"); - pac_expectation_model_name = *arg; - delete arg; + OptionsList::string_options_t::const_iterator it = options_list.string_options.find("pac.model_name"); + if (it == options_list.string_options.end()) + error("You must pass the model_name option to the pac_model statement."); + const string *name = new string(it->second); + + it = options_list.string_options.find("pac.var_model_name"); + if (it == options_list.string_options.end()) + error("You must pass the var_model_name option to the pac_model statement."); + const string *var_name = new string(it->second); + + it = options_list.string_options.find("pac.discount"); + if (it == options_list.string_options.end()) + error("You must pass the discount option to the pac_model statement."); + const string *discount = new string(it->second); + + string *growth; + it = options_list.string_options.find("pac.growth"); + if (it == options_list.string_options.end()) + growth = new string(""); + else + growth = new string(it->second); + + mod_file->addStatement(new PacModelStatement(*name, *var_name, *discount, *growth, pac_undiff, mod_file->symbol_table)); + + symbol_list.clear(); + options_list.clear(); + pac_undiff.clear(); } void -ParsingDriver::add_pac_expectation_var_model_name(string *arg) +ParsingDriver::pac_model_undiff(string *eqtag, string *order) { - if (!pac_expectation_var_model_name.empty()) - error("pac_expectation: you can only pass the var_model_name option once"); - pac_expectation_var_model_name = *arg; - delete arg; -} - -void -ParsingDriver::add_pac_expectation_discount(string *arg) -{ - if (!pac_expectation_discount.empty()) - error("pac_expectation: you can only pass the discount option once"); - check_symbol_is_parameter(arg); - pac_expectation_discount = *arg; - delete arg; -} - -void -ParsingDriver::add_pac_expectation_growth(string *arg) -{ - if (!pac_expectation_growth.empty()) - error("pac_expectation: you can only pass the growth option once"); - check_symbol_existence(*arg); - SymbolType type = mod_file->symbol_table.getType(mod_file->symbol_table.getID(*arg)); - if (type != eParameter && type != eEndogenous && type != eExogenous) - error("pac_expectation growth argument must either be a parameter or an endogenous or exogenous variable."); - pac_expectation_growth = *arg; - delete arg; + pac_undiff[*eqtag] = atoi(order->c_str()); + delete eqtag; + delete order; } expr_t diff --git a/src/ParsingDriver.hh b/src/ParsingDriver.hh index c4d29342..ce80b945 100644 --- a/src/ParsingDriver.hh +++ b/src/ParsingDriver.hh @@ -234,6 +234,8 @@ private: SymbolList graph_formats; //! Temporary storage for equation tags vector > eq_tags; + //! Temporary storage for pac statement undiff option + map pac_undiff; //! Map Var name to variables map > var_map; @@ -251,9 +253,6 @@ private: //! Used by VAR restrictions void clear_VAR_storage(); - //! Used by pac_expectation - string pac_expectation_model_name, pac_expectation_var_model_name, pac_expectation_discount, pac_expectation_growth; - public: ParsingDriver(WarningConsolidation &warnings_arg, bool nostrict_arg) : warnings(warnings_arg), nostrict(nostrict_arg) { }; @@ -693,12 +692,11 @@ public: //! Writes token "VAR_EXPECTATION(arg1, arg2, arg3)" to model tree expr_t add_var_expectation(string *arg1, string *arg2, string *arg3); //! Writes token "PAC_EXPECTATION(model_name, discount, growth)" to model tree - expr_t add_pac_expectation(); - //! Adds arguments for pac_expectation - void add_pac_expectation_model_name(string *arg); - void add_pac_expectation_var_model_name(string *arg); - void add_pac_expectation_discount(string *arg); - void add_pac_expectation_growth(string *arg); + expr_t add_pac_expectation(string *var_model_name); + //! Creates pac_model statement + void pac_model(); + //! Add undiff option for pac_model statement + void pac_model_undiff(string *eqtag, string *order); //! Writes token "diff(arg1)" to model tree expr_t add_diff(expr_t arg1); //! Writes token "adl(arg1, lag)" to model tree diff --git a/src/Statement.hh b/src/Statement.hh index e9b0a96e..b08e64c5 100644 --- a/src/Statement.hh +++ b/src/Statement.hh @@ -125,6 +125,8 @@ public: bool write_latex_steady_state_model_present; //! Histval values that do not have the appropriate lag map hist_vals_wrong_lag; + //! Pac growth and discount + set pac_params; }; class Statement