Block decomposition: further streamlining of function prototypes
parent
bd6eee93df
commit
fcef9cf8b9
|
@ -4832,15 +4832,15 @@ DynamicModel::computingPass(bool jacobianExo, int derivsOrder, int paramsDerivsO
|
|||
tie(blocks, equation_lag_lead, variable_lag_lead, n_static, n_forward, n_backward, n_mixed)
|
||||
= select_non_linear_equations_and_variables(is_equation_linear);
|
||||
|
||||
equation_type_and_normalized_equation = equationTypeDetermination(first_order_endo_derivatives, 0);
|
||||
equationTypeDetermination(first_order_endo_derivatives, 0);
|
||||
prologue = 0;
|
||||
epilogue = 0;
|
||||
|
||||
block_type_firstequation_size_mfs = reduceBlocksAndTypeDetermination(blocks, equation_type_and_normalized_equation, n_static, n_forward, n_backward, n_mixed, linear_decomposition);
|
||||
reduceBlocksAndTypeDetermination(blocks, equation_type_and_normalized_equation, n_static, n_forward, n_backward, n_mixed, linear_decomposition);
|
||||
|
||||
computeChainRuleJacobian();
|
||||
|
||||
blocks_linear = BlockLinear();
|
||||
determineLinearBlocks();
|
||||
|
||||
collect_block_first_order_derivatives();
|
||||
|
||||
|
@ -4861,7 +4861,7 @@ DynamicModel::computingPass(bool jacobianExo, int derivsOrder, int paramsDerivsO
|
|||
|
||||
first_order_endo_derivatives = collect_first_order_derivatives_endogenous();
|
||||
|
||||
equation_type_and_normalized_equation = equationTypeDetermination(first_order_endo_derivatives, mfs);
|
||||
equationTypeDetermination(first_order_endo_derivatives, mfs);
|
||||
|
||||
cout << "Finding the optimal block decomposition of the model ..." << endl;
|
||||
|
||||
|
@ -4869,13 +4869,13 @@ DynamicModel::computingPass(bool jacobianExo, int derivsOrder, int paramsDerivsO
|
|||
|
||||
tie(blocks, equation_lag_lead, variable_lag_lead, n_static, n_forward, n_backward, n_mixed) = computeBlockDecompositionAndFeedbackVariablesForEachBlock(static_jacobian, equation_type_and_normalized_equation, false, true);
|
||||
|
||||
block_type_firstequation_size_mfs = reduceBlocksAndTypeDetermination(blocks, equation_type_and_normalized_equation, n_static, n_forward, n_backward, n_mixed, linear_decomposition);
|
||||
reduceBlocksAndTypeDetermination(blocks, equation_type_and_normalized_equation, n_static, n_forward, n_backward, n_mixed, linear_decomposition);
|
||||
|
||||
printBlockDecomposition(blocks);
|
||||
|
||||
computeChainRuleJacobian();
|
||||
|
||||
blocks_linear = BlockLinear();
|
||||
determineLinearBlocks();
|
||||
|
||||
collect_block_first_order_derivatives();
|
||||
|
||||
|
|
|
@ -728,13 +728,14 @@ ModelTree::computePrologueAndEpilogue(const jacob_map_t &static_jacobian_arg)
|
|||
}
|
||||
}
|
||||
|
||||
equation_type_and_normalized_equation_t
|
||||
ModelTree::equationTypeDetermination(const map<tuple<int, int, int>, expr_t> &first_order_endo_derivatives, int mfs) const
|
||||
void
|
||||
ModelTree::equationTypeDetermination(const map<tuple<int, int, int>, expr_t> &first_order_endo_derivatives, int mfs)
|
||||
{
|
||||
expr_t lhs;
|
||||
BinaryOpNode *eq_node;
|
||||
EquationType Equation_Simulation_Type;
|
||||
equation_type_and_normalized_equation_t V_Equation_Simulation_Type(equations.size());
|
||||
equation_type_and_normalized_equation.clear();
|
||||
equation_type_and_normalized_equation.resize(equations.size());
|
||||
for (unsigned int i = 0; i < equations.size(); i++)
|
||||
{
|
||||
int eq = equation_reordered[i];
|
||||
|
@ -768,9 +769,8 @@ ModelTree::equationTypeDetermination(const map<tuple<int, int, int>, expr_t> &fi
|
|||
}
|
||||
}
|
||||
}
|
||||
V_Equation_Simulation_Type[eq] = { Equation_Simulation_Type, dynamic_cast<BinaryOpNode *>(res.second) };
|
||||
equation_type_and_normalized_equation[eq] = { Equation_Simulation_Type, dynamic_cast<BinaryOpNode *>(res.second) };
|
||||
}
|
||||
return V_Equation_Simulation_Type;
|
||||
}
|
||||
|
||||
pair<lag_lead_vector_t, lag_lead_vector_t>
|
||||
|
@ -1072,14 +1072,14 @@ ModelTree::printBlockDecomposition(const vector<pair<int, int>> &blocks) const
|
|||
<< " and " << Nb_feedback_variable << " feedback variable(s)." << endl;
|
||||
}
|
||||
|
||||
block_type_firstequation_size_mfs_t
|
||||
void
|
||||
ModelTree::reduceBlocksAndTypeDetermination(const vector<pair<int, int>> &blocks, const equation_type_and_normalized_equation_t &Equation_Type, const vector<unsigned int> &n_static, const vector<unsigned int> &n_forward, const vector<unsigned int> &n_backward, const vector<unsigned int> &n_mixed, bool linear_decomposition)
|
||||
{
|
||||
int i = 0;
|
||||
int count_equ = 0, blck_count_simult = 0;
|
||||
int Blck_Size, MFS_Size;
|
||||
int Lead, Lag;
|
||||
block_type_firstequation_size_mfs_t block_type_size_mfs;
|
||||
block_type_firstequation_size_mfs.clear();
|
||||
BlockSimulationType Simulation_Type, prev_Type = UNKNOWN;
|
||||
int eq = 0;
|
||||
unsigned int l_n_static = 0, l_n_forward = 0, l_n_backward = 0, l_n_mixed = 0;
|
||||
|
@ -1174,8 +1174,8 @@ ModelTree::reduceBlocksAndTypeDetermination(const vector<pair<int, int>> &blocks
|
|||
if (i > 0)
|
||||
{
|
||||
bool is_lead = false, is_lag = false;
|
||||
int c_Size = get<2>(block_type_size_mfs[block_type_size_mfs.size()-1]);
|
||||
int first_equation = get<1>(block_type_size_mfs[block_type_size_mfs.size()-1]);
|
||||
int c_Size = get<2>(block_type_firstequation_size_mfs[block_type_firstequation_size_mfs.size()-1]);
|
||||
int first_equation = get<1>(block_type_firstequation_size_mfs[block_type_firstequation_size_mfs.size()-1]);
|
||||
if (c_Size > 0 && ((prev_Type == EVALUATE_FORWARD && Simulation_Type == EVALUATE_FORWARD && !is_lead)
|
||||
|| (prev_Type == EVALUATE_BACKWARD && Simulation_Type == EVALUATE_BACKWARD && !is_lag)))
|
||||
{
|
||||
|
@ -1193,41 +1193,40 @@ ModelTree::reduceBlocksAndTypeDetermination(const vector<pair<int, int>> &blocks
|
|||
|| (prev_Type == EVALUATE_BACKWARD && Simulation_Type == EVALUATE_BACKWARD && !is_lag))
|
||||
{
|
||||
//merge the current block with the previous one
|
||||
BlockSimulationType c_Type = get<0>(block_type_size_mfs[block_type_size_mfs.size()-1]);
|
||||
BlockSimulationType c_Type = get<0>(block_type_firstequation_size_mfs[block_type_firstequation_size_mfs.size()-1]);
|
||||
c_Size++;
|
||||
block_type_size_mfs[block_type_size_mfs.size()-1] = { c_Type, first_equation, c_Size, c_Size };
|
||||
if (block_lag_lead[block_type_size_mfs.size()-1].first > Lag)
|
||||
Lag = block_lag_lead[block_type_size_mfs.size()-1].first;
|
||||
if (block_lag_lead[block_type_size_mfs.size()-1].second > Lead)
|
||||
Lead = block_lag_lead[block_type_size_mfs.size()-1].second;
|
||||
block_lag_lead[block_type_size_mfs.size()-1] = { Lag, Lead };
|
||||
block_type_firstequation_size_mfs[block_type_firstequation_size_mfs.size()-1] = { c_Type, first_equation, c_Size, c_Size };
|
||||
if (block_lag_lead[block_type_firstequation_size_mfs.size()-1].first > Lag)
|
||||
Lag = block_lag_lead[block_type_firstequation_size_mfs.size()-1].first;
|
||||
if (block_lag_lead[block_type_firstequation_size_mfs.size()-1].second > Lead)
|
||||
Lead = block_lag_lead[block_type_firstequation_size_mfs.size()-1].second;
|
||||
block_lag_lead[block_type_firstequation_size_mfs.size()-1] = { Lag, Lead };
|
||||
auto tmp = block_col_type[block_col_type.size()-1];
|
||||
block_col_type[block_col_type.size()-1] = { get<0>(tmp)+l_n_static, get<1>(tmp)+l_n_forward, get<2>(tmp)+l_n_backward, get<3>(tmp)+l_n_mixed };
|
||||
}
|
||||
else
|
||||
{
|
||||
block_type_size_mfs.emplace_back(Simulation_Type, eq, Blck_Size, MFS_Size);
|
||||
block_type_firstequation_size_mfs.emplace_back(Simulation_Type, eq, Blck_Size, MFS_Size);
|
||||
block_lag_lead.emplace_back(Lag, Lead);
|
||||
block_col_type.emplace_back(l_n_static, l_n_forward, l_n_backward, l_n_mixed);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
block_type_size_mfs.emplace_back(Simulation_Type, eq, Blck_Size, MFS_Size);
|
||||
block_type_firstequation_size_mfs.emplace_back(Simulation_Type, eq, Blck_Size, MFS_Size);
|
||||
block_lag_lead.emplace_back(Lag, Lead);
|
||||
block_col_type.emplace_back(l_n_static, l_n_forward, l_n_backward, l_n_mixed);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
block_type_size_mfs.emplace_back(Simulation_Type, eq, Blck_Size, MFS_Size);
|
||||
block_type_firstequation_size_mfs.emplace_back(Simulation_Type, eq, Blck_Size, MFS_Size);
|
||||
block_lag_lead.emplace_back(Lag, Lead);
|
||||
block_col_type.emplace_back(l_n_static, l_n_forward, l_n_backward, l_n_mixed);
|
||||
}
|
||||
prev_Type = Simulation_Type;
|
||||
eq += Blck_Size;
|
||||
}
|
||||
return block_type_size_mfs;
|
||||
}
|
||||
|
||||
vector<bool>
|
||||
|
@ -1248,11 +1247,12 @@ ModelTree::equationLinear(const map<tuple<int, int, int>, expr_t> &first_order_e
|
|||
return is_linear;
|
||||
}
|
||||
|
||||
vector<bool>
|
||||
ModelTree::BlockLinear() const
|
||||
void
|
||||
ModelTree::determineLinearBlocks()
|
||||
{
|
||||
unsigned int nb_blocks = getNbBlocks();
|
||||
vector<bool> blocks_linear(nb_blocks, true);
|
||||
blocks_linear.clear();
|
||||
blocks_linear.resize(nb_blocks, true);
|
||||
for (unsigned int block = 0; block < nb_blocks; block++)
|
||||
{
|
||||
BlockSimulationType simulation_type = getBlockSimulationType(block);
|
||||
|
@ -1291,7 +1291,6 @@ ModelTree::BlockLinear() const
|
|||
the_end:
|
||||
;
|
||||
}
|
||||
return blocks_linear;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -295,13 +295,13 @@ protected:
|
|||
//! 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
|
||||
equation_type_and_normalized_equation_t equationTypeDetermination(const map<tuple<int, int, int>, expr_t> &first_order_endo_derivatives, int mfs) const;
|
||||
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,
|
||||
n_forward, n_backward, n_mixed) */
|
||||
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>> computeBlockDecompositionAndFeedbackVariablesForEachBlock(const jacob_map_t &static_jacobian, const equation_type_and_normalized_equation_t &Equation_Type, bool verbose_, bool select_feedback_variable);
|
||||
//! Reduce the number of block merging the same type equation in the prologue and the epilogue and determine the type of each block
|
||||
block_type_firstequation_size_mfs_t reduceBlocksAndTypeDetermination(const vector<pair<int, int>> &blocks, const equation_type_and_normalized_equation_t &Equation_Type, const vector<unsigned int> &n_static, const vector<unsigned int> &n_forward, const vector<unsigned int> &n_backward, const vector<unsigned int> &n_mixed, bool linear_decomposition);
|
||||
void reduceBlocksAndTypeDetermination(const vector<pair<int, int>> &blocks, const equation_type_and_normalized_equation_t &Equation_Type, const vector<unsigned int> &n_static, const vector<unsigned int> &n_forward, const vector<unsigned int> &n_backward, const vector<unsigned int> &n_mixed, bool linear_decomposition);
|
||||
//! Determine the maximum number of lead and lag for the endogenous variable in a bloc
|
||||
/*! Returns a pair { equation_lead,lag, variable_lead_lag } */
|
||||
pair<lag_lead_vector_t, lag_lead_vector_t> getVariableLeadLagByBlock(const vector<int> &components_set, int nb_blck_sim) const;
|
||||
|
@ -310,7 +310,7 @@ protected:
|
|||
//! Print an abstract of the block structure of the model
|
||||
void printBlockDecomposition(const vector<pair<int, int>> &blocks) const;
|
||||
//! Determine for each block if it is linear or not
|
||||
vector<bool> BlockLinear() const;
|
||||
void determineLinearBlocks();
|
||||
//! Remove equations specified by exclude_eqs
|
||||
vector<int> includeExcludeEquations(set<pair<string, string>> &eqs, bool exclude_eqs,
|
||||
vector<BinaryOpNode *> &equations, vector<int> &equations_lineno,
|
||||
|
|
|
@ -1152,19 +1152,19 @@ StaticModel::computingPass(int derivsOrder, int paramsDerivsOrder, const eval_co
|
|||
|
||||
auto first_order_endo_derivatives = collect_first_order_derivatives_endogenous();
|
||||
|
||||
equation_type_and_normalized_equation = equationTypeDetermination(first_order_endo_derivatives, mfs);
|
||||
equationTypeDetermination(first_order_endo_derivatives, mfs);
|
||||
|
||||
cout << "Finding the optimal block decomposition of the model ..." << endl;
|
||||
|
||||
auto [blocks, equation_lag_lead, variable_lag_lead, n_static, n_forward, n_backward, n_mixed] = computeBlockDecompositionAndFeedbackVariablesForEachBlock(static_jacobian, equation_type_and_normalized_equation, false, false);
|
||||
|
||||
block_type_firstequation_size_mfs = reduceBlocksAndTypeDetermination(blocks, equation_type_and_normalized_equation, n_static, n_forward, n_backward, n_mixed, false);
|
||||
reduceBlocksAndTypeDetermination(blocks, equation_type_and_normalized_equation, n_static, n_forward, n_backward, n_mixed, false);
|
||||
|
||||
printBlockDecomposition(blocks);
|
||||
|
||||
computeChainRuleJacobian();
|
||||
|
||||
blocks_linear = BlockLinear();
|
||||
determineLinearBlocks();
|
||||
|
||||
collect_block_first_order_derivatives();
|
||||
|
||||
|
|
Loading…
Reference in New Issue