From 263725aa1ff2eec295a5bdf5fe0bd724bb6c5ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Mon, 22 Feb 2010 15:58:44 +0100 Subject: [PATCH] Estimation DLL, ModelSolution class: * fixed initialization of matrices * removed useless ModelSolutionException, rather forward upwards the exception thrown below * DynamicModelDLL is now a full member instead of a pointer --- mex/sources/estimation/ModelSolution.cc | 40 ++++++++----------------- mex/sources/estimation/ModelSolution.hh | 15 ++-------- 2 files changed, 15 insertions(+), 40 deletions(-) diff --git a/mex/sources/estimation/ModelSolution.cc b/mex/sources/estimation/ModelSolution.cc index 8207dc479..9dddb6cb0 100644 --- a/mex/sources/estimation/ModelSolution.cc +++ b/mex/sources/estimation/ModelSolution.cc @@ -23,6 +23,8 @@ // Created on: 02-Feb-2010 13:06:35 /////////////////////////////////////////////////////////// +#include + #include "ModelSolution.hh" /** @@ -34,21 +36,15 @@ ModelSolution::ModelSolution(const std::string& modName, size_t n_endo_arg, siz : n_endo(n_endo_arg), n_exo(n_exo_arg), // n_jcols = Num of Jacobian columns = nStat+2*nPred+3*nBoth+2*nForw+nExog n_jcols (n_exo+n_endo+ zeta_back_arg.size() /*nsPred*/ + zeta_fwrd_arg.size() /*nsForw*/ +2*zeta_mixed_arg.size()), ll_incidence(llincidence), jacobian (n_endo,n_jcols), residual(n_endo), Mx(2,n_exo), - decisionRules ( n_endo_arg, n_exo_arg, zeta_fwrd_arg, zeta_back_arg, zeta_mixed_arg, zeta_static_arg, INqz_criterium) - + decisionRules ( n_endo_arg, n_exo_arg, zeta_fwrd_arg, zeta_back_arg, zeta_mixed_arg, zeta_static_arg, INqz_criterium), + dynamicDLLp(modName, n_endo, n_jcols, /* nMax_lag= */ 1, n_exo, std::string("")) { - std::string sExt(""); // use a pre-constructed model_dynamic.ext file name - dynamicDLLp = new DynamicModelDLL(modName, n_endo, n_jcols, /* nMax_lag= */ 1, n_exo, sExt) ; - -} - -ModelSolution::~ModelSolution() -{ - delete dynamicDLLp; + Mx.setAll(0.0); + jacobian.setAll(0.0); } void -ModelSolution::compute(Vector& steadyState, const Vector& deepParams, Matrix& ghx, Matrix& ghu) +ModelSolution::compute(Vector& steadyState, const Vector& deepParams, Matrix& ghx, Matrix& ghu) throw (DecisionRules::BlanchardKahnException, GeneralizedSchurDecomposition::GSDException) { // compute Steady State ComputeSteadyState(steadyState, deepParams); @@ -60,14 +56,13 @@ ModelSolution::compute(Vector& steadyState, const Vector& deepParams, Matrix& gh } void -ModelSolution::ComputeModelSolution(Vector& steadyState, const Vector& deepParams, Matrix& ghx, Matrix& ghu) +ModelSolution::ComputeModelSolution(Vector& steadyState, const Vector& deepParams, Matrix& ghx, Matrix& ghu) throw (DecisionRules::BlanchardKahnException, GeneralizedSchurDecomposition::GSDException) { // set extended Steady State Vector llXsteadyState(n_jcols-n_exo); - try - { - for (int ll_row = 0; ll_row < ll_incidence.getRows(); ll_row++) + + for (int ll_row = 0; ll_row < ll_incidence.getRows(); ll_row++) { // populate (non-sparse) vector with ysteady values for (int i = 0; i < n_endo; i++) @@ -81,25 +76,14 @@ ModelSolution::ComputeModelSolution(Vector& steadyState, const Vector& deepParam mexPrintf(" get jacobian \n"); #endif //get jacobian - dynamicDLLp->eval(llXsteadyState, Mx, &deepParams, 1, residual, &jacobian, NULL, NULL); + dynamicDLLp.eval(llXsteadyState, Mx, &deepParams, 1, residual, &jacobian, NULL, NULL); -#ifdef DEBUG std::cout << "jacobian: " << std::endl << jacobian << std::endl; +#ifdef DEBUG mexPrintf(" compute rules \n"); #endif //compute rules decisionRules.compute(jacobian,ghx, ghu); - } - catch (const ModelSolutionException &e) - { - mexPrintf("Caught ModelSolution exception in LLxSteady: "); - e.print(); - } - catch (...) - { - mexPrintf("Caught unknown error in ModelSolution::ComputeModelSolution\n"); - } - } void ModelSolution::ComputeSteadyState(Vector& steadyState, const Vector& deepParams) diff --git a/mex/sources/estimation/ModelSolution.hh b/mex/sources/estimation/ModelSolution.hh index 17e73edb2..722c63183 100644 --- a/mex/sources/estimation/ModelSolution.hh +++ b/mex/sources/estimation/ModelSolution.hh @@ -38,19 +38,10 @@ class ModelSolution{ public: - class ModelSolutionException: public TSException - { - public: - const lapack_int info, n; - ModelSolutionException(lapack_int info_arg, lapack_int n_arg, std::string& mes) - : TSException(__FILE__, __LINE__, mes), info(info_arg), n(n_arg) {}; - }; - - virtual ~ModelSolution(); ModelSolution(const std::string& modName, size_t n_endo, size_t n_exo, const std::vector& zeta_fwrd_arg, const std::vector& zeta_back_arg, const std::vector& zeta_mixed_arg, const std::vector& zeta_static_arg, const Matrix& llincidence, double qz_criterium); - void compute( Vector& steadyState, const Vector& deepParams, Matrix& ghx, Matrix& ghu ); + void compute( Vector& steadyState, const Vector& deepParams, Matrix& ghx, Matrix& ghu ) throw (DecisionRules::BlanchardKahnException, GeneralizedSchurDecomposition::GSDException); private: const int n_endo; @@ -61,9 +52,9 @@ private: Vector residual; Matrix Mx; DecisionRules decisionRules; - DynamicModelDLL* dynamicDLLp; + DynamicModelDLL dynamicDLLp; //Matrix jacobian; - void ComputeModelSolution( Vector& steadyState, const Vector& deepParams, Matrix& ghx, Matrix& ghu ); + void ComputeModelSolution( Vector& steadyState, const Vector& deepParams, Matrix& ghx, Matrix& ghu ) throw (DecisionRules::BlanchardKahnException, GeneralizedSchurDecomposition::GSDException); void ComputeSteadyState( Vector& steadyState, const Vector& deepParams); };