cosmetic: simplify jacobianHelper, hessianHelper and sparseHelper functions and fix spacing in dynamic file
parent
65d05f1a31
commit
426682d632
|
@ -2055,7 +2055,6 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll) const
|
||||||
int var = it->first.second;
|
int var = it->first.second;
|
||||||
expr_t d1 = it->second;
|
expr_t d1 = it->second;
|
||||||
|
|
||||||
jacobian_output << "g1";
|
|
||||||
jacobianHelper(jacobian_output, eq, getDynJacobianCol(var), output_type);
|
jacobianHelper(jacobian_output, eq, getDynJacobianCol(var), output_type);
|
||||||
jacobian_output << "=";
|
jacobian_output << "=";
|
||||||
d1->writeOutput(jacobian_output, output_type, temporary_terms, tef_terms);
|
d1->writeOutput(jacobian_output, output_type, temporary_terms, tef_terms);
|
||||||
|
@ -3690,28 +3689,6 @@ DynamicModel::writeLatexFile(const string &basename) const
|
||||||
writeLatexModelFile(basename + "_dynamic.tex", oLatexDynamicModel);
|
writeLatexModelFile(basename + "_dynamic.tex", oLatexDynamicModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
DynamicModel::jacobianHelper(ostream &output, int eq_nb, int col_nb, ExprNodeOutputType output_type) const
|
|
||||||
{
|
|
||||||
output << LEFT_ARRAY_SUBSCRIPT(output_type);
|
|
||||||
if (IS_MATLAB(output_type))
|
|
||||||
output << eq_nb + 1 << "," << col_nb + 1;
|
|
||||||
else
|
|
||||||
output << eq_nb + col_nb *equations.size();
|
|
||||||
output << RIGHT_ARRAY_SUBSCRIPT(output_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DynamicModel::sparseHelper(int order, ostream &output, int row_nb, int col_nb, ExprNodeOutputType output_type) const
|
|
||||||
{
|
|
||||||
output << "v" << order << LEFT_ARRAY_SUBSCRIPT(output_type);
|
|
||||||
if (IS_MATLAB(output_type))
|
|
||||||
output << row_nb + 1 << "," << col_nb + 1;
|
|
||||||
else
|
|
||||||
output << row_nb + col_nb * NNZDerivatives[order-1];
|
|
||||||
output << RIGHT_ARRAY_SUBSCRIPT(output_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::substituteEndoLeadGreaterThanTwo(bool deterministic_model)
|
DynamicModel::substituteEndoLeadGreaterThanTwo(bool deterministic_model)
|
||||||
{
|
{
|
||||||
|
|
|
@ -168,15 +168,6 @@ private:
|
||||||
/*! Also computes max_{endo,exo}_{lead_lag}, and initializes dynJacobianColsNbr to the number of dynamic endos */
|
/*! Also computes max_{endo,exo}_{lead_lag}, and initializes dynJacobianColsNbr to the number of dynamic endos */
|
||||||
void computeDerivIDs();
|
void computeDerivIDs();
|
||||||
|
|
||||||
//! Helper for writing the Jacobian elements in MATLAB and C
|
|
||||||
/*! Writes either (i+1,j+1) or [i+j*no_eq] */
|
|
||||||
void jacobianHelper(ostream &output, int eq_nb, int col_nb, ExprNodeOutputType output_type) const;
|
|
||||||
|
|
||||||
//! Helper for writing the sparse Hessian or third derivatives in MATLAB and C
|
|
||||||
/*! If order=2, writes either v2(i+1,j+1) or v2[i+j*NNZDerivatives[1]]
|
|
||||||
If order=3, writes either v3(i+1,j+1) or v3[i+j*NNZDerivatives[2]] */
|
|
||||||
void sparseHelper(int order, ostream &output, int row_nb, int col_nb, ExprNodeOutputType output_type) const;
|
|
||||||
|
|
||||||
//! Write chain rule derivative of a recursive equation w.r. to a variable
|
//! Write chain rule derivative of a recursive equation w.r. to a variable
|
||||||
void writeChainRuleDerivative(ostream &output, int eq, int var, int lag, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const;
|
void writeChainRuleDerivative(ostream &output, int eq, int var, int lag, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const;
|
||||||
|
|
||||||
|
|
|
@ -1423,3 +1423,25 @@ ModelTree::set_cutoff_to_zero()
|
||||||
{
|
{
|
||||||
cutoff = 0;
|
cutoff = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ModelTree::jacobianHelper(ostream &output, int eq_nb, int col_nb, ExprNodeOutputType output_type) const
|
||||||
|
{
|
||||||
|
output << " g1" << LEFT_ARRAY_SUBSCRIPT(output_type);
|
||||||
|
if (IS_MATLAB(output_type))
|
||||||
|
output << eq_nb + 1 << "," << col_nb + 1;
|
||||||
|
else
|
||||||
|
output << eq_nb + col_nb *equations.size();
|
||||||
|
output << RIGHT_ARRAY_SUBSCRIPT(output_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ModelTree::sparseHelper(int order, ostream &output, int row_nb, int col_nb, ExprNodeOutputType output_type) const
|
||||||
|
{
|
||||||
|
output << " v" << order << LEFT_ARRAY_SUBSCRIPT(output_type);
|
||||||
|
if (IS_MATLAB(output_type))
|
||||||
|
output << row_nb + 1 << "," << col_nb + 1;
|
||||||
|
else
|
||||||
|
output << row_nb + col_nb * NNZDerivatives[order-1];
|
||||||
|
output << RIGHT_ARRAY_SUBSCRIPT(output_type);
|
||||||
|
}
|
||||||
|
|
|
@ -262,6 +262,13 @@ public:
|
||||||
//! Adds a nonstationary variable with its deflator
|
//! Adds a nonstationary variable with its deflator
|
||||||
void addNonstationaryVariables(vector<int> nonstationary_vars, expr_t deflator) throw (TrendException);
|
void addNonstationaryVariables(vector<int> nonstationary_vars, expr_t deflator) throw (TrendException);
|
||||||
void set_cutoff_to_zero();
|
void set_cutoff_to_zero();
|
||||||
|
//! Helper for writing the Jacobian elements in MATLAB and C
|
||||||
|
/*! Writes either (i+1,j+1) or [i+j*no_eq] */
|
||||||
|
void jacobianHelper(ostream &output, int eq_nb, int col_nb, ExprNodeOutputType output_type) const;
|
||||||
|
//! Helper for writing the sparse Hessian or third derivatives in MATLAB and C
|
||||||
|
/*! If order=2, writes either v2(i+1,j+1) or v2[i+j*NNZDerivatives[1]]
|
||||||
|
If order=3, writes either v3(i+1,j+1) or v3[i+j*NNZDerivatives[2]] */
|
||||||
|
void sparseHelper(int order, ostream &output, int row_nb, int col_nb, ExprNodeOutputType output_type) const;
|
||||||
|
|
||||||
inline static std::string
|
inline static std::string
|
||||||
c_Equation_Type(int type)
|
c_Equation_Type(int type)
|
||||||
|
|
|
@ -1168,7 +1168,6 @@ StaticModel::writeStaticModel(ostream &StaticOutput, bool use_dll) const
|
||||||
int symb_id = it->first.second;
|
int symb_id = it->first.second;
|
||||||
expr_t d1 = it->second;
|
expr_t d1 = it->second;
|
||||||
|
|
||||||
jacobian_output << " g1";
|
|
||||||
jacobianHelper(jacobian_output, eq, symbol_table.getTypeSpecificID(symb_id), output_type);
|
jacobianHelper(jacobian_output, eq, symbol_table.getTypeSpecificID(symb_id), output_type);
|
||||||
jacobian_output << "=";
|
jacobian_output << "=";
|
||||||
d1->writeOutput(jacobian_output, output_type, temporary_terms, tef_terms);
|
d1->writeOutput(jacobian_output, output_type, temporary_terms, tef_terms);
|
||||||
|
@ -1192,13 +1191,13 @@ StaticModel::writeStaticModel(ostream &StaticOutput, bool use_dll) const
|
||||||
int col_nb = tsid1*symbol_table.endo_nbr()+tsid2;
|
int col_nb = tsid1*symbol_table.endo_nbr()+tsid2;
|
||||||
int col_nb_sym = tsid2*symbol_table.endo_nbr()+tsid1;
|
int col_nb_sym = tsid2*symbol_table.endo_nbr()+tsid1;
|
||||||
|
|
||||||
hessianHelper(hessian_output, k, 0, output_type);
|
sparseHelper(2, hessian_output, k, 0, output_type);
|
||||||
hessian_output << "=" << eq + 1 << ";" << endl;
|
hessian_output << "=" << eq + 1 << ";" << endl;
|
||||||
|
|
||||||
hessianHelper(hessian_output, k, 1, output_type);
|
sparseHelper(2, hessian_output, k, 1, output_type);
|
||||||
hessian_output << "=" << col_nb + 1 << ";" << endl;
|
hessian_output << "=" << col_nb + 1 << ";" << endl;
|
||||||
|
|
||||||
hessianHelper(hessian_output, k, 2, output_type);
|
sparseHelper(2, hessian_output, k, 2, output_type);
|
||||||
hessian_output << "=";
|
hessian_output << "=";
|
||||||
d2->writeOutput(hessian_output, output_type, temporary_terms, tef_terms);
|
d2->writeOutput(hessian_output, output_type, temporary_terms, tef_terms);
|
||||||
hessian_output << ";" << endl;
|
hessian_output << ";" << endl;
|
||||||
|
@ -1208,15 +1207,15 @@ StaticModel::writeStaticModel(ostream &StaticOutput, bool use_dll) const
|
||||||
// Treating symetric elements
|
// Treating symetric elements
|
||||||
if (symb_id1 != symb_id2)
|
if (symb_id1 != symb_id2)
|
||||||
{
|
{
|
||||||
hessianHelper(hessian_output, k, 0, output_type);
|
sparseHelper(2, hessian_output, k, 0, output_type);
|
||||||
hessian_output << "=" << eq + 1 << ";" << endl;
|
hessian_output << "=" << eq + 1 << ";" << endl;
|
||||||
|
|
||||||
hessianHelper(hessian_output, k, 1, output_type);
|
sparseHelper(2, hessian_output, k, 1, output_type);
|
||||||
hessian_output << "=" << col_nb_sym + 1 << ";" << endl;
|
hessian_output << "=" << col_nb_sym + 1 << ";" << endl;
|
||||||
|
|
||||||
hessianHelper(hessian_output, k, 2, output_type);
|
sparseHelper(2, hessian_output, k, 2, output_type);
|
||||||
hessian_output << "=";
|
hessian_output << "=";
|
||||||
hessianHelper(hessian_output, k-1, 2, output_type);
|
sparseHelper(2, hessian_output, k-1, 2, output_type);
|
||||||
hessian_output << ";" << endl;
|
hessian_output << ";" << endl;
|
||||||
|
|
||||||
k++;
|
k++;
|
||||||
|
@ -1700,28 +1699,6 @@ StaticModel::writeLatexFile(const string &basename) const
|
||||||
writeLatexModelFile(basename + "_static.tex", oLatexStaticModel);
|
writeLatexModelFile(basename + "_static.tex", oLatexStaticModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
StaticModel::jacobianHelper(ostream &output, int eq_nb, int col_nb, ExprNodeOutputType output_type) const
|
|
||||||
{
|
|
||||||
output << LEFT_ARRAY_SUBSCRIPT(output_type);
|
|
||||||
if (IS_MATLAB(output_type))
|
|
||||||
output << eq_nb + 1 << "," << col_nb + 1;
|
|
||||||
else
|
|
||||||
output << eq_nb + col_nb *equations.size();
|
|
||||||
output << RIGHT_ARRAY_SUBSCRIPT(output_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
StaticModel::hessianHelper(ostream &output, int row_nb, int col_nb, ExprNodeOutputType output_type) const
|
|
||||||
{
|
|
||||||
output << "v2" << LEFT_ARRAY_SUBSCRIPT(output_type);
|
|
||||||
if (IS_MATLAB(output_type))
|
|
||||||
output << row_nb + 1 << ", " << col_nb + 1;
|
|
||||||
else
|
|
||||||
output << row_nb + col_nb * NNZDerivatives[1];
|
|
||||||
output << RIGHT_ARRAY_SUBSCRIPT(output_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
StaticModel::writeAuxVarInitval(ostream &output, ExprNodeOutputType output_type) const
|
StaticModel::writeAuxVarInitval(ostream &output, ExprNodeOutputType output_type) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -107,14 +107,6 @@ private:
|
||||||
//! Collect only the first derivatives
|
//! Collect only the first derivatives
|
||||||
map<pair<int, pair<int, int> >, expr_t> collect_first_order_derivatives_endogenous();
|
map<pair<int, pair<int, int> >, expr_t> collect_first_order_derivatives_endogenous();
|
||||||
|
|
||||||
//! Helper for writing the Jacobian elements in MATLAB and C
|
|
||||||
/*! Writes either (i+1,j+1) or [i+j*no_eq] */
|
|
||||||
void jacobianHelper(ostream &output, int eq_nb, int col_nb, ExprNodeOutputType output_type) const;
|
|
||||||
|
|
||||||
//! Helper for writing the sparse Hessian elements in MATLAB and C
|
|
||||||
/*! Writes either (i+1,j+1) or [i+j*NNZDerivatives[1]] */
|
|
||||||
void hessianHelper(ostream &output, int row_nb, int col_nb, ExprNodeOutputType output_type) const;
|
|
||||||
|
|
||||||
//! Write chain rule derivative of a recursive equation w.r. to a variable
|
//! Write chain rule derivative of a recursive equation w.r. to a variable
|
||||||
void writeChainRuleDerivative(ostream &output, int eq, int var, int lag, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const;
|
void writeChainRuleDerivative(ostream &output, int eq, int var, int lag, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue