VAR/TCM models: use lag-equivalence relationship to compute maximum lags
This is made possible by the getLagEquivalenceClass() method introduced in the previous commit. Previously, the static version of the LHS expressions was used. As a consequence, drop ModFile::diff_static_model, now useless.issue#70
parent
8a83e08e79
commit
2a127b1f23
|
@ -3974,7 +3974,7 @@ DynamicModel::fillVarModelTable() const
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::fillVarModelTableFromOrigModel(StaticModel &static_model) const
|
DynamicModel::fillVarModelTableFromOrigModel() const
|
||||||
{
|
{
|
||||||
map<string, vector<int>> lags, orig_diff_var;
|
map<string, vector<int>> lags, orig_diff_var;
|
||||||
map<string, vector<bool>> diff;
|
map<string, vector<bool>> diff;
|
||||||
|
@ -4024,13 +4024,16 @@ DynamicModel::fillVarModelTableFromOrigModel(StaticModel &static_model) const
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
set<expr_t> lhs_static;
|
set<expr_t> lhs_lag_equiv;
|
||||||
for(const auto & lh : lhs)
|
for(const auto & lh : lhs)
|
||||||
lhs_static.insert(lh->toStatic(static_model));
|
{
|
||||||
|
auto [lag_equiv_repr, index] = lh->getLagEquivalenceClass();
|
||||||
|
lhs_lag_equiv.insert(lag_equiv_repr);
|
||||||
|
}
|
||||||
|
|
||||||
vector<int> max_lag;
|
vector<int> max_lag;
|
||||||
for (auto eqn : it.second)
|
for (auto eqn : it.second)
|
||||||
max_lag.push_back(equations[eqn]->arg2->VarMaxLag(static_model, lhs_static));
|
max_lag.push_back(equations[eqn]->arg2->VarMaxLag(lhs_lag_equiv));
|
||||||
lags[it.first] = max_lag;
|
lags[it.first] = max_lag;
|
||||||
diff[it.first] = diff_vec;
|
diff[it.first] = diff_vec;
|
||||||
orig_diff_var[it.first] = orig_diff_var_vec;
|
orig_diff_var[it.first] = orig_diff_var_vec;
|
||||||
|
@ -4197,7 +4200,7 @@ DynamicModel::fillErrorComponentMatrix(const ExprNode::subst_table_t &diff_subst
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::fillTrendComponentModelTableFromOrigModel(StaticModel &static_model) const
|
DynamicModel::fillTrendComponentModelTableFromOrigModel() const
|
||||||
{
|
{
|
||||||
map<string, vector<int>> lags, orig_diff_var;
|
map<string, vector<int>> lags, orig_diff_var;
|
||||||
map<string, vector<bool>> diff;
|
map<string, vector<bool>> diff;
|
||||||
|
@ -4247,13 +4250,16 @@ DynamicModel::fillTrendComponentModelTableFromOrigModel(StaticModel &static_mode
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
set<expr_t> lhs_static;
|
set<expr_t> lhs_lag_equiv;
|
||||||
for(const auto & lh : lhs)
|
for(const auto & lh : lhs)
|
||||||
lhs_static.insert(lh->toStatic(static_model));
|
{
|
||||||
|
auto [lag_equiv_repr, index] = lh->getLagEquivalenceClass();
|
||||||
|
lhs_lag_equiv.insert(lag_equiv_repr);
|
||||||
|
}
|
||||||
|
|
||||||
vector<int> max_lag;
|
vector<int> max_lag;
|
||||||
for (auto eqn : it.second)
|
for (auto eqn : it.second)
|
||||||
max_lag.push_back(equations[eqn]->arg2->VarMaxLag(static_model, lhs_static));
|
max_lag.push_back(equations[eqn]->arg2->VarMaxLag(lhs_lag_equiv));
|
||||||
lags[it.first] = max_lag;
|
lags[it.first] = max_lag;
|
||||||
diff[it.first] = diff_vec;
|
diff[it.first] = diff_vec;
|
||||||
orig_diff_var[it.first] = orig_diff_var_vec;
|
orig_diff_var[it.first] = orig_diff_var_vec;
|
||||||
|
|
|
@ -323,12 +323,12 @@ public:
|
||||||
|
|
||||||
//! Fill the Trend Component Model Table
|
//! Fill the Trend Component Model Table
|
||||||
void fillTrendComponentModelTable() const;
|
void fillTrendComponentModelTable() const;
|
||||||
void fillTrendComponentModelTableFromOrigModel(StaticModel &static_model) const;
|
void fillTrendComponentModelTableFromOrigModel() const;
|
||||||
void fillTrendComponentmodelTableAREC(const ExprNode::subst_table_t &diff_subst_table) const;
|
void fillTrendComponentmodelTableAREC(const ExprNode::subst_table_t &diff_subst_table) const;
|
||||||
|
|
||||||
//! Fill the Var Model Table
|
//! Fill the Var Model Table
|
||||||
void fillVarModelTable() const;
|
void fillVarModelTable() const;
|
||||||
void fillVarModelTableFromOrigModel(StaticModel &static_model) const;
|
void fillVarModelTableFromOrigModel() const;
|
||||||
|
|
||||||
//! Update the rhs references in the var model and trend component tables
|
//! Update the rhs references in the var model and trend component tables
|
||||||
//! after substitution of auxiliary variables and find the trend variables
|
//! after substitution of auxiliary variables and find the trend variables
|
||||||
|
|
|
@ -599,7 +599,7 @@ NumConstNode::VarMinLag() const
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
NumConstNode::VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs) const
|
NumConstNode::VarMaxLag(const set<expr_t> &lhs_lag_equiv) const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1638,10 +1638,11 @@ VariableNode::undiff() const
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
VariableNode::VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs) const
|
VariableNode::VarMaxLag(const set<expr_t> &lhs_lag_equiv) const
|
||||||
{
|
{
|
||||||
auto it = static_lhs.find(this->toStatic(static_datatree));
|
auto [lag_equiv_repr, index] = getLagEquivalenceClass();
|
||||||
if (it == static_lhs.end())
|
auto it = lhs_lag_equiv.find(lag_equiv_repr);
|
||||||
|
if (it == lhs_lag_equiv.end())
|
||||||
return 0;
|
return 0;
|
||||||
return maxLag();
|
return maxLag();
|
||||||
}
|
}
|
||||||
|
@ -3355,10 +3356,11 @@ UnaryOpNode::undiff() const
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
UnaryOpNode::VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs) const
|
UnaryOpNode::VarMaxLag(const set<expr_t> &lhs_lag_equiv) const
|
||||||
{
|
{
|
||||||
auto it = static_lhs.find(this->toStatic(static_datatree));
|
auto [lag_equiv_repr, index] = getLagEquivalenceClass();
|
||||||
if (it == static_lhs.end())
|
auto it = lhs_lag_equiv.find(lag_equiv_repr);
|
||||||
|
if (it == lhs_lag_equiv.end())
|
||||||
return 0;
|
return 0;
|
||||||
return arg->maxLag();
|
return arg->maxLag();
|
||||||
}
|
}
|
||||||
|
@ -4832,10 +4834,10 @@ BinaryOpNode::VarMinLag() const
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
BinaryOpNode::VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs) const
|
BinaryOpNode::VarMaxLag(const set<expr_t> &lhs_lag_equiv) const
|
||||||
{
|
{
|
||||||
return max(arg1->VarMaxLag(static_datatree, static_lhs),
|
return max(arg1->VarMaxLag(lhs_lag_equiv),
|
||||||
arg2->VarMaxLag(static_datatree, static_lhs));
|
arg2->VarMaxLag(lhs_lag_equiv));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -6636,11 +6638,11 @@ TrinaryOpNode::VarMinLag() const
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
TrinaryOpNode::VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs) const
|
TrinaryOpNode::VarMaxLag(const set<expr_t> &lhs_lag_equiv) const
|
||||||
{
|
{
|
||||||
return max(arg1->VarMaxLag(static_datatree, static_lhs),
|
return max(arg1->VarMaxLag(lhs_lag_equiv),
|
||||||
max(arg2->VarMaxLag(static_datatree, static_lhs),
|
max(arg2->VarMaxLag(lhs_lag_equiv),
|
||||||
arg3->VarMaxLag(static_datatree, static_lhs)));
|
arg3->VarMaxLag(lhs_lag_equiv)));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -7119,11 +7121,11 @@ int val = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
AbstractExternalFunctionNode::VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs) const
|
AbstractExternalFunctionNode::VarMaxLag(const set<expr_t> &lhs_lag_equiv) const
|
||||||
{
|
{
|
||||||
int max_lag = 0;
|
int max_lag = 0;
|
||||||
for (auto argument : arguments)
|
for (auto argument : arguments)
|
||||||
max_lag = max(max_lag, argument->VarMaxLag(static_datatree, static_lhs));
|
max_lag = max(max_lag, argument->VarMaxLag(lhs_lag_equiv));
|
||||||
return max_lag;
|
return max_lag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8756,7 +8758,7 @@ VarExpectationNode::VarMinLag() const
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
VarExpectationNode::VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs) const
|
VarExpectationNode::VarMaxLag(const set<expr_t> &lhs_lag_equiv) const
|
||||||
{
|
{
|
||||||
cerr << "VarExpectationNode::VarMaxLag not implemented." << endl;
|
cerr << "VarExpectationNode::VarMaxLag not implemented." << endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -9192,7 +9194,7 @@ PacExpectationNode::VarMinLag() const
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
PacExpectationNode::VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs) const
|
PacExpectationNode::VarMaxLag(const set<expr_t> &lhs_lag_equiv) const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -345,7 +345,7 @@ class ExprNode
|
||||||
virtual int VarMinLag() const = 0;
|
virtual int VarMinLag() const = 0;
|
||||||
|
|
||||||
//! Find the maximum lag in a VAR: handles case where LHS is diff
|
//! Find the maximum lag in a VAR: handles case where LHS is diff
|
||||||
virtual int VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs) const = 0;
|
virtual int VarMaxLag(const set<expr_t> &lhs_lag_equiv) const = 0;
|
||||||
|
|
||||||
//! Finds LHS variable in a VAR equation
|
//! Finds LHS variable in a VAR equation
|
||||||
virtual void collectVARLHSVariable(set<expr_t> &result) const = 0;
|
virtual void collectVARLHSVariable(set<expr_t> &result) const = 0;
|
||||||
|
@ -730,7 +730,7 @@ public:
|
||||||
int maxLag() const override;
|
int maxLag() const override;
|
||||||
int maxLagWithDiffsExpanded() const override;
|
int maxLagWithDiffsExpanded() const override;
|
||||||
int VarMinLag() const override;
|
int VarMinLag() const override;
|
||||||
int VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs) const override;
|
int VarMaxLag(const set<expr_t> &lhs_lag_equiv) const override;
|
||||||
int PacMaxLag(int lhs_symb_id) const override;
|
int PacMaxLag(int lhs_symb_id) const override;
|
||||||
int getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const override;
|
int getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const override;
|
||||||
expr_t undiff() const override;
|
expr_t undiff() const override;
|
||||||
|
@ -813,7 +813,7 @@ public:
|
||||||
int maxLag() const override;
|
int maxLag() const override;
|
||||||
int maxLagWithDiffsExpanded() const override;
|
int maxLagWithDiffsExpanded() const override;
|
||||||
int VarMinLag() const override;
|
int VarMinLag() const override;
|
||||||
int VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs) const override;
|
int VarMaxLag(const set<expr_t> &lhs_lag_equiv) const override;
|
||||||
int PacMaxLag(int lhs_symb_id) const override;
|
int PacMaxLag(int lhs_symb_id) const override;
|
||||||
int getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const override;
|
int getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const override;
|
||||||
expr_t undiff() const override;
|
expr_t undiff() const override;
|
||||||
|
@ -921,7 +921,7 @@ public:
|
||||||
int maxLag() const override;
|
int maxLag() const override;
|
||||||
int maxLagWithDiffsExpanded() const override;
|
int maxLagWithDiffsExpanded() const override;
|
||||||
int VarMinLag() const override;
|
int VarMinLag() const override;
|
||||||
int VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs) const override;
|
int VarMaxLag(const set<expr_t> &lhs_lag_equiv) const override;
|
||||||
int PacMaxLag(int lhs_symb_id) const override;
|
int PacMaxLag(int lhs_symb_id) const override;
|
||||||
int getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const override;
|
int getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const override;
|
||||||
expr_t undiff() const override;
|
expr_t undiff() const override;
|
||||||
|
@ -1033,7 +1033,7 @@ public:
|
||||||
int maxLag() const override;
|
int maxLag() const override;
|
||||||
int maxLagWithDiffsExpanded() const override;
|
int maxLagWithDiffsExpanded() const override;
|
||||||
int VarMinLag() const override;
|
int VarMinLag() const override;
|
||||||
int VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs) const override;
|
int VarMaxLag(const set<expr_t> &lhs_lag_equiv) const override;
|
||||||
int PacMaxLag(int lhs_symb_id) 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 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;
|
int getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const override;
|
||||||
|
@ -1164,7 +1164,7 @@ public:
|
||||||
int maxLag() const override;
|
int maxLag() const override;
|
||||||
int maxLagWithDiffsExpanded() const override;
|
int maxLagWithDiffsExpanded() const override;
|
||||||
int VarMinLag() const override;
|
int VarMinLag() const override;
|
||||||
int VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs) const override;
|
int VarMaxLag(const set<expr_t> &lhs_lag_equiv) const override;
|
||||||
int PacMaxLag(int lhs_symb_id) const override;
|
int PacMaxLag(int lhs_symb_id) const override;
|
||||||
int getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const override;
|
int getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const override;
|
||||||
expr_t undiff() const override;
|
expr_t undiff() const override;
|
||||||
|
@ -1284,7 +1284,7 @@ public:
|
||||||
int maxLag() const override;
|
int maxLag() const override;
|
||||||
int maxLagWithDiffsExpanded() const override;
|
int maxLagWithDiffsExpanded() const override;
|
||||||
int VarMinLag() const override;
|
int VarMinLag() const override;
|
||||||
int VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs) const override;
|
int VarMaxLag(const set<expr_t> &lhs_lag_equiv) const override;
|
||||||
int PacMaxLag(int lhs_symb_id) const override;
|
int PacMaxLag(int lhs_symb_id) const override;
|
||||||
int getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const override;
|
int getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const override;
|
||||||
expr_t undiff() const override;
|
expr_t undiff() const override;
|
||||||
|
@ -1481,7 +1481,7 @@ public:
|
||||||
int maxLag() const override;
|
int maxLag() const override;
|
||||||
int maxLagWithDiffsExpanded() const override;
|
int maxLagWithDiffsExpanded() const override;
|
||||||
int VarMinLag() const override;
|
int VarMinLag() const override;
|
||||||
int VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs) const override;
|
int VarMaxLag(const set<expr_t> &lhs_lag_equiv) const override;
|
||||||
int PacMaxLag(int lhs_symb_id) const override;
|
int PacMaxLag(int lhs_symb_id) const override;
|
||||||
int getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const override;
|
int getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const override;
|
||||||
expr_t undiff() const override;
|
expr_t undiff() const override;
|
||||||
|
@ -1562,7 +1562,7 @@ public:
|
||||||
int maxLag() const override;
|
int maxLag() const override;
|
||||||
int maxLagWithDiffsExpanded() const override;
|
int maxLagWithDiffsExpanded() const override;
|
||||||
int VarMinLag() const override;
|
int VarMinLag() const override;
|
||||||
int VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs) const override;
|
int VarMaxLag(const set<expr_t> &lhs_lag_equiv) const override;
|
||||||
int PacMaxLag(int lhs_symb_id) const override;
|
int PacMaxLag(int lhs_symb_id) const override;
|
||||||
int getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const override;
|
int getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const override;
|
||||||
expr_t undiff() const override;
|
expr_t undiff() const override;
|
||||||
|
|
|
@ -51,7 +51,6 @@ ModFile::ModFile(WarningConsolidation &warnings_arg)
|
||||||
trend_component_model_table, var_model_table},
|
trend_component_model_table, var_model_table},
|
||||||
static_model{symbol_table, num_constants, external_functions_table},
|
static_model{symbol_table, num_constants, external_functions_table},
|
||||||
steady_state_model{symbol_table, num_constants, external_functions_table, static_model},
|
steady_state_model{symbol_table, num_constants, external_functions_table, static_model},
|
||||||
diff_static_model{symbol_table, num_constants, external_functions_table},
|
|
||||||
warnings{warnings_arg}
|
warnings{warnings_arg}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -454,10 +453,10 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, const
|
||||||
|
|
||||||
// Fill Trend Component Model Table
|
// Fill Trend Component Model Table
|
||||||
dynamic_model.fillTrendComponentModelTable();
|
dynamic_model.fillTrendComponentModelTable();
|
||||||
original_model.fillTrendComponentModelTableFromOrigModel(diff_static_model);
|
original_model.fillTrendComponentModelTableFromOrigModel();
|
||||||
dynamic_model.fillTrendComponentmodelTableAREC(diff_subst_table);
|
dynamic_model.fillTrendComponentmodelTableAREC(diff_subst_table);
|
||||||
dynamic_model.fillVarModelTable();
|
dynamic_model.fillVarModelTable();
|
||||||
original_model.fillVarModelTableFromOrigModel(diff_static_model);
|
original_model.fillVarModelTableFromOrigModel();
|
||||||
|
|
||||||
// Pac Model
|
// Pac Model
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
|
@ -75,8 +75,6 @@ public:
|
||||||
StaticModel static_model;
|
StaticModel static_model;
|
||||||
//! Static model, as declared in the "steady_state_model" block if present
|
//! Static model, as declared in the "steady_state_model" block if present
|
||||||
SteadyStateModel steady_state_model;
|
SteadyStateModel steady_state_model;
|
||||||
//! Static model used for mapping arguments of diff operator
|
|
||||||
StaticModel diff_static_model;
|
|
||||||
|
|
||||||
//! Option linear
|
//! Option linear
|
||||||
bool linear{false};
|
bool linear{false};
|
||||||
|
|
Loading…
Reference in New Issue