preprocessor: only compute first order derivatives w.r.t. parameters with identification. closes #1187
parent
89667ea8da
commit
9d26ab46e9
|
@ -1253,7 +1253,7 @@ PlannerObjectiveStatement::getPlannerObjective() const
|
||||||
void
|
void
|
||||||
PlannerObjectiveStatement::computingPass()
|
PlannerObjectiveStatement::computingPass()
|
||||||
{
|
{
|
||||||
model_tree->computingPass(eval_context_t(), false, true, true, false, false, false);
|
model_tree->computingPass(eval_context_t(), false, true, true, none, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -3113,7 +3113,7 @@ DynamicModel::runTrendTest(const eval_context_t &eval_context)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::computingPass(bool jacobianExo, bool hessian, bool thirdDerivatives, bool paramsDerivatives,
|
DynamicModel::computingPass(bool jacobianExo, bool hessian, bool thirdDerivatives, FileOutputType paramsDerivatives,
|
||||||
const eval_context_t &eval_context, bool no_tmp_terms, bool block, bool use_dll,
|
const eval_context_t &eval_context, bool no_tmp_terms, bool block, bool use_dll,
|
||||||
bool bytecode, bool compute_xrefs)
|
bool bytecode, bool compute_xrefs)
|
||||||
{
|
{
|
||||||
|
@ -3148,10 +3148,10 @@ DynamicModel::computingPass(bool jacobianExo, bool hessian, bool thirdDerivative
|
||||||
computeHessian(vars);
|
computeHessian(vars);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paramsDerivatives)
|
if (paramsDerivatives != none)
|
||||||
{
|
{
|
||||||
cout << " - derivatives of Jacobian/Hessian w.r. to parameters" << endl;
|
cout << " - derivatives of Jacobian/Hessian w.r. to parameters" << endl;
|
||||||
computeParamsDerivatives();
|
computeParamsDerivatives(paramsDerivatives);
|
||||||
|
|
||||||
if (!no_tmp_terms)
|
if (!no_tmp_terms)
|
||||||
computeParamsDerivativesTemporaryTerms();
|
computeParamsDerivativesTemporaryTerms();
|
||||||
|
|
|
@ -212,7 +212,7 @@ public:
|
||||||
\param eval_context evaluation context for normalization
|
\param eval_context evaluation context for normalization
|
||||||
\param no_tmp_terms if true, no temporary terms will be computed in the dynamic files
|
\param no_tmp_terms if true, no temporary terms will be computed in the dynamic files
|
||||||
*/
|
*/
|
||||||
void computingPass(bool jacobianExo, bool hessian, bool thirdDerivatives, bool paramsDerivatives,
|
void computingPass(bool jacobianExo, bool hessian, bool thirdDerivatives, FileOutputType paramsDerivatives,
|
||||||
const eval_context_t &eval_context, bool no_tmp_terms, bool block, bool use_dll, bool bytecode, bool compute_xrefs);
|
const eval_context_t &eval_context, bool no_tmp_terms, bool block, bool use_dll, bool bytecode, bool compute_xrefs);
|
||||||
//! Writes model initialization and lead/lag incidence matrix to output
|
//! Writes model initialization and lead/lag incidence matrix to output
|
||||||
void writeOutput(ostream &output, const string &basename, bool block, bool byte_code, bool use_dll, int order, bool estimation_present, bool compute_xrefs, bool julia) const;
|
void writeOutput(ostream &output, const string &basename, bool block, bool byte_code, bool use_dll, int order, bool estimation_present, bool compute_xrefs, bool julia) const;
|
||||||
|
|
|
@ -489,8 +489,11 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output, bool compute_xr
|
||||||
|
|
||||||
const bool static_hessian = mod_file_struct.identification_present
|
const bool static_hessian = mod_file_struct.identification_present
|
||||||
|| mod_file_struct.estimation_analytic_derivation;
|
|| mod_file_struct.estimation_analytic_derivation;
|
||||||
const bool paramsDerivatives = mod_file_struct.identification_present
|
FileOutputType paramsDerivatives = none;
|
||||||
|| mod_file_struct.estimation_analytic_derivation;
|
if (mod_file_struct.identification_present)
|
||||||
|
paramsDerivatives = first;
|
||||||
|
if (mod_file_struct.estimation_analytic_derivation)
|
||||||
|
paramsDerivatives = third;
|
||||||
static_model.computingPass(global_eval_context, no_tmp_terms, static_hessian,
|
static_model.computingPass(global_eval_context, no_tmp_terms, static_hessian,
|
||||||
false, paramsDerivatives, block, byte_code);
|
false, paramsDerivatives, block, byte_code);
|
||||||
}
|
}
|
||||||
|
@ -502,7 +505,7 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output, bool compute_xr
|
||||||
|| mod_file_struct.calib_smoother_present)
|
|| mod_file_struct.calib_smoother_present)
|
||||||
{
|
{
|
||||||
if (mod_file_struct.perfect_foresight_solver_present)
|
if (mod_file_struct.perfect_foresight_solver_present)
|
||||||
dynamic_model.computingPass(true, false, false, false, global_eval_context, no_tmp_terms, block, use_dll, byte_code, compute_xrefs);
|
dynamic_model.computingPass(true, false, false, none, global_eval_context, no_tmp_terms, block, use_dll, byte_code, compute_xrefs);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (mod_file_struct.stoch_simul_present
|
if (mod_file_struct.stoch_simul_present
|
||||||
|
@ -523,12 +526,16 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output, bool compute_xr
|
||||||
bool thirdDerivatives = mod_file_struct.order_option == 3
|
bool thirdDerivatives = mod_file_struct.order_option == 3
|
||||||
|| mod_file_struct.estimation_analytic_derivation
|
|| mod_file_struct.estimation_analytic_derivation
|
||||||
|| output == third;
|
|| output == third;
|
||||||
bool paramsDerivatives = mod_file_struct.identification_present || mod_file_struct.estimation_analytic_derivation;
|
FileOutputType paramsDerivatives = none;
|
||||||
|
if (mod_file_struct.identification_present)
|
||||||
|
paramsDerivatives = first;
|
||||||
|
if (mod_file_struct.estimation_analytic_derivation)
|
||||||
|
paramsDerivatives = third;
|
||||||
dynamic_model.computingPass(true, hessian, thirdDerivatives, paramsDerivatives, global_eval_context, no_tmp_terms, block, use_dll, byte_code, compute_xrefs);
|
dynamic_model.computingPass(true, hessian, thirdDerivatives, paramsDerivatives, global_eval_context, no_tmp_terms, block, use_dll, byte_code, compute_xrefs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // No computing task requested, compute derivatives up to 2nd order by default
|
else // No computing task requested, compute derivatives up to 2nd order by default
|
||||||
dynamic_model.computingPass(true, true, false, false, global_eval_context, no_tmp_terms, block, use_dll, byte_code, compute_xrefs);
|
dynamic_model.computingPass(true, true, false, none, global_eval_context, no_tmp_terms, block, use_dll, byte_code, compute_xrefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (vector<Statement *>::iterator it = statements.begin();
|
for (vector<Statement *>::iterator it = statements.begin();
|
||||||
|
|
|
@ -1657,8 +1657,10 @@ ModelTree::sparseHelper(int order, ostream &output, int row_nb, int col_nb, Expr
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ModelTree::computeParamsDerivatives()
|
ModelTree::computeParamsDerivatives(FileOutputType paramsDerivatives)
|
||||||
{
|
{
|
||||||
|
if (!(paramsDerivatives == first || paramsDerivatives == second || paramsDerivatives == third))
|
||||||
|
return;
|
||||||
set<int> deriv_id_set;
|
set<int> deriv_id_set;
|
||||||
addAllParamDerivId(deriv_id_set);
|
addAllParamDerivId(deriv_id_set);
|
||||||
|
|
||||||
|
@ -1675,18 +1677,19 @@ ModelTree::computeParamsDerivatives()
|
||||||
residuals_params_derivatives[make_pair(eq, param)] = d1;
|
residuals_params_derivatives[make_pair(eq, param)] = d1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (first_derivatives_t::const_iterator it2 = residuals_params_derivatives.begin();
|
if (paramsDerivatives == second || paramsDerivatives == third)
|
||||||
it2 != residuals_params_derivatives.end(); it2++)
|
for (first_derivatives_t::const_iterator it2 = residuals_params_derivatives.begin();
|
||||||
{
|
it2 != residuals_params_derivatives.end(); it2++)
|
||||||
int eq = it2->first.first;
|
{
|
||||||
int param1 = it2->first.second;
|
int eq = it2->first.first;
|
||||||
expr_t d1 = it2->second;
|
int param1 = it2->first.second;
|
||||||
|
expr_t d1 = it2->second;
|
||||||
|
|
||||||
expr_t d2 = d1->getDerivative(param);
|
expr_t d2 = d1->getDerivative(param);
|
||||||
if (d2 == Zero)
|
if (d2 == Zero)
|
||||||
continue;
|
continue;
|
||||||
residuals_params_second_derivatives[make_pair(eq, make_pair(param1, param))] = d2;
|
residuals_params_second_derivatives[make_pair(eq, make_pair(param1, param))] = d2;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (first_derivatives_t::const_iterator it2 = first_derivatives.begin();
|
for (first_derivatives_t::const_iterator it2 = first_derivatives.begin();
|
||||||
it2 != first_derivatives.end(); it2++)
|
it2 != first_derivatives.end(); it2++)
|
||||||
|
@ -1701,33 +1704,35 @@ ModelTree::computeParamsDerivatives()
|
||||||
jacobian_params_derivatives[make_pair(eq, make_pair(var, param))] = d2;
|
jacobian_params_derivatives[make_pair(eq, make_pair(var, param))] = d2;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (second_derivatives_t::const_iterator it2 = jacobian_params_derivatives.begin();
|
if (paramsDerivatives == second || paramsDerivatives == third)
|
||||||
it2 != jacobian_params_derivatives.end(); it2++)
|
for (second_derivatives_t::const_iterator it2 = jacobian_params_derivatives.begin();
|
||||||
{
|
it2 != jacobian_params_derivatives.end(); it2++)
|
||||||
int eq = it2->first.first;
|
{
|
||||||
int var = it2->first.second.first;
|
int eq = it2->first.first;
|
||||||
int param1 = it2->first.second.second;
|
int var = it2->first.second.first;
|
||||||
expr_t d1 = it2->second;
|
int param1 = it2->first.second.second;
|
||||||
|
expr_t d1 = it2->second;
|
||||||
|
|
||||||
expr_t d2 = d1->getDerivative(param);
|
expr_t d2 = d1->getDerivative(param);
|
||||||
if (d2 == Zero)
|
if (d2 == Zero)
|
||||||
continue;
|
continue;
|
||||||
jacobian_params_second_derivatives[make_pair(eq, make_pair(var, make_pair(param1, param)))] = d2;
|
jacobian_params_second_derivatives[make_pair(eq, make_pair(var, make_pair(param1, param)))] = d2;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (second_derivatives_t::const_iterator it2 = second_derivatives.begin();
|
if (paramsDerivatives == third)
|
||||||
it2 != second_derivatives.end(); it2++)
|
for (second_derivatives_t::const_iterator it2 = second_derivatives.begin();
|
||||||
{
|
it2 != second_derivatives.end(); it2++)
|
||||||
int eq = it2->first.first;
|
{
|
||||||
int var1 = it2->first.second.first;
|
int eq = it2->first.first;
|
||||||
int var2 = it2->first.second.second;
|
int var1 = it2->first.second.first;
|
||||||
expr_t d1 = it2->second;
|
int var2 = it2->first.second.second;
|
||||||
|
expr_t d1 = it2->second;
|
||||||
|
|
||||||
expr_t d2 = d1->getDerivative(param);
|
expr_t d2 = d1->getDerivative(param);
|
||||||
if (d2 == Zero)
|
if (d2 == Zero)
|
||||||
continue;
|
continue;
|
||||||
hessian_params_derivatives[make_pair(eq, make_pair(var1, make_pair(var2, param)))] = d2;
|
hessian_params_derivatives[make_pair(eq, make_pair(var1, make_pair(var2, param)))] = d2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2003-2015 Dynare Team
|
* Copyright (C) 2003-2016 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -29,6 +29,7 @@ using namespace std;
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
#include "DataTree.hh"
|
#include "DataTree.hh"
|
||||||
|
#include "ExtendedPreprocessorTypes.hh"
|
||||||
|
|
||||||
//! Vector describing equations: BlockSimulationType, if BlockSimulationType == EVALUATE_s then a expr_t on the new normalized equation
|
//! Vector describing equations: BlockSimulationType, if BlockSimulationType == EVALUATE_s then a expr_t on the new normalized equation
|
||||||
typedef vector<pair<EquationType, expr_t > > equation_type_and_normalized_equation_t;
|
typedef vector<pair<EquationType, expr_t > > equation_type_and_normalized_equation_t;
|
||||||
|
@ -176,7 +177,7 @@ protected:
|
||||||
/*! \param vars the derivation IDs w.r. to which derive the 2nd derivatives */
|
/*! \param vars the derivation IDs w.r. to which derive the 2nd derivatives */
|
||||||
void computeThirdDerivatives(const set<int> &vars);
|
void computeThirdDerivatives(const set<int> &vars);
|
||||||
//! Computes derivatives of the Jacobian and Hessian w.r. to parameters
|
//! Computes derivatives of the Jacobian and Hessian w.r. to parameters
|
||||||
void computeParamsDerivatives();
|
void computeParamsDerivatives(FileOutputType paramsDerivatives);
|
||||||
//! Write derivative of an equation w.r. to a variable
|
//! Write derivative of an equation w.r. to a variable
|
||||||
void writeDerivative(ostream &output, int eq, int symb_id, int lag, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const;
|
void writeDerivative(ostream &output, int eq, int symb_id, int lag, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const;
|
||||||
//! Computes temporary terms (for all equations and derivatives)
|
//! Computes temporary terms (for all equations and derivatives)
|
||||||
|
|
|
@ -1047,7 +1047,7 @@ StaticModel::collect_first_order_derivatives_endogenous()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
StaticModel::computingPass(const eval_context_t &eval_context, bool no_tmp_terms, bool hessian, bool thirdDerivatives, bool paramsDerivatives, bool block, bool bytecode)
|
StaticModel::computingPass(const eval_context_t &eval_context, bool no_tmp_terms, bool hessian, bool thirdDerivatives, FileOutputType paramsDerivatives, bool block, bool bytecode)
|
||||||
{
|
{
|
||||||
initializeVariablesAndEquations();
|
initializeVariablesAndEquations();
|
||||||
|
|
||||||
|
@ -1095,10 +1095,10 @@ StaticModel::computingPass(const eval_context_t &eval_context, bool no_tmp_terms
|
||||||
computeThirdDerivatives(vars);
|
computeThirdDerivatives(vars);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paramsDerivatives)
|
if (paramsDerivatives != none)
|
||||||
{
|
{
|
||||||
cout << " - derivatives of Jacobian/Hessian w.r. to parameters" << endl;
|
cout << " - derivatives of Jacobian/Hessian w.r. to parameters" << endl;
|
||||||
computeParamsDerivatives();
|
computeParamsDerivatives(paramsDerivatives);
|
||||||
|
|
||||||
if (!no_tmp_terms)
|
if (!no_tmp_terms)
|
||||||
computeParamsDerivativesTemporaryTerms();
|
computeParamsDerivativesTemporaryTerms();
|
||||||
|
|
|
@ -164,7 +164,7 @@ public:
|
||||||
\param hessian whether 2nd derivatives w.r. to exo, exo_det and endo should be computed
|
\param hessian whether 2nd derivatives w.r. to exo, exo_det and endo should be computed
|
||||||
\param paramsDerivatives whether 2nd derivatives w.r. to a pair (endo/exo/exo_det, parameter) should be computed
|
\param paramsDerivatives whether 2nd derivatives w.r. to a pair (endo/exo/exo_det, parameter) should be computed
|
||||||
*/
|
*/
|
||||||
void computingPass(const eval_context_t &eval_context, bool no_tmp_terms, bool hessian, bool thirdDerivatices, bool paramsDerivatives, bool block, bool bytecode);
|
void computingPass(const eval_context_t &eval_context, bool no_tmp_terms, bool hessian, bool thirdDerivatices, FileOutputType paramsDerivatives, bool block, bool bytecode);
|
||||||
|
|
||||||
//! Adds informations for simulation in a binary file for a block decomposed model
|
//! Adds informations for simulation in a binary file for a block decomposed model
|
||||||
void Write_Inf_To_Bin_File_Block(const string &static_basename, const string &bin_basename, const int &num,
|
void Write_Inf_To_Bin_File_Block(const string &static_basename, const string &bin_basename, const int &num,
|
||||||
|
|
Loading…
Reference in New Issue