Block decomposition: no longer compute static Jacobian, it’s not used
Also remove a message about elements below the cutoff that was no longer correct (elements below the cutoff have no impact on the incidence matrix outside of normalization).issue#70
parent
a1b37288f9
commit
c699d57308
|
@ -4508,10 +4508,10 @@ DynamicModel::computingPass(bool jacobianExo, int derivsOrder, int paramsDerivsO
|
|||
auto first_order_endo_derivatives = collectFirstOrderDerivativesEndogenous();
|
||||
equationLinear(first_order_endo_derivatives);
|
||||
|
||||
auto [contemporaneous_jacobian, static_jacobian] = evaluateAndReduceJacobian(eval_context, cutoff, false);
|
||||
auto contemporaneous_jacobian = evaluateAndReduceJacobian(eval_context);
|
||||
|
||||
if (!computeNaturalNormalization())
|
||||
computeNonSingularNormalization(contemporaneous_jacobian, cutoff, static_jacobian);
|
||||
computeNonSingularNormalization(contemporaneous_jacobian);
|
||||
|
||||
select_non_linear_equations_and_variables();
|
||||
|
||||
|
@ -4531,9 +4531,9 @@ DynamicModel::computingPass(bool jacobianExo, int derivsOrder, int paramsDerivsO
|
|||
}
|
||||
else if (block)
|
||||
{
|
||||
auto [contemporaneous_jacobian, static_jacobian] = evaluateAndReduceJacobian(eval_context, cutoff, false);
|
||||
auto contemporaneous_jacobian = evaluateAndReduceJacobian(eval_context);
|
||||
|
||||
computeNonSingularNormalization(contemporaneous_jacobian, cutoff, static_jacobian);
|
||||
computeNonSingularNormalization(contemporaneous_jacobian);
|
||||
|
||||
auto [prologue, epilogue] = computePrologueAndEpilogue();
|
||||
|
||||
|
|
|
@ -255,7 +255,7 @@ ModelTree::computeNormalization(const jacob_map_t &contemporaneous_jacobian, boo
|
|||
}
|
||||
|
||||
void
|
||||
ModelTree::computeNonSingularNormalization(const jacob_map_t &contemporaneous_jacobian, double cutoff, const jacob_map_t &static_jacobian)
|
||||
ModelTree::computeNonSingularNormalization(const jacob_map_t &contemporaneous_jacobian)
|
||||
{
|
||||
cout << "Normalizing the model..." << endl;
|
||||
|
||||
|
@ -317,12 +317,10 @@ ModelTree::computeNonSingularNormalization(const jacob_map_t &contemporaneous_ja
|
|||
}
|
||||
}
|
||||
|
||||
pair<ModelTree::jacob_map_t, ModelTree::jacob_map_t>
|
||||
ModelTree::evaluateAndReduceJacobian(const eval_context_t &eval_context, double cutoff, bool verbose) const
|
||||
ModelTree::jacob_map_t
|
||||
ModelTree::evaluateAndReduceJacobian(const eval_context_t &eval_context) const
|
||||
{
|
||||
jacob_map_t contemporaneous_jacobian, static_jacobian;
|
||||
int nb_elements_contemporaneous_jacobian = 0;
|
||||
set<vector<int>> jacobian_elements_to_delete;
|
||||
jacob_map_t contemporaneous_jacobian;
|
||||
for (const auto &[indices, d1] : derivatives[1])
|
||||
{
|
||||
int deriv_id = indices[1];
|
||||
|
@ -348,35 +346,12 @@ ModelTree::evaluateAndReduceJacobian(const eval_context_t &eval_context, double
|
|||
cerr << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (fabs(val) < cutoff)
|
||||
{
|
||||
if (verbose)
|
||||
cout << "The coefficient related to variable " << var << " with lag " << lag << " in equation " << eq << " is equal to " << val << " and is set to 0 in the incidence matrix (size=" << symbol_table.endo_nbr() << ")." << endl;
|
||||
jacobian_elements_to_delete.insert({ eq, deriv_id });
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lag == 0)
|
||||
{
|
||||
nb_elements_contemporaneous_jacobian++;
|
||||
contemporaneous_jacobian[{ eq, var }] = val;
|
||||
}
|
||||
|
||||
if (static_jacobian.find({ eq, var }) != static_jacobian.end())
|
||||
static_jacobian[{ eq, var }] += val;
|
||||
else
|
||||
static_jacobian[{ eq, var }] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (jacobian_elements_to_delete.size() > 0)
|
||||
{
|
||||
cout << jacobian_elements_to_delete.size() << " elements among " << derivatives[1].size() << " in the incidence matrices are below the cutoff (" << cutoff << ") and are discarded." << endl
|
||||
<< "The contemporaneous incidence matrix has " << nb_elements_contemporaneous_jacobian << " elements." << endl;
|
||||
}
|
||||
|
||||
return { contemporaneous_jacobian, static_jacobian };
|
||||
return contemporaneous_jacobian;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -279,13 +279,13 @@ protected:
|
|||
If no matching is found with a zero cutoff, an error message is printed.
|
||||
The resulting normalization is stored in endo2eq.
|
||||
*/
|
||||
void computeNonSingularNormalization(const jacob_map_t &contemporaneous_jacobian, double cutoff, const jacob_map_t &static_jacobian);
|
||||
void computeNonSingularNormalization(const jacob_map_t &contemporaneous_jacobian);
|
||||
//! Try to find a natural normalization if all equations are matched to an endogenous variable on the LHS
|
||||
bool computeNaturalNormalization();
|
||||
//! Evaluate the jacobian (w.r.t. endogenous) and suppress all the elements below the cutoff
|
||||
/*! Returns a pair (contemporaneous_jacobian, static_jacobian).
|
||||
/*! Returns the contemporaneous_jacobian.
|
||||
Elements below the cutoff are discarded. External functions are evaluated to 1. */
|
||||
pair<jacob_map_t, jacob_map_t> evaluateAndReduceJacobian(const eval_context_t &eval_context, double cutoff, bool verbose) const;
|
||||
jacob_map_t evaluateAndReduceJacobian(const eval_context_t &eval_context) const;
|
||||
//! Select and reorder the non linear equations of the model
|
||||
void select_non_linear_equations_and_variables();
|
||||
/* Search the equations and variables belonging to the prologue and the
|
||||
|
|
|
@ -1064,9 +1064,9 @@ StaticModel::computingPass(int derivsOrder, int paramsDerivsOrder, const eval_co
|
|||
|
||||
if (block)
|
||||
{
|
||||
auto [contemporaneous_jacobian, static_jacobian] = evaluateAndReduceJacobian(eval_context, cutoff, false);
|
||||
auto contemporaneous_jacobian = evaluateAndReduceJacobian(eval_context);
|
||||
|
||||
computeNonSingularNormalization(contemporaneous_jacobian, cutoff, static_jacobian);
|
||||
computeNonSingularNormalization(contemporaneous_jacobian);
|
||||
|
||||
auto [prologue, epilogue] = computePrologueAndEpilogue();
|
||||
|
||||
|
|
Loading…
Reference in New Issue