Commit d922ae8f authored by Houtan Bastani's avatar Houtan Bastani

pac_model: permit lag on growth option

parent 9c95bfa3
Pipeline #651 passed with stage
in 1 minute and 22 seconds
......@@ -260,12 +260,14 @@ PriorPosteriorFunctionStatement::writeJsonOutput(ostream &output) const
PacModelStatement::PacModelStatement(string name_arg,
string aux_model_name_arg,
string discount_arg,
string growth_arg,
int growth_symb_id_arg,
int growth_lag_arg,
const SymbolTable &symbol_table_arg) :
name{move(name_arg)},
aux_model_name{move(aux_model_name_arg)},
discount{move(discount_arg)},
growth{move(growth_arg)},
growth_symb_id{growth_symb_id_arg},
growth_lag{growth_lag_arg},
symbol_table{symbol_table_arg}
{
}
......@@ -274,8 +276,24 @@ 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));
if (growth_symb_id >= 0)
{
switch (symbol_table.getType(growth_symb_id))
{
case SymbolType::endogenous:
case SymbolType::exogenous:
case SymbolType::parameter:
break;
default:
{
cerr << "ERROR: The Expression passed to the growth option of pac_model must be an "
<< "endogenous (lagged or not), exogenous (lagged or not), or parameter" << endl;
exit(EXIT_FAILURE);
}
}
mod_file_struct.pac_params.insert(growth_symb_id);
mod_file_struct.pac_params.insert(growth_lag);
}
}
void
......@@ -290,27 +308,53 @@ PacModelStatement::writeOutput(ostream &output, const string &basename, bool min
output << "M_.pac." << name << ".auxiliary_model_name = '" << aux_model_name << "';" << endl
<< "M_.pac." << name << ".discount_index = " << symbol_table.getTypeSpecificID(discount) + 1 << ";" << endl;
if (!growth.empty())
if (growth_symb_id >= 0)
{
output << "M_.pac." << name << ".growth_index = " << symbol_table.getTypeSpecificID(growth) + 1 << ";" << endl
<< "M_.pac." << name << ".growth_type = ";
switch(symbol_table.getType(growth))
string growth_type;
switch (symbol_table.getType(growth_symb_id))
{
case SymbolType::endogenous:
output << "'endogenous';" << endl;
growth_type = "endogenous";
break;
case SymbolType::exogenous:
output << "'exogenous';" << endl;
growth_type = "exogenous";
break;
case SymbolType::parameter:
output << "'parameter';" << endl;
growth_type = "parameter";
break;
default:
cerr << "pac_model: error encountered in growth type" << endl;
exit(EXIT_FAILURE);
{
}
}
}
try
{
// case when this is not the highest lag of the growth variable
int aux_symb_id = symbol_table.searchAuxiliaryVars(growth_symb_id, growth_lag);
output << "M_.pac." << name << ".growth_index = " << symbol_table.getTypeSpecificID(aux_symb_id) + 1 << ";" << endl
<< "M_.pac." << name << ".growth_lag = 0;" << endl
<< "M_.pac." << name << ".growth_type = '" << growth_type << "';" << endl;
}
catch (...)
{
try
{
// case when this is the highest lag of the growth variable
int tmp_growth_lag = growth_lag + 1;
int aux_symb_id = symbol_table.searchAuxiliaryVars(growth_symb_id, tmp_growth_lag);
output << "M_.pac." << name << ".growth_index = " << symbol_table.getTypeSpecificID(aux_symb_id) + 1 << ";" << endl
<< "M_.pac." << name << ".growth_lag = -1;" << endl
<< "M_.pac." << name << ".growth_type = '" << growth_type << "';" << endl;
}
catch (...)
{
// case when there is no aux var for the variable
output << "M_.pac." << name << ".growth_index = " << symbol_table.getTypeSpecificID(growth_symb_id) + 1 << ";" << endl
<< "M_.pac." << name << ".growth_lag = " << growth_lag << ";" << endl
<< "M_.pac." << name << ".growth_type = '" << growth_type << "';" << endl;
}
}
}
output << "M_.pac." << name << ".lhs = [";
for (auto it = lhs.begin(); it !=lhs.end(); it++)
{
......@@ -319,24 +363,6 @@ PacModelStatement::writeOutput(ostream &output, const string &basename, bool min
output << *it + 1;
}
output << "];" << endl;
/*
<< "M_.pac." << name << ".undiff_eqtags = {";
for (auto it = undiff.begin(); it != undiff.end(); it++)
{
if (it != undiff.begin())
output << "; ";
output << "'" << it->first << "'";
}
output << "};" << endl
<< "M_.pac." << name << ".undiff_num = [";
for (auto it = undiff.begin(); it != undiff.end(); it++)
{
if (it != undiff.begin())
output << " ";
output << it->second;
}
output << "];" << endl;
*/
}
void
......@@ -347,37 +373,36 @@ PacModelStatement::writeJsonOutput(ostream &output) const
<< "\"auxiliary_model_name\": \"" << aux_model_name << "\","
<< "\"discount_index\": " << symbol_table.getTypeSpecificID(discount) + 1;
if (!growth.empty())
if (growth_symb_id >= 0)
{
output << ","
<< "\"growth_index\": " << symbol_table.getTypeSpecificID(growth) + 1 << ","
<< "\"growth_type\": ";
switch(symbol_table.getType(growth))
string growth_type;
switch (symbol_table.getType(growth_symb_id))
{
case SymbolType::endogenous:
output << "\"endogenous\"" << endl;
growth_type = "endogenous";
break;
case SymbolType::exogenous:
output << "\"exogenous\"" << endl;
growth_type = "exogenous";
break;
case SymbolType::parameter:
output << "\"parameter\"" << endl;
growth_type = "parameter";
break;
default:
cerr << "pac_model: error encountered in growth type" << endl;
exit(EXIT_FAILURE);
{
}
}
output << ","
<< "\"growth_index\": " << symbol_table.getTypeSpecificID(growth_symb_id) + 1 << ","
<< "\"growth_lag\": " << growth_lag << ","
<< "\"growth_type\": " << "\"" << growth_type << "\"" << endl;
}
output << "}";
}
tuple<string, string, int>
tuple<string, string, int, int>
PacModelStatement::getPacModelInfoForPacExpectation() const
{
int growth_symb_id = -1;
if (!growth.empty())
growth_symb_id = symbol_table.getID(growth);
return { name, aux_model_name, growth_symb_id };
return { name, aux_model_name, growth_symb_id, growth_lag };
}
VarEstimationStatement::VarEstimationStatement(OptionsList options_list_arg) :
......
/*
* Copyright (C) 2003-2018 Dynare Team
* Copyright (C) 2003-2019 Dynare Team
*
* This file is part of Dynare.
*
......@@ -140,20 +140,21 @@ private:
const string name;
const string aux_model_name;
const string discount;
const string growth;
const int growth_symb_id, growth_lag;
const SymbolTable &symbol_table;
vector<int> lhs;
public:
PacModelStatement(string name_arg,
string aux_model_name_arg,
string discount_arg,
string growth_arg,
int growth_symb_id_arg,
int growth_lag_arg,
const SymbolTable &symbol_table_arg);
void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) override;
void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const override;
void writeJsonOutput(ostream &output) const override;
void fillUndiffedLHS(vector<int> &lhs);
tuple<string, string, int> getPacModelInfoForPacExpectation() const;
tuple<string, string, int, int> getPacModelInfoForPacExpectation() const;
};
class VarRestrictionsStatement : public Statement
......
/*
* Copyright (C) 2003-2018 Dynare Team
* Copyright (C) 2003-2019 Dynare Team
*
* This file is part of Dynare.
*
......@@ -4318,11 +4318,11 @@ DynamicModel::fillPacExpectationVarInfo(string &pac_model_name,
int max_lag,
int pac_max_lag,
vector<bool> &nonstationary,
int growth_symb_id)
int growth_symb_id, int growth_lag)
{
for (size_t i = 0; i < equations.size(); i++)
equations[i]->fillPacExpectationVarInfo(pac_model_name, lhs, max_lag,
pac_max_lag, nonstationary, growth_symb_id, i);
pac_max_lag, nonstationary, growth_symb_id, growth_lag, i);
}
void
......
/*
* Copyright (C) 2003-2018 Dynare Team
* Copyright (C) 2003-2019 Dynare Team
*
* This file is part of Dynare.
*
......@@ -351,7 +351,7 @@ public:
int max_lag,
int pac_max_lag,
vector<bool> &nonstationary,
int growth_symb_id);
int growth_symb_id, int growth_lag);
//! Substitutes pac_expectation operator
void substitutePacExpectation();
......
// -*- C++ -*-
/*
* Copyright (C) 2003-2018 Dynare Team
* Copyright (C) 2003-2019 Dynare Team
*
* This file is part of Dynare.
*
......@@ -3130,7 +3130,9 @@ 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_aux_model_name : AUXILIARY_MODEL_NAME EQUAL symbol { driver.option_str("pac.aux_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_pac_growth : GROWTH EQUAL symbol { driver.set_pac_growth($3, 0); }
| GROWTH EQUAL symbol '(' MINUS INT_NUMBER ')' { driver.set_pac_growth($3, stoi($6)); }
;
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); };
......
This diff is collapsed.
This diff is collapsed.
......@@ -419,9 +419,9 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, const
{
vector<int> lhs;
vector<bool> nonstationary;
int growth_symb_id, max_lag;
int growth_symb_id, growth_lag, max_lag;
string aux_model_name, pac_model_name;
tie ( pac_model_name, aux_model_name, growth_symb_id ) =
tie ( pac_model_name, aux_model_name, growth_symb_id, growth_lag ) =
pms->getPacModelInfoForPacExpectation();
if (trend_component_model_table.isExistingTrendComponentModelName(aux_model_name))
{
......@@ -447,7 +447,7 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, const
dynamic_model.walkPacParameters();
int pac_max_lag = original_model.getPacMaxLag(pac_model_name);
dynamic_model.fillPacExpectationVarInfo(pac_model_name, lhs, max_lag,
pac_max_lag, nonstationary, growth_symb_id);
pac_max_lag, nonstationary, growth_symb_id, growth_lag);
dynamic_model.substitutePacExpectation();
}
}
......
/*
* Copyright (C) 2003-2018 Dynare Team
* Copyright (C) 2003-2019 Dynare Team
*
* This file is part of Dynare.
*
......@@ -2625,18 +2625,21 @@ ParsingDriver::pac_model()
error("You must pass the discount option to the pac_model statement.");
auto discount = it->second;
string growth;
it = options_list.string_options.find("pac.growth");
if (it != options_list.string_options.end())
growth = it->second;
mod_file->addStatement(make_unique<PacModelStatement>(name, aux_model_name, discount, growth,
mod_file->addStatement(make_unique<PacModelStatement>(name, aux_model_name, discount,
pac_growth_symb_id, pac_growth_lag,
mod_file->symbol_table));
symbol_list.clear();
pac_growth_symb_id = -1;
pac_growth_lag = 0;
options_list.clear();
}
void
ParsingDriver::set_pac_growth(const string &name, int lag)
{
pac_growth_symb_id = mod_file->symbol_table.getID(name);
pac_growth_lag = -lag;
}
expr_t
ParsingDriver::add_exp(expr_t arg1)
{
......
/*
* Copyright (C) 2003-2018 Dynare Team
* Copyright (C) 2003-2019 Dynare Team
*
* This file is part of Dynare.
*
......@@ -254,6 +254,10 @@ private:
WarningConsolidation &warnings;
//! Temporary storage for growth declared in pac_model
int pac_growth_symb_id = -1;
int pac_growth_lag = 0;
bool nostrict;
vector<pair<string, string>> model_errors;
......@@ -727,6 +731,8 @@ public:
expr_t add_pac_expectation(const string &var_model_name);
//! Creates pac_model statement
void pac_model();
//! Adds growth for pac
void set_pac_growth(const string &name, int lag = 0);
//! Writes token "diff(arg1)" to model tree
expr_t add_diff(expr_t arg1);
//! Writes token "adl(arg1, lag)" to model tree
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment