Commit 7a438a3c authored by Houtan Bastani's avatar Houtan Bastani

ensure that trend_variable found is actually a trend variable as declared in...

ensure that trend_variable found is actually a trend variable as declared in the trend_component_model statement
parent fde836d7
......@@ -3456,31 +3456,48 @@ DynamicModel::runTrendTest(const eval_context_t &eval_context)
}
void
DynamicModel::updateVarAndTrendModelRhs() const
DynamicModel::updateVarAndTrendModel() const
{
for (int i = 0; i < 2; i++)
{
map<string, vector<int>> eqnums;
map<string, vector<int>> eqnums, trend_eqnums;
if (i == 0)
eqnums = var_model_table.getEqNums();
else if (i == 1)
eqnums = trend_component_model_table.getEqNums();
{
eqnums = trend_component_model_table.getEqNums();
trend_eqnums = trend_component_model_table.getTrendEqNums();
}
map<string, vector<int>> trend_varr;
map<string, vector<set<pair<int, int>>>> rhsr;
for (const auto & it : eqnums)
{
vector<int> lhs;
vector<int> trend_var;
vector<int> lhs, trend_var, trend_lhs;
vector<set<pair<int, int>>> rhs;
int lhs_idx = 0;
if (i == 1)
lhs = trend_component_model_table.getLhs(it.first);
{
lhs = trend_component_model_table.getLhs(it.first);
for (auto teqn : trend_eqnums.at(it.first))
{
int eqnidx = 0;
for (auto eqn : it.second)
{
if (eqn == teqn)
trend_lhs.push_back(lhs[eqnidx]);
eqnidx++;
}
}
}
int lhs_idx = 0;
for (auto eqn : it.second)
{
set<pair<int, int>> rhs_set;
equations[eqn]->get_arg2()->collectDynamicVariables(SymbolType::endogenous, rhs_set);
rhs.push_back(rhs_set);
if (i == 1)
{
int lhs_symb_id = lhs[lhs_idx++];
......@@ -3492,11 +3509,31 @@ DynamicModel::updateVarAndTrendModelRhs() const
catch (...)
{
}
trend_var.push_back(equations[eqn]->get_arg2()->findTrendVariable(lhs_symb_id));
int trend_var_symb_id = equations[eqn]->get_arg2()->findTrendVariable(lhs_symb_id);
trend_var.push_back(trend_var_symb_id);
if (trend_var_symb_id >= 0)
{
if (symbol_table.isAuxiliaryVariable(trend_var_symb_id))
try
{
trend_var_symb_id = symbol_table.getOrigSymbIdForAuxVar(trend_var_symb_id);
}
catch (...)
{
}
if (find(trend_lhs.begin(), trend_lhs.end(), trend_var_symb_id) == trend_lhs.end())
{
cerr << "ERROR: trend found in trend_component equation #" << eqn << " ("
<< symbol_table.getName(trend_var_symb_id) << ") does not correspond to a trend equation" << endl;
exit(EXIT_FAILURE);
}
}
}
}
rhsr[it.first] = rhs;
trend_varr[it.first] = trend_var;
if (i == 1)
trend_varr[it.first] = trend_var;
}
if (i == 0)
......
......@@ -313,8 +313,9 @@ public:
void fillVarModelTableFromOrigModel(StaticModel &static_model) const;
//! Update the rhs references in the var model and trend component tables
//! after substitution of auxiliary variables
void updateVarAndTrendModelRhs() const;
//! after substitution of auxiliary variables and find the trend variables
//! in the trend_component model
void updateVarAndTrendModel() const;
//! Add aux equations (and aux variables) for variables declared in var_model
//! at max order if they don't already exist
......
......@@ -580,7 +580,7 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, const
dynamic_model.substituteEndoLagGreaterThanTwo(true);
}
dynamic_model.updateVarAndTrendModelRhs();
dynamic_model.updateVarAndTrendModel();
if (differentiate_forward_vars)
dynamic_model.differentiateForwardVars(differentiate_forward_vars_subset);
......
......@@ -177,6 +177,12 @@ TrendComponentModelTable::getEqNums() const
return eqnums;
}
map<string, vector<int>>
TrendComponentModelTable::getTrendEqNums() const
{
return trend_eqnums;
}
vector<int>
TrendComponentModelTable::getNonTrendEqNums(const string &name_arg) const
{
......
......@@ -59,6 +59,7 @@ public:
vector<string> getEqTags(const string &name_arg) const;
map<string, vector<string>> getTrendEqTags() const;
map<string, vector<int>> getEqNums() const;
map<string, vector<int>> getTrendEqNums() const;
vector<int> getEqNums(const string &name_arg) const;
vector<int> getMaxLags(const string &name_arg) const;
int getMaxLag(const string &name_arg) const;
......
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