Commit 5d339b69 authored by Houtan Bastani's avatar Houtan Bastani
Browse files

simplify pac_expectation code

parent 7a4312c4
......@@ -305,23 +305,6 @@ VarModelStatement::fillVarModelInfoFromEquations(vector<int> &eqnumber_arg, vect
diff = diff_arg;
orig_diff_var = orig_diff_var_arg;
max_lag = max_lag_arg;
// Order RHS vars by time (already ordered by equation tag)
for (vector<set<pair<int, int> > >::const_iterator it = rhs_by_eq.begin();
it != rhs_by_eq.end(); it++)
for (set<pair<int, int> >::const_iterator it1 = it->begin();
it1 != it->end(); it1++)
{
map<int, set<int> >::iterator mit = rhs.find(abs(it1->second));
if (mit == rhs.end())
{
set<int> si;
si.insert(it1->first);
rhs[abs(it1->second)] = si;
}
else
mit->second.insert(it1->first);
}
}
void
......@@ -330,12 +313,6 @@ VarModelStatement::getVarModelName(string &var_model_name) const
var_model_name = name;
}
void
VarModelStatement::getVarModelRHS(map<int, set<int > > &rhs_arg) const
{
rhs_arg = rhs;
}
void
VarModelStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
{
......
......@@ -127,7 +127,6 @@ private:
const string &name;
const SymbolTable &symbol_table;
vector<int> eqnumber, lhs, orig_diff_var;
map<int, set<int > > rhs; // lag -> set< symb_id > (all vars that appear at a given lag)
vector<set<pair<int, int> > > rhs_by_eq; // rhs by equation
vector<bool> nonstationary, diff;
int max_lag;
......@@ -144,7 +143,6 @@ public:
vector<bool> &diff_arg, vector<int> &orig_diff_var_arg,
int max_lag_arg);
void getVarModelName(string &var_model_name) const;
void getVarModelRHS(map<int, set<int > > &rhs_arg) const;
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
void createVarModelMFunction(ostream &output, const map<string, set<int> > &var_expectation_functions_to_write) const;
......
......@@ -3415,11 +3415,11 @@ DynamicModel::walkPacParameters()
void
DynamicModel::fillPacExpectationVarInfo(string &var_model_name,
vector<int> &lhs,
map<int, set<int > > &rhs,
int max_lag,
vector<bool> &nonstationary)
{
for (size_t i = 0; i < equations.size(); i++)
equations[i]->fillPacExpectationVarInfo(var_model_name, lhs, rhs, nonstationary, i);
equations[i]->fillPacExpectationVarInfo(var_model_name, lhs, max_lag, nonstationary, i);
}
void
......
......@@ -306,7 +306,7 @@ public:
//! Add var_model info to pac_expectation nodes
void fillPacExpectationVarInfo(string &var_model_name,
vector<int> &lhs,
map<int, set<int > > &rhs,
int max_lag,
vector<bool> &nonstationary);
//! Substitutes pac_expectation operator
void substitutePacExpectation();
......
......@@ -600,7 +600,7 @@ NumConstNode::addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int,
}
void
NumConstNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, map<int, set<int > > &rhs_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
NumConstNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
{
}
......@@ -1702,7 +1702,7 @@ VariableNode::addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int,
}
void
VariableNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, map<int, set<int > > &rhs_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
VariableNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
{
}
......@@ -3171,9 +3171,9 @@ UnaryOpNode::addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int,
}
void
UnaryOpNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, map<int, set<int > > &rhs_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
UnaryOpNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
{
arg->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, rhs_arg, nonstationary_arg, equation_number_arg);
arg->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, equation_number_arg);
}
bool
......@@ -4800,10 +4800,10 @@ BinaryOpNode::addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int,
}
void
BinaryOpNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, map<int, set<int > > &rhs_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
BinaryOpNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
{
arg1->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, rhs_arg, nonstationary_arg, equation_number_arg);
arg2->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, rhs_arg, nonstationary_arg, equation_number_arg);
arg1->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, equation_number_arg);
arg2->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, equation_number_arg);
}
bool
......@@ -5606,11 +5606,11 @@ TrinaryOpNode::addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int
}
void
TrinaryOpNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, map<int, set<int > > &rhs_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
TrinaryOpNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
{
arg1->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, rhs_arg, nonstationary_arg, equation_number_arg);
arg2->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, rhs_arg, nonstationary_arg, equation_number_arg);
arg3->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, rhs_arg, nonstationary_arg, equation_number_arg);
arg1->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, equation_number_arg);
arg2->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, equation_number_arg);
arg3->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, equation_number_arg);
}
bool
......@@ -6011,10 +6011,10 @@ AbstractExternalFunctionNode::addParamInfoToPac(pair<int, int> &lhs_arg, set<pai
}
void
AbstractExternalFunctionNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, map<int, set<int > > &rhs_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
AbstractExternalFunctionNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
{
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++)
(*it)->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, rhs_arg, nonstationary_arg, equation_number_arg);
(*it)->fillPacExpectationVarInfo(var_model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, equation_number_arg);
}
bool
......@@ -7503,7 +7503,7 @@ VarExpectationNode::addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pai
}
void
VarExpectationNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, map<int, set<int > > &rhs_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
VarExpectationNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
{
}
......@@ -7959,13 +7959,13 @@ PacExpectationNode::addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pai
void
PacExpectationNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, map<int, set<int > > &rhs_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
PacExpectationNode::fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg)
{
if (var_model_name != var_model_name_arg)
return;
lhs = lhs_arg;
z_vec = rhs_arg;
max_lag = max_lag_arg;
equation_number = equation_number_arg;
for (vector<bool>::const_iterator it = nonstationary_arg.begin();
......@@ -7988,10 +7988,9 @@ PacExpectationNode::substitutePacExpectation(map<const PacExpectationNode *, con
if (myit != subst_table.end())
return const_cast<BinaryOpNode *>(myit->second);
int maxlag = z_vec.size();
expr_t subExpr = datatree.AddNonNegativeConstant("0");
if (stationary_vars_present)
for (int i = 1; i < maxlag + 1; i++)
for (int i = 1; i < max_lag + 1; i++)
for (vector<int>::const_iterator it = lhs.begin(); it != lhs.end(); it++)
{
stringstream param_name_h0;
......@@ -8006,7 +8005,7 @@ PacExpectationNode::substitutePacExpectation(map<const PacExpectationNode *, con
}
if (nonstationary_vars_present)
for (int i = 1; i < maxlag + 1; i++)
for (int i = 1; i < max_lag + 1; i++)
for (vector<int>::const_iterator it = lhs.begin(); it != lhs.end(); it++)
{
stringstream param_name_h1;
......
......@@ -506,7 +506,7 @@ class ExprNode
virtual void addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int, int> > > &params_and_vals_arg) = 0;
//! Fills var_model info for pac_expectation node
virtual void fillPacExpectationVarInfo(string &var_model_name, vector<int> &lhs, map<int, set<int > > &rhs_arg, vector<bool> &nonstationary_arg, int equation_number_arg) = 0;
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg) = 0;
//! Fills map
virtual void getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const = 0;
......@@ -580,7 +580,7 @@ public:
virtual void setVarExpectationIndex(map<string, pair<SymbolList, int> > &var_model_info);
virtual void walkPacParameters(bool &pac_encountered, pair<int, int> &lhs, set<pair<int, pair<int, int> > > &params_and_vals) const;
virtual void addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int, int> > > &params_and_vals_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, map<int, set<int > > &rhs_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual bool isVarModelReferenced(const string &model_info_name) const;
virtual void getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const;
virtual expr_t substituteStaticAuxiliaryVariable() const;
......@@ -663,7 +663,7 @@ public:
virtual void setVarExpectationIndex(map<string, pair<SymbolList, int> > &var_model_info);
virtual void walkPacParameters(bool &pac_encountered, pair<int, int> &lhs, set<pair<int, pair<int, int> > > &params_and_vals) const;
virtual void addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int, int> > > &params_and_vals_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, map<int, set<int > > &rhs_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual bool isVarModelReferenced(const string &model_info_name) const;
virtual void getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const;
//! Substitute auxiliary variables by their expression in static model
......@@ -768,7 +768,7 @@ public:
virtual void setVarExpectationIndex(map<string, pair<SymbolList, int> > &var_model_info);
virtual void walkPacParameters(bool &pac_encountered, pair<int, int> &lhs, set<pair<int, pair<int, int> > > &params_and_vals) const;
virtual void addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int, int> > > &params_and_vals_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, map<int, set<int > > &rhs_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual bool isVarModelReferenced(const string &model_info_name) const;
virtual void getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const;
//! Substitute auxiliary variables by their expression in static model
......@@ -895,7 +895,7 @@ public:
virtual void setVarExpectationIndex(map<string, pair<SymbolList, int> > &var_model_info);
virtual void walkPacParameters(bool &pac_encountered, pair<int, int> &lhs, set<pair<int, pair<int, int> > > &params_and_vals) const;
virtual void addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int, int> > > &params_and_vals_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, map<int, set<int > > &rhs_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual bool isVarModelReferenced(const string &model_info_name) const;
virtual void getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const;
//! Substitute auxiliary variables by their expression in static model
......@@ -987,7 +987,7 @@ public:
virtual void setVarExpectationIndex(map<string, pair<SymbolList, int> > &var_model_info);
virtual void walkPacParameters(bool &pac_encountered, pair<int, int> &lhs, set<pair<int, pair<int, int> > > &params_and_vals) const;
virtual void addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int, int> > > &params_and_vals_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, map<int, set<int > > &rhs_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual bool isVarModelReferenced(const string &model_info_name) const;
virtual void getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const;
//! Substitute auxiliary variables by their expression in static model
......@@ -1087,7 +1087,7 @@ public:
virtual void setVarExpectationIndex(map<string, pair<SymbolList, int> > &var_model_info);
virtual void walkPacParameters(bool &pac_encountered, pair<int, int> &lhs, set<pair<int, pair<int, int> > > &params_and_vals) const;
virtual void addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int, int> > > &params_and_vals_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, map<int, set<int > > &rhs_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual bool isVarModelReferenced(const string &model_info_name) const;
virtual void getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const;
//! Substitute auxiliary variables by their expression in static model
......@@ -1280,7 +1280,7 @@ public:
virtual void setVarExpectationIndex(map<string, pair<SymbolList, int> > &var_model_info);
virtual void walkPacParameters(bool &pac_encountered, pair<int, int> &lhs, set<pair<int, pair<int, int> > > &params_and_vals) const;
virtual void addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int, int> > > &params_and_vals_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, map<int, set<int > > &rhs_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual bool isVarModelReferenced(const string &model_info_name) const;
virtual void getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const;
virtual expr_t substituteStaticAuxiliaryVariable() const;
......@@ -1295,7 +1295,7 @@ private:
bool stationary_vars_present, nonstationary_vars_present;
vector<int> lhs;
pair<int, int> lhs_pac_var;
map<int, set<int > > z_vec; // lag -> set< symb_id > (all vars that appear at a given lag)
int max_lag;
vector<int> h0_indices, h1_indices;
int growth_param_index, equation_number;
set<pair<int, pair<int, int> > > params_and_vals;
......@@ -1357,7 +1357,7 @@ public:
virtual void setVarExpectationIndex(map<string, pair<SymbolList, int> > &var_model_info);
virtual void walkPacParameters(bool &pac_encountered, pair<int, int> &lhs, set<pair<int, pair<int, int> > > &params_and_vals) const;
virtual void addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int, int> > > &params_and_vals_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, map<int, set<int > > &rhs_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual void fillPacExpectationVarInfo(string &var_model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int equation_number_arg);
virtual bool isVarModelReferenced(const string &model_info_name) const;
virtual void getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const;
virtual expr_t substituteStaticAuxiliaryVariable() const;
......
......@@ -389,11 +389,9 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, const
vms->fillVarModelInfoFromEquations(eqnumber, lhs, rhs, nonstationary,
diff, orig_diff_var, max_lag);
string var_model_name;
map<int, set<int > > rhs_pac;
vms->getVarModelName(var_model_name);
vms->getVarModelRHS(rhs_pac);
dynamic_model.walkPacParameters();
dynamic_model.fillPacExpectationVarInfo(var_model_name, lhs, rhs_pac, nonstationary);
dynamic_model.fillPacExpectationVarInfo(var_model_name, lhs, max_lag, nonstationary);
dynamic_model.substitutePacExpectation();
}
}
......
Supports Markdown
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