Verified Commit 0ea84fa9 authored by Houtan Bastani's avatar Houtan Bastani
Browse files

pac: allow steady state growth and model consistent expectation substitution in pac equation

parent b3fbb862
Pipeline #829 passed with stage
in 1 minute and 43 seconds
......@@ -262,12 +262,16 @@ PacModelStatement::PacModelStatement(string name_arg,
string discount_arg,
int growth_symb_id_arg,
int growth_lag_arg,
double steady_state_growth_rate_number_arg,
int steady_state_growth_rate_symb_id_arg,
const SymbolTable &symbol_table_arg) :
name{move(name_arg)},
aux_model_name{move(aux_model_name_arg)},
discount{move(discount_arg)},
growth_symb_id{growth_symb_id_arg},
growth_lag{growth_lag_arg},
steady_state_growth_rate_number{steady_state_growth_rate_number_arg},
steady_state_growth_rate_symb_id{steady_state_growth_rate_symb_id_arg},
symbol_table{symbol_table_arg}
{
}
......@@ -306,7 +310,12 @@ void
PacModelStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
{
output << "M_.pac." << name << ".auxiliary_model_name = '" << aux_model_name << "';" << endl
<< "M_.pac." << name << ".discount_index = " << symbol_table.getTypeSpecificID(discount) + 1 << ";" << endl;
<< "M_.pac." << name << ".discount_index = " << symbol_table.getTypeSpecificID(discount) + 1 << ";" << endl
<< "M_.pac." << name << ".steady_state_growth_rate = ";
if (steady_state_growth_rate_symb_id < 0)
output << steady_state_growth_rate_number << ";" << endl;
else
output << symbol_table.getTypeSpecificID(steady_state_growth_rate_symb_id) + 1 << ";" << endl;
if (growth_symb_id >= 0)
{
......@@ -399,12 +408,6 @@ PacModelStatement::writeJsonOutput(ostream &output) const
output << "}";
}
tuple<string, string, int, int>
PacModelStatement::getPacModelInfoForPacExpectation() const
{
return { name, aux_model_name, growth_symb_id, growth_lag };
}
VarEstimationStatement::VarEstimationStatement(OptionsList options_list_arg) :
options_list{move(options_list_arg)}
{
......
......@@ -136,11 +136,12 @@ public:
class PacModelStatement : public Statement
{
private:
const string name;
const string aux_model_name;
const string discount;
public:
const string name, aux_model_name, discount;
const int growth_symb_id, growth_lag;
private:
const double steady_state_growth_rate_number;
const int steady_state_growth_rate_symb_id;
const SymbolTable &symbol_table;
vector<int> lhs;
public:
......@@ -149,12 +150,13 @@ public:
string discount_arg,
int growth_symb_id_arg,
int growth_lag_arg,
double steady_state_growth_rate_number_arg,
int steady_state_growth_rate_symb_id_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, int> getPacModelInfoForPacExpectation() const;
};
class VarRestrictionsStatement : public Statement
......
......@@ -3615,6 +3615,15 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de
output << "-1";
output << "];" << endl;
// Write Pac Model Consistent Expectation parameter info
for (auto & it : pac_mce_alpha_symb_ids)
{
output << modstruct << "pac." << it.first << ".mce_alpha_idxs = [";
for (auto it : it.second)
output << symbol_table.getTypeSpecificID(it) + 1 << " ";
output << "];" << endl;
}
// Write PacExpectationInfo
for (auto it : pac_expectation_info)
it->ExprNode::writeOutput(output, ExprNodeOutputType::matlabDynamicModel);
......@@ -4312,8 +4321,128 @@ DynamicModel::getPacMaxLag(const string &pac_model_name) const
return 0;
}
int
DynamicModel::getPacTargetSymbId(const string &pac_model_name) const
{
for (auto & equation : equations)
if (equation->containsPacExpectation(pac_model_name))
{
pair<int, int> lhs (-1, -1);
equation->getPacLHS(lhs);
int lhs_symb_id = lhs.first;
int lhs_orig_symb_id = lhs_symb_id;
if (symbol_table.isAuxiliaryVariable(lhs_symb_id))
try
{
lhs_orig_symb_id = symbol_table.getOrigSymbIdForAuxVar(lhs_symb_id);
}
catch (...)
{
}
return equation->arg2->getPacTargetSymbId(lhs_symb_id, lhs_orig_symb_id);
}
return -1;
}
int
DynamicModel::addPacModelConsistentExpectationEquation(const string & name, int pac_target_symb_id,
int discount_symb_id, int pac_max_lag_m,
ExprNode::subst_table_t &diff_subst_table)
{
int mce_symb_id;
try
{
mce_symb_id = symbol_table.addSymbol("mce_Z_" + name, SymbolType::endogenous);
}
catch (SymbolTable::AlreadyDeclaredException &e)
{
cerr << "Variable name needed by PAC (mce_Z_" << name << endl;
exit(EXIT_FAILURE);
}
expr_t A = One;
expr_t fp = Zero;
expr_t beta = AddVariable(discount_symb_id);
for (int i = 1; i <= pac_max_lag_m; i++)
try
{
int alpha_i_symb_id = symbol_table.addSymbol("mce_alpha_" + name + "_" + to_string(i),
SymbolType::parameter);
pac_mce_alpha_symb_ids[name].push_back(alpha_i_symb_id);
A = AddPlus(A, AddVariable(alpha_i_symb_id));
fp = AddPlus(fp,
AddTimes(AddTimes(AddVariable(alpha_i_symb_id),
AddPower(beta, AddPossiblyNegativeConstant(i))),
AddVariable(mce_symb_id, i)));
}
catch (SymbolTable::AlreadyDeclaredException &e)
{
cerr << "Variable name needed by PAC (mce_alpha_" << name << "_" << i << ")" << endl;
exit(EXIT_FAILURE);
}
// Add diff nodes and eqs for pac_target_symb_id
int neqs = 0;
const VariableNode *target_base_diff_node;
expr_t diff_node_to_search = AddDiff(AddVariable(pac_target_symb_id));
ExprNode::subst_table_t::const_iterator sit = diff_subst_table.find(diff_node_to_search);
if (sit != diff_subst_table.end())
target_base_diff_node = sit->second;
else
{
int symb_id = symbol_table.addDiffAuxiliaryVar(diff_node_to_search->idx, diff_node_to_search);
target_base_diff_node = AddVariable(symb_id);
addEquation(dynamic_cast<BinaryOpNode *>(AddEqual((expr_t) target_base_diff_node,
AddMinus(AddVariable(pac_target_symb_id),
AddVariable(pac_target_symb_id, -1)))), -1);
neqs++;
}
map<int, VariableNode *> target_aux_var_to_add;
const VariableNode *last_aux_var = target_base_diff_node;
for (int i = 1; i <= pac_max_lag_m - 1; i++, neqs++)
{
expr_t this_diff_node = AddDiff(AddVariable(pac_target_symb_id, i));
int symb_id = symbol_table.addDiffLeadAuxiliaryVar(this_diff_node->idx, this_diff_node,
last_aux_var->symb_id, last_aux_var->lag);
VariableNode *current_aux_var = AddVariable(symb_id);
addEquation(dynamic_cast<BinaryOpNode *>(AddEqual(current_aux_var,
AddVariable(last_aux_var->symb_id, 1))), -1);
last_aux_var = current_aux_var;
target_aux_var_to_add[i] = current_aux_var;
}
expr_t fs = Zero;
for (int k = 1; k <= pac_max_lag_m - 1; k++)
{
expr_t ssum = Zero;
for (int j = k+1; j <= pac_max_lag_m; j++)
{
int alpha_j_symb_id = -1;
string varname = "mce_alpha_" + name + "_" + to_string(j);
try
{
alpha_j_symb_id = symbol_table.getID(varname);
}
catch (SymbolTable::UnknownSymbolNameException &e)
{
alpha_j_symb_id = symbol_table.addSymbol(varname, SymbolType::parameter);
}
ssum = AddPlus(ssum,
AddTimes(AddVariable(alpha_j_symb_id), AddPower(beta, AddPossiblyNegativeConstant(j))));
}
fs = AddPlus(fs, AddTimes(ssum, target_aux_var_to_add[k]));
}
addEquation(AddEqual(AddVariable(mce_symb_id),
AddMinus(AddTimes(A, AddMinus((expr_t) target_base_diff_node, fs)), fp)), -1);
neqs++;
cout << "Pac Model Consistent Expectation: added " << neqs << " auxiliary variables and equations." << endl;
return mce_symb_id;
}
void
DynamicModel::fillPacExpectationVarInfo(string &pac_model_name,
DynamicModel::fillPacExpectationVarInfo(const string &pac_model_name,
vector<int> &lhs,
int max_lag,
int pac_max_lag,
......@@ -4326,15 +4455,34 @@ DynamicModel::fillPacExpectationVarInfo(string &pac_model_name,
}
void
DynamicModel::substitutePacExpectation()
DynamicModel::substitutePacExpectation(const string & name, int model_consistent_expectation_symb_id)
{
map<const PacExpectationNode *, const BinaryOpNode *> subst_table;
for (auto & it : local_variables_table)
it.second = it.second->substitutePacExpectation(name, model_consistent_expectation_symb_id, subst_table);
for (auto & equation : equations)
{
auto *substeq = dynamic_cast<BinaryOpNode *>(equation->substitutePacExpectation(name, model_consistent_expectation_symb_id, subst_table));
assert(substeq != nullptr);
equation = substeq;
}
for (map<const PacExpectationNode *, const BinaryOpNode *>::const_iterator it = subst_table.begin();
it != subst_table.end(); it++)
pac_expectation_info.insert(const_cast<PacExpectationNode *>(it->first));
}
void
DynamicModel::substitutePacExpectation(const string & name)
{
map<const PacExpectationNode *, const BinaryOpNode *> subst_table;
for (auto & it : local_variables_table)
it.second = it.second->substitutePacExpectation(subst_table);
it.second = it.second->substitutePacExpectation(name, subst_table);
for (auto & equation : equations)
{
auto *substeq = dynamic_cast<BinaryOpNode *>(equation->substitutePacExpectation(subst_table));
auto *substeq = dynamic_cast<BinaryOpNode *>(equation->substitutePacExpectation(name, subst_table));
assert(substeq != nullptr);
equation = substeq;
}
......
......@@ -346,15 +346,18 @@ public:
//! Get Pac equation parameter info
void walkPacParameters();
//! Add var_model info to pac_expectation nodes
void fillPacExpectationVarInfo(string &pac_model_name,
void fillPacExpectationVarInfo(const string &pac_model_name,
vector<int> &lhs,
int max_lag,
int pac_max_lag,
vector<bool> &nonstationary,
int growth_symb_id, int growth_lag);
//! Substitutes pac_expectation operator
void substitutePacExpectation();
//! Substitutes pac_expectation operator with expectation based on auxiliary model
void substitutePacExpectation(const string & name);
//! Substitute pac_expectation operator with model consistent expectation
void substitutePacExpectation(const string & name, int model_consistent_expectation_symb_id);
//! Adds informations for simulation in a binary file
void Write_Inf_To_Bin_File_Block(const string &basename,
......@@ -454,6 +457,15 @@ public:
//! Return max lag of pac equation
int getPacMaxLag(const string &pac_model_name) const;
//! Return target of the pac equation
int getPacTargetSymbId(const string &pac_model_name) const;
//! Add model consistent expectation equation for pac model
int addPacModelConsistentExpectationEquation(const string & name, int pac_target_symb_id, int discount, int pac_max_lag_m, ExprNode::subst_table_t &diff_subst_table);
//! store symb_ids for alphas created in addPacModelConsistentExpectationEquation
map<string, vector<int>> pac_mce_alpha_symb_ids;
//! Table to undiff LHS variables for pac vector z
vector<int> getUndiffLHSForPac(const string &aux_model_name,
ExprNode::subst_table_t &diff_subst_table) const;
......
......@@ -163,7 +163,7 @@ class ParsingDriver;
%token NUMBER_OF_POSTERIOR_DRAWS_AFTER_PERTURBATION MAX_NUMBER_OF_STAGES
%token RANDOM_FUNCTION_CONVERGENCE_CRITERION RANDOM_PARAMETER_CONVERGENCE_CRITERION
%token CENTERED_MOMENTS AUTOLAG RECURSIVE_ORDER_ESTIMATION BARTLETT_KERNEL_LAG WEIGHTING_MATRIX PENALIZED_ESTIMATOR VERBOSE
%token SIMULATION_MULTIPLE SEED BOUNDED_SHOCK_SUPPORT EQTAGS
%token SIMULATION_MULTIPLE SEED BOUNDED_SHOCK_SUPPORT EQTAGS STEADY_STATE_GROWTH
%token ANALYTICAL_GIRF IRF_IN_PERCENT EMAS_GIRF EMAS_DROP EMAS_TOLF EMAS_MAX_ITER
%token <vector<string>> SYMBOL_VEC
......@@ -398,6 +398,7 @@ pac_model_options : o_pac_name
| o_pac_aux_model_name
| o_pac_discount
| o_pac_growth
| o_pac_steady_state_growth
;
var_expectation_model : VAR_EXPECTATION_MODEL '(' var_expectation_model_options_list ')' ';'
......@@ -3133,6 +3134,9 @@ o_pac_discount : DISCOUNT EQUAL symbol { driver.option_str("pac.discount", $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_pac_steady_state_growth : STEADY_STATE_GROWTH EQUAL signed_number { driver.set_pac_steady_state_growth($3); }
| STEADY_STATE_GROWTH EQUAL symbol { driver.set_pac_steady_state_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); };
......
/* -*- C++ -*- */
/*
* Copyright (C) 2003-2018 Dynare Team
* Copyright (C) 2003-2019 Dynare Team
*
* This file is part of Dynare.
*
......@@ -830,6 +830,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_BLOCK>var_expectation {return token::VAR_EXPECTATION;}
<DYNARE_BLOCK>pac_expectation {return token::PAC_EXPECTATION;}
<DYNARE_STATEMENT>discount {return token::DISCOUNT;}
<DYNARE_STATEMENT>steady_state_growth {return token::STEADY_STATE_GROWTH;}
<DYNARE_STATEMENT,DYNARE_BLOCK>varobs {return token::VAROBS;}
<DYNARE_STATEMENT,DYNARE_BLOCK>varexobs {return token::VAREXOBS;}
<DYNARE_STATEMENT,DYNARE_BLOCK>nan {return token::NAN_CONSTANT;}
......
......@@ -506,6 +506,12 @@ NumConstNode::PacMaxLag(int lhs_symb_id) const
return 0;
}
int
NumConstNode::getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const
{
return -1;
}
expr_t
NumConstNode::decreaseLeadsLags(int n) const
{
......@@ -589,7 +595,14 @@ NumConstNode::substituteUnaryOpNodes(DataTree &static_datatree, diff_table_t &no
}
expr_t
NumConstNode::substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)
NumConstNode::substitutePacExpectation(const string & name, map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)
{
return const_cast<NumConstNode *>(this);
}
expr_t
NumConstNode::substitutePacExpectation(const string & name, int mce_symb_id,
map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)
{
return const_cast<NumConstNode *>(this);
}
......@@ -687,7 +700,7 @@ NumConstNode::addParamInfoToPac(pair<int, int> &lhs_arg, int optim_share_arg, pa
}
void
NumConstNode::fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, int pac_max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int growth_lag_arg, int equation_number_arg)
NumConstNode::fillPacExpectationVarInfo(const string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, int pac_max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int growth_lag_arg, int equation_number_arg)
{
}
......@@ -1575,6 +1588,12 @@ VariableNode::PacMaxLag(int lhs_symb_id) const
return 0;
}
int
VariableNode::getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const
{
return -1;
}
expr_t
VariableNode::substituteAdl() const
{
......@@ -1617,7 +1636,14 @@ VariableNode::substituteUnaryOpNodes(DataTree &static_datatree, diff_table_t &no
}
expr_t
VariableNode::substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)
VariableNode::substitutePacExpectation(const string & name, map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)
{
return const_cast<VariableNode *>(this);
}
expr_t
VariableNode::substitutePacExpectation(const string & name, int mce_symb_id,
map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)
{
return const_cast<VariableNode *>(this);
}
......@@ -1992,7 +2018,7 @@ VariableNode::addParamInfoToPac(pair<int, int> &lhs_arg, int optim_share_arg, pa
}
void
VariableNode::fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, int pac_max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int growth_lag_arg, int equation_number_arg)
VariableNode::fillPacExpectationVarInfo(const string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, int pac_max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int growth_lag_arg, int equation_number_arg)
{
}
......@@ -3294,6 +3320,12 @@ UnaryOpNode::PacMaxLag(int lhs_symb_id) const
return arg->PacMaxLag(lhs_symb_id);
}
int
UnaryOpNode::getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const
{
return arg->getPacTargetSymbId(lhs_symb_id, undiff_lhs_symb_id);
}
expr_t
UnaryOpNode::substituteAdl() const
{
......@@ -3610,9 +3642,17 @@ UnaryOpNode::substituteUnaryOpNodes(DataTree &static_datatree, diff_table_t &nod
}
expr_t
UnaryOpNode::substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)
UnaryOpNode::substitutePacExpectation(const string & name, map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)
{
expr_t argsubst = arg->substitutePacExpectation(subst_table);
expr_t argsubst = arg->substitutePacExpectation(name, subst_table);
return buildSimilarUnaryOpNode(argsubst, datatree);
}
expr_t
UnaryOpNode::substitutePacExpectation(const string & name, int mce_symb_id,
map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)
{
expr_t argsubst = arg->substitutePacExpectation(name, mce_symb_id, subst_table);
return buildSimilarUnaryOpNode(argsubst, datatree);
}
......@@ -3817,7 +3857,7 @@ UnaryOpNode::addParamInfoToPac(pair<int, int> &lhs_arg, int optim_share_arg, pai
}
void
UnaryOpNode::fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, int pac_max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int growth_lag_arg, int equation_number_arg)
UnaryOpNode::fillPacExpectationVarInfo(const string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, int pac_max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int growth_lag_arg, int equation_number_arg)
{
arg->fillPacExpectationVarInfo(model_name_arg, lhs_arg, max_lag_arg, pac_max_lag_arg, nonstationary_arg, growth_symb_id_arg, growth_lag_arg, equation_number_arg);
}
......@@ -5211,6 +5251,39 @@ BinaryOpNode::PacMaxLag(int lhs_symb_id) const
return max(arg1->PacMaxLag(lhs_symb_id), arg2->PacMaxLag(lhs_symb_id));
}
int
BinaryOpNode::getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const
{
set<pair<int, int>> endogs;
arg1->collectDynamicVariables(SymbolType::endogenous, endogs);
arg2->collectDynamicVariables(SymbolType::endogenous, endogs);
int ret_symb_id = -1;
for (auto & it : endogs)
{
int id = it.first;
while (datatree.symbol_table.isAuxiliaryVariable(id))
try
{
id = datatree.symbol_table.getOrigSymbIdForAuxVar(id);
}
catch (...)
{
break;
}
if (id != lhs_symb_id && id != undiff_lhs_symb_id)
if (ret_symb_id < 0)
ret_symb_id = it.first;
else
{
cerr << "Error: Pac model is of wrong format: endogenous vars found: "
<< datatree.symbol_table.getName(ret_symb_id) << ", "
<< datatree.symbol_table.getName(it.first) << endl;
exit(EXIT_FAILURE);
}
}
return ret_symb_id;
}
expr_t
BinaryOpNode::decreaseLeadsLags(int n) const
{
......@@ -5394,10 +5467,19 @@ BinaryOpNode::countDiffs() const
}
expr_t
BinaryOpNode::substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)
BinaryOpNode::substitutePacExpectation(const string & name, map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)
{
expr_t arg1subst = arg1->substitutePacExpectation(name, subst_table);
expr_t arg2subst = arg2->substitutePacExpectation(name, subst_table);
return buildSimilarBinaryOpNode(arg1subst, arg2subst, datatree);
}
expr_t
BinaryOpNode::substitutePacExpectation(const string & name, int mce_symb_id,
map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)
{
expr_t arg1subst = arg1->substitutePacExpectation(subst_table);
expr_t arg2subst = arg2->substitutePacExpectation(subst_table);
expr_t arg1subst = arg1->substitutePacExpectation(name, mce_symb_id, subst_table);
expr_t arg2subst = arg2->substitutePacExpectation(name, mce_symb_id, subst_table);
return buildSimilarBinaryOpNode(arg1subst, arg2subst, datatree);
}
......@@ -5903,7 +5985,7 @@ BinaryOpNode::addParamInfoToPac(pair<int, int> &lhs_arg, int optim_share_arg, pa
}
void
BinaryOpNode::fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, int pac_max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int growth_lag_arg, int equation_number_arg)
BinaryOpNode::fillPacExpectationVarInfo(const string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, int pac_max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int growth_lag_arg, int equation_number_arg)
{
arg1->fillPacExpectationVarInfo(model_name_arg, lhs_arg, max_lag_arg, pac_max_lag_arg, nonstationary_arg, growth_symb_id_arg, growth_lag_arg, equation_number_arg);
arg2->fillPacExpectationVarInfo(model_name_arg, lhs_arg, max_lag_arg, pac_max_lag_arg, nonstationary_arg, growth_symb_id_arg, growth_lag_arg, equation_number_arg);
......@@ -6562,6 +6644,20 @@ TrinaryOpNode::PacMaxLag(int lhs_symb_id) const
return max(arg1->PacMaxLag(lhs_symb_id), max(arg2->PacMaxLag(lhs_symb_id), arg3->PacMaxLag(lhs_symb_id)));
}
int
TrinaryOpNode::getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const
{
int symb_id = arg1->getPacTargetSymbId(lhs_symb_id, undiff_lhs_symb_id);
if (symb_id >= 0)
return symb_id;
symb_id = arg2->getPacTargetSymbId(lhs_symb_id, undiff_lhs_symb_id);
if (symb_id >= 0)
return symb_id;
return arg3->getPacTargetSymbId(lhs_symb_id, undiff_lhs_symb_id);
}
expr_t
TrinaryOpNode::decreaseLeadsLags(int n) const
{
......@@ -6711,11 +6807,21 @@ TrinaryOpNode::countDiffs() const
}
expr_t
TrinaryOpNode::substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)
TrinaryOpNode::substitutePacExpectation(const string & name, map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)
{
expr_t arg1subst = arg1->substitutePacExpectation(subst_table);
expr_t arg2subst = arg2->substitutePacExpectation(subst_table);
expr_t arg3subst = arg3->substitutePacExpectation(subst_table);
expr_t arg1subst = arg1->substitutePacExpectation(name, subst_table);
expr_t arg2subst = arg2->substitutePacExpectation(name, subst_table);
expr_t arg3subst = arg3->substitutePacExpectation(name, subst_table);
return buildSimilarTrinaryOpNode(arg1subst, arg2subst, arg3subst, datatree);
}
expr_t
TrinaryOpNode::substitutePacExpectation(const string & name, int mce_symb_id,
map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)
{
expr_t arg1subst = arg1->substitutePacExpectation(name, mce_symb_id, subst_table);
expr_t arg2subst = arg2->substitutePacExpectation(name, mce_symb_id, subst_table);
expr_t arg3subst = arg2->substitutePacExpectation(name, mce_symb_id, subst_table);
return buildSimilarTrinaryOpNode(arg1subst, arg2subst, arg3subst, datatree);
}
......@@ -6827,7 +6933,7 @@ TrinaryOpNode::addParamInfoToPac(pair<int, int> &lhs_arg, int optim_share_arg, p
}
void
TrinaryOpNode::fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, int pac_max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int growth_lag_arg, int equation_number_arg)
TrinaryOpNode::fillPacExpectationVarInfo(const string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, int pac_max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int growth_lag_arg, int equation_number_arg)
{
arg1->fillPacExpectationVarInfo(model_name_arg, lhs_arg, max_lag_arg, pac_max_lag_arg, nonstationary_arg, growth_symb_id_arg, growth_lag_arg, equation_number_arg);
arg2->fillPacExpectationVarInfo(model_name_arg, lhs_arg, max_lag_arg, pac_max_lag_arg, nonstationary_arg, growth_symb_id_arg, growth_lag_arg, equation_number_arg);
......@@ -7086,6 +7192,19 @@ AbstractExternalFunctionNode::PacMaxLag(int lhs_symb_id) const
return val;
}
int
AbstractExternalFunctionNode::getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const
{
int symb_id = -1;
for (auto argument : arguments)
{
symb_id = argument->getPacTargetSymbId(lhs_symb_id, undiff_lhs_symb_id);
if (symb_id >= 0)
return symb_id;
}
return -1;
}
expr_t
AbstractExternalFunctionNode::decreaseLeadsLags(int n) const
{
......@@ -7222,11 +7341,21 @@ AbstractExternalFunctionNode::countDiffs() const
}
expr_t
AbstractExternalFunctionNode::substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)
AbstractExternalFunctionNode::substitutePacExpectation(const string & name, map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)
{
vector<expr_t> arguments_subst;
for (auto argument : arguments)
arguments_subst.push_back(argument->substitutePacExpectation(subst_table));
arguments_subst.push_back(argument->substitutePacExpectation(name, subst_table));
return buildSimilarExternalFunctionNode(arguments_subst, datatree);
}
expr_t
AbstractExternalFunctionNode::substitutePacExpectation(const string & name, int mce_symb_id,
map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)
{
vector<expr_t> arguments_subst;
for (auto argument : arguments)
arguments_subst.push_back(argument->substitutePacExpectation(name, mce_symb_id, subst_table));
return buildSimilarExternalFunctionNode(arguments_subst, datatree);
}
......@@ -7395,7 +7524,7 @@ AbstractExternalFunctionNode::addParamInfoToPac(pair<int, int> &lhs_arg, int opt
}
void
AbstractExternalFunctionNode::fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, int pac_max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int growth_lag_arg, int equation_number_arg)
AbstractExternalFunctionNode::fillPacExpectationVarInfo(const string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, int pac_max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int growth_lag_arg, int equation_number_arg)
{
for (auto argument : arguments)
argument->fillPacExpectationVarInfo(model_name_arg, lhs_arg, max_lag_arg, pac_max_lag_arg, nonstationary_arg, growth_symb_id_arg, growth_lag_arg, equation_number_arg);
......@@ -8746,6 +8875,12 @@ VarExpectationNode::PacMaxLag(int lhs_symb_id) const
exit(EXIT_FAILURE);
}
int
VarExpectationNode::getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const
{
return -1;
}
expr_t
VarExpectationNode::decreaseLeadsLags(int n) const
{
......@@ -8916,7 +9051,14 @@ VarExpectationNode::substituteUnaryOpNodes(DataTree &static_datatree, diff_table
}
expr_t
VarExpectationNode::substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)
VarExpectationNode::substitutePacExpectation(const string & name, map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)