Block decomposition: remove unused codepaths in computation of normalization

parent 097bdfde
Pipeline #3393 passed with stages
in 2 minutes and 34 seconds
......@@ -270,33 +270,7 @@ ModelTree::computeNormalization(const jacob_map_t &contemporaneous_jacobian, boo
// Compute maximum cardinality matching
vector<int> mate_map(2*n);
#if 1
bool check = checked_edmonds_maximum_cardinality_matching(g, &mate_map[0]);
#else // Alternative way to compute normalization, by giving an initial matching using natural normalizations
fill(mate_map.begin(), mate_map.end(), boost::graph_traits<BipartiteGraph>::null_vertex());
auto natural_endo2eqs = computeNormalizedEquations();
for (int i = 0; i < symbol_table.endo_nbr(); i++)
{
if (natural_endo2eqs.count(i) == 0)
continue;
int j = natural_endo2eqs.find(i)->second;
put(&mate_map[0], i, n+j);
put(&mate_map[0], n+j, i);
}
boost::edmonds_augmenting_path_finder<BipartiteGraph, int *, boost::property_map<BipartiteGraph, boost::vertex_index_t>::type> augmentor(g, &mate_map[0], get(boost::vertex_index, g));
while (augmentor.augment_matching())
{
};
augmentor.get_current_matching(&mate_map[0]);
bool check = boost::maximum_cardinality_matching_verifier<BipartiteGraph, int *, boost::property_map<BipartiteGraph, boost::vertex_index_t>::type>::verify_matching(g, &mate_map[0], get(boost::vertex_index, g));
#endif
assert(check);
......@@ -310,29 +284,6 @@ ModelTree::computeNormalization(const jacob_map_t &contemporaneous_jacobian, boo
endo2eq.resize(equations.size());
transform(mate_map.begin(), mate_map.begin() + n, endo2eq.begin(), [=](int i) { return i-n; });
#ifdef DEBUG
auto natural_endo2eqs = computeNormalizedEquations(natural_endo2eqs);
int n1 = 0, n2 = 0;
for (int i = 0; i < symbol_table.endo_nbr(); i++)
{
if (natural_endo2eqs.count(i) == 0)
continue;
n1++;
auto x = natural_endo2eqs.equal_range(i);
if (find_if(x.first, x.second, [=](auto y) { return y.second == endo2eq[i]; }) == x.second)
cout << "Natural normalization of variable " << symbol_table.getName(symbol_table.getID(SymbolType::endogenous, i))
<< " not used." << endl;
else
n2++;
}
cout << "Used " << n2 << " natural normalizations out of " << n1 << ", for a total of " << n << " equations." << endl;
#endif
// Check if all variables are normalized
if (auto it = find(mate_map.begin(), mate_map.begin() + n, boost::graph_traits<BipartiteGraph>::null_vertex());
it != mate_map.begin() + n)
......@@ -437,31 +388,6 @@ ModelTree::computeNonSingularNormalization(jacob_map_t &contemporaneous_jacobian
}
}
multimap<int, int>
ModelTree::computeNormalizedEquations() const
{
multimap<int, int> endo2eqs;
for (size_t i = 0; i < equations.size(); i++)
{
auto lhs = dynamic_cast<VariableNode *>(equations[i]->arg1);
if (!lhs)
continue;
int symb_id = lhs->symb_id;
if (symbol_table.getType(symb_id) != SymbolType::endogenous)
continue;
set<pair<int, int>> endo;
equations[i]->arg2->collectEndogenous(endo);
if (endo.find({ symbol_table.getTypeSpecificID(symb_id), 0 }) != endo.end())
continue;
endo2eqs.emplace(symbol_table.getTypeSpecificID(symb_id), static_cast<int>(i));
cout << "Endogenous " << symbol_table.getName(symb_id) << " normalized in equation " << i+1 << endl;
}
return endo2eqs;
}
pair<ModelTree::jacob_map_t, ModelTree::jacob_map_t>
ModelTree::evaluateAndReduceJacobian(const eval_context_t &eval_context, double cutoff, bool verbose)
{
......
......@@ -282,8 +282,6 @@ protected:
void computeNonSingularNormalization(jacob_map_t &contemporaneous_jacobian, double cutoff, jacob_map_t &static_jacobian);
//! Try to find a natural normalization if all equations are matched to an endogenous variable on the LHS
bool computeNaturalNormalization();
//! Try to normalized each unnormalized equation (matched endogenous variable only on the LHS)
multimap<int, int> computeNormalizedEquations() const;
//! Evaluate the jacobian (w.r.t. endogenous) and suppress all the elements below the cutoff
/*! Returns a pair (contemporaneous_jacobian, static_jacobian). Also fills
dynamic_jacobian. External functions are evaluated to 1. */
......@@ -294,7 +292,7 @@ protected:
tuple<vector<pair<int, int>>, lag_lead_vector_t, lag_lead_vector_t, vector<unsigned int>, vector<unsigned int>, vector<unsigned int>, vector<unsigned int>> select_non_linear_equations_and_variables(const vector<bool> &is_equation_linear);
//! Search the equations and variables belonging to the prologue and the epilogue of the model
void computePrologueAndEpilogue(const jacob_map_t &static_jacobian);
//! Determine the type of each equation of model and try to normalized the unnormalized equation using computeNormalizedEquations
//! Determine the type of each equation of model and try to normalize the unnormalized equation
void equationTypeDetermination(const map<tuple<int, int, int>, expr_t> &first_order_endo_derivatives, int mfs);
//! Compute the block decomposition and for a non-recusive block find the minimum feedback set
/*! Returns a tuple (blocks, equation_lag_lead, variable_lag_lead, n_static,
......
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