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
time-shift
Sébastien Villemot 2010-02-22 15:58:44 +01:00
parent 3cacb48c81
commit 263725aa1f
2 changed files with 15 additions and 40 deletions

View File

@ -23,6 +23,8 @@
// Created on: 02-Feb-2010 13:06:35 // Created on: 02-Feb-2010 13:06:35
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
#include <string>
#include "ModelSolution.hh" #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_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()), 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), 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 Mx.setAll(0.0);
dynamicDLLp = new DynamicModelDLL(modName, n_endo, n_jcols, /* nMax_lag= */ 1, n_exo, sExt) ; jacobian.setAll(0.0);
}
ModelSolution::~ModelSolution()
{
delete dynamicDLLp;
} }
void 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 // compute Steady State
ComputeSteadyState(steadyState, deepParams); ComputeSteadyState(steadyState, deepParams);
@ -60,14 +56,13 @@ ModelSolution::compute(Vector& steadyState, const Vector& deepParams, Matrix& gh
} }
void 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 // set extended Steady State
Vector llXsteadyState(n_jcols-n_exo); 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 // populate (non-sparse) vector with ysteady values
for (int i = 0; i < n_endo; i++) for (int i = 0; i < n_endo; i++)
@ -81,25 +76,14 @@ ModelSolution::ComputeModelSolution(Vector& steadyState, const Vector& deepParam
mexPrintf(" get jacobian \n"); mexPrintf(" get jacobian \n");
#endif #endif
//get jacobian //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; std::cout << "jacobian: " << std::endl << jacobian << std::endl;
#ifdef DEBUG
mexPrintf(" compute rules \n"); mexPrintf(" compute rules \n");
#endif #endif
//compute rules //compute rules
decisionRules.compute(jacobian,ghx, ghu); 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 void
ModelSolution::ComputeSteadyState(Vector& steadyState, const Vector& deepParams) ModelSolution::ComputeSteadyState(Vector& steadyState, const Vector& deepParams)

View File

@ -38,19 +38,10 @@
class ModelSolution{ class ModelSolution{
public: 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<size_t>& zeta_fwrd_arg, ModelSolution(const std::string& modName, size_t n_endo, size_t n_exo, const std::vector<size_t>& zeta_fwrd_arg,
const std::vector<size_t>& zeta_back_arg, const std::vector<size_t>& zeta_mixed_arg, const std::vector<size_t>& zeta_back_arg, const std::vector<size_t>& zeta_mixed_arg,
const std::vector<size_t>& zeta_static_arg, const Matrix& llincidence, double qz_criterium); const std::vector<size_t>& 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: private:
const int n_endo; const int n_endo;
@ -61,9 +52,9 @@ private:
Vector residual; Vector residual;
Matrix Mx; Matrix Mx;
DecisionRules decisionRules; DecisionRules decisionRules;
DynamicModelDLL* dynamicDLLp; DynamicModelDLL dynamicDLLp;
//Matrix jacobian; //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); void ComputeSteadyState( Vector& steadyState, const Vector& deepParams);
}; };