add pac_model statement

issue#70
Houtan Bastani 2018-03-28 18:46:15 +02:00
parent c4ae840b20
commit fb8d9258d0
14 changed files with 502 additions and 240 deletions

View File

@ -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<string, int> &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<int> &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<int>::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<string, pair<string, pair<string, pair<int, map<string, int> > > > > &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<string, pair<SymbolList,
}
void
VarModelStatement::getVarModelEqTags(vector<string> &var_model_eqtags) const
VarModelStatement::getVarModelEqTags(map<string, vector<string> > &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

View File

@ -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<string, int> undiff;
const SymbolTable &symbol_table;
vector<int> lhs;
public:
PacModelStatement(const string &name_arg,
const string &var_name_arg,
const string &discount_arg,
const string &growth_arg,
const map<string, int> &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<int> &lhs);
void getPacModelInfoForPacExpectation(pair<string, pair<string, pair<string, pair<int, map<string, int> > > > > &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<string, pair<SymbolList, int> > &var_model_info) const;
void getVarModelEqTags(vector<string> &var_model_eqtags) const;
void getVarModelEqTags(map<string, vector<string> > &var_model_eqtags) const;
void fillVarModelInfoFromEquations(vector<int> &eqnumber_arg, vector<int> &lhs_arg,
vector<set<pair<int, int> > > &rhs_arg,
vector<bool> &nonstationary_arg,

View File

@ -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

View File

@ -81,8 +81,8 @@ protected:
typedef map<pair<string, pair<int, int> >, VarExpectationNode *> var_expectation_node_map_t;
var_expectation_node_map_t var_expectation_node_map;
// (model_name, (discount, growth)) -> PacExpectationNode
typedef map<pair<string, pair<string, pair<int, int> > >, PacExpectationNode *> pac_expectation_node_map_t;
// model_name -> PacExpectationNode
typedef map<string, PacExpectationNode *> 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

View File

@ -3418,6 +3418,85 @@ DynamicModel::addEquationsForVar(map<string, pair<SymbolList, int> > &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<int> &eqnumber, vector<int> &lhs)
{
int max_lag = 0;
for (vector<int>::const_iterator it = eqnumber.begin();
it != eqnumber.end(); it++)
{
int max_lag_tmp = dynamic_cast<BinaryOpNode *>(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<int> &lhs, vector<bool> &diff, vector<int> &orig_diff_var,
vector<int> &eqnumber, map<string, int> &undiff, map<int, int> &undiff_table)
{
if (undiff.empty())
return;
for (map<string, int>::const_iterator it = undiff.begin();
it != undiff.end(); it++)
{
int eqn = -1;
string eqtag (it->first);
for (vector<pair<int, pair<string, string> > >::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<int>::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<int> &lhs,
int max_lag,
vector<bool> &nonstationary)
vector<bool> &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<int, int> &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<int, expr_t>::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<BinaryOpNode *>(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;
}

View File

@ -307,7 +307,11 @@ public:
void fillPacExpectationVarInfo(string &var_model_name,
vector<int> &lhs,
int max_lag,
vector<bool> &nonstationary);
vector<bool> &nonstationary,
int growth_symb_id);
//! Get the max lag for the PAC VAR
int get_undiff_max_lag(vector<int> &eqnumber, vector<int> &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<int, int> &undiff_table);
//! Table to undiff LHS variables for pac vector z
void undiff_lhs_for_pac(vector<int> &lhs, vector<bool> &diff, vector<int> &orig_diff_var,
vector<int> &eqnumber, map<string, int> &undiff, map<int, int> &undiff_table);
//! Adds contents of diff_aux_equations to the back of aux_equations
void combineDiffAuxEquations();

View File

@ -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); };

View File

@ -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
<INITIAL>simul {BEGIN DYNARE_STATEMENT; return token::SIMUL;}
<INITIAL>stoch_simul {BEGIN DYNARE_STATEMENT; return token::STOCH_SIMUL;}
<INITIAL>var_model {BEGIN DYNARE_STATEMENT; return token::VAR_MODEL;}
<INITIAL>pac_model {BEGIN DYNARE_STATEMENT; return token::PAC_MODEL;}
<INITIAL>dsample {BEGIN DYNARE_STATEMENT; return token::DSAMPLE;}
<INITIAL>Sigma_e {BEGIN DYNARE_STATEMENT; sigma_e = 1; return token::SIGMA_E;}
<INITIAL>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
<DYNARE_STATEMENT>kalman_algo {return token::KALMAN_ALGO;}
<DYNARE_STATEMENT>fast_kalman_filter {return token::FAST_KALMAN_FILTER;}
<DYNARE_STATEMENT>kalman_tol {return token::KALMAN_TOL;}
<DYNARE_STATEMENT>undiff {return token::UNDIFF;}
<DYNARE_STATEMENT>diffuse_kalman_tol {return token::DIFFUSE_KALMAN_TOL;}
<DYNARE_STATEMENT>forecast {return token::FORECAST;}
<DYNARE_STATEMENT>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
<DYNARE_STATEMENT>optim {return token::OPTIM;}
<DYNARE_STATEMENT>periods {return token::PERIODS;}
<DYNARE_STATEMENT,DYNARE_BLOCK>model_name {return token::MODEL_NAME;}
<DYNARE_BLOCK>var_model_name {return token::VAR_MODEL_NAME;}
<DYNARE_STATEMENT>var_model_name {return token::VAR_MODEL_NAME;}
<DYNARE_STATEMENT>endogenous_terminal_period {return token::ENDOGENOUS_TERMINAL_PERIOD;}
<DYNARE_STATEMENT>sub_draws {return token::SUB_DRAWS;}
<DYNARE_STATEMENT>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
<DYNARE_STATEMENT>log_deflator {return token::LOG_DEFLATOR;}
<DYNARE_STATEMENT>growth_factor {return token::GROWTH_FACTOR;}
<DYNARE_STATEMENT>log_growth_factor {return token::LOG_GROWTH_FACTOR;}
<DYNARE_STATEMENT>growth {return token::GROWTH;}
<DYNARE_STATEMENT>cova_compute {return token::COVA_COMPUTE;}
<DYNARE_STATEMENT>discretionary_tol {return token::DISCRETIONARY_TOL;}
<DYNARE_STATEMENT>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 */
<DYNARE_BLOCK>growth {return token::GROWTH;}
<DYNARE_BLOCK>var {return token::VAR;}
<DYNARE_BLOCK>stderr {return token::STDERR;}
<DYNARE_BLOCK>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
<DYNARE_STATEMENT,DYNARE_BLOCK>expectation {return token::EXPECTATION;}
<DYNARE_BLOCK>var_expectation {return token::VAR_EXPECTATION;}
<DYNARE_BLOCK>pac_expectation {return token::PAC_EXPECTATION;}
<DYNARE_BLOCK>discount {return token::DISCOUNT;}
<DYNARE_STATEMENT>discount {return token::DISCOUNT;}
<DYNARE_STATEMENT,DYNARE_BLOCK>varobs {return token::VAROBS;}
<DYNARE_STATEMENT,DYNARE_BLOCK>varexobs {return token::VAREXOBS;}
<DYNARE_STATEMENT,DYNARE_BLOCK>full {return token::FULL;}

View File

@ -457,6 +457,12 @@ NumConstNode::maxLag() const
return 0;
}
int
NumConstNode::PacMaxLag(vector<int> &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<BinaryOpNode *> &neweqs) const
NumConstNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, map<int, int> &undiff_table) const
{
return const_cast<NumConstNode *>(this);
}
@ -600,7 +606,7 @@ NumConstNode::addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int,
}
void
NumConstNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
NumConstNode::fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg)
{
}
@ -1324,6 +1330,12 @@ VariableNode::maxLag() const
}
}
int
VariableNode::PacMaxLag(vector<int> &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<BinaryOpNode *> &neweqs) const
VariableNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, map<int, int> &undiff_table) const
{
return const_cast<VariableNode *>(this);
}
@ -1702,7 +1714,7 @@ VariableNode::addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int,
}
void
VariableNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
VariableNode::fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &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<int> &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<BinaryOpNode *> &neweqs) const
UnaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table,
vector<BinaryOpNode *> &neweqs, map<int, int> &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<UnaryOpNode *>(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<VariableNode *>(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<VariableNode *>(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<BinaryOpNode *>(datatree.AddEqual(new_aux_var,
last_aux_var->decreaseLeadsLags(1))));
@ -3171,9 +3191,9 @@ UnaryOpNode::addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int,
}
void
UnaryOpNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
UnaryOpNode::fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &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<int> &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<BinaryOpNode *> &neweqs) const
BinaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, map<int, int> &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<int, int> &lhs_arg, set<pair<int, pair<int,
}
void
BinaryOpNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
BinaryOpNode::fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &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<int> &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<BinaryOpNode *> &neweqs) const
TrinaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, map<int, int> &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<int, int> &lhs_arg, set<pair<int, pair<int
}
void
TrinaryOpNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
TrinaryOpNode::fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &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<int> &lhs) const
{
int val = 0;
for (vector<expr_t>::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<BinaryOpNode *> &neweqs) const
AbstractExternalFunctionNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, map<int, int> &undiff_table) const
{
vector<expr_t> arguments_subst;
for (vector<expr_t>::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<int, int> &lhs_arg, set<pai
}
void
AbstractExternalFunctionNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
AbstractExternalFunctionNode::fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg)
{
for (vector<expr_t>::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<int> &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<BinaryOpNode *> &neweqs) const
VarExpectationNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, map<int, int> &undiff_table) const
{
return const_cast<VarExpectationNode *>(this);
}
@ -7503,7 +7551,7 @@ VarExpectationNode::addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pai
}
void
VarExpectationNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
VarExpectationNode::fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &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<expr_t, int> &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<pair<int, pair<int, int> > >::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<pair<int, pair<int, int> > >::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<pair<int, pair<int, int> > >::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<int>::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<int>::const_iterator it = h1_indices.begin();
it != h1_indices.end(); it++)
{
@ -7709,6 +7721,12 @@ PacExpectationNode::maxLag() const
return 0;
}
int
PacExpectationNode::PacMaxLag(vector<int> &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<BinaryOpNode *> &neweqs) const
PacExpectationNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, map<int, int> &undiff_table) const
{
return const_cast<PacExpectationNode *>(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<int, int> &lhs_arg, set<pair<int, pai
void
PacExpectationNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
PacExpectationNode::fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &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<bool>::const_iterator it = nonstationary_arg.begin();

View File

@ -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<int> &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<BinaryOpNode *> &neweqs) const = 0;
virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, map<int, int> &undiff_table) const = 0;
//! Substitute pac_expectation operator
virtual expr_t substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table) = 0;
@ -506,7 +510,7 @@ class ExprNode
virtual void addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int, int> > > &params_and_vals_arg) = 0;
//! Fills var_model info for pac_expectation node
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg) = 0;
virtual void fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg) = 0;
//! Fills map
virtual void getEndosAndMaxLags(map<string, int> &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<int> &lhs) const;
virtual expr_t decreaseLeadsLags(int n) const;
virtual expr_t substituteEndoLeadGreaterThanTwo(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const;
virtual expr_t substituteEndoLagGreaterThanTwo(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
@ -563,7 +568,7 @@ public:
virtual expr_t substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &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<BinaryOpNode *> &neweqs) const;
virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, map<int, int> &undiff_table) const;
virtual expr_t substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table);
virtual expr_t decreaseLeadsLagsPredeterminedVariables() const;
virtual expr_t differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
@ -580,7 +585,7 @@ public:
virtual void setVarExpectationIndex(map<string, pair<SymbolList, int> > &var_model_info);
virtual void walkPacParameters(bool &pac_encountered, pair<int, int> &lhs, set<pair<int, pair<int, int> > > &params_and_vals) const;
virtual void addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int, int> > > &params_and_vals_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual void fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg);
virtual bool isVarModelReferenced(const string &model_info_name) const;
virtual void getEndosAndMaxLags(map<string, int> &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<int> &lhs) const;
virtual expr_t decreaseLeadsLags(int n) const;
virtual expr_t substituteEndoLeadGreaterThanTwo(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const;
virtual expr_t substituteEndoLagGreaterThanTwo(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
@ -646,7 +652,7 @@ public:
virtual expr_t substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &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<BinaryOpNode *> &neweqs) const;
virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, map<int, int> &undiff_table) const;
virtual expr_t substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table);
virtual expr_t decreaseLeadsLagsPredeterminedVariables() const;
virtual expr_t differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
@ -663,7 +669,7 @@ public:
virtual void setVarExpectationIndex(map<string, pair<SymbolList, int> > &var_model_info);
virtual void walkPacParameters(bool &pac_encountered, pair<int, int> &lhs, set<pair<int, pair<int, int> > > &params_and_vals) const;
virtual void addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int, int> > > &params_and_vals_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual void fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg);
virtual bool isVarModelReferenced(const string &model_info_name) const;
virtual void getEndosAndMaxLags(map<string, int> &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<int> &lhs) const;
virtual expr_t decreaseLeadsLags(int n) const;
virtual expr_t substituteEndoLeadGreaterThanTwo(subst_table_t &subst_table, vector<BinaryOpNode *> &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<BinaryOpNode *> &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<BinaryOpNode *> &neweqs) const;
virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, map<int, int> &undiff_table) const;
virtual expr_t substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table);
virtual expr_t decreaseLeadsLagsPredeterminedVariables() const;
virtual expr_t differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
@ -768,7 +775,7 @@ public:
virtual void setVarExpectationIndex(map<string, pair<SymbolList, int> > &var_model_info);
virtual void walkPacParameters(bool &pac_encountered, pair<int, int> &lhs, set<pair<int, pair<int, int> > > &params_and_vals) const;
virtual void addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int, int> > > &params_and_vals_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual void fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg);
virtual bool isVarModelReferenced(const string &model_info_name) const;
virtual void getEndosAndMaxLags(map<string, int> &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<int> &lhs) const;
virtual expr_t decreaseLeadsLags(int n) const;
virtual expr_t substituteEndoLeadGreaterThanTwo(subst_table_t &subst_table, vector<BinaryOpNode *> &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<BinaryOpNode *> &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<BinaryOpNode *> &neweqs) const;
virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, map<int, int> &undiff_table) const;
virtual expr_t substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table);
virtual expr_t decreaseLeadsLagsPredeterminedVariables() const;
virtual expr_t differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
@ -895,7 +903,7 @@ public:
virtual void setVarExpectationIndex(map<string, pair<SymbolList, int> > &var_model_info);
virtual void walkPacParameters(bool &pac_encountered, pair<int, int> &lhs, set<pair<int, pair<int, int> > > &params_and_vals) const;
virtual void addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int, int> > > &params_and_vals_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual void fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg);
virtual bool isVarModelReferenced(const string &model_info_name) const;
virtual void getEndosAndMaxLags(map<string, int> &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<int> &lhs) const;
virtual expr_t decreaseLeadsLags(int n) const;
virtual expr_t substituteEndoLeadGreaterThanTwo(subst_table_t &subst_table, vector<BinaryOpNode *> &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<BinaryOpNode *> &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<BinaryOpNode *> &neweqs) const;
virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, map<int, int> &undiff_table) const;
virtual expr_t substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table);
virtual expr_t decreaseLeadsLagsPredeterminedVariables() const;
virtual expr_t differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
@ -987,7 +996,7 @@ public:
virtual void setVarExpectationIndex(map<string, pair<SymbolList, int> > &var_model_info);
virtual void walkPacParameters(bool &pac_encountered, pair<int, int> &lhs, set<pair<int, pair<int, int> > > &params_and_vals) const;
virtual void addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int, int> > > &params_and_vals_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual void fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg);
virtual bool isVarModelReferenced(const string &model_info_name) const;
virtual void getEndosAndMaxLags(map<string, int> &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<int> &lhs) const;
virtual expr_t decreaseLeadsLags(int n) const;
virtual expr_t substituteEndoLeadGreaterThanTwo(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const;
virtual expr_t substituteEndoLagGreaterThanTwo(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
@ -1068,7 +1078,7 @@ public:
virtual expr_t substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &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<BinaryOpNode *> &neweqs) const;
virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, map<int, int> &undiff_table) const;
virtual expr_t substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table);
virtual expr_t buildSimilarExternalFunctionNode(vector<expr_t> &alt_args, DataTree &alt_datatree) const = 0;
virtual expr_t decreaseLeadsLagsPredeterminedVariables() const;
@ -1087,7 +1097,7 @@ public:
virtual void setVarExpectationIndex(map<string, pair<SymbolList, int> > &var_model_info);
virtual void walkPacParameters(bool &pac_encountered, pair<int, int> &lhs, set<pair<int, pair<int, int> > > &params_and_vals) const;
virtual void addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int, int> > > &params_and_vals_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual void fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg);
virtual bool isVarModelReferenced(const string &model_info_name) const;
virtual void getEndosAndMaxLags(map<string, int> &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<int> &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<BinaryOpNode *> &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<BinaryOpNode *> &neweqs) const;
virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, map<int, int> &undiff_table) const;
virtual expr_t substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table);
virtual pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<pair<int, pair<expr_t, expr_t> > > &List_of_Op_RHS) const;
virtual void compile(ostream &CompileCode, unsigned int &instruction_number,
@ -1280,7 +1291,7 @@ public:
virtual void setVarExpectationIndex(map<string, pair<SymbolList, int> > &var_model_info);
virtual void walkPacParameters(bool &pac_encountered, pair<int, int> &lhs, set<pair<int, pair<int, int> > > &params_and_vals) const;
virtual void addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int, int> > > &params_and_vals_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual void fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg);
virtual bool isVarModelReferenced(const string &model_info_name) const;
virtual void getEndosAndMaxLags(map<string, int> &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<int> lhs;
pair<int, int> lhs_pac_var;
@ -1300,8 +1312,7 @@ private:
int growth_param_index, equation_number;
set<pair<int, pair<int, int> > > 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<expr_t, pair<int, NodeTreeReference> > &reference_count,
map<NodeTreeReference, temporary_terms_t> &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<int> &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<BinaryOpNode *> &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<BinaryOpNode *> &neweqs) const;
virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, map<int, int> &undiff_table) const;
virtual expr_t substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table);
virtual pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<pair<int, pair<expr_t, expr_t> > > &List_of_Op_RHS) const;
virtual void compile(ostream &CompileCode, unsigned int &instruction_number,
@ -1357,7 +1369,7 @@ public:
virtual void setVarExpectationIndex(map<string, pair<SymbolList, int> > &var_model_info);
virtual void walkPacParameters(bool &pac_encountered, pair<int, int> &lhs, set<pair<int, pair<int, int> > > &params_and_vals) const;
virtual void addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int, int> > > &params_and_vals_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual void fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg);
virtual bool isVarModelReferenced(const string &model_info_name) const;
virtual void getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const;
virtual expr_t substituteStaticAuxiliaryVariable() const;

View File

@ -324,7 +324,11 @@ ModFile::checkPass(bool nostrict, bool stochastic)
}
// Check if some exogenous is not used in the model block, Issue #841
set<int> unusedExo = dynamic_model.findUnusedExogenous();
set<int> unusedExo0 = dynamic_model.findUnusedExogenous();
set<int> 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<int, int> undiff_table;
dynamic_model.substituteDiff(diff_static_model, undiff_table);
// Var Model
map<string, pair<SymbolList, int> > var_model_info_var_expectation;
map<string, vector<string> > var_model_eq_tags;
map<string, pair<pair<vector<int>, pair<vector<bool>, vector<int> > >, pair<pair<int, vector<bool> >, vector<int> > > > var_model_info_pac_expectation;
for (vector<Statement *>::const_iterator it = statements.begin();
it != statements.end(); it++)
{
VarModelStatement *vms = dynamic_cast<VarModelStatement *>(*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<string> var_model_eqtags;
vms->getVarModelEqTags(var_model_eqtags);
if (!var_model_eqtags.empty())
{
int max_lag = 0;
vector<int> eqnumber, lhs, orig_diff_var;
vector<set<pair<int, int> > > rhs;
vector<bool> 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<int> eqnumber, lhs, orig_diff_var;
vector<set<pair<int, int> > > rhs;
vector<bool> nonstationary, diff;
vector<string> 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<PacModelStatement *>(*it);
if (pms != NULL)
{
pair<string, pair<string, pair<string, pair<int, map<string, int> > > > > 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<string> eqtags = var_model_eq_tags[var_model_name];
if (!eqtags.empty())
{
vector<int> lhs = var_model_info_pac_expectation[var_model_name].first.first;
map<string, int> 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<bool> nonstationary = var_model_info_pac_expectation[var_model_name].second.first.second;
if (!undiff.empty())
{
vector<bool> diff = var_model_info_pac_expectation[var_model_name].first.second.first;
vector<int> orig_diff_var = var_model_info_pac_expectation[var_model_name].first.second.second;
vector<int> 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())
{

View File

@ -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

View File

@ -234,6 +234,8 @@ private:
SymbolList graph_formats;
//! Temporary storage for equation tags
vector<pair<string, string> > eq_tags;
//! Temporary storage for pac statement undiff option
map<string, int> pac_undiff;
//! Map Var name to variables
map<string, vector<string> > 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

View File

@ -125,6 +125,8 @@ public:
bool write_latex_steady_state_model_present;
//! Histval values that do not have the appropriate lag
map<int, int> hist_vals_wrong_lag;
//! Pac growth and discount
set<int> pac_params;
};
class Statement