Verified Commit effa4054 authored by Houtan Bastani's avatar Houtan Bastani
Browse files

pac: find correct target variable when pac equation accounts for share of optimizing agents

parent 3d42e646
Pipeline #888 passed with stage
in 1 minute and 22 seconds
......@@ -5198,12 +5198,10 @@ BinaryOpNode::PacMaxLag(int lhs_symb_id) const
}
int
BinaryOpNode::getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const
BinaryOpNode::getPacTargetSymbIdHelper(int lhs_symb_id, int undiff_lhs_symb_id, const set<pair<int, int>> & endogs) const
{
set<pair<int, int>> endogs;
arg1->collectDynamicVariables(SymbolType::endogenous, endogs);
arg2->collectDynamicVariables(SymbolType::endogenous, endogs);
int ret_symb_id = -1;
int target_symb_id = -1;
bool found_lagged_lhs = false;
for (auto & it : endogs)
{
int id = it.first;
......@@ -5216,18 +5214,37 @@ BinaryOpNode::getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const
{
break;
}
if (id == lhs_symb_id || id == undiff_lhs_symb_id)
found_lagged_lhs = true;
if (id != lhs_symb_id && id != undiff_lhs_symb_id)
if (ret_symb_id < 0)
ret_symb_id = it.first;
else
if (target_symb_id < 0)
target_symb_id = it.first;
}
if (!found_lagged_lhs)
target_symb_id = -1;
return target_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);
int target_symb_id = getPacTargetSymbIdHelper(lhs_symb_id, undiff_lhs_symb_id, endogs);
if (target_symb_id >= 0)
return target_symb_id;
endogs.clear();
arg2->collectDynamicVariables(SymbolType::endogenous, endogs);
target_symb_id = getPacTargetSymbIdHelper(lhs_symb_id, undiff_lhs_symb_id, endogs);
if (target_symb_id < 0)
{
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;
cerr << "Error finding target variable in PAC equation" << endl;
exit(EXIT_FAILURE);
}
}
return ret_symb_id;
return target_symb_id;
}
expr_t
......
......@@ -1029,6 +1029,7 @@ public:
int VarMinLag() const override;
int VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs) const override;
int PacMaxLag(int lhs_symb_id) const override;
int getPacTargetSymbIdHelper(int lhs_symb_id, int undiff_lhs_symb_id, const set<pair<int, int>> & endogs) const;
int getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const override;
expr_t undiff() const override;
expr_t decreaseLeadsLags(int n) const override;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment