just formatting changes
git-svn-id: https://www.dynare.org/svn/dynare/trunk@2659 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
aa3b7c78f3
commit
473b4d9a2f
File diff suppressed because it is too large
Load Diff
|
@ -1,283 +1,250 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2005 Ondra Kamenik
|
* Copyright (C) 2005 Ondra Kamenik
|
||||||
* Copyright (C) 2008-2009 Dynare Team
|
* Copyright (C) 2008-2009 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
* Dynare is free software: you can redistribute it and/or modify
|
* Dynare is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Dynare is distributed in the hope that it will be useful,
|
* Dynare is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// based on: $Id: dynare3.h 1764 2008-03-31 14:30:55Z kamenik $
|
// based on: $Id: dynare3.h 1764 2008-03-31 14:30:55Z kamenik $
|
||||||
// by 2005, Ondra Kamenik
|
// by 2005, Ondra Kamenik
|
||||||
|
|
||||||
#ifndef K_ORD_DYNARE3_H
|
#ifndef K_ORD_DYNARE3_H
|
||||||
#define K_ORD_DYNARE3_H
|
#define K_ORD_DYNARE3_H
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "t_container.h"
|
#include "t_container.h"
|
||||||
#include "sparse_tensor.h"
|
#include "sparse_tensor.h"
|
||||||
#include "decision_rule.h"
|
#include "decision_rule.h"
|
||||||
#include "dynamic_model.h"
|
#include "dynamic_model.h"
|
||||||
|
|
||||||
#include "exception.h"
|
#include "exception.h"
|
||||||
#include "dynare_exception.h"
|
#include "dynare_exception.h"
|
||||||
#include "fs_tensor.h"
|
#include "fs_tensor.h"
|
||||||
#include "SylvException.h"
|
#include "SylvException.h"
|
||||||
#include "tl_exception.h"
|
#include "tl_exception.h"
|
||||||
#include "kord_exception.h"
|
#include "kord_exception.h"
|
||||||
#include "nlsolve.h"
|
#include "nlsolve.h"
|
||||||
#include "approximation.h"
|
#include "approximation.h"
|
||||||
#include "k_order_perturbation.h"
|
#include "k_order_perturbation.h"
|
||||||
|
|
||||||
class KordpDynare;
|
class KordpDynare;
|
||||||
|
|
||||||
// derive from Approximation to get protected derivatives
|
/*////////////////////////////////////////////*/
|
||||||
/******
|
// instantiations of pure abstract class NameList in dynamic_model.h:
|
||||||
class FistOrderApproximation: public Approximation{
|
/*////////////////////////////////////////////*/
|
||||||
TwoDMatrix *gy;
|
class DynareNameList : public NameList {
|
||||||
TwoDMatrix *gu;
|
vector<const char*> names;
|
||||||
public:
|
public:
|
||||||
FistOrderApproximation();
|
DynareNameList(const KordpDynare& dynare);
|
||||||
FistOrderApproximation(FistOrderApproximation& fo): ::Approximation(fo){
|
DynareNameList(const KordpDynare& dynare, const char ** names);
|
||||||
if (&(fo.GetGy())!=0){
|
int getNum() const {return (int)names.size();}
|
||||||
gy= new TwoDMatrix(fo.GetGy());
|
const char* getName(int i) const {return names[i];}
|
||||||
gu= new TwoDMatrix(fo.GetGu());
|
/** This for each string of the input vector calculates its index
|
||||||
}
|
* in the names. And returns the resulting vector of indices. If
|
||||||
};
|
* the name cannot be found, then an exception is raised. */
|
||||||
virtual ~FistOrderApproximation(){
|
vector<int> selectIndices(const vector<const char*>& ns) const;
|
||||||
delete gy;
|
};
|
||||||
delete gu;
|
|
||||||
};
|
class DynareExogNameList : public NameList {
|
||||||
virtual void approxAtSteady(); // NOTE: change the Approximation parent to use virual too so that it can be overriden !!
|
vector<const char*> names;
|
||||||
//FGSContainer* GetRuleDers(){return rule_ders;};
|
public:
|
||||||
//FGSContainer* GetRuleDersSS(){return rule_ders_ss;};
|
DynareExogNameList(const KordpDynare& dynare);
|
||||||
const TwoDMatrix& GetGy(){return (const TwoDMatrix&)(*gy);};
|
DynareExogNameList(const KordpDynare& dynare, const char ** names);
|
||||||
const TwoDMatrix& GetGu(){return (const TwoDMatrix&)(*gu);};
|
int getNum() const
|
||||||
virtual void saveRuleDerivs(FirstOrder& fo);
|
{return (int)names.size();}
|
||||||
};
|
const char* getName(int i) const
|
||||||
***********/
|
{return names[i];}
|
||||||
|
};
|
||||||
|
|
||||||
|
class DynareStateNameList : public NameList {
|
||||||
/*////////////////////////////////////////////*/
|
vector<const char*> names;
|
||||||
// instantiations of pure abstract class NameList in dynamic_model.h:
|
public:
|
||||||
/*////////////////////////////////////////////*/
|
DynareStateNameList(const KordpDynare& dynare, const DynareNameList& dnl,
|
||||||
class DynareNameList : public NameList {
|
const DynareExogNameList& denl);
|
||||||
vector<const char*> names;
|
int getNum() const
|
||||||
public:
|
{return (int)names.size();}
|
||||||
DynareNameList(const KordpDynare& dynare);
|
const char* getName(int i) const
|
||||||
DynareNameList(const KordpDynare& dynare, const char ** names);
|
{return names[i];}
|
||||||
int getNum() const {return (int)names.size();}
|
};
|
||||||
const char* getName(int i) const {return names[i];}
|
/*********************************************/
|
||||||
/** This for each string of the input vector calculates its index
|
// The following only implements DynamicModel with help of ogdyn::DynareModel
|
||||||
* in the names. And returns the resulting vector of indices. If
|
// instantiation of pure abstract DynamicModel decl. in dynamic_model.h
|
||||||
* the name cannot be found, then an exception is raised. */
|
//class DynamicModelDLL;
|
||||||
vector<int> selectIndices(const vector<const char*>& ns) const;
|
class KordpJacobian;
|
||||||
};
|
class KordpDynare : public DynamicModel {
|
||||||
|
friend class DynareNameList;
|
||||||
class DynareExogNameList : public NameList {
|
friend class DynareExogNameList;
|
||||||
vector<const char*> names;
|
friend class DynareStateNameList;
|
||||||
public:
|
friend class KordpDynareJacobian;
|
||||||
DynareExogNameList(const KordpDynare& dynare);
|
friend class DynamicModelDLL;
|
||||||
DynareExogNameList(const KordpDynare& dynare, const char ** names);
|
//////////
|
||||||
int getNum() const
|
const int nStat;
|
||||||
{return (int)names.size();}
|
const int nBoth;
|
||||||
const char* getName(int i) const
|
const int nPred;
|
||||||
{return names[i];}
|
const int nForw;
|
||||||
};
|
const int nExog;
|
||||||
|
const int nPar;
|
||||||
class DynareStateNameList : public NameList {
|
const int nYs; // ={npred + nboth ; }
|
||||||
vector<const char*> names;
|
const int nYss; // nyss ={ nboth + nforw ; }
|
||||||
public:
|
const int nY; // = num_endo={ nstat + npred + nboth + nforw ; }
|
||||||
DynareStateNameList(const KordpDynare& dynare, const DynareNameList& dnl,
|
const int nJcols; // no of jacobian columns= nExog+nEndo+nsPred+nsForw
|
||||||
const DynareExogNameList& denl);
|
const int nSteps;
|
||||||
int getNum() const
|
const int nOrder;
|
||||||
{return (int)names.size();}
|
Journal& journal;
|
||||||
const char* getName(int i) const
|
/// DynamicModel* model;
|
||||||
{return names[i];}
|
///const char* modName;
|
||||||
};
|
Vector* ySteady;
|
||||||
/*********************************************/
|
Vector* params;
|
||||||
// The following only implements DynamicModel with help of ogdyn::DynareModel
|
TwoDMatrix* vCov;
|
||||||
// instantiation of pure abstract DynamicModel decl. in dynamic_model.h
|
TensorContainer<FSSparseTensor> md; // ModelDerivatives
|
||||||
//class DynamicModelDLL;
|
DynareNameList* dnl;
|
||||||
class KordpJacobian;
|
DynareExogNameList* denl;
|
||||||
class KordpDynare : public DynamicModel {
|
DynareStateNameList* dsnl;
|
||||||
friend class DynareNameList;
|
const double ss_tol;
|
||||||
friend class DynareExogNameList;
|
const vector<int>* varOrder;
|
||||||
friend class DynareStateNameList;
|
const TwoDMatrix * ll_Incidence;
|
||||||
friend class KordpDynareJacobian;
|
double qz_criterium;
|
||||||
friend class DynamicModelDLL;
|
vector<int> * JacobianIndices;
|
||||||
//////////
|
public:
|
||||||
const int nStat;
|
KordpDynare(const char** endo, int num_endo,
|
||||||
const int nBoth;
|
const char** exo, int num_exo, int num_par, //const char** par,
|
||||||
const int nPred;
|
Vector* ySteady, TwoDMatrix* vCov, Vector* params, int nstat,int nPred,
|
||||||
const int nForw;
|
int nforw, int nboth, const int nJcols, const int nSteps, const int ord, //const char* modName,
|
||||||
const int nExog;
|
Journal& jr, DynamicModelDLL& dynamicDLL, double sstol,
|
||||||
const int nPar;
|
const vector<int>* varOrder, const TwoDMatrix * ll_Incidence,
|
||||||
const int nYs; // ={npred + nboth ; }
|
double qz_criterium );
|
||||||
const int nYss; // nyss ={ nboth + nforw ; }
|
|
||||||
const int nY; // = num_endo={ nstat + npred + nboth + nforw ; }
|
/** Makes a deep copy of the object. */
|
||||||
const int nJcols; // no of jacobian columns= nExog+nEndo+nsPred+nsForw
|
KordpDynare(const KordpDynare& dyn);
|
||||||
const int nSteps;
|
virtual ~KordpDynare();
|
||||||
const int nOrder;
|
int nstat() const
|
||||||
Journal& journal;
|
{return nStat;}
|
||||||
/// DynamicModel* model;
|
int nboth() const
|
||||||
///const char* modName;
|
{return nBoth;}
|
||||||
Vector* ySteady;
|
int npred() const
|
||||||
Vector* params;
|
{return nPred;}
|
||||||
TwoDMatrix* vCov;
|
int nforw() const
|
||||||
TensorContainer<FSSparseTensor> md; // ModelDerivatives
|
{return nForw;}
|
||||||
DynareNameList* dnl;
|
int nexog() const
|
||||||
DynareExogNameList* denl;
|
{return nExog;}
|
||||||
DynareStateNameList* dsnl;
|
int nys() const
|
||||||
const double ss_tol;
|
{return nYs;}
|
||||||
const vector<int>* varOrder;
|
int nyss() const
|
||||||
const TwoDMatrix * ll_Incidence;
|
{return nYss;}
|
||||||
double qz_criterium;
|
int ny() const
|
||||||
vector<int> * JacobianIndices;
|
{return nY;}
|
||||||
public:
|
int steps() const
|
||||||
KordpDynare(const char** endo, int num_endo,
|
{return nSteps;}
|
||||||
const char** exo, int num_exo, int num_par, //const char** par,
|
int order() const
|
||||||
Vector* ySteady, TwoDMatrix* vCov, Vector* params, int nstat,int nPred,
|
{return nOrder;}
|
||||||
int nforw, int nboth, const int nJcols, const int nSteps, const int ord, //const char* modName,
|
const NameList& getAllEndoNames() const
|
||||||
Journal& jr, DynamicModelDLL& dynamicDLL, double sstol,
|
{return *dnl;}
|
||||||
const vector<int>* varOrder, const TwoDMatrix * ll_Incidence,
|
const NameList& getStateNames() const
|
||||||
double qz_criterium );
|
{return *dsnl;}
|
||||||
|
const NameList& getExogNames() const
|
||||||
/** Makes a deep copy of the object. */
|
{return *denl;}
|
||||||
KordpDynare(const KordpDynare& dyn);
|
const TwoDMatrix& getVcov() const
|
||||||
virtual ~KordpDynare();
|
{return *vCov;}
|
||||||
int nstat() const
|
Vector& getParams()
|
||||||
{return nStat;}
|
{return *params;}
|
||||||
int nboth() const
|
|
||||||
{return nBoth;}
|
const TensorContainer<FSSparseTensor>& getModelDerivatives() const
|
||||||
int npred() const
|
{return md;}
|
||||||
{return nPred;}
|
const Vector& getSteady() const
|
||||||
int nforw() const
|
{return *ySteady;}
|
||||||
{return nForw;}
|
Vector& getSteady()
|
||||||
int nexog() const
|
{return *ySteady;}
|
||||||
{return nExog;}
|
|
||||||
int nys() const
|
// here is true public interface
|
||||||
{return nYs;}
|
void solveDeterministicSteady(Vector& steady);
|
||||||
int nyss() const
|
void solveDeterministicSteady()
|
||||||
{return nYss;}
|
{solveDeterministicSteady(*ySteady);}
|
||||||
int ny() const
|
void evaluateSystem(Vector& out, const Vector& yy, const Vector& xx);
|
||||||
{return nY;}
|
void evaluateSystem(Vector& out, const Vector& yym, const Vector& yy,
|
||||||
int steps() const
|
const Vector& yyp, const Vector& xx);
|
||||||
{return nSteps;}
|
void calcDerivatives(const Vector& yy, const Vector& xx);
|
||||||
int order() const
|
//void calcDerivatives(const Vector& yy, TwoDMatrix& jj);
|
||||||
{return nOrder;}
|
void calcDerivatives(const Vector& yy, ogu::Jacobian& jacob);
|
||||||
const NameList& getAllEndoNames() const
|
void calcDerivativesAtSteady();
|
||||||
{return *dnl;}
|
DynamicModelDLL& dynamicDLL;
|
||||||
const NameList& getStateNames() const
|
/// void writeMat4(FILE* fd, const char* prefix) const;
|
||||||
{return *dsnl;}
|
/// void writeDump(const std::string& basename) const;
|
||||||
const NameList& getExogNames() const
|
DynamicModel* clone() const
|
||||||
{return *denl;}
|
{return new KordpDynare(*this);}
|
||||||
const TwoDMatrix& getVcov() const
|
void ReorderCols(TwoDMatrix * tdx, const int * varOrder);
|
||||||
{return *vCov;}
|
void ReorderCols(TwoDMatrix * tdx, const vector<int> * varOrder);
|
||||||
Vector& getParams()
|
Vector * LLxSteady( const Vector& yS); // returns ySteady extended with leads and lags
|
||||||
{return *params;}
|
|
||||||
|
private:
|
||||||
const TensorContainer<FSSparseTensor>& getModelDerivatives() const
|
void writeModelInfo(Journal& jr) const;
|
||||||
{return md;}
|
int * ReorderDynareJacobianIndices( const int * varOrder);
|
||||||
const Vector& getSteady() const
|
vector<int> * ReorderDynareJacobianIndices( const vector<int> * varOrder);
|
||||||
{return *ySteady;}
|
void ReorderBlocks(TwoDMatrix * tdx, const int * varOrder);
|
||||||
Vector& getSteady()
|
void ReorderBlocks(TwoDMatrix * tdx, const vector<int> * vOrder);
|
||||||
{return *ySteady;}
|
void populateDerivativesContainer(TwoDMatrix*g, int ord, const vector<int>* vOrder);
|
||||||
/// const ogdyn::DynareModel& getModel() const
|
};
|
||||||
/// {return *model;}
|
|
||||||
|
/****************************
|
||||||
// here is true public interface
|
* ModelDerivativeContainer manages derivatives container
|
||||||
void solveDeterministicSteady(Vector& steady);
|
************************************/
|
||||||
void solveDeterministicSteady()
|
|
||||||
{solveDeterministicSteady(*ySteady);}
|
class ModelDerivativeContainer //: public ogp::FormulaDerEvalLoader
|
||||||
void evaluateSystem(Vector& out, const Vector& yy, const Vector& xx);
|
{
|
||||||
void evaluateSystem(Vector& out, const Vector& yym, const Vector& yy,
|
protected:
|
||||||
const Vector& yyp, const Vector& xx);
|
// const ogp::FineAtoms& atoms;
|
||||||
void calcDerivatives(const Vector& yy, const Vector& xx);
|
TensorContainer<FSSparseTensor>& md;
|
||||||
//void calcDerivatives(const Vector& yy, TwoDMatrix& jj);
|
public:
|
||||||
void calcDerivatives(const Vector& yy, ogu::Jacobian& jacob);
|
ModelDerivativeContainer(const KordpDynare& model, TensorContainer<FSSparseTensor>& mod_ders,
|
||||||
void calcDerivativesAtSteady();
|
int order);
|
||||||
DynamicModelDLL& dynamicDLL;
|
void load(int i, int iord, const int* vars, double res);
|
||||||
/// void writeMat4(FILE* fd, const char* prefix) const;
|
};
|
||||||
/// void writeDump(const std::string& basename) const;
|
|
||||||
DynamicModel* clone() const
|
/****************************
|
||||||
{return new KordpDynare(*this);}
|
* K-Order Perturbation instance of Jacobian:
|
||||||
void ReorderCols(TwoDMatrix * tdx, const int * varOrder);
|
************************************/
|
||||||
void ReorderCols(TwoDMatrix * tdx, const vector<int> * varOrder);
|
|
||||||
Vector * LLxSteady( const Vector& yS); // returns ySteady extended with leads and lags
|
class KordpJacobian : public ogu::Jacobian ///, public ogp::FormulaDerEvalLoader
|
||||||
|
{
|
||||||
private:
|
protected:
|
||||||
void writeModelInfo(Journal& jr) const;
|
KordpDynare& dyn;
|
||||||
int * ReorderDynareJacobianIndices( const int * varOrder);
|
public:
|
||||||
vector<int> * ReorderDynareJacobianIndices( const vector<int> * varOrder);
|
KordpJacobian( KordpDynare& dyn);
|
||||||
void ReorderBlocks(TwoDMatrix * tdx, const int * varOrder);
|
virtual ~KordpJacobian() {}
|
||||||
void ReorderBlocks(TwoDMatrix * tdx, const vector<int> * vOrder);
|
// Load <mod>_dynamic.DLL
|
||||||
void populateDerivativesContainer(TwoDMatrix*g, int ord, const vector<int>* vOrder);
|
// void load(const char** modName);
|
||||||
};
|
void eval(const Vector& in);
|
||||||
|
};
|
||||||
/****************************
|
|
||||||
* ModelDerivativeContainer manages derivatives container
|
|
||||||
************************************/
|
/****************************
|
||||||
|
* K-Order Perturbation instance of VectorFunction:
|
||||||
class ModelDerivativeContainer //: public ogp::FormulaDerEvalLoader
|
************************************/
|
||||||
{
|
|
||||||
protected:
|
class KordpVectorFunction : public ogu::VectorFunction {
|
||||||
// const ogp::FineAtoms& atoms;
|
protected:
|
||||||
TensorContainer<FSSparseTensor>& md;
|
KordpDynare& d;
|
||||||
public:
|
public:
|
||||||
ModelDerivativeContainer(const KordpDynare& model, TensorContainer<FSSparseTensor>& mod_ders,
|
KordpVectorFunction( KordpDynare& dyn)
|
||||||
int order);
|
: d(dyn) {}
|
||||||
void load(int i, int iord, const int* vars, double res);
|
virtual ~KordpVectorFunction() {}
|
||||||
};
|
int inDim() const
|
||||||
|
{return d.ny();}
|
||||||
/****************************
|
int outDim() const
|
||||||
* K-Order Perturbation instance of Jacobian:
|
{return d.ny();}
|
||||||
************************************/
|
void eval(const ConstVector& in, Vector& out);
|
||||||
|
};
|
||||||
class KordpJacobian : public ogu::Jacobian ///, public ogp::FormulaDerEvalLoader
|
|
||||||
{
|
#endif
|
||||||
protected:
|
|
||||||
KordpDynare& dyn;
|
|
||||||
public:
|
|
||||||
KordpJacobian( KordpDynare& dyn);
|
|
||||||
virtual ~KordpJacobian() {}
|
|
||||||
// Load <mod>_dynamic.DLL
|
|
||||||
// void load(const char** modName);
|
|
||||||
void eval(const Vector& in);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/****************************
|
|
||||||
* K-Order Perturbation instance of VectorFunction:
|
|
||||||
************************************/
|
|
||||||
|
|
||||||
class KordpVectorFunction : public ogu::VectorFunction {
|
|
||||||
protected:
|
|
||||||
KordpDynare& d;
|
|
||||||
public:
|
|
||||||
KordpVectorFunction( KordpDynare& dyn)
|
|
||||||
: d(dyn) {}
|
|
||||||
virtual ~KordpVectorFunction() {}
|
|
||||||
int inDim() const
|
|
||||||
{return d.ny();}
|
|
||||||
int outDim() const
|
|
||||||
{return d.ny();}
|
|
||||||
void eval(const ConstVector& in, Vector& out);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Local Variables:
|
|
||||||
// mode:C++
|
|
||||||
// End:
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,110 +1,108 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2008-2009 Dynare Team
|
* Copyright (C) 2008-2009 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
* Dynare is free software: you can redistribute it and/or modify
|
* Dynare is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Dynare is distributed in the hope that it will be useful,
|
* Dynare is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// The following ifdef block is the standard way of creating macros which make exporting
|
// The following ifdef block is the standard way of creating macros which make exporting
|
||||||
// from a DLL simpler. All files within this DLL are compiled with the K_ORDER_PERTURBATION_EXPORTS
|
// from a DLL simpler. All files within this DLL are compiled with the K_ORDER_PERTURBATION_EXPORTS
|
||||||
// symbol defined on the command line. this symbol should not be defined on any project
|
// symbol defined on the command line. this symbol should not be defined on any project
|
||||||
// that uses this DLL. This way any other project whose source files include this file see
|
// that uses this DLL. This way any other project whose source files include this file see
|
||||||
// K_ORDER_PERTURBATION_API functions as being imported from a DLL, wheras this DLL sees symbols
|
// K_ORDER_PERTURBATION_API functions as being imported from a DLL, wheras this DLL sees symbols
|
||||||
// defined with this macro as being exported.
|
// defined with this macro as being exported.
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
#ifdef K_ORDER_PERTURBATION_EXPORTS
|
#ifdef K_ORDER_PERTURBATION_EXPORTS
|
||||||
#define K_ORDER_PERTURBATION_API __declspec(dllexport)
|
#define K_ORDER_PERTURBATION_API __declspec(dllexport)
|
||||||
#else
|
#else
|
||||||
#define K_ORDER_PERTURBATION_API __declspec(dllimport)
|
#define K_ORDER_PERTURBATION_API __declspec(dllimport)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#include <dlfcn.h> // unix/linux DLL (.so) handling routines
|
#include <dlfcn.h> // unix/linux DLL (.so) handling routines
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "mex.h"
|
#include "mex.h"
|
||||||
|
|
||||||
// <model>_Dynamic DLL pointer
|
// <model>_Dynamic DLL pointer
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
typedef void *(DynamicFn)
|
typedef void *(DynamicFn)
|
||||||
#else // linux
|
#else // linux
|
||||||
typedef void (*DynamicFn)
|
typedef void (*DynamicFn)
|
||||||
#endif
|
#endif
|
||||||
(double *y, double *x, int nb_row_x, double *params,
|
(double *y, double *x, int nb_row_x, double *params,
|
||||||
int it_, double *residual, double *g1, double *g2);
|
int it_, double *residual, double *g1, double *g2);
|
||||||
|
|
||||||
//DynamicFn Dynamic;
|
//DynamicFn Dynamic;
|
||||||
|
|
||||||
typedef void *(mexFunctionPtr)(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]);
|
typedef void *(mexFunctionPtr)(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]);
|
||||||
|
|
||||||
const int MAX_MODEL_NAME=100;
|
const int MAX_MODEL_NAME=100;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates pointer to Dynamic function inside <model>_dynamic.dll
|
* creates pointer to Dynamic function inside <model>_dynamic.dll
|
||||||
* and handles calls to it.
|
* and handles calls to it.
|
||||||
**/
|
**/
|
||||||
class DynamicModelDLL
|
class DynamicModelDLL
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
DynamicFn *Dynamic;// pointer to the Dynamic function in DLL
|
DynamicFn *Dynamic;// pointer to the Dynamic function in DLL
|
||||||
#else
|
#else
|
||||||
DynamicFn Dynamic;// pointer to the Dynamic function in DLL
|
DynamicFn Dynamic;// pointer to the Dynamic function in DLL
|
||||||
#endif
|
#endif
|
||||||
const int length; // tot num vars = Num of Jacobian rows
|
const int length; // tot num vars = Num of Jacobian rows
|
||||||
const int jcols; // tot num var t-1, t and t+1 instances + exogs = Num of Jacobian columns
|
const int jcols; // tot num var t-1, t and t+1 instances + exogs = Num of Jacobian columns
|
||||||
const int nMax_lag; // no of lags
|
const int nMax_lag; // no of lags
|
||||||
const int nExog; // no of exogenous
|
const int nExog; // no of exogenous
|
||||||
// const char * sExt; // dynamic file extension: dll, mexw32, ...
|
// const char * sExt; // dynamic file extension: dll, mexw32, ...
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
HINSTANCE dynamicHinstance; // DLL instance pointer in Windows
|
HINSTANCE dynamicHinstance; // DLL instance pointer in Windows
|
||||||
# else // linux
|
# else // linux
|
||||||
void * dynamicHinstance ; // and in Linux
|
void * dynamicHinstance ; // and in Linux
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// construct and load Dynamic model DLL
|
// construct and load Dynamic model DLL
|
||||||
DynamicModelDLL(const char* fname, const int length,const int jcols,
|
DynamicModelDLL(const char* fname, const int length,const int jcols,
|
||||||
const int nMax_lag, const int nExog, const char * sExt);
|
const int nMax_lag, const int nExog, const char * sExt);
|
||||||
virtual ~DynamicModelDLL(){close();};
|
virtual ~DynamicModelDLL(){close();};
|
||||||
// DynamicFn get(){return DynamicDLLfunc;};
|
|
||||||
// void
|
// evaluate Dynamic model DLL
|
||||||
// ((DynamicFn())*) get(){return Dynamic;};
|
void eval(double *y, double *x, int nb_row_x, double *params,
|
||||||
// evaluate Dynamic model DLL
|
int it_, double *residual, double *g1, double *g2){
|
||||||
void eval(double *y, double *x, int nb_row_x, double *params,
|
Dynamic(y, x, nb_row_x, params, it_, residual, g1, g2);
|
||||||
int it_, double *residual, double *g1, double *g2){
|
};
|
||||||
Dynamic(y, x, nb_row_x, params, it_, residual, g1, g2);
|
void eval(const Vector&y, const Vector&x, const Vector* params,
|
||||||
};
|
Vector&residual, TwoDMatrix*g1, TwoDMatrix*g2);
|
||||||
void eval(const Vector&y, const Vector&x, const Vector* params,
|
void eval(const Vector&y, const TwoDMatrix&x, const Vector* params,
|
||||||
Vector&residual, TwoDMatrix*g1, TwoDMatrix*g2);
|
int it_, Vector&residual, TwoDMatrix*g1, TwoDMatrix*g2);
|
||||||
void eval(const Vector&y, const TwoDMatrix&x, const Vector* params,
|
void eval(const Vector&y, const TwoDMatrix&x, const Vector* params,
|
||||||
int it_, Vector&residual, TwoDMatrix*g1, TwoDMatrix*g2);
|
Vector& residual, TwoDMatrix *g1, TwoDMatrix *g2);
|
||||||
void eval(const Vector&y, const TwoDMatrix&x, const Vector* params,
|
// void eval(const Vector&y, const TwoDMatrix&x, const Vector* params,
|
||||||
Vector& residual, TwoDMatrix *g1, TwoDMatrix *g2);
|
// Vector& residual, double *g1, double *g2);
|
||||||
// void eval(const Vector&y, const TwoDMatrix&x, const Vector* params,
|
// close DLL: If the referenced object was successfully closed,
|
||||||
// Vector& residual, double *g1, double *g2);
|
// close() returns 0, non 0 otherwise
|
||||||
// close DLL: If the referenced object was successfully closed,
|
int close();
|
||||||
// close() returns 0, non 0 otherwise
|
|
||||||
int close();
|
};
|
||||||
|
// convert Matlab endo and exo names array to C type array of strings
|
||||||
};
|
const char ** DynareMxArrayToString(const mxArray * mxFldp, const int len, const int width );
|
||||||
// convert Matlab endo and exo names array to C type array of strings
|
const char ** DynareMxArrayToString(const char * cArray, const int len, const int width );
|
||||||
const char ** DynareMxArrayToString(const mxArray * mxFldp, const int len, const int width );
|
|
||||||
const char ** DynareMxArrayToString(const char * cArray, const int len, const int width );
|
|
||||||
|
|
|
@ -1,324 +1,324 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2008-2009 Dynare Team
|
* Copyright (C) 2008-2009 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
* Dynare is free software: you can redistribute it and/or modify
|
* Dynare is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Dynare is distributed in the hope that it will be useful,
|
* Dynare is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*************************************
|
/*************************************
|
||||||
* This main() is for testing k_order DLL entry point by linking to
|
* This main() is for testing k_order DLL entry point by linking to
|
||||||
* the k_ord library statically and passing its hard-coded data:
|
* the k_ord library statically and passing its hard-coded data:
|
||||||
* parameters, covar, ysteady and the variable names from fs2000a.mod model
|
* parameters, covar, ysteady and the variable names from fs2000a.mod model
|
||||||
* The main has been derived from mxFunction used for K-Order DLL
|
* The main has been derived from mxFunction used for K-Order DLL
|
||||||
***************************************/
|
***************************************/
|
||||||
|
|
||||||
//#include "stdafx.h"
|
//#include "stdafx.h"
|
||||||
#include "k_ord_dynare.h"
|
#include "k_ord_dynare.h"
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
double qz_criterium = 1+1e-6;
|
double qz_criterium = 1+1e-6;
|
||||||
const int check_flag = 0;
|
const int check_flag = 0;
|
||||||
const char* fName = "fs2000k";//mxArrayToString(mFname);
|
const char* fName = "fs2000k";//mxArrayToString(mFname);
|
||||||
const char * dfExt=NULL ;//Dyanamic file extension, e.g.".dll";
|
const char * dfExt=NULL ;//Dyanamic file extension, e.g.".dll";
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
mexPrintf("k_order_perturbation: check_flag = %d , fName = %s .\n", check_flag,fName);
|
mexPrintf("k_order_perturbation: check_flag = %d , fName = %s .\n", check_flag,fName);
|
||||||
#endif
|
#endif
|
||||||
int kOrder =2;
|
int kOrder =2;
|
||||||
int npar = 7;//(int)mxGetM(mxFldp);
|
int npar = 7;//(int)mxGetM(mxFldp);
|
||||||
double dparams[7]={ 0.3300,
|
double dparams[7]={ 0.3300,
|
||||||
0.9900,
|
0.9900,
|
||||||
0.0030,
|
0.0030,
|
||||||
1.0110,
|
1.0110,
|
||||||
0.7000,
|
0.7000,
|
||||||
0.7870,
|
0.7870,
|
||||||
0.0200
|
0.0200
|
||||||
};
|
};
|
||||||
Vector * modParams = new Vector(dparams, npar);
|
Vector * modParams = new Vector(dparams, npar);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
mexPrintf("k_ord_perturbation: nParams=%d .\n",npar);
|
mexPrintf("k_ord_perturbation: nParams=%d .\n",npar);
|
||||||
for (int i = 0; i < npar; i++) {
|
for (int i = 0; i < npar; i++) {
|
||||||
mexPrintf("k_ord_perturbation: dParams[%d]= %g.\n", i, dparams+i*(sizeof(double)) ); }
|
mexPrintf("k_ord_perturbation: dParams[%d]= %g.\n", i, dparams+i*(sizeof(double)) ); }
|
||||||
for (int i = 0; i < npar; i++) {
|
for (int i = 0; i < npar; i++) {
|
||||||
mexPrintf("k_ord_perturbation: Params[%d]= %g.\n", i, (*modParams)[i]); }
|
mexPrintf("k_ord_perturbation: Params[%d]= %g.\n", i, (*modParams)[i]); }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
double d2Dparams[4] = { //(double *) mxGetData(mxFldp);
|
double d2Dparams[4] = { //(double *) mxGetData(mxFldp);
|
||||||
0.1960e-3, 0.0,
|
0.1960e-3, 0.0,
|
||||||
0.0, 0.0250e-3};
|
0.0, 0.0250e-3};
|
||||||
npar = 2;//(int)mxGetN(mxFldp);
|
npar = 2;//(int)mxGetN(mxFldp);
|
||||||
TwoDMatrix * vCov = new TwoDMatrix(npar, npar, (d2Dparams));
|
TwoDMatrix * vCov = new TwoDMatrix(npar, npar, (d2Dparams));
|
||||||
double dYSparams [16]= { // 27 mxGetData(mxFldp);
|
double dYSparams [16]= { // 27 mxGetData(mxFldp);
|
||||||
// 1.0110, 2.2582, 5.8012, 0.5808,
|
// 1.0110, 2.2582, 5.8012, 0.5808,
|
||||||
1.0110, 2.2582, 0.4477, 1.0000
|
1.0110, 2.2582, 0.4477, 1.0000
|
||||||
, 4.5959, 1.0212, 5.8012, 0.8494
|
, 4.5959, 1.0212, 5.8012, 0.8494
|
||||||
, 0.1872, 0.8604, 1.0030, 1.0080
|
, 0.1872, 0.8604, 1.0030, 1.0080
|
||||||
, 0.5808, 1.0030, 2.2582, 0.4477
|
, 0.5808, 1.0030, 2.2582, 0.4477
|
||||||
//, 1.0110, 2.2582, 0.4477, 1.0000, 0.1872, 2.2582, 0.4477
|
//, 1.0110, 2.2582, 0.4477, 1.0000, 0.1872, 2.2582, 0.4477
|
||||||
};
|
};
|
||||||
const int nSteady = 16;//27 //31;//29, 16 (int)mxGetM(mxFldp);
|
const int nSteady = 16;//27 //31;//29, 16 (int)mxGetM(mxFldp);
|
||||||
Vector * ySteady = new Vector(dYSparams, nSteady);
|
Vector * ySteady = new Vector(dYSparams, nSteady);
|
||||||
|
|
||||||
|
|
||||||
//mxFldp = mxGetField(dr, 0,"nstatic" );
|
//mxFldp = mxGetField(dr, 0,"nstatic" );
|
||||||
const int nStat = 7;//(int)mxGetScalar(mxFldp);
|
const int nStat = 7;//(int)mxGetScalar(mxFldp);
|
||||||
// mxFldp = mxGetField(dr, 0,"npred" );
|
// mxFldp = mxGetField(dr, 0,"npred" );
|
||||||
const int nPred = 2;//6 - nBoth (int)mxGetScalar(mxFldp);
|
const int nPred = 2;//6 - nBoth (int)mxGetScalar(mxFldp);
|
||||||
//mxFldp = mxGetField(dr, 0,"nspred" );
|
//mxFldp = mxGetField(dr, 0,"nspred" );
|
||||||
const int nsPred = 4;//(int)mxGetScalar(mxFldp);
|
const int nsPred = 4;//(int)mxGetScalar(mxFldp);
|
||||||
//mxFldp = mxGetField(dr, 0,"nboth" );
|
//mxFldp = mxGetField(dr, 0,"nboth" );
|
||||||
const int nBoth = 2;// (int)mxGetScalar(mxFldp);
|
const int nBoth = 2;// (int)mxGetScalar(mxFldp);
|
||||||
//mxFldp = mxGetField(dr, 0,"nfwrd" );
|
//mxFldp = mxGetField(dr, 0,"nfwrd" );
|
||||||
const int nForw = 5;// 3 (int)mxGetScalar(mxFldp);
|
const int nForw = 5;// 3 (int)mxGetScalar(mxFldp);
|
||||||
//mxFldp = mxGetField(dr, 0,"nsfwrd" );
|
//mxFldp = mxGetField(dr, 0,"nsfwrd" );
|
||||||
const int nsForw = 7;//(int)mxGetScalar(mxFldp);
|
const int nsForw = 7;//(int)mxGetScalar(mxFldp);
|
||||||
|
|
||||||
//mxFldp = mxGetField(M_, 0,"exo_nbr" );
|
//mxFldp = mxGetField(M_, 0,"exo_nbr" );
|
||||||
const int nExog =2;// (int)mxGetScalar(mxFldp);
|
const int nExog =2;// (int)mxGetScalar(mxFldp);
|
||||||
//mxFldp = mxGetField(M_, 0,"endo_nbr" );
|
//mxFldp = mxGetField(M_, 0,"endo_nbr" );
|
||||||
const int nEndo = 16;//16(int)mxGetScalar(mxFldp);
|
const int nEndo = 16;//16(int)mxGetScalar(mxFldp);
|
||||||
//mxFldp = mxGetField(M_, 0,"param_nbr" );
|
//mxFldp = mxGetField(M_, 0,"param_nbr" );
|
||||||
const int nPar = 7;//(int)mxGetScalar(mxFldp);
|
const int nPar = 7;//(int)mxGetScalar(mxFldp);
|
||||||
// it_ should be set to M_.maximum_lag
|
// it_ should be set to M_.maximum_lag
|
||||||
//mxFldp = mxGetField(M_, 0,"maximum_lag" );
|
//mxFldp = mxGetField(M_, 0,"maximum_lag" );
|
||||||
const int nMax_lag = 1;//(int)mxGetScalar(mxFldp);
|
const int nMax_lag = 1;//(int)mxGetScalar(mxFldp);
|
||||||
|
|
||||||
int var_order[]//[18]
|
int var_order[]//[18]
|
||||||
= {
|
= {
|
||||||
5, 6, 8, 10, 11, 12, 14, 7, 13, 1, 2, 3, 4, 9, 15, 16
|
5, 6, 8, 10, 11, 12, 14, 7, 13, 1, 2, 3, 4, 9, 15, 16
|
||||||
// 5, 6, 8, 10, 11, 12, 16, 7, 13, 14, 15, 1, 2, 3, 4, 9, 17, 18
|
// 5, 6, 8, 10, 11, 12, 16, 7, 13, 14, 15, 1, 2, 3, 4, 9, 17, 18
|
||||||
};
|
};
|
||||||
//Vector * varOrder = new Vector(var_order, nEndo);
|
//Vector * varOrder = new Vector(var_order, nEndo);
|
||||||
vector<int> * var_order_vp = new vector<int>(nEndo);//nEndo));
|
vector<int> * var_order_vp = new vector<int>(nEndo);//nEndo));
|
||||||
for (int v=0;v<nEndo;v++)
|
for (int v=0;v<nEndo;v++)
|
||||||
(*var_order_vp)[v] =var_order[v];
|
(*var_order_vp)[v] =var_order[v];
|
||||||
|
|
||||||
const double ll_incidence []//[3][18]
|
const double ll_incidence []//[3][18]
|
||||||
= {
|
= {
|
||||||
1, 5, 21
|
1, 5, 21
|
||||||
, 2, 6, 22
|
, 2, 6, 22
|
||||||
, 0, 7, 23
|
, 0, 7, 23
|
||||||
, 0, 8, 24
|
, 0, 8, 24
|
||||||
, 0, 9, 0
|
, 0, 9, 0
|
||||||
, 0, 10, 0
|
, 0, 10, 0
|
||||||
, 3, 11, 0
|
, 3, 11, 0
|
||||||
, 0, 12, 0
|
, 0, 12, 0
|
||||||
, 0, 13, 25
|
, 0, 13, 25
|
||||||
, 0, 14, 0
|
, 0, 14, 0
|
||||||
, 0, 15, 0
|
, 0, 15, 0
|
||||||
, 0, 16, 0
|
, 0, 16, 0
|
||||||
, 4, 17, 0
|
, 4, 17, 0
|
||||||
, 0, 18, 0
|
, 0, 18, 0
|
||||||
, 0, 19, 26
|
, 0, 19, 26
|
||||||
, 0, 20, 27
|
, 0, 20, 27
|
||||||
};
|
};
|
||||||
TwoDMatrix * llincidence = new TwoDMatrix ( 3, nEndo, ll_incidence );
|
TwoDMatrix * llincidence = new TwoDMatrix ( 3, nEndo, ll_incidence );
|
||||||
|
|
||||||
const int jcols = nExog+nEndo+nsPred+nsForw; // Num of Jacobian columns
|
const int jcols = nExog+nEndo+nsPred+nsForw; // Num of Jacobian columns
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
mexPrintf("k_order_perturbation: jcols= %d .\n", jcols);
|
mexPrintf("k_order_perturbation: jcols= %d .\n", jcols);
|
||||||
#endif
|
#endif
|
||||||
//mxFldp= mxGetField(M_, 0,"endo_names" );
|
//mxFldp= mxGetField(M_, 0,"endo_names" );
|
||||||
const int nendo = 16;//16(int)mxGetM(mxFldp);
|
const int nendo = 16;//16(int)mxGetM(mxFldp);
|
||||||
const int widthEndo = 6;// (int)mxGetN(mxFldp);
|
const int widthEndo = 6;// (int)mxGetN(mxFldp);
|
||||||
const char * cNamesCharStr= "mPceWRkdnlggydPc yp A22 __ oo bb ss ";
|
const char * cNamesCharStr= "mPceWRkdnlggydPc yp A22 __ oo bb ss ";
|
||||||
// const char** endoNamesMX= DynareMxArrayToString( mxFldp,nendo,widthEndo);
|
// const char** endoNamesMX= DynareMxArrayToString( mxFldp,nendo,widthEndo);
|
||||||
const char** endoNamesMX= DynareMxArrayToString( cNamesCharStr, nendo, widthEndo);
|
const char** endoNamesMX= DynareMxArrayToString( cNamesCharStr, nendo, widthEndo);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
for (int i = 0; i < nEndo; i++) {
|
for (int i = 0; i < nEndo; i++) {
|
||||||
mexPrintf("k_ord_perturbation: EndoNameList[%d][0]= %s.\n", i, endoNamesMX[i] );
|
mexPrintf("k_ord_perturbation: EndoNameList[%d][0]= %s.\n", i, endoNamesMX[i] );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
//mxFldp = mxGetField(M_, 0,"exo_names" );
|
//mxFldp = mxGetField(M_, 0,"exo_names" );
|
||||||
const int nexo = 2;//(int)mxGetM(mxFldp);
|
const int nexo = 2;//(int)mxGetM(mxFldp);
|
||||||
const int widthExog = 3;//(int)mxGetN(mxFldp);
|
const int widthExog = 3;//(int)mxGetN(mxFldp);
|
||||||
// const char** exoNamesMX= DynareMxArrayToString( mxFldp,nexo,widthExog);
|
// const char** exoNamesMX= DynareMxArrayToString( mxFldp,nexo,widthExog);
|
||||||
const char * cExoNamesCharStr= "ee__am";
|
const char * cExoNamesCharStr= "ee__am";
|
||||||
const char** exoNamesMX= DynareMxArrayToString( cExoNamesCharStr,nexo,widthExog);
|
const char** exoNamesMX= DynareMxArrayToString( cExoNamesCharStr,nexo,widthExog);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
for (int i = 0; i < nexo; i++) {
|
for (int i = 0; i < nexo; i++) {
|
||||||
mexPrintf("k_ord_perturbation: ExoNameList[%d][0]= %s.\n", i, exoNamesMX[i] );
|
mexPrintf("k_ord_perturbation: ExoNameList[%d][0]= %s.\n", i, exoNamesMX[i] );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if ((nEndo != nendo)||(nExog != nexo)) { //(nPar != npar)
|
if ((nEndo != nendo)||(nExog != nexo)) { //(nPar != npar)
|
||||||
mexErrMsgTxt("Incorrect number of input parameters.\n");
|
mexErrMsgTxt("Incorrect number of input parameters.\n");
|
||||||
//return;
|
//return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
for (int i = 0; i < nEndo; i++) {
|
for (int i = 0; i < nEndo; i++) {
|
||||||
mexPrintf("k_ord_perturbation: EndoNameList[%d]= %s.\n", i, endoNamesMX[i] ); }
|
mexPrintf("k_ord_perturbation: EndoNameList[%d]= %s.\n", i, endoNamesMX[i] ); }
|
||||||
// for (int i = 0; i < nPar; i++) {
|
// for (int i = 0; i < nPar; i++) {
|
||||||
//, , mexPrintf("k_ord_perturbation: params_vec[%d]= %g.\n", i, params_vec[i] ); }
|
//, , mexPrintf("k_ord_perturbation: params_vec[%d]= %g.\n", i, params_vec[i] ); }
|
||||||
for (int i = 0; i < nPar; i++) {
|
for (int i = 0; i < nPar; i++) {
|
||||||
mexPrintf("k_ord_perturbation: Params[%d]= %g.\n", i, (*modParams)[i]); }
|
mexPrintf("k_ord_perturbation: Params[%d]= %g.\n", i, (*modParams)[i]); }
|
||||||
for (int i = 0; i < nSteady; i++) {
|
for (int i = 0; i < nSteady; i++) {
|
||||||
mexPrintf("k_ord_perturbation: ysteady[%d]= %g.\n", i, (*ySteady)[i]); }
|
mexPrintf("k_ord_perturbation: ysteady[%d]= %g.\n", i, (*ySteady)[i]); }
|
||||||
|
|
||||||
mexPrintf("k_order_perturbation: nEndo = %d , nExo = %d .\n", nEndo,nExog);
|
mexPrintf("k_order_perturbation: nEndo = %d , nExo = %d .\n", nEndo,nExog);
|
||||||
#endif
|
#endif
|
||||||
/* Fetch time index */
|
/* Fetch time index */
|
||||||
// int it_ = (int) mxGetScalar(prhs[3]) - 1;
|
// int it_ = (int) mxGetScalar(prhs[3]) - 1;
|
||||||
|
|
||||||
const int nSteps =0; // Dynare++ solving steps, for time being default to 0 = deterministic steady state
|
const int nSteps =0; // Dynare++ solving steps, for time being default to 0 = deterministic steady state
|
||||||
const double sstol=1.e-13; //NL solver tolerance from
|
const double sstol=1.e-13; //NL solver tolerance from
|
||||||
|
|
||||||
THREAD_GROUP::max_parallel_threads = 1;//2 params.num_threads;
|
THREAD_GROUP::max_parallel_threads = 1;//2 params.num_threads;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// make journal name and journal
|
// make journal name and journal
|
||||||
std::string jName(fName); //params.basename);
|
std::string jName(fName); //params.basename);
|
||||||
jName += ".jnl";
|
jName += ".jnl";
|
||||||
Journal journal(jName.c_str());
|
Journal journal(jName.c_str());
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
mexPrintf("k_order_perturbation: Call tls init\n");
|
mexPrintf("k_order_perturbation: Call tls init\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
tls.init(kOrder, (nStat+2*nPred+3*nBoth+2*nForw+nExog));
|
tls.init(kOrder, (nStat+2*nPred+3*nBoth+2*nForw+nExog));
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
mexPrintf("k_order_perturbation: Calling dynamicDLL constructor.\n");
|
mexPrintf("k_order_perturbation: Calling dynamicDLL constructor.\n");
|
||||||
#endif
|
#endif
|
||||||
// DynamicFn * pDynamicFn = loadModelDynamicDLL (fname);
|
// DynamicFn * pDynamicFn = loadModelDynamicDLL (fname);
|
||||||
DynamicModelDLL dynamicDLL(fName, nEndo, jcols, nMax_lag, nExog, dfExt);
|
DynamicModelDLL dynamicDLL(fName, nEndo, jcols, nMax_lag, nExog, dfExt);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
mexPrintf("k_order_perturbation: Calling dynare constructor.\n");
|
mexPrintf("k_order_perturbation: Calling dynare constructor.\n");
|
||||||
#endif
|
#endif
|
||||||
// make KordpDynare object
|
// make KordpDynare object
|
||||||
KordpDynare dynare(endoNamesMX, nEndo, exoNamesMX, nExog, nPar // paramNames,
|
KordpDynare dynare(endoNamesMX, nEndo, exoNamesMX, nExog, nPar // paramNames,
|
||||||
, ySteady, vCov, modParams, nStat, nPred, nForw, nBoth
|
, ySteady, vCov, modParams, nStat, nPred, nForw, nBoth
|
||||||
, jcols, nSteps, kOrder, journal, dynamicDLL, sstol, var_order_vp //var_order
|
, jcols, nSteps, kOrder, journal, dynamicDLL, sstol, var_order_vp //var_order
|
||||||
, llincidence, qz_criterium);
|
, llincidence, qz_criterium);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
mexPrintf("k_order_perturbation: Call Approximation constructor \n");
|
mexPrintf("k_order_perturbation: Call Approximation constructor \n");
|
||||||
#endif
|
#endif
|
||||||
Approximation app(dynare, journal, nSteps, false, qz_criterium);
|
Approximation app(dynare, journal, nSteps, false, qz_criterium);
|
||||||
// run stochastic steady
|
// run stochastic steady
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
mexPrintf("k_order_perturbation: Calling walkStochSteady.\n");
|
mexPrintf("k_order_perturbation: Calling walkStochSteady.\n");
|
||||||
#endif
|
#endif
|
||||||
app.walkStochSteady();
|
app.walkStochSteady();
|
||||||
|
|
||||||
// open mat file
|
// open mat file
|
||||||
std::string matfile(fName);//(params.basename);
|
std::string matfile(fName);//(params.basename);
|
||||||
matfile += ".mat";
|
matfile += ".mat";
|
||||||
FILE* matfd = NULL;
|
FILE* matfd = NULL;
|
||||||
if (NULL == (matfd=fopen(matfile.c_str(), "wb"))) {
|
if (NULL == (matfd=fopen(matfile.c_str(), "wb"))) {
|
||||||
fprintf(stderr, "Couldn't open %s for writing.\n", matfile.c_str());
|
fprintf(stderr, "Couldn't open %s for writing.\n", matfile.c_str());
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
mexPrintf("k_order_perturbation: Filling Mat file outputs.\n");
|
mexPrintf("k_order_perturbation: Filling Mat file outputs.\n");
|
||||||
#endif
|
#endif
|
||||||
std::string ss_matrix_name(fName);//params.prefix);
|
std::string ss_matrix_name(fName);//params.prefix);
|
||||||
ss_matrix_name += "_steady_states";
|
ss_matrix_name += "_steady_states";
|
||||||
ConstTwoDMatrix(app.getSS()).writeMat4(matfd, ss_matrix_name.c_str());
|
ConstTwoDMatrix(app.getSS()).writeMat4(matfd, ss_matrix_name.c_str());
|
||||||
|
|
||||||
// write the folded decision rule to the Mat-4 file
|
// write the folded decision rule to the Mat-4 file
|
||||||
app.getFoldDecisionRule().writeMat4(matfd, fName);//params.prefix);
|
app.getFoldDecisionRule().writeMat4(matfd, fName);//params.prefix);
|
||||||
|
|
||||||
fclose(matfd);
|
fclose(matfd);
|
||||||
|
|
||||||
map<string,ConstTwoDMatrix> mm;
|
map<string,ConstTwoDMatrix> mm;
|
||||||
app.getFoldDecisionRule().writeMMap(&mm);
|
app.getFoldDecisionRule().writeMMap(&mm);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
app.getFoldDecisionRule().print();
|
app.getFoldDecisionRule().print();
|
||||||
mexPrintf("k_order_perturbation: Map print: \n");
|
mexPrintf("k_order_perturbation: Map print: \n");
|
||||||
for (map<string,ConstTwoDMatrix>::const_iterator cit=mm.begin();
|
for (map<string,ConstTwoDMatrix>::const_iterator cit=mm.begin();
|
||||||
cit !=mm.end(); ++cit) {
|
cit !=mm.end(); ++cit) {
|
||||||
mexPrintf("k_order_perturbation: Map print: string: %s , g:\n", (*cit).first.c_str());
|
mexPrintf("k_order_perturbation: Map print: string: %s , g:\n", (*cit).first.c_str());
|
||||||
(*cit).second.print();
|
(*cit).second.print();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// get latest ysteady
|
// get latest ysteady
|
||||||
double * dYsteady = (dynare.getSteady().base());
|
double * dYsteady = (dynare.getSteady().base());
|
||||||
ySteady = (Vector*)(&dynare.getSteady());
|
ySteady = (Vector*)(&dynare.getSteady());
|
||||||
} catch (const KordException& e) {
|
} catch (const KordException& e) {
|
||||||
printf("Caugth Kord exception: ");
|
printf("Caugth Kord exception: ");
|
||||||
e.print();
|
e.print();
|
||||||
return 1;// e.code();
|
return 1;// e.code();
|
||||||
} catch (const TLException& e) {
|
} catch (const TLException& e) {
|
||||||
printf("Caugth TL exception: ");
|
printf("Caugth TL exception: ");
|
||||||
e.print();
|
e.print();
|
||||||
return 2;// 255;
|
return 2;// 255;
|
||||||
} catch (SylvException& e) {
|
} catch (SylvException& e) {
|
||||||
printf("Caught Sylv exception: ");
|
printf("Caught Sylv exception: ");
|
||||||
e.printMessage();
|
e.printMessage();
|
||||||
return 3;// 255;
|
return 3;// 255;
|
||||||
} catch (const DynareException& e) {
|
} catch (const DynareException& e) {
|
||||||
printf("Caught KordpDynare exception: %s\n", e.message());
|
printf("Caught KordpDynare exception: %s\n", e.message());
|
||||||
return 4;// 255;
|
return 4;// 255;
|
||||||
} catch (const ogu::Exception& e) {
|
} catch (const ogu::Exception& e) {
|
||||||
printf("Caught ogu::Exception: ");
|
printf("Caught ogu::Exception: ");
|
||||||
e.print();
|
e.print();
|
||||||
return 5;// 255;
|
return 5;// 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
// bones for future developement of the Matlab output.
|
// bones for future developement of the Matlab output.
|
||||||
const int nrhs=5;
|
const int nrhs=5;
|
||||||
const int nlhs=2;
|
const int nlhs=2;
|
||||||
|
|
||||||
mxArray* prhs[nrhs];
|
mxArray* prhs[nrhs];
|
||||||
mxArray* plhs[nlhs];
|
mxArray* plhs[nlhs];
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
mexPrintf("k_order_perturbation: Filling Matlab outputs.\n");
|
mexPrintf("k_order_perturbation: Filling Matlab outputs.\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
double *dgy, *dgu, *ysteady;
|
double *dgy, *dgu, *ysteady;
|
||||||
int nb_row_x;
|
int nb_row_x;
|
||||||
|
|
||||||
ysteady = NULL;
|
ysteady = NULL;
|
||||||
if (nlhs >= 1)
|
if (nlhs >= 1)
|
||||||
{
|
{
|
||||||
/* Set the output pointer to the output matrix ysteady. */
|
/* Set the output pointer to the output matrix ysteady. */
|
||||||
plhs[0] = mxCreateDoubleMatrix(nEndo,1, mxREAL);
|
plhs[0] = mxCreateDoubleMatrix(nEndo,1, mxREAL);
|
||||||
/* Create a C pointer to a copy of the output ysteady. */
|
/* Create a C pointer to a copy of the output ysteady. */
|
||||||
ysteady = mxGetPr(plhs[0]);
|
ysteady = mxGetPr(plhs[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
dgy = NULL;
|
dgy = NULL;
|
||||||
if (nlhs >= 2)
|
if (nlhs >= 2)
|
||||||
{
|
{
|
||||||
/* Set the output pointer to the output matrix gy. */
|
/* Set the output pointer to the output matrix gy. */
|
||||||
plhs[1] = mxCreateDoubleMatrix(nEndo, jcols, mxREAL);
|
plhs[1] = mxCreateDoubleMatrix(nEndo, jcols, mxREAL);
|
||||||
// plhs[1] = (double*)(gy->getData())->base();
|
// plhs[1] = (double*)(gy->getData())->base();
|
||||||
/* Create a C pointer to a copy of the output matrix gy. */
|
/* Create a C pointer to a copy of the output matrix gy. */
|
||||||
dgy = mxGetPr(plhs[1]);
|
dgy = mxGetPr(plhs[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
dgu = NULL;
|
dgu = NULL;
|
||||||
if (nlhs >= 3)
|
if (nlhs >= 3)
|
||||||
{
|
{
|
||||||
/* Set the output pointer to the output matrix gu. */
|
/* Set the output pointer to the output matrix gu. */
|
||||||
plhs[2] = mxCreateDoubleMatrix(nEndo, nExog, mxREAL);
|
plhs[2] = mxCreateDoubleMatrix(nEndo, nExog, mxREAL);
|
||||||
// plhs[2] = (double*)((gu->getData())->base());
|
// plhs[2] = (double*)((gu->getData())->base());
|
||||||
/* Create a C pointer to a copy of the output matrix gu. */
|
/* Create a C pointer to a copy of the output matrix gu. */
|
||||||
dgu = mxGetPr(plhs[2]);
|
dgu = mxGetPr(plhs[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue