pac: keep order of variables in ec part of pac equation and add scaling factor to output

parent b0dac547
Pipeline #948 passed with stage
in 1 minute and 29 seconds
......@@ -3662,7 +3662,7 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de
pair<int, int> lhs_pac_var;
int optim_share_index;
set<pair<int, pair<int, int>>> ar_params_and_vars;
pair<int, vector<pair<int,bool>>> ec_params_and_vars;
pair<int, vector<tuple<int, bool, int>>> ec_params_and_vars;
vector<tuple<int, int, int, double>> non_optim_vars_params_and_constants, additive_vars_params_and_constants;
tie(lhs_pac_var, optim_share_index, ar_params_and_vars, ec_params_and_vars, non_optim_vars_params_and_constants, additive_vars_params_and_constants) = pit.second;
string substruct = pit.first.first + ".equations." + pit.first.second + ".";
......@@ -3678,15 +3678,19 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de
<< symbol_table.getTypeSpecificID(ec_params_and_vars.first) + 1 << ";" << endl
<< modstruct << "pac." << substruct << "ec.vars = [";
for (auto it : ec_params_and_vars.second)
output << symbol_table.getTypeSpecificID(it.first) + 1 << " ";
output << symbol_table.getTypeSpecificID(get<0>(it)) + 1 << " ";
output << "];" << endl
<< modstruct << "pac." << substruct << "ec.istarget = [";
for (auto it : ec_params_and_vars.second)
output << (it.second ? "true " : "false ");
output << (get<1>(it) ? "true " : "false ");
output << "];" << endl
<< modstruct << "pac." << substruct << "ec.scale = [";
for (auto it : ec_params_and_vars.second)
output << get<2>(it) << " ";
output << "];" << endl
<< modstruct << "pac." << substruct << "ec.isendo = [";
for (auto it : ec_params_and_vars.second)
switch (symbol_table.getType(it.first))
switch (symbol_table.getType(get<0>(it)))
{
case SymbolType::endogenous:
output << "true ";
......@@ -4434,7 +4438,7 @@ DynamicModel::walkPacParameters(const string &name, map<pair<string, string>, pa
for (auto & equation : equations)
{
pair<int, int> lhs (-1, -1);
pair<int, vector<pair<int,bool>>> ec_params_and_vars;
pair<int, vector<tuple<int, bool, int>>> ec_params_and_vars;
set<pair<int, pair<int, int>>> ar_params_and_vars;
vector<tuple<int, int, int, double>> non_optim_vars_params_and_constants, additive_vars_params_and_constants;
......
......@@ -487,7 +487,7 @@ public:
//! (pac_model_name, standardized_eqtag) ->
//! (lhs, optim_share_index, ar_params_and_vars, ec_params_and_vars, non_optim_vars_params_and_constants)
map<pair<string, string>,
tuple<pair<int, int>, int, set<pair<int, pair<int, int>>>, pair<int, vector<pair<int,bool>>>, vector<tuple<int, int, int, double>>, vector<tuple<int, int, int, double>>>> pac_equation_info;
tuple<pair<int, int>, int, set<pair<int, pair<int, int>>>, pair<int, vector<tuple<int, bool, int>>>, vector<tuple<int, int, int, double>>, vector<tuple<int, int, int, double>>>> pac_equation_info;
//! Table to undiff LHS variables for pac vector z
vector<int> getUndiffLHSForPac(const string &aux_model_name,
......
......@@ -5536,10 +5536,10 @@ BinaryOpNode::findTargetVariable(int lhs_symb_id) const
return retval;
}
pair<int, vector<pair<int,bool>>>
pair<int, vector<tuple<int, bool, int>>>
BinaryOpNode::getPacEC(BinaryOpNode *bopn, int lhs_symb_id, int lhs_orig_symb_id) const
{
pair<int, vector<pair<int,bool>>> ec_params_and_vars = {-1, vector<pair<int, bool>>()};
pair<int, vector<tuple<int, bool, int>>> ec_params_and_vars = {-1, vector<tuple<int, bool, int>>()};
int optim_param_symb_id = -1;
expr_t optim_part = nullptr;
set<pair<int, int>> endogs;
......@@ -5563,10 +5563,27 @@ BinaryOpNode::getPacEC(BinaryOpNode *bopn, int lhs_symb_id, int lhs_orig_symb_id
endogs.clear();
optim_part->collectDynamicVariables(SymbolType::endogenous, endogs);
optim_part->collectDynamicVariables(SymbolType::exogenous, endogs);
vector<pair<int,bool>> symb_ids;
for (const auto & it : endogs)
if (endogs.size() != 2)
{
cerr << "Error getting EC part of PAC equation" << endl;
exit(EXIT_FAILURE);
}
vector<pair<expr_t, int>> terms;
vector<tuple<int, bool, int>> ordered_symb_ids;
optim_part->decomposeAdditiveTerms(terms, 1);
for (const auto & it : terms)
{
int id = it.first;
int scale = it.second;
auto vn = dynamic_cast<VariableNode *>(it.first);
if (!vn
|| !(datatree.symbol_table.getType(vn->symb_id) == SymbolType::endogenous
|| datatree.symbol_table.getType(vn->symb_id) == SymbolType::exogenous))
{
cerr << "Problem with error component portion of PAC equation" << endl;
exit(EXIT_FAILURE);
}
int id = vn->symb_id;
int orig_id = id;
bool istarget = true;
while (datatree.symbol_table.isAuxiliaryVariable(id))
try
......@@ -5579,16 +5596,16 @@ BinaryOpNode::getPacEC(BinaryOpNode *bopn, int lhs_symb_id, int lhs_orig_symb_id
}
if (id == lhs_symb_id || id == lhs_orig_symb_id)
istarget = false;
symb_ids.push_back({it.first, istarget});
ordered_symb_ids.push_back({orig_id, istarget, scale});
Please register or sign in to reply
}
ec_params_and_vars = make_pair(optim_param_symb_id, symb_ids);
ec_params_and_vars = make_pair(optim_param_symb_id, ordered_symb_ids);
}
return ec_params_and_vars;
}
void
BinaryOpNode::getPacAREC(int lhs_symb_id, int lhs_orig_symb_id,
pair<int, vector<pair<int,bool>>> &ec_params_and_vars,
pair<int, vector<tuple<int, bool, int>>> &ec_params_and_vars,
set<pair<int, pair<int, int>>> &ar_params_and_vars,
vector<tuple<int, int, int, double>> &additive_vars_params_and_constants) const
{
......
......@@ -1048,9 +1048,9 @@ public:
void findConstantEquations(map<VariableNode *, NumConstNode *> &table) const override;
expr_t replaceVarsInEquation(map<VariableNode *, NumConstNode *> &table) const override;
bool containsPacExpectation(const string &pac_model_name = "") const override;
pair<int, vector<pair<int,bool>>> getPacEC(BinaryOpNode *bopn, int lhs_symb_id, int lhs_orig_symb_id) const;
pair<int, vector<tuple<int, bool, int>>> getPacEC(BinaryOpNode *bopn, int lhs_symb_id, int lhs_orig_symb_id) const;
void getPacAREC(int lhs_symb_id, int lhs_orig_symb_id,
pair<int, vector<pair<int,bool>>> &ec_params_and_vars,
pair<int, vector<tuple<int, bool, int>>> &ec_params_and_vars,
set<pair<int, pair<int, int>>> &ar_params_and_vars,
vector<tuple<int, int, int, double>> &additive_vars_params_and_constants) 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