support undiff in pac model
parent
bb1cc0bebf
commit
7ac33099f8
|
@ -3258,6 +3258,7 @@ void
|
|||
DynamicModel::getVarModelVariablesFromEqTags(vector<string> &var_model_eqtags,
|
||||
vector<int> &eqnumber,
|
||||
vector<int> &lhs,
|
||||
vector<expr_t> &lhs_expr_t,
|
||||
vector<set<pair<int, int> > > &rhs,
|
||||
vector<bool> &nonstationary) const
|
||||
{
|
||||
|
@ -3316,6 +3317,10 @@ DynamicModel::getVarModelVariablesFromEqTags(vector<string> &var_model_eqtags,
|
|||
|
||||
eqnumber.push_back(eqn);
|
||||
lhs.push_back(it->first);
|
||||
lhs_set.clear();
|
||||
set<expr_t> lhs_expr_t_set;
|
||||
equations[eqn]->get_arg1()->collectVARLHSVariable(lhs_expr_t_set);
|
||||
lhs_expr_t.push_back(*(lhs_expr_t_set.begin()));
|
||||
|
||||
equations[eqn]->get_arg2()->collectDynamicVariables(eEndogenous, rhs_set);
|
||||
for (it = rhs_set.begin(); it != rhs_set.end(); it++)
|
||||
|
@ -3332,7 +3337,7 @@ DynamicModel::getVarModelVariablesFromEqTags(vector<string> &var_model_eqtags,
|
|||
int
|
||||
DynamicModel::getVarMaxLag(StaticModel &static_model, vector<int> &eqnumber) const
|
||||
{
|
||||
set<expr_t> lhs;
|
||||
vector<expr_t> lhs;
|
||||
for (vector<int>::const_iterator it = eqnumber.begin();
|
||||
it != eqnumber.end(); it++)
|
||||
{
|
||||
|
@ -3344,11 +3349,11 @@ DynamicModel::getVarMaxLag(StaticModel &static_model, vector<int> &eqnumber) con
|
|||
<< ". A VAR may only have one endogenous variable on the LHS. " << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
lhs.insert(*(lhs_set.begin()));
|
||||
lhs.push_back(*(lhs_set.begin()));
|
||||
}
|
||||
|
||||
set<expr_t> lhs_static;
|
||||
for(set<expr_t>::const_iterator it = lhs.begin();
|
||||
for(vector<expr_t>::const_iterator it = lhs.begin();
|
||||
it != lhs.end(); it++)
|
||||
lhs_static.insert((*it)->toStatic(static_model));
|
||||
|
||||
|
@ -3444,23 +3449,9 @@ 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)
|
||||
DynamicModel::getUndiffLHSForPac(vector<int> &lhs, vector<expr_t> &lhs_expr_t, vector<bool> &diff, vector<int> &orig_diff_var,
|
||||
vector<int> &eqnumber, map<string, int> &undiff, ExprNode::subst_table_t &diff_subst_table)
|
||||
{
|
||||
if (undiff.empty())
|
||||
return;
|
||||
|
@ -3486,18 +3477,12 @@ DynamicModel::undiff_lhs_for_pac(vector<int> &lhs, vector<bool> &diff, vector<in
|
|||
}
|
||||
|
||||
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++;
|
||||
it1 != eqnumber.end(); it1++, i++)
|
||||
if (*it1 == eqn)
|
||||
break;
|
||||
|
||||
if (!found)
|
||||
if (eqnumber[i] != eqn)
|
||||
{
|
||||
cerr << "ERROR: equation not found in VAR";
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -3511,18 +3496,67 @@ DynamicModel::undiff_lhs_for_pac(vector<int> &lhs, vector<bool> &diff, vector<in
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
bool printerr = false;
|
||||
ExprNode::subst_table_t::const_iterator it1;
|
||||
expr_t node = NULL;
|
||||
expr_t aux_var = lhs_expr_t.at(i);
|
||||
for (it1 = diff_subst_table.begin(); it1 != diff_subst_table.end(); it1++)
|
||||
if (it1->second == aux_var)
|
||||
{
|
||||
node = const_cast<expr_t>(it1->first);
|
||||
break;
|
||||
}
|
||||
|
||||
if (node == NULL)
|
||||
{
|
||||
cerr << "Unexpected error encountered." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (int j = it->second; j > 0; j--)
|
||||
if (undiff_table.find(lhs.at(eqnumber.at(i))) == undiff_table.end())
|
||||
if (printerr)
|
||||
{
|
||||
cerr << "You are undiffing the LHS of equation #" << eqn << " "
|
||||
<< it->second << " times but it has only been diffed " << j - 1 << " time(s)" << endl;
|
||||
<< it->second << " times but it has only been diffed " << j << " time(s)" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else
|
||||
lhs.at(eqnumber.at(i)) = undiff_table.at(lhs.at(eqnumber.at(i)));
|
||||
{
|
||||
node = node->undiff();
|
||||
it1 = diff_subst_table.find(node);
|
||||
if (it1 == diff_subst_table.end())
|
||||
printerr = true;
|
||||
}
|
||||
|
||||
if (printerr)
|
||||
{ // we have undiffed something like diff(x), hence x is not in diff_subst_table
|
||||
lhs_expr_t.at(i) = node;
|
||||
lhs.at(i) = dynamic_cast<VariableNode *>(node)->get_symb_id();
|
||||
}
|
||||
else
|
||||
{
|
||||
lhs_expr_t.at(i) = const_cast<expr_t>(it1->first);
|
||||
lhs.at(i) = const_cast<VariableNode *>(it1->second)->get_symb_id();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
DynamicModel::getUndiffMaxLag(StaticModel &static_model, vector<expr_t> &lhs, vector<int> &eqnumber) const
|
||||
{
|
||||
set<expr_t> lhs_static;
|
||||
for(vector<expr_t>::const_iterator it = lhs.begin();
|
||||
it != lhs.end(); it++)
|
||||
lhs_static.insert((*it)->toStatic(static_model));
|
||||
|
||||
int max_lag = 0;
|
||||
for (vector<int>::const_iterator it = eqnumber.begin();
|
||||
it != eqnumber.end(); it++)
|
||||
equations[*it]->get_arg2()->VarMaxLag(static_model, lhs_static, max_lag);
|
||||
|
||||
return max_lag;
|
||||
}
|
||||
|
||||
void
|
||||
DynamicModel::walkPacParameters()
|
||||
{
|
||||
|
@ -5136,7 +5170,7 @@ DynamicModel::substituteAdl()
|
|||
}
|
||||
|
||||
void
|
||||
DynamicModel::substituteDiff(StaticModel &static_model, map<int, int> &undiff_table)
|
||||
DynamicModel::substituteDiff(StaticModel &static_model, ExprNode::subst_table_t &diff_subst_table)
|
||||
{
|
||||
// Find diff Nodes
|
||||
diff_table_t diff_table;
|
||||
|
@ -5149,16 +5183,15 @@ DynamicModel::substituteDiff(StaticModel &static_model, map<int, int> &undiff_ta
|
|||
|
||||
// Substitute in model local variables
|
||||
vector<BinaryOpNode *> neweqs;
|
||||
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, undiff_table);
|
||||
it->second = it->second->substituteDiff(static_model, diff_table, diff_subst_table, neweqs);
|
||||
|
||||
// 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, undiff_table));
|
||||
substituteDiff(static_model, diff_table, diff_subst_table, neweqs));
|
||||
assert(substeq != NULL);
|
||||
equations[i] = substeq;
|
||||
}
|
||||
|
|
|
@ -290,6 +290,7 @@ public:
|
|||
void getVarModelVariablesFromEqTags(vector<string> &var_model_eqtags,
|
||||
vector<int> &eqnumber,
|
||||
vector<int> &lhs,
|
||||
vector<expr_t> &lhs_expr_t,
|
||||
vector<set<pair<int, int> > > &rhs,
|
||||
vector<bool> &nonstationary) const;
|
||||
|
||||
|
@ -313,7 +314,7 @@ public:
|
|||
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);
|
||||
int getUndiffMaxLag(StaticModel &static_model, vector<expr_t> &lhs, vector<int> &eqnumber) const;
|
||||
|
||||
//! Substitutes pac_expectation operator
|
||||
void substitutePacExpectation();
|
||||
|
@ -406,11 +407,11 @@ public:
|
|||
void substituteAdl();
|
||||
|
||||
//! Substitutes diff operator
|
||||
void substituteDiff(StaticModel &static_model, map<int, int> &undiff_table);
|
||||
void substituteDiff(StaticModel &static_model, ExprNode::subst_table_t &diff_subst_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);
|
||||
void getUndiffLHSForPac(vector<int> &lhs, vector<expr_t> &lhs_expr_t, vector<bool> &diff, vector<int> &orig_diff_var,
|
||||
vector<int> &eqnumber, map<string, int> &undiff, ExprNode::subst_table_t &diff_subst_table);
|
||||
|
||||
//! Adds contents of diff_aux_equations to the back of aux_equations
|
||||
void combineDiffAuxEquations();
|
||||
|
|
105
src/ExprNode.cc
105
src/ExprNode.cc
|
@ -462,6 +462,12 @@ NumConstNode::maxLag() const
|
|||
return 0;
|
||||
}
|
||||
|
||||
expr_t
|
||||
NumConstNode::undiff() const
|
||||
{
|
||||
return const_cast<NumConstNode *>(this);
|
||||
}
|
||||
|
||||
void
|
||||
NumConstNode::VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs, int &max_lag) const
|
||||
{
|
||||
|
@ -527,7 +533,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, map<int, int> &undiff_table) const
|
||||
NumConstNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const
|
||||
{
|
||||
return const_cast<NumConstNode *>(this);
|
||||
}
|
||||
|
@ -1352,6 +1358,12 @@ VariableNode::maxLag() const
|
|||
}
|
||||
}
|
||||
|
||||
expr_t
|
||||
VariableNode::undiff() const
|
||||
{
|
||||
return const_cast<VariableNode *>(this);
|
||||
}
|
||||
|
||||
void
|
||||
VariableNode::VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs, int &max_lag) const
|
||||
{
|
||||
|
@ -1383,7 +1395,8 @@ 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, map<int, int> &undiff_table) const
|
||||
VariableNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table,
|
||||
vector<BinaryOpNode *> &neweqs) const
|
||||
{
|
||||
return const_cast<VariableNode *>(this);
|
||||
}
|
||||
|
@ -2896,6 +2909,14 @@ UnaryOpNode::maxLag() const
|
|||
return arg->maxLag();
|
||||
}
|
||||
|
||||
expr_t
|
||||
UnaryOpNode::undiff() const
|
||||
{
|
||||
if (op_code == oDiff)
|
||||
return arg;
|
||||
return arg->undiff();
|
||||
}
|
||||
|
||||
void
|
||||
UnaryOpNode::VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs, int &max_lag) const
|
||||
{
|
||||
|
@ -2992,11 +3013,11 @@ 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, map<int, int> &undiff_table) const
|
||||
vector<BinaryOpNode *> &neweqs) const
|
||||
{
|
||||
if (op_code != oDiff)
|
||||
{
|
||||
expr_t argsubst = arg->substituteDiff(static_datatree, diff_table, subst_table, neweqs, undiff_table);
|
||||
expr_t argsubst = arg->substituteDiff(static_datatree, diff_table, subst_table, neweqs);
|
||||
return buildSimilarUnaryOpNode(argsubst, datatree);
|
||||
}
|
||||
|
||||
|
@ -3006,7 +3027,11 @@ UnaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table,
|
|||
|
||||
expr_t sthis = dynamic_cast<UnaryOpNode *>(this->toStatic(static_datatree));
|
||||
diff_table_t::iterator it = diff_table.find(sthis);
|
||||
assert(it != diff_table.end() && it->second[-arg->maxLag()] == this);
|
||||
if (it == diff_table.end() || it->second[-arg->maxLag()] != this)
|
||||
{
|
||||
cerr << "Internal error encountered. Please report" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int last_arg_max_lag = 0;
|
||||
VariableNode *last_aux_var = NULL;
|
||||
|
@ -3014,7 +3039,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, undiff_table);
|
||||
get_arg()->substituteDiff(static_datatree, diff_table, subst_table, neweqs);
|
||||
int symb_id;
|
||||
VariableNode *vn = dynamic_cast<VariableNode *>(argsubst);
|
||||
if (rit == it->second.rbegin())
|
||||
|
@ -3032,11 +3057,10 @@ 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
|
||||
{
|
||||
// just add equation of form: AUX_DIFF = ORIG_AUX_DIFF(last_arg_max_lag - rit->first)
|
||||
// just add equation of form: AUX_DIFF = LAST_AUX_VAR(-1)
|
||||
VariableNode *new_aux_var = NULL;
|
||||
for (int i = last_arg_max_lag; i > rit->first; i--)
|
||||
{
|
||||
|
@ -4577,6 +4601,14 @@ BinaryOpNode::maxLag() const
|
|||
return max(arg1->maxLag(), arg2->maxLag());
|
||||
}
|
||||
|
||||
expr_t
|
||||
BinaryOpNode::undiff() const
|
||||
{
|
||||
expr_t arg1subst = arg1->undiff();
|
||||
expr_t arg2subst = arg2->undiff();
|
||||
return buildSimilarBinaryOpNode(arg1subst, arg2subst, datatree);
|
||||
}
|
||||
|
||||
int
|
||||
BinaryOpNode::PacMaxLag(vector<int> &lhs) const
|
||||
{
|
||||
|
@ -4727,10 +4759,11 @@ 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, map<int, int> &undiff_table) const
|
||||
BinaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table,
|
||||
vector<BinaryOpNode *> &neweqs) const
|
||||
{
|
||||
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 arg1subst = arg1->substituteDiff(static_datatree, diff_table, subst_table, neweqs);
|
||||
expr_t arg2subst = arg2->substituteDiff(static_datatree, diff_table, subst_table, neweqs);
|
||||
return buildSimilarBinaryOpNode(arg1subst, arg2subst, datatree);
|
||||
}
|
||||
|
||||
|
@ -5511,6 +5544,15 @@ TrinaryOpNode::maxLag() const
|
|||
return max(arg1->maxLag(), max(arg2->maxLag(), arg3->maxLag()));
|
||||
}
|
||||
|
||||
expr_t
|
||||
TrinaryOpNode::undiff() const
|
||||
{
|
||||
expr_t arg1subst = arg1->undiff();
|
||||
expr_t arg2subst = arg2->undiff();
|
||||
expr_t arg3subst = arg3->undiff();
|
||||
return buildSimilarTrinaryOpNode(arg1subst, arg2subst, arg3subst, datatree);
|
||||
}
|
||||
|
||||
void
|
||||
TrinaryOpNode::VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs, int &max_lag) const
|
||||
{
|
||||
|
@ -5620,11 +5662,12 @@ 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, map<int, int> &undiff_table) const
|
||||
TrinaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table,
|
||||
vector<BinaryOpNode *> &neweqs) const
|
||||
{
|
||||
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);
|
||||
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);
|
||||
return buildSimilarTrinaryOpNode(arg1subst, arg2subst, arg3subst, datatree);
|
||||
}
|
||||
|
||||
|
@ -5925,6 +5968,15 @@ AbstractExternalFunctionNode::maxLag() const
|
|||
return val;
|
||||
}
|
||||
|
||||
expr_t
|
||||
AbstractExternalFunctionNode::undiff() const
|
||||
{
|
||||
vector<expr_t> arguments_subst;
|
||||
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++)
|
||||
arguments_subst.push_back((*it)->undiff());
|
||||
return buildSimilarExternalFunctionNode(arguments_subst, datatree);
|
||||
}
|
||||
|
||||
void
|
||||
AbstractExternalFunctionNode::VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs, int &max_lag) const
|
||||
{
|
||||
|
@ -6023,11 +6075,12 @@ 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, map<int, int> &undiff_table) const
|
||||
AbstractExternalFunctionNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table,
|
||||
vector<BinaryOpNode *> &neweqs) 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, undiff_table));
|
||||
arguments_subst.push_back((*it)->substituteDiff(static_datatree, diff_table, subst_table, neweqs));
|
||||
return buildSimilarExternalFunctionNode(arguments_subst, datatree);
|
||||
}
|
||||
|
||||
|
@ -7434,6 +7487,12 @@ VarExpectationNode::maxLag() const
|
|||
return 0;
|
||||
}
|
||||
|
||||
expr_t
|
||||
VarExpectationNode::undiff() const
|
||||
{
|
||||
return const_cast<VarExpectationNode *>(this);
|
||||
}
|
||||
|
||||
void
|
||||
VarExpectationNode::VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs, int &max_lag) const
|
||||
{
|
||||
|
@ -7573,7 +7632,8 @@ 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, map<int, int> &undiff_table) const
|
||||
VarExpectationNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table,
|
||||
vector<BinaryOpNode *> &neweqs) const
|
||||
{
|
||||
return const_cast<VarExpectationNode *>(this);
|
||||
}
|
||||
|
@ -7843,6 +7903,12 @@ PacExpectationNode::maxLag() const
|
|||
return 0;
|
||||
}
|
||||
|
||||
expr_t
|
||||
PacExpectationNode::undiff() const
|
||||
{
|
||||
return const_cast<PacExpectationNode *>(this);
|
||||
}
|
||||
|
||||
void
|
||||
PacExpectationNode::VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs, int &max_lag) const
|
||||
{
|
||||
|
@ -7981,7 +8047,8 @@ 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, map<int, int> &undiff_table) const
|
||||
PacExpectationNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table,
|
||||
vector<BinaryOpNode *> &neweqs) const
|
||||
{
|
||||
return const_cast<PacExpectationNode *>(this);
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ typedef map<int, double> eval_context_t;
|
|||
typedef map<pair<int, vector<expr_t> >, int> deriv_node_temp_terms_t;
|
||||
|
||||
//! Type for the substitution map used in the process of substitutitng diff expressions
|
||||
//! diff_table[static_expr_t][lag] -> dynamic_expr_t
|
||||
typedef map<expr_t, map<int, expr_t> > diff_table_t;
|
||||
|
||||
//! Possible types of output when writing ExprNode(s)
|
||||
|
@ -359,6 +360,8 @@ class ExprNode
|
|||
//! Takes account of undiffed LHS variables in calculating the max lag
|
||||
virtual int PacMaxLag(vector<int> &lhs) const = 0;
|
||||
|
||||
virtual expr_t undiff() 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
|
||||
|
@ -486,7 +489,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, map<int, int> &undiff_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;
|
||||
|
||||
//! Substitute pac_expectation operator
|
||||
virtual expr_t substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table) = 0;
|
||||
|
@ -568,6 +571,7 @@ public:
|
|||
virtual int maxLag() const;
|
||||
virtual void VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs, int &max_lag) const;
|
||||
virtual int PacMaxLag(vector<int> &lhs) const;
|
||||
virtual expr_t undiff() 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;
|
||||
|
@ -576,7 +580,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, map<int, int> &undiff_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 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;
|
||||
|
@ -654,6 +658,7 @@ public:
|
|||
virtual int maxLag() const;
|
||||
virtual void VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs, int &max_lag) const;
|
||||
virtual int PacMaxLag(vector<int> &lhs) const;
|
||||
virtual expr_t undiff() 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;
|
||||
|
@ -662,7 +667,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, map<int, int> &undiff_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 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;
|
||||
|
@ -760,6 +765,7 @@ public:
|
|||
virtual int maxLag() const;
|
||||
virtual void VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs, int &max_lag) const;
|
||||
virtual int PacMaxLag(vector<int> &lhs) const;
|
||||
virtual expr_t undiff() 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
|
||||
|
@ -770,7 +776,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, map<int, int> &undiff_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 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;
|
||||
|
@ -884,6 +890,7 @@ public:
|
|||
virtual int maxLag() const;
|
||||
virtual void VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs, int &max_lag) const;
|
||||
virtual int PacMaxLag(vector<int> &lhs) const;
|
||||
virtual expr_t undiff() 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
|
||||
|
@ -894,7 +901,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, map<int, int> &undiff_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 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;
|
||||
|
@ -985,6 +992,7 @@ public:
|
|||
virtual int maxLag() const;
|
||||
virtual void VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs, int &max_lag) const;
|
||||
virtual int PacMaxLag(vector<int> &lhs) const;
|
||||
virtual expr_t undiff() 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
|
||||
|
@ -995,7 +1003,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, map<int, int> &undiff_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 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;
|
||||
|
@ -1088,6 +1096,7 @@ public:
|
|||
virtual int maxLag() const;
|
||||
virtual void VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs, int &max_lag) const;
|
||||
virtual int PacMaxLag(vector<int> &lhs) const;
|
||||
virtual expr_t undiff() 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;
|
||||
|
@ -1096,7 +1105,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, map<int, int> &undiff_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 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;
|
||||
|
@ -1273,6 +1282,7 @@ public:
|
|||
virtual int maxLag() const;
|
||||
virtual void VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs, int &max_lag) const;
|
||||
virtual int PacMaxLag(vector<int> &lhs) const;
|
||||
virtual expr_t undiff() const;
|
||||
virtual expr_t decreaseLeadsLags(int n) const;
|
||||
virtual void prepareForDerivation();
|
||||
virtual expr_t computeDerivative(int deriv_id);
|
||||
|
@ -1287,7 +1297,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, map<int, int> &undiff_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 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,
|
||||
|
@ -1353,6 +1363,7 @@ public:
|
|||
virtual int maxLag() const;
|
||||
virtual void VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs, int &max_lag) const;
|
||||
virtual int PacMaxLag(vector<int> &lhs) const;
|
||||
virtual expr_t undiff() const;
|
||||
virtual expr_t decreaseLeadsLags(int n) const;
|
||||
virtual void prepareForDerivation();
|
||||
virtual expr_t computeDerivative(int deriv_id);
|
||||
|
@ -1367,7 +1378,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, map<int, int> &undiff_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 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,
|
||||
|
|
|
@ -367,13 +367,15 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, const
|
|||
}
|
||||
|
||||
// Create auxiliary variable and equations for Diff operator
|
||||
map<int, int> undiff_table;
|
||||
dynamic_model.substituteDiff(diff_static_model, undiff_table);
|
||||
ExprNode::subst_table_t diff_subst_table;
|
||||
dynamic_model.substituteDiff(diff_static_model, diff_subst_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> > > >
|
||||
map<string, pair<pair<pair<vector<int>, vector<expr_t> >,
|
||||
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++)
|
||||
|
@ -382,42 +384,46 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, const
|
|||
if (vms != NULL)
|
||||
{
|
||||
string var_model_name;
|
||||
vms->getVarModelInfoForVarExpectation(var_model_name, var_model_info_var_expectation, var_model_eq_tags);
|
||||
vector<int> eqnumber, lhs, orig_diff_var;
|
||||
vms->getVarModelInfo(var_model_name, var_model_info_var_expectation, var_model_eq_tags);
|
||||
vector<expr_t> lhs_expr_t;
|
||||
vector<int> lhs, eqnumber, 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);
|
||||
eqnumber, lhs, lhs_expr_t, rhs, nonstationary);
|
||||
int max_lag = original_model.getVarMaxLag(diff_static_model, eqnumber);
|
||||
original_model.getVarLhsDiffAndInfo(eqnumber, diff, orig_diff_var);
|
||||
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));
|
||||
make_pair(make_pair(make_pair(lhs, lhs_expr_t),
|
||||
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;
|
||||
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;
|
||||
vector<int> lhs = var_model_info_pac_expectation[var_model_name].first.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<expr_t> lhs_expr_t = var_model_info_pac_expectation[var_model_name].first.first.second;
|
||||
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);
|
||||
dynamic_model.getUndiffLHSForPac(lhs, lhs_expr_t, diff, orig_diff_var, eqnumber, undiff, diff_subst_table);
|
||||
max_lag = original_model.getUndiffMaxLag(diff_static_model, lhs_expr_t, eqnumber);
|
||||
}
|
||||
pms->fillUndiffedLHS(lhs);
|
||||
dynamic_model.walkPacParameters();
|
||||
|
|
Loading…
Reference in New Issue