From fc9cc2dc503e2c8b0921b320e041b0d5f49057ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Thu, 22 Nov 2018 17:49:47 +0100 Subject: [PATCH] Output symmetric elements in derivatives of hessian w.r.t. parameters The preprocessor now writes all the symmetric elements in the "hp" matrix (derivatives of the hessian w.r.t. parameters), for consistency with all other derivatives output. Previously it was only writing one of the two symmetric elements, when indices of endogenous were different. --- src/DynamicModel.cc | 18 ++++++++++++++++++ src/StaticModel.cc | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index 52b62373..2acd9d11 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -5526,6 +5526,24 @@ DynamicModel::writeParamsDerivativesFile(const string &basename, bool julia) con third_derivs1_output << ";" << endl; i++; + + if (var1 != var2) + { + // Treat symmetric elements + third_derivs1_output << "hp" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << ",1" + << RIGHT_ARRAY_SUBSCRIPT(output_type) << "=" << eq+1 << ";" << endl + << "hp" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << ",2" + << RIGHT_ARRAY_SUBSCRIPT(output_type) << "=" << var2_col << ";" << endl + << "hp" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << ",3" + << RIGHT_ARRAY_SUBSCRIPT(output_type) << "=" << var1_col << ";" << endl + << "hp" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << ",4" + << RIGHT_ARRAY_SUBSCRIPT(output_type) << "=" << param_col << ";" << endl + << "hp" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << ",5" + << RIGHT_ARRAY_SUBSCRIPT(output_type) + << "=hp" << LEFT_ARRAY_SUBSCRIPT(output_type) << i-1 << ",5" + << RIGHT_ARRAY_SUBSCRIPT(output_type) << ";" << endl; + i++; + } } string filename = julia ? basename + "DynamicParamsDerivs.jl" : packageDir(basename) + "/dynamic_params_derivs.m"; diff --git a/src/StaticModel.cc b/src/StaticModel.cc index b2d9641a..584aad05 100644 --- a/src/StaticModel.cc +++ b/src/StaticModel.cc @@ -2798,6 +2798,24 @@ StaticModel::writeParamsDerivativesFile(const string &basename, bool julia) cons third_derivs1_output << ";" << endl; i++; + + if (var1 != var2) + { + // Treat symmetric elements + third_derivs1_output << "hp" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << ",1" + << RIGHT_ARRAY_SUBSCRIPT(output_type) << "=" << eq+1 << ";" << endl + << "hp" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << ",2" + << RIGHT_ARRAY_SUBSCRIPT(output_type) << "=" << var2_col << ";" << endl + << "hp" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << ",3" + << RIGHT_ARRAY_SUBSCRIPT(output_type) << "=" << var1_col << ";" << endl + << "hp" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << ",4" + << RIGHT_ARRAY_SUBSCRIPT(output_type) << "=" << param_col << ";" << endl + << "hp" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << ",5" + << RIGHT_ARRAY_SUBSCRIPT(output_type) + << "=hp" << LEFT_ARRAY_SUBSCRIPT(output_type) << i-1 << ",5" + << RIGHT_ARRAY_SUBSCRIPT(output_type) << ";" << endl; + i++; + } } ofstream paramsDerivsFile;