added steady_state operator to preprocessor
git-svn-id: https://www.dynare.org/svn/dynare/trunk@2916 ac1d8469-bf42-47a9-8791-bf33cf982152issue#70
parent
88a84a53de
commit
5591a412a8
|
@ -114,7 +114,8 @@ enum UnaryOpcode
|
|||
oAcosh,
|
||||
oAsinh,
|
||||
oAtanh,
|
||||
oSqrt
|
||||
oSqrt,
|
||||
oSteadyState
|
||||
};
|
||||
|
||||
enum BinaryOpcode
|
||||
|
|
|
@ -408,6 +408,12 @@ DataTree::AddNormcdf(NodeID iArg1, NodeID iArg2, NodeID iArg3)
|
|||
return AddTrinaryOp(iArg1, oNormcdf, iArg2, iArg3);
|
||||
}
|
||||
|
||||
NodeID
|
||||
DataTree::AddSteadyState(NodeID iArg1)
|
||||
{
|
||||
return AddUnaryOp(oSteadyState, iArg1);
|
||||
}
|
||||
|
||||
NodeID
|
||||
DataTree::AddEqual(NodeID iArg1, NodeID iArg2)
|
||||
{
|
||||
|
|
|
@ -69,7 +69,6 @@ protected:
|
|||
|
||||
//! Computes a new deriv_id, or returns -1 if the variable is not one w.r. to which to derive
|
||||
virtual int computeDerivID(int symb_id, int lag);
|
||||
|
||||
private:
|
||||
typedef list<NodeID> node_list_type;
|
||||
//! The list of nodes
|
||||
|
@ -164,6 +163,8 @@ public:
|
|||
NodeID AddMin(NodeID iArg1, NodeID iArg2);
|
||||
//! Adds "normcdf(arg1,arg2,arg3)" to model tree
|
||||
NodeID AddNormcdf(NodeID iArg1, NodeID iArg2, NodeID iArg3);
|
||||
//! Adds "steadyState(arg)" to model tree
|
||||
NodeID AddSteadyState(NodeID iArg1);
|
||||
//! Adds "arg1=arg2" to model tree
|
||||
NodeID AddEqual(NodeID iArg1, NodeID iArg2);
|
||||
//! Adds a model local variable with its value
|
||||
|
@ -175,7 +176,6 @@ public:
|
|||
void fillEvalContext(eval_context_type &eval_context) const;
|
||||
//! Checks if a given symbol is used somewhere in the data tree
|
||||
bool isSymbolUsed(int symb_id) const;
|
||||
|
||||
//! Thrown when trying to access an unknown variable by deriv_id
|
||||
class UnknownDerivIDException
|
||||
{
|
||||
|
@ -185,6 +185,9 @@ public:
|
|||
virtual int getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException);
|
||||
//! Returns the column of the dynamic Jacobian associated to a derivation ID
|
||||
virtual int getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDException);
|
||||
|
||||
//! Returns bool indicating whether DataTree represents a Dynamic Model (returns true in DynamicModel.hh)
|
||||
virtual bool isDynamic() const { return false; };
|
||||
};
|
||||
|
||||
inline NodeID
|
||||
|
|
|
@ -193,6 +193,9 @@ public:
|
|||
|
||||
virtual int getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException);
|
||||
virtual int getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDException);
|
||||
|
||||
//! Returns true indicating that this is a dynamic model
|
||||
virtual bool isDynamic() const { return true; };
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -133,7 +133,8 @@ class ParsingDriver;
|
|||
%left TIMES DIVIDE
|
||||
%left UMINUS UPLUS
|
||||
%nonassoc POWER
|
||||
%token EXP LOG LN LOG10 SIN COS TAN ASIN ACOS ATAN SINH COSH TANH ASINH ACOSH ATANH SQRT NORMCDF
|
||||
%token EXP LOG LN LOG10 SIN COS TAN ASIN ACOS ATAN SINH COSH TANH
|
||||
%token ASINH ACOSH ATANH SQRT NORMCDF STEADY_STATE
|
||||
/* GSA analysis */
|
||||
%token DYNARE_SENSITIVITY MORRIS STAB REDFORM PPRIOR PRIOR_RANGE PPOST ILPTAU GLUE MORRIS_NLIV
|
||||
%token MORRIS_NTRA NSAM LOAD_REDFORM LOAD_RMSE LOAD_STAB ALPHA2_STAB KSSTAT LOGTRANS_REDFORM THRESHOLD_REDFORM
|
||||
|
@ -392,6 +393,8 @@ expression : '(' expression ')'
|
|||
{ $$ = driver.add_normcdf($3, $5, $7); }
|
||||
| NORMCDF '(' expression ')'
|
||||
{ $$ = driver.add_normcdf($3); }
|
||||
| STEADY_STATE '(' expression ')'
|
||||
{ $$ = driver.add_steady_state($3); }
|
||||
| NAN_CONSTANT
|
||||
{ $$ = driver.add_nan_constant(); }
|
||||
| INF_CONSTANT
|
||||
|
@ -536,6 +539,8 @@ hand_side : '(' hand_side ')'
|
|||
{ $$ = driver.add_normcdf($3, $5, $7); }
|
||||
| NORMCDF '(' hand_side ')'
|
||||
{ $$ = driver.add_normcdf($3); }
|
||||
| STEADY_STATE '(' hand_side ')'
|
||||
{ $$ = driver.add_steady_state($3); }
|
||||
;
|
||||
|
||||
pound_expression: '#' symbol EQUAL hand_side ';'
|
||||
|
|
|
@ -396,6 +396,7 @@ int sigma_e = 0;
|
|||
<DYNARE_STATEMENT,DYNARE_BLOCK>max {return token::MAX;}
|
||||
<DYNARE_STATEMENT,DYNARE_BLOCK>min {return token::MIN;}
|
||||
<DYNARE_STATEMENT,DYNARE_BLOCK>normcdf {return token::NORMCDF;}
|
||||
<DYNARE_STATEMENT,DYNARE_BLOCK>steady_state {return token::STEADY_STATE;}
|
||||
<DYNARE_STATEMENT,DYNARE_BLOCK>nan {return token::NAN_CONSTANT;}
|
||||
<DYNARE_STATEMENT,DYNARE_BLOCK>inf {return token::INF_CONSTANT;}
|
||||
|
||||
|
|
58
ExprNode.cc
58
ExprNode.cc
|
@ -375,6 +375,10 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
|||
case oMatlabOutsideModel:
|
||||
output << "oo_.steady_state" << "(" << tsid + 1 << ")";
|
||||
break;
|
||||
case oLatexDynamicSteadyStateOperator:
|
||||
case oMatlabDynamicSteadyStateOperator:
|
||||
output << "oo_.steady_state" << "(" << tsid + 1 << ")";
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
@ -409,6 +413,11 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
|||
assert(lag == 0);
|
||||
output << "oo_.exo_steady_state" << "(" << i << ")";
|
||||
break;
|
||||
case oLatexDynamicSteadyStateOperator:
|
||||
case oMatlabDynamicSteadyStateOperator:
|
||||
assert(lag == 0);
|
||||
output << "oo_.exo_steady_state" << "(" << i << ")";
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
@ -443,6 +452,11 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
|||
assert(lag == 0);
|
||||
output << "oo_.exo_det_steady_state" << "(" << tsid + 1 << ")";
|
||||
break;
|
||||
case oLatexDynamicSteadyStateOperator:
|
||||
case oMatlabDynamicSteadyStateOperator:
|
||||
assert(lag == 0);
|
||||
output << "oo_.exo_det_steady_state" << "(" << tsid + 1 << ")";
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
@ -705,6 +719,11 @@ UnaryOpNode::composeDerivatives(NodeID darg)
|
|||
case oSqrt:
|
||||
t11 = datatree.AddPlus(this, this);
|
||||
return datatree.AddDivide(darg, t11);
|
||||
case oSteadyState:
|
||||
if (datatree.isDynamic())
|
||||
return datatree.Zero;
|
||||
else
|
||||
return darg;
|
||||
}
|
||||
// Suppress GCC warning
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -763,6 +782,8 @@ UnaryOpNode::cost(const temporary_terms_type &temporary_terms, bool is_matlab) c
|
|||
return cost + 350;
|
||||
case oSqrt:
|
||||
return cost + 570;
|
||||
case oSteadyState:
|
||||
return cost + 0;
|
||||
}
|
||||
else
|
||||
// Cost for C files
|
||||
|
@ -797,6 +818,8 @@ UnaryOpNode::cost(const temporary_terms_type &temporary_terms, bool is_matlab) c
|
|||
return cost + 150;
|
||||
case oSqrt:
|
||||
return cost + 90;
|
||||
case oSteadyState:
|
||||
return cost + 0;
|
||||
}
|
||||
// Suppress GCC warning
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -864,8 +887,7 @@ UnaryOpNode::collectTemporary_terms(const temporary_terms_type &temporary_terms,
|
|||
void
|
||||
UnaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_type &temporary_terms) const
|
||||
{
|
||||
//cout << "writeOutput unary\n";
|
||||
{
|
||||
// If node is a temporary term
|
||||
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<UnaryOpNode *>(this));
|
||||
if (it != temporary_terms.end())
|
||||
|
@ -937,6 +959,28 @@ UnaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
|||
case oSqrt:
|
||||
output << "sqrt";
|
||||
break;
|
||||
case oSteadyState:
|
||||
ExprNodeOutputType new_output_type;
|
||||
switch(output_type)
|
||||
{
|
||||
case oMatlabDynamicModel:
|
||||
new_output_type = oMatlabDynamicSteadyStateOperator;
|
||||
break;
|
||||
case oLatexDynamicModel:
|
||||
new_output_type = oLatexDynamicSteadyStateOperator;
|
||||
break;
|
||||
case oCDynamicModel:
|
||||
cerr << "Steady State Operator not imlpemented for oCDynamicModel.\n";
|
||||
exit(EXIT_FAILURE);
|
||||
case oMatlabDynamicModelSparse:
|
||||
cerr << "Steady State Operator not imlpemented for oMatlabDynamicModelSparse.\n";
|
||||
exit(EXIT_FAILURE);
|
||||
default:
|
||||
new_output_type = output_type;
|
||||
break;
|
||||
}
|
||||
arg->writeOutput(output, new_output_type, temporary_terms);
|
||||
return;
|
||||
}
|
||||
|
||||
bool close_parenthesis = false;
|
||||
|
@ -945,7 +989,7 @@ UnaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
|||
- current opcode is not uminus, or
|
||||
- current opcode is uminus and argument has lowest precedence
|
||||
*/
|
||||
if (op_code != oUminus
|
||||
if (op_code != oUminus
|
||||
|| (op_code == oUminus
|
||||
&& arg->precedence(output_type, temporary_terms) < precedence(output_type, temporary_terms)))
|
||||
{
|
||||
|
@ -1003,6 +1047,8 @@ UnaryOpNode::eval_opcode(UnaryOpcode op_code, double v) throw (EvalException)
|
|||
return(atanh(v));
|
||||
case oSqrt:
|
||||
return(sqrt(v));
|
||||
case oSteadyState:
|
||||
return(v);
|
||||
}
|
||||
// Suppress GCC warning
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -1094,6 +1140,8 @@ UnaryOpNode::normalizeEquation(int var_endo, vector<pair<int, pair<NodeID, NodeI
|
|||
case oSqrt:
|
||||
List_of_Op_RHS.push_back(make_pair(oPower, make_pair((NodeID)NULL, datatree.AddNumConstant("2"))));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
case oSteadyState:
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -1134,6 +1182,8 @@ UnaryOpNode::normalizeEquation(int var_endo, vector<pair<int, pair<NodeID, NodeI
|
|||
return(make_pair(0, datatree.AddAtanh(New_NodeID)));
|
||||
case oSqrt:
|
||||
return(make_pair(0, datatree.AddSqrt(New_NodeID)));
|
||||
case oSteadyState:
|
||||
return(make_pair(0, datatree.AddSteadyState(New_NodeID)));
|
||||
}
|
||||
}
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
|
@ -1187,6 +1237,8 @@ UnaryOpNode::toStatic(DataTree &static_datatree) const
|
|||
return static_datatree.AddAtanh(sarg);
|
||||
case oSqrt:
|
||||
return static_datatree.AddSqrt(sarg);
|
||||
case oSteadyState:
|
||||
return static_datatree.AddSteadyState(sarg);
|
||||
}
|
||||
// Suppress GCC warning
|
||||
exit(EXIT_FAILURE);
|
||||
|
|
26
ExprNode.hh
26
ExprNode.hh
|
@ -51,26 +51,32 @@ typedef map<int, double> eval_context_type;
|
|||
//! Possible types of output when writing ExprNode(s)
|
||||
enum ExprNodeOutputType
|
||||
{
|
||||
oMatlabStaticModel, //!< Matlab code, static model declarations
|
||||
oMatlabDynamicModel, //!< Matlab code, dynamic model declarations
|
||||
oMatlabStaticModelSparse, //!< Matlab code, static block decomposed mode declaration
|
||||
oMatlabDynamicModelSparse,//!< Matlab code, dynamic block decomposed mode declaration
|
||||
oCDynamicModel, //!< C code, dynamic model declarations
|
||||
oMatlabOutsideModel, //!< Matlab code, outside model block (for example in initval)
|
||||
oLatexStaticModel, //!< LaTeX code, static model declarations
|
||||
oLatexDynamicModel //!< LaTeX code, dynamic model declarations
|
||||
oMatlabStaticModel, //!< Matlab code, static model declarations
|
||||
oMatlabDynamicModel, //!< Matlab code, dynamic model declarations
|
||||
oMatlabStaticModelSparse, //!< Matlab code, static block decomposed mode declaration
|
||||
oMatlabDynamicModelSparse, //!< Matlab code, dynamic block decomposed mode declaration
|
||||
oCDynamicModel, //!< C code, dynamic model declarations
|
||||
oMatlabOutsideModel, //!< Matlab code, outside model block (for example in initval)
|
||||
oLatexStaticModel, //!< LaTeX code, static model declarations
|
||||
oLatexDynamicModel, //!< LaTeX code, dynamic model declarations
|
||||
oLatexDynamicSteadyStateOperator, //!< LaTeX code, dynamic model steady state declarations
|
||||
oMatlabDynamicSteadyStateOperator, //!< Matlab code, dynamic model steady state declarations
|
||||
oMatlabDynamicModelSparseSteadyStateOperator //!< Matlab code, dynamic block decomposed mode steady state declarations
|
||||
};
|
||||
|
||||
#define IS_MATLAB(output_type) ((output_type) == oMatlabStaticModel \
|
||||
|| (output_type) == oMatlabDynamicModel \
|
||||
|| (output_type) == oMatlabOutsideModel \
|
||||
|| (output_type) == oMatlabStaticModelSparse \
|
||||
|| (output_type) == oMatlabDynamicModelSparse)
|
||||
|| (output_type) == oMatlabDynamicModelSparse \
|
||||
|| (output_type) == oMatlabDynamicSteadyStateOperator \
|
||||
|| (output_type) == oMatlabDynamicModelSparseSteadyStateOperator)
|
||||
|
||||
#define IS_C(output_type) ((output_type) == oCDynamicModel)
|
||||
|
||||
#define IS_LATEX(output_type) ((output_type) == oLatexStaticModel \
|
||||
|| (output_type) == oLatexDynamicModel)
|
||||
|| (output_type) == oLatexDynamicModel \
|
||||
|| (output_type) == oLatexDynamicSteadyStateOperator)
|
||||
|
||||
/* Equal to 1 for Matlab langage, or to 0 for C language. Not defined for LaTeX.
|
||||
In Matlab, array indexes begin at 1, while they begin at 0 in C */
|
||||
|
|
|
@ -1352,6 +1352,12 @@ ParsingDriver::add_normcdf(NodeID arg)
|
|||
return add_normcdf(arg, data_tree->Zero, data_tree->One);
|
||||
}
|
||||
|
||||
NodeID
|
||||
ParsingDriver::add_steady_state(NodeID arg1)
|
||||
{
|
||||
return data_tree->AddSteadyState(arg1);
|
||||
}
|
||||
|
||||
void
|
||||
ParsingDriver::add_unknown_function_arg(NodeID arg)
|
||||
{
|
||||
|
|
|
@ -426,6 +426,8 @@ public:
|
|||
NodeID add_normcdf(NodeID arg1, NodeID arg2, NodeID arg3);
|
||||
//! Writes token "normcdf(arg,0,1)" to model tree
|
||||
NodeID add_normcdf(NodeID arg);
|
||||
//! Writes token "steadyState(arg1)" to model tree
|
||||
NodeID add_steady_state(NodeID arg1);
|
||||
//! Adds an unknwon function argument
|
||||
void add_unknown_function_arg(NodeID arg);
|
||||
//! Adds an unknown function call node
|
||||
|
|
Loading…
Reference in New Issue