Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • giovanma/dynare
  • giorgiomas/dynare
  • Vermandel/dynare
  • Dynare/dynare
  • normann/dynare
  • MichelJuillard/dynare
  • wmutschl/dynare
  • FerhatMihoubi/dynare
  • sebastien/dynare
  • lnsongxf/dynare
  • rattoma/dynare
  • CIMERS/dynare
  • FredericKarame/dynare
  • SumuduK/dynare
  • MinjeJeon/dynare
  • camilomrch/dynare
  • DoraK/dynare
  • avtishin/dynare
  • selma/dynare
  • claudio_olguin/dynare
  • jeffjiang07/dynare
  • EthanSystem/dynare
  • stepan-a/dynare
  • wjgatt/dynare
  • JohannesPfeifer/dynare
  • gboehl/dynare
  • ebenetce/dynare
  • chskcau/dynare-doc-fixes
28 results
Select Git revision
Loading items
Show changes
Showing
with 496 additions and 249 deletions
/* /*
* Copyright (C) 2003-2012 Dynare Team * Copyright (C) 2003-2014 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
...@@ -512,7 +512,7 @@ DataTree::AddExternalFunction(int symb_id, const vector<expr_t> &arguments) ...@@ -512,7 +512,7 @@ DataTree::AddExternalFunction(int symb_id, const vector<expr_t> &arguments)
} }
expr_t expr_t
DataTree::AddFirstDerivExternalFunctionNode(int top_level_symb_id, const vector<expr_t> &arguments, int input_index) DataTree::AddFirstDerivExternalFunction(int top_level_symb_id, const vector<expr_t> &arguments, int input_index)
{ {
assert(symbol_table.getType(top_level_symb_id) == eExternalFunction); assert(symbol_table.getType(top_level_symb_id) == eExternalFunction);
...@@ -526,7 +526,7 @@ DataTree::AddFirstDerivExternalFunctionNode(int top_level_symb_id, const vector< ...@@ -526,7 +526,7 @@ DataTree::AddFirstDerivExternalFunctionNode(int top_level_symb_id, const vector<
} }
expr_t expr_t
DataTree::AddSecondDerivExternalFunctionNode(int top_level_symb_id, const vector<expr_t> &arguments, int input_index1, int input_index2) DataTree::AddSecondDerivExternalFunction(int top_level_symb_id, const vector<expr_t> &arguments, int input_index1, int input_index2)
{ {
assert(symbol_table.getType(top_level_symb_id) == eExternalFunction); assert(symbol_table.getType(top_level_symb_id) == eExternalFunction);
......
...@@ -44,6 +44,7 @@ class DataTree ...@@ -44,6 +44,7 @@ class DataTree
friend class UnaryOpNode; friend class UnaryOpNode;
friend class BinaryOpNode; friend class BinaryOpNode;
friend class TrinaryOpNode; friend class TrinaryOpNode;
friend class AbstractExternalFunctionNode;
friend class ExternalFunctionNode; friend class ExternalFunctionNode;
friend class FirstDerivExternalFunctionNode; friend class FirstDerivExternalFunctionNode;
friend class SecondDerivExternalFunctionNode; friend class SecondDerivExternalFunctionNode;
...@@ -202,9 +203,9 @@ public: ...@@ -202,9 +203,9 @@ public:
//! Adds an external function node //! Adds an external function node
expr_t AddExternalFunction(int symb_id, const vector<expr_t> &arguments); expr_t AddExternalFunction(int symb_id, const vector<expr_t> &arguments);
//! Adds an external function node for the first derivative of an external function //! Adds an external function node for the first derivative of an external function
expr_t AddFirstDerivExternalFunctionNode(int top_level_symb_id, const vector<expr_t> &arguments, int input_index); expr_t AddFirstDerivExternalFunction(int top_level_symb_id, const vector<expr_t> &arguments, int input_index);
//! Adds an external function node for the second derivative of an external function //! Adds an external function node for the second derivative of an external function
expr_t AddSecondDerivExternalFunctionNode(int top_level_symb_id, const vector<expr_t> &arguments, int input_index1, int input_index2); expr_t AddSecondDerivExternalFunction(int top_level_symb_id, const vector<expr_t> &arguments, int input_index1, int input_index2);
//! Checks if a given symbol is used somewhere in the data tree //! Checks if a given symbol is used somewhere in the data tree
bool isSymbolUsed(int symb_id) const; bool isSymbolUsed(int symb_id) const;
//! Checks if a given unary op is used somewhere in the data tree //! Checks if a given unary op is used somewhere in the data tree
......
...@@ -187,6 +187,10 @@ DynamicModel::computeTemporaryTermsOrdered() ...@@ -187,6 +187,10 @@ DynamicModel::computeTemporaryTermsOrdered()
it->second->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block); it->second->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block);
for (derivative_t::const_iterator it = derivative_other_endo[block].begin(); it != derivative_other_endo[block].end(); it++) for (derivative_t::const_iterator it = derivative_other_endo[block].begin(); it != derivative_other_endo[block].end(); it++)
it->second->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block); it->second->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block);
for (derivative_t::const_iterator it = derivative_exo[block].begin(); it != derivative_exo[block].end(); it++)
it->second->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block);
for (derivative_t::const_iterator it = derivative_exo_det[block].begin(); it != derivative_exo_det[block].end(); it++)
it->second->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block);
v_temporary_terms_inuse[block] = temporary_terms_in_use; v_temporary_terms_inuse[block] = temporary_terms_in_use;
} }
computeTemporaryTermsMapping(); computeTemporaryTermsMapping();
...@@ -460,7 +464,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const ...@@ -460,7 +464,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
for (temporary_terms_t::const_iterator it = v_temporary_terms[block][i].begin(); for (temporary_terms_t::const_iterator it = v_temporary_terms[block][i].begin();
it != v_temporary_terms[block][i].end(); it++) it != v_temporary_terms[block][i].end(); it++)
{ {
if (dynamic_cast<ExternalFunctionNode *>(*it) != NULL) if (dynamic_cast<AbstractExternalFunctionNode *>(*it) != NULL)
(*it)->writeExternalFunctionOutput(output, local_output_type, tt2, tef_terms); (*it)->writeExternalFunctionOutput(output, local_output_type, tt2, tef_terms);
output << " " << sps; output << " " << sps;
...@@ -1181,7 +1185,7 @@ DynamicModel::writeModelEquationsCode_Block(string &file_name, const string &bin ...@@ -1181,7 +1185,7 @@ DynamicModel::writeModelEquationsCode_Block(string &file_name, const string &bin
for (temporary_terms_t::const_iterator it = v_temporary_terms[block][i].begin(); for (temporary_terms_t::const_iterator it = v_temporary_terms[block][i].begin();
it != v_temporary_terms[block][i].end(); it++) it != v_temporary_terms[block][i].end(); it++)
{ {
if (dynamic_cast<ExternalFunctionNode *>(*it) != NULL) if (dynamic_cast<AbstractExternalFunctionNode *>(*it) != NULL)
(*it)->compileExternalFunctionOutput(code_file, instruction_number, false, tt2, map_idx, true, false, tef_terms); (*it)->compileExternalFunctionOutput(code_file, instruction_number, false, tt2, map_idx, true, false, tef_terms);
FNUMEXPR_ fnumexpr(TemporaryTerm, (int) (map_idx.find((*it)->idx)->second)); FNUMEXPR_ fnumexpr(TemporaryTerm, (int) (map_idx.find((*it)->idx)->second));
...@@ -1525,14 +1529,14 @@ DynamicModel::writeDynamicMFile(const string &dynamic_basename) const ...@@ -1525,14 +1529,14 @@ DynamicModel::writeDynamicMFile(const string &dynamic_basename) const
<< "% residual [M_.endo_nbr by 1] double vector of residuals of the dynamic model equations in order of " << endl << "% residual [M_.endo_nbr by 1] double vector of residuals of the dynamic model equations in order of " << endl
<< "% declaration of the equations" << endl << "% declaration of the equations" << endl
<< "% g1 [M_.endo_nbr by #dynamic variables] double Jacobian matrix of the dynamic model equations;" << endl << "% g1 [M_.endo_nbr by #dynamic variables] double Jacobian matrix of the dynamic model equations;" << endl
<< "% columns: equations in order of declaration" << endl << "% rows: equations in order of declaration" << endl
<< "% rows: variables in order stored in M_.lead_lag_incidence" << endl << "% columns: variables in order stored in M_.lead_lag_incidence" << endl
<< "% g2 [M_.endo_nbr by (#dynamic variables)^2] double Hessian matrix of the dynamic model equations;" << endl << "% g2 [M_.endo_nbr by (#dynamic variables)^2] double Hessian matrix of the dynamic model equations;" << endl
<< "% columns: equations in order of declaration" << endl << "% rows: equations in order of declaration" << endl
<< "% rows: variables in order stored in M_.lead_lag_incidence" << endl << "% columns: variables in order stored in M_.lead_lag_incidence" << endl
<< "% g3 [M_.endo_nbr by (#dynamic variables)^3] double Third order derivative matrix of the dynamic model equations;" << endl << "% g3 [M_.endo_nbr by (#dynamic variables)^3] double Third order derivative matrix of the dynamic model equations;" << endl
<< "% columns: equations in order of declaration" << endl << "% rows: equations in order of declaration" << endl
<< "% rows: variables in order stored in M_.lead_lag_incidence" << endl << "% columns: variables in order stored in M_.lead_lag_incidence" << endl
<< "%" << endl << "%" << endl
<< "%" << endl << "%" << endl
<< "% Warning : this file is generated automatically by Dynare" << endl << "% Warning : this file is generated automatically by Dynare" << endl
...@@ -1746,7 +1750,6 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri ...@@ -1746,7 +1750,6 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
string sp; string sp;
ofstream mDynamicModelFile; ofstream mDynamicModelFile;
ostringstream tmp, tmp1, tmp_eq; ostringstream tmp, tmp1, tmp_eq;
int prev_Simulation_Type;
bool OK; bool OK;
chdir(basename.c_str()); chdir(basename.c_str());
string filename = dynamic_basename + ".m"; string filename = dynamic_basename + ".m";
...@@ -1764,7 +1767,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri ...@@ -1764,7 +1767,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
mDynamicModelFile << "%/\n"; mDynamicModelFile << "%/\n";
int Nb_SGE = 0; int Nb_SGE = 0;
bool skip_head, open_par = false; bool open_par = false;
mDynamicModelFile << "function [varargout] = " << dynamic_basename << "(varargin)\n"; mDynamicModelFile << "function [varargout] = " << dynamic_basename << "(varargin)\n";
mDynamicModelFile << " global oo_ options_ M_ ;\n"; mDynamicModelFile << " global oo_ options_ M_ ;\n";
...@@ -1810,7 +1813,6 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri ...@@ -1810,7 +1813,6 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
<< " Per_u_=0;" << endl << " Per_u_=0;" << endl
<< " Per_y_=it_*y_size;" << endl << " Per_y_=it_*y_size;" << endl
<< " ys=y(it_,:);" << endl; << " ys=y(it_,:);" << endl;
prev_Simulation_Type = -1;
tmp.str(""); tmp.str("");
tmp_eq.str(""); tmp_eq.str("");
unsigned int nb_blocks = getNbBlocks(); unsigned int nb_blocks = getNbBlocks();
...@@ -1901,7 +1903,6 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri ...@@ -1901,7 +1903,6 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
<< " y=oo_.endo_simul';" << endl << " y=oo_.endo_simul';" << endl
<< " x=oo_.exo_simul;" << endl; << " x=oo_.exo_simul;" << endl;
prev_Simulation_Type = -1;
mDynamicModelFile << " params=M_.params;\n"; mDynamicModelFile << " params=M_.params;\n";
mDynamicModelFile << " steady_state=oo_.steady_state;\n"; mDynamicModelFile << " steady_state=oo_.steady_state;\n";
mDynamicModelFile << " oo_.deterministic_simulation.status = 0;\n"; mDynamicModelFile << " oo_.deterministic_simulation.status = 0;\n";
...@@ -1912,14 +1913,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri ...@@ -1912,14 +1913,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
unsigned int block_recursive = block_size - block_mfs; unsigned int block_recursive = block_size - block_mfs;
BlockSimulationType simulation_type = getBlockSimulationType(block); BlockSimulationType simulation_type = getBlockSimulationType(block);
if (BlockSim(prev_Simulation_Type) == BlockSim(simulation_type)
&& (simulation_type == EVALUATE_FORWARD || simulation_type == EVALUATE_BACKWARD))
skip_head = true;
else
skip_head = false;
if ((simulation_type == EVALUATE_FORWARD) && (block_size)) if ((simulation_type == EVALUATE_FORWARD) && (block_size))
{
if (!skip_head)
{ {
if (open_par) if (open_par)
{ {
...@@ -1944,10 +1938,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri ...@@ -1944,10 +1938,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
mDynamicModelFile << " return;\n"; mDynamicModelFile << " return;\n";
mDynamicModelFile << " end;\n"; mDynamicModelFile << " end;\n";
} }
}
else if ((simulation_type == EVALUATE_BACKWARD) && (block_size)) else if ((simulation_type == EVALUATE_BACKWARD) && (block_size))
{
if (!skip_head)
{ {
if (open_par) if (open_par)
{ {
...@@ -1972,7 +1963,6 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri ...@@ -1972,7 +1963,6 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
mDynamicModelFile << " return;\n"; mDynamicModelFile << " return;\n";
mDynamicModelFile << " end;\n"; mDynamicModelFile << " end;\n";
} }
}
else if ((simulation_type == SOLVE_FORWARD_COMPLETE || simulation_type == SOLVE_FORWARD_SIMPLE) && (block_size)) else if ((simulation_type == SOLVE_FORWARD_COMPLETE || simulation_type == SOLVE_FORWARD_SIMPLE) && (block_size))
{ {
if (open_par) if (open_par)
...@@ -2062,7 +2052,6 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri ...@@ -2062,7 +2052,6 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
mDynamicModelFile << " return;\n"; mDynamicModelFile << " return;\n";
mDynamicModelFile << " end;\n"; mDynamicModelFile << " end;\n";
} }
prev_Simulation_Type = simulation_type;
} }
if (open_par) if (open_par)
mDynamicModelFile << " end;\n"; mDynamicModelFile << " end;\n";
...@@ -3244,12 +3233,13 @@ DynamicModel::collect_block_first_order_derivatives() ...@@ -3244,12 +3233,13 @@ DynamicModel::collect_block_first_order_derivatives()
int var = symbol_table.getTypeSpecificID(getSymbIDByDerivID(it2->first.second)); int var = symbol_table.getTypeSpecificID(getSymbIDByDerivID(it2->first.second));
int lag = getLagByDerivID(it2->first.second); int lag = getLagByDerivID(it2->first.second);
int block_eq = equation_2_block[eq]; int block_eq = equation_2_block[eq];
int block_var = variable_2_block[var]; int block_var=0;
derivative_t tmp_derivative; derivative_t tmp_derivative;
lag_var_t lag_var; lag_var_t lag_var;
switch (getTypeByDerivID(it2->first.second)) switch (getTypeByDerivID(it2->first.second))
{ {
case eEndogenous: case eEndogenous:
block_var = variable_2_block[var];
if (block_eq == block_var) if (block_eq == block_var)
{ {
if (lag < 0 && lag < -endo_max_leadlag_block[block_eq].first) if (lag < 0 && lag < -endo_max_leadlag_block[block_eq].first)
......
/* /*
* Copyright (C) 2003-2013 Dynare Team * Copyright (C) 2003-2014 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
*/ */
%skeleton "lalr1.cc" %skeleton "lalr1.cc"
%require "2.3" %require "2.5"
%defines %defines
/* Prologue: /* Prologue:
...@@ -28,8 +28,6 @@ ...@@ -28,8 +28,6 @@
with the prologue. with the prologue.
*/ */
%{ %{
using namespace std;
class ParsingDriver; class ParsingDriver;
#include "ExprNode.hh" #include "ExprNode.hh"
...@@ -42,19 +40,19 @@ class ParsingDriver; ...@@ -42,19 +40,19 @@ class ParsingDriver;
do { \ do { \
if (N) \ if (N) \
{ \ { \
(Current).begin = (Rhs)[1].begin; \ (Current).begin = YYRHSLOC(Rhs, 1).begin; \
(Current).end = (Rhs)[N].end; \ (Current).end = YYRHSLOC(Rhs, N).end; \
} \ } \
else \ else \
{ \ { \
(Current).begin = (Current).end = (Rhs)[0].end; \ (Current).begin = (Current).end = YYRHSLOC(Rhs, 0).end; \
} \ } \
driver.location = (Current); \ driver.location = (Current); \
} while(false) } while(false)
%} %}
%name-prefix="Dynare" %name-prefix "Dynare"
%parse-param { ParsingDriver &driver } %parse-param { ParsingDriver &driver }
%lex-param { ParsingDriver &driver } %lex-param { ParsingDriver &driver }
...@@ -96,7 +94,7 @@ class ParsingDriver; ...@@ -96,7 +94,7 @@ class ParsingDriver;
%token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN %token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN
%token BVAR_REPLIC BYTECODE ALL_VALUES_REQUIRED %token BVAR_REPLIC BYTECODE ALL_VALUES_REQUIRED
%token CALIB_SMOOTHER CHANGE_TYPE CHECK CONDITIONAL_FORECAST CONDITIONAL_FORECAST_PATHS CONF_SIG CONSTANT CONTROLLED_VAREXO CORR COVAR CUTOFF CYCLE_REDUCTION LOGARITHMIC_REDUCTION %token CALIB_SMOOTHER CHANGE_TYPE CHECK CONDITIONAL_FORECAST CONDITIONAL_FORECAST_PATHS CONF_SIG CONSTANT CONTROLLED_VAREXO CORR COVAR CUTOFF CYCLE_REDUCTION LOGARITHMIC_REDUCTION
%token DATAFILE FILE DETERMINISTIC DOUBLING DR_CYCLE_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_MAXITER DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE CALIBRATION DIFFERENTIATE_FORWARD_VARS %token DATAFILE FILE DOUBLING DR_CYCLE_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_MAXITER DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE CALIBRATION DIFFERENTIATE_FORWARD_VARS
%token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT EXTENDED_PATH ENDOGENOUS_PRIOR %token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT EXTENDED_PATH ENDOGENOUS_PRIOR
%token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS LAST_OBS SET_TIME %token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS LAST_OBS SET_TIME
%token <string_val> FLOAT_NUMBER DATES %token <string_val> FLOAT_NUMBER DATES
...@@ -110,7 +108,7 @@ class ParsingDriver; ...@@ -110,7 +108,7 @@ class ParsingDriver;
%token KALMAN_ALGO KALMAN_TOL SUBSAMPLES OPTIONS TOLF %token KALMAN_ALGO KALMAN_TOL SUBSAMPLES OPTIONS TOLF
%token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_IDENT_FILES LOAD_MH_FILE LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR LYAPUNOV %token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_IDENT_FILES LOAD_MH_FILE LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR LYAPUNOV
%token LYAPUNOV_FIXED_POINT_TOL LYAPUNOV_DOUBLING_TOL LYAPUNOV_SQUARE_ROOT_SOLVER_TOL LOG_DEFLATOR LOG_TREND_VAR LOG_GROWTH_FACTOR MARKOWITZ MARGINAL_DENSITY MAX MAXIT %token LYAPUNOV_FIXED_POINT_TOL LYAPUNOV_DOUBLING_TOL LYAPUNOV_SQUARE_ROOT_SOLVER_TOL LOG_DEFLATOR LOG_TREND_VAR LOG_GROWTH_FACTOR MARKOWITZ MARGINAL_DENSITY MAX MAXIT
%token MFS MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER MIN MINIMAL_SOLVING_PERIODS %token MFS MH_CONF_SIG MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER MIN MINIMAL_SOLVING_PERIODS
%token MODE_CHECK MODE_CHECK_NEIGHBOURHOOD_SIZE MODE_CHECK_SYMMETRIC_PLOTS MODE_CHECK_NUMBER_OF_POINTS MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MODEL_INFO MSHOCKS ABS SIGN %token MODE_CHECK MODE_CHECK_NEIGHBOURHOOD_SIZE MODE_CHECK_SYMMETRIC_PLOTS MODE_CHECK_NUMBER_OF_POINTS MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MODEL_INFO MSHOCKS ABS SIGN
%token MODEL_DIAGNOSTICS MODIFIEDHARMONICMEAN MOMENTS_VARENDO DIFFUSE_FILTER SUB_DRAWS TAPER_STEPS GEWEKE_INTERVAL MCMC_JUMPING_COVARIANCE %token MODEL_DIAGNOSTICS MODIFIEDHARMONICMEAN MOMENTS_VARENDO DIFFUSE_FILTER SUB_DRAWS TAPER_STEPS GEWEKE_INTERVAL MCMC_JUMPING_COVARIANCE
%token <string_val> NAME %token <string_val> NAME
...@@ -122,8 +120,8 @@ class ParsingDriver; ...@@ -122,8 +120,8 @@ class ParsingDriver;
%token <string_val> QUOTED_STRING %token <string_val> QUOTED_STRING
%token QZ_CRITERIUM QZ_ZERO_THRESHOLD FULL DSGE_VAR DSGE_VARLAG DSGE_PRIOR_WEIGHT TRUNCATE %token QZ_CRITERIUM QZ_ZERO_THRESHOLD FULL DSGE_VAR DSGE_VARLAG DSGE_PRIOR_WEIGHT TRUNCATE
%token RELATIVE_IRF REPLIC SIMUL_REPLIC RPLOT SAVE_PARAMS_AND_STEADY_STATE PARAMETER_UNCERTAINTY %token RELATIVE_IRF REPLIC SIMUL_REPLIC RPLOT SAVE_PARAMS_AND_STEADY_STATE PARAMETER_UNCERTAINTY
%token SHOCKS SHOCK_DECOMPOSITION SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED SIMULATION_TYPE %token SHOCKS SHOCK_DECOMPOSITION SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED
%token SMOOTHER SQUARE_ROOT_SOLVER STACK_SOLVE_ALGO STEADY_STATE_MODEL STOCHASTIC SOLVE_ALGO SOLVER_PERIODS %token SMOOTHER SQUARE_ROOT_SOLVER STACK_SOLVE_ALGO STEADY_STATE_MODEL SOLVE_ALGO SOLVER_PERIODS
%token STDERR STEADY STOCH_SIMUL SURPRISE SYLVESTER SYLVESTER_FIXED_POINT_TOL REGIMES REGIME %token STDERR STEADY STOCH_SIMUL SURPRISE SYLVESTER SYLVESTER_FIXED_POINT_TOL REGIMES REGIME
%token TEX RAMSEY_POLICY PLANNER_DISCOUNT DISCRETIONARY_POLICY DISCRETIONARY_TOL %token TEX RAMSEY_POLICY PLANNER_DISCOUNT DISCRETIONARY_POLICY DISCRETIONARY_TOL
%token <string_val> TEX_NAME %token <string_val> TEX_NAME
...@@ -331,6 +329,12 @@ nonstationary_var_list : nonstationary_var_list symbol ...@@ -331,6 +329,12 @@ nonstationary_var_list : nonstationary_var_list symbol
{ driver.declare_nonstationary_var($3); } { driver.declare_nonstationary_var($3); }
| symbol | symbol
{ driver.declare_nonstationary_var($1); } { driver.declare_nonstationary_var($1); }
| nonstationary_var_list symbol named_var
{ driver.declare_nonstationary_var($2, NULL, $3); }
| nonstationary_var_list COMMA symbol named_var
{ driver.declare_nonstationary_var($3, NULL, $4); }
| symbol named_var
{ driver.declare_nonstationary_var($1, NULL, $2); }
| nonstationary_var_list symbol TEX_NAME | nonstationary_var_list symbol TEX_NAME
{ driver.declare_nonstationary_var($2, $3); } { driver.declare_nonstationary_var($2, $3); }
| nonstationary_var_list COMMA symbol TEX_NAME | nonstationary_var_list COMMA symbol TEX_NAME
...@@ -363,6 +367,12 @@ var_list : var_list symbol ...@@ -363,6 +367,12 @@ var_list : var_list symbol
{ driver.declare_endogenous($3); } { driver.declare_endogenous($3); }
| symbol | symbol
{ driver.declare_endogenous($1); } { driver.declare_endogenous($1); }
| var_list symbol named_var
{ driver.declare_endogenous($2, NULL, $3); }
| var_list COMMA symbol named_var
{ driver.declare_endogenous($3, NULL, $4); }
| symbol named_var
{ driver.declare_endogenous($1, NULL, $2); }
| var_list symbol TEX_NAME | var_list symbol TEX_NAME
{ driver.declare_endogenous($2, $3); } { driver.declare_endogenous($2, $3); }
| var_list COMMA symbol TEX_NAME | var_list COMMA symbol TEX_NAME
...@@ -383,6 +393,12 @@ varexo_list : varexo_list symbol ...@@ -383,6 +393,12 @@ varexo_list : varexo_list symbol
{ driver.declare_exogenous($3); } { driver.declare_exogenous($3); }
| symbol | symbol
{ driver.declare_exogenous($1); } { driver.declare_exogenous($1); }
| varexo_list symbol named_var
{ driver.declare_exogenous($2, NULL, $3); }
| varexo_list COMMA symbol named_var
{ driver.declare_exogenous($3, NULL, $4); }
| symbol named_var
{ driver.declare_exogenous($1, NULL, $2); }
| varexo_list symbol TEX_NAME | varexo_list symbol TEX_NAME
{ driver.declare_exogenous($2, $3); } { driver.declare_exogenous($2, $3); }
| varexo_list COMMA symbol TEX_NAME | varexo_list COMMA symbol TEX_NAME
...@@ -403,6 +419,12 @@ varexo_det_list : varexo_det_list symbol ...@@ -403,6 +419,12 @@ varexo_det_list : varexo_det_list symbol
{ driver.declare_exogenous_det($3); } { driver.declare_exogenous_det($3); }
| symbol | symbol
{ driver.declare_exogenous_det($1); } { driver.declare_exogenous_det($1); }
| varexo_det_list symbol named_var
{ driver.declare_exogenous_det($2, NULL, $3); }
| varexo_det_list COMMA symbol named_var
{ driver.declare_exogenous_det($3, NULL, $4); }
| symbol named_var
{ driver.declare_exogenous_det($1, NULL, $2); }
| varexo_det_list symbol TEX_NAME | varexo_det_list symbol TEX_NAME
{ driver.declare_exogenous_det($2, $3); } { driver.declare_exogenous_det($2, $3); }
| varexo_det_list COMMA symbol TEX_NAME | varexo_det_list COMMA symbol TEX_NAME
...@@ -423,6 +445,12 @@ parameter_list : parameter_list symbol ...@@ -423,6 +445,12 @@ parameter_list : parameter_list symbol
{ driver.declare_parameter($3); } { driver.declare_parameter($3); }
| symbol | symbol
{ driver.declare_parameter($1); } { driver.declare_parameter($1); }
| parameter_list symbol named_var
{ driver.declare_parameter($2, NULL, $3); }
| parameter_list COMMA symbol named_var
{ driver.declare_parameter($3, NULL, $4); }
| symbol named_var
{ driver.declare_parameter($1, NULL, $2); }
| parameter_list symbol TEX_NAME | parameter_list symbol TEX_NAME
{ driver.declare_parameter($2, $3); } { driver.declare_parameter($2, $3); }
| parameter_list COMMA symbol TEX_NAME | parameter_list COMMA symbol TEX_NAME
...@@ -854,12 +882,6 @@ period_list : period_list COMMA INT_NUMBER ...@@ -854,12 +882,6 @@ period_list : period_list COMMA INT_NUMBER
{ driver.add_period($1); } { driver.add_period($1); }
; ;
expectation_type : PERFECT_FORESIGHT
{ driver.add_expectation_pf(true); }
| SURPRISE
{ driver.add_expectation_pf(false); }
;
sigma_e : SIGMA_E EQUAL '[' triangular_matrix ']' ';' { driver.do_sigma_e(); }; sigma_e : SIGMA_E EQUAL '[' triangular_matrix ']' ';' { driver.do_sigma_e(); };
value_list : value_list COMMA '(' expression ')' value_list : value_list COMMA '(' expression ')'
...@@ -1538,6 +1560,7 @@ estimation_options : o_datafile ...@@ -1538,6 +1560,7 @@ estimation_options : o_datafile
| o_nodisplay | o_nodisplay
| o_graph_format | o_graph_format
| o_conf_sig | o_conf_sig
| o_mh_conf_sig
| o_mh_replic | o_mh_replic
| o_mh_drop | o_mh_drop
| o_mh_jscale | o_mh_jscale
...@@ -2148,6 +2171,7 @@ dynare_sensitivity_option : o_gsa_identification ...@@ -2148,6 +2171,7 @@ dynare_sensitivity_option : o_gsa_identification
| o_nodisplay | o_nodisplay
| o_graph_format | o_graph_format
| o_conf_sig | o_conf_sig
| o_mh_conf_sig
| o_loglinear | o_loglinear
| o_mode_file | o_mode_file
| o_load_ident_files | o_load_ident_files
...@@ -2208,7 +2232,6 @@ conditional_forecast_option : o_periods ...@@ -2208,7 +2232,6 @@ conditional_forecast_option : o_periods
| o_conf_sig | o_conf_sig
| o_controlled_varexo | o_controlled_varexo
| o_parameter_set | o_parameter_set
| o_simulation_type
; ;
plot_conditional_forecast : PLOT_CONDITIONAL_FORECAST symbol_list ';' plot_conditional_forecast : PLOT_CONDITIONAL_FORECAST symbol_list ';'
...@@ -2227,8 +2250,6 @@ conditional_forecast_paths_shock_list : conditional_forecast_paths_shock_elem ...@@ -2227,8 +2250,6 @@ conditional_forecast_paths_shock_list : conditional_forecast_paths_shock_elem
conditional_forecast_paths_shock_elem : VAR symbol ';' PERIODS period_list ';' VALUES value_list ';' conditional_forecast_paths_shock_elem : VAR symbol ';' PERIODS period_list ';' VALUES value_list ';'
{ driver.add_det_shock($2, true); } { driver.add_det_shock($2, true); }
| VAR symbol ';' PERIODS period_list ';' VALUES value_list ';' EXPECTATION expectation_type ';'
{ driver.add_det_shock($2, true); }
; ;
steady_state_model : STEADY_STATE_MODEL ';' { driver.begin_steady_state_model(); } steady_state_model : STEADY_STATE_MODEL ';' { driver.begin_steady_state_model(); }
...@@ -2392,6 +2413,7 @@ o_subsample_name : symbol EQUAL date_expr ':' date_expr ...@@ -2392,6 +2413,7 @@ o_subsample_name : symbol EQUAL date_expr ':' date_expr
{ driver.set_subsample_name_equal_to_date_range($1, $3, $5); } { driver.set_subsample_name_equal_to_date_range($1, $3, $5); }
; ;
o_conf_sig : CONF_SIG EQUAL non_negative_number { driver.option_num("conf_sig", $3); }; o_conf_sig : CONF_SIG EQUAL non_negative_number { driver.option_num("conf_sig", $3); };
o_mh_conf_sig : MH_CONF_SIG EQUAL non_negative_number { driver.option_num("mh_conf_sig", $3); };
o_mh_replic : MH_REPLIC EQUAL INT_NUMBER { driver.option_num("mh_replic", $3); }; o_mh_replic : MH_REPLIC EQUAL INT_NUMBER { driver.option_num("mh_replic", $3); };
o_mh_drop : MH_DROP EQUAL non_negative_number { driver.option_num("mh_drop", $3); }; o_mh_drop : MH_DROP EQUAL non_negative_number { driver.option_num("mh_drop", $3); };
o_mh_jscale : MH_JSCALE EQUAL non_negative_number { driver.option_num("mh_jscale", $3); }; o_mh_jscale : MH_JSCALE EQUAL non_negative_number { driver.option_num("mh_jscale", $3); };
...@@ -2536,11 +2558,6 @@ o_parameter_set : PARAMETER_SET EQUAL PRIOR_MODE ...@@ -2536,11 +2558,6 @@ o_parameter_set : PARAMETER_SET EQUAL PRIOR_MODE
| PARAMETER_SET EQUAL CALIBRATION | PARAMETER_SET EQUAL CALIBRATION
{ driver.option_str("parameter_set", "calibration"); } { driver.option_str("parameter_set", "calibration"); }
; ;
o_simulation_type : SIMULATION_TYPE EQUAL DETERMINISTIC
{ driver.option_str("simulation_type", "deterministic"); }
| SIMULATION_TYPE EQUAL STOCHASTIC
{ driver.option_str("simulation_type", "stochastic"); }
;
o_ms_drop : DROP EQUAL INT_NUMBER { driver.option_num("ms.drop", $3); }; o_ms_drop : DROP EQUAL INT_NUMBER { driver.option_num("ms.drop", $3); };
o_ms_mh_replic : MH_REPLIC EQUAL INT_NUMBER { driver.option_num("ms.mh_replic", $3); }; o_ms_mh_replic : MH_REPLIC EQUAL INT_NUMBER { driver.option_num("ms.mh_replic", $3); };
o_freq : FREQ EQUAL INT_NUMBER o_freq : FREQ EQUAL INT_NUMBER
......
...@@ -260,6 +260,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 ...@@ -260,6 +260,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2
<DYNARE_STATEMENT>print {return token::PRINT;} <DYNARE_STATEMENT>print {return token::PRINT;}
<DYNARE_STATEMENT>noprint {return token::NOPRINT;} <DYNARE_STATEMENT>noprint {return token::NOPRINT;}
<DYNARE_STATEMENT>conf_sig {return token::CONF_SIG;} <DYNARE_STATEMENT>conf_sig {return token::CONF_SIG;}
<DYNARE_STATEMENT>mh_conf_sig {return token::MH_CONF_SIG;}
<DYNARE_STATEMENT>mh_replic {return token::MH_REPLIC;} <DYNARE_STATEMENT>mh_replic {return token::MH_REPLIC;}
<DYNARE_STATEMENT>mh_drop {return token::MH_DROP;} <DYNARE_STATEMENT>mh_drop {return token::MH_DROP;}
<DYNARE_STATEMENT>mh_jscale {return token::MH_JSCALE;} <DYNARE_STATEMENT>mh_jscale {return token::MH_JSCALE;}
...@@ -503,9 +504,6 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 ...@@ -503,9 +504,6 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2
<DYNARE_STATEMENT>posterior_mode {return token::POSTERIOR_MODE; } <DYNARE_STATEMENT>posterior_mode {return token::POSTERIOR_MODE; }
<DYNARE_STATEMENT>posterior_mean {return token::POSTERIOR_MEAN; } <DYNARE_STATEMENT>posterior_mean {return token::POSTERIOR_MEAN; }
<DYNARE_STATEMENT>posterior_median {return token::POSTERIOR_MEDIAN; } <DYNARE_STATEMENT>posterior_median {return token::POSTERIOR_MEDIAN; }
<DYNARE_STATEMENT>simulation_type {return token::SIMULATION_TYPE; }
<DYNARE_STATEMENT>deterministic {return token::DETERMINISTIC; }
<DYNARE_STATEMENT>stochastic {return token::STOCHASTIC; }
<DYNARE_STATEMENT>k_order_solver {return token::K_ORDER_SOLVER; } <DYNARE_STATEMENT>k_order_solver {return token::K_ORDER_SOLVER; }
<DYNARE_STATEMENT>filter_covariance {return token::FILTER_COVARIANCE; } <DYNARE_STATEMENT>filter_covariance {return token::FILTER_COVARIANCE; }
<DYNARE_STATEMENT>filter_decomposition {return token::FILTER_DECOMPOSITION; } <DYNARE_STATEMENT>filter_decomposition {return token::FILTER_DECOMPOSITION; }
...@@ -535,8 +533,6 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 ...@@ -535,8 +533,6 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2
<DYNARE_BLOCK>stderr {return token::STDERR;} <DYNARE_BLOCK>stderr {return token::STDERR;}
<DYNARE_BLOCK>values {return token::VALUES;} <DYNARE_BLOCK>values {return token::VALUES;}
<DYNARE_BLOCK>corr {return token::CORR;} <DYNARE_BLOCK>corr {return token::CORR;}
<DYNARE_BLOCK>surprise {return token::SURPRISE;}
<DYNARE_BLOCK>perfect_foresight {return token::PERFECT_FORESIGHT;}
<DYNARE_BLOCK>periods {return token::PERIODS;} <DYNARE_BLOCK>periods {return token::PERIODS;}
<DYNARE_BLOCK>cutoff {return token::CUTOFF;} <DYNARE_BLOCK>cutoff {return token::CUTOFF;}
<DYNARE_BLOCK>mfs {return token::MFS;} <DYNARE_BLOCK>mfs {return token::MFS;}
......
...@@ -621,7 +621,9 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type, ...@@ -621,7 +621,9 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
break; break;
case eModelLocalVariable: case eModelLocalVariable:
if (output_type == oMatlabDynamicModelSparse || output_type == oMatlabStaticModelSparse) if (output_type == oMatlabDynamicModelSparse || output_type == oMatlabStaticModelSparse
|| output_type == oMatlabDynamicSteadyStateOperator || output_type == oMatlabDynamicSparseSteadyStateOperator
|| output_type == oCDynamicSteadyStateOperator)
{ {
output << "("; output << "(";
datatree.local_variables_table[symb_id]->writeOutput(output, output_type, temporary_terms, tef_terms); datatree.local_variables_table[symb_id]->writeOutput(output, output_type, temporary_terms, tef_terms);
...@@ -4265,19 +4267,26 @@ TrinaryOpNode::isInStaticForm() const ...@@ -4265,19 +4267,26 @@ TrinaryOpNode::isInStaticForm() const
return arg1->isInStaticForm() && arg2->isInStaticForm() && arg3->isInStaticForm(); return arg1->isInStaticForm() && arg2->isInStaticForm() && arg3->isInStaticForm();
} }
ExternalFunctionNode::ExternalFunctionNode(DataTree &datatree_arg, AbstractExternalFunctionNode::AbstractExternalFunctionNode(DataTree &datatree_arg,
int symb_id_arg, int symb_id_arg,
const vector<expr_t> &arguments_arg) : const vector<expr_t> &arguments_arg) :
ExprNode(datatree_arg), ExprNode(datatree_arg),
symb_id(symb_id_arg), symb_id(symb_id_arg),
arguments(arguments_arg) arguments(arguments_arg)
{
}
ExternalFunctionNode::ExternalFunctionNode(DataTree &datatree_arg,
int symb_id_arg,
const vector<expr_t> &arguments_arg) :
AbstractExternalFunctionNode(datatree_arg, symb_id_arg, arguments_arg)
{ {
// Add myself to the external function map // Add myself to the external function map
datatree.external_function_node_map[make_pair(arguments, symb_id)] = this; datatree.external_function_node_map[make_pair(arguments, symb_id)] = this;
} }
void void
ExternalFunctionNode::prepareForDerivation() AbstractExternalFunctionNode::prepareForDerivation()
{ {
if (preparedForDerivation) if (preparedForDerivation)
return; return;
...@@ -4297,7 +4306,7 @@ ExternalFunctionNode::prepareForDerivation() ...@@ -4297,7 +4306,7 @@ ExternalFunctionNode::prepareForDerivation()
} }
expr_t expr_t
ExternalFunctionNode::computeDerivative(int deriv_id) AbstractExternalFunctionNode::computeDerivative(int deriv_id)
{ {
assert(datatree.external_functions_table.getNargs(symb_id) > 0); assert(datatree.external_functions_table.getNargs(symb_id) > 0);
vector<expr_t> dargs; vector<expr_t> dargs;
...@@ -4313,7 +4322,7 @@ ExternalFunctionNode::composeDerivatives(const vector<expr_t> &dargs) ...@@ -4313,7 +4322,7 @@ ExternalFunctionNode::composeDerivatives(const vector<expr_t> &dargs)
for (int i = 0; i < (int) dargs.size(); i++) for (int i = 0; i < (int) dargs.size(); i++)
if (dargs.at(i) != 0) if (dargs.at(i) != 0)
dNodes.push_back(datatree.AddTimes(dargs.at(i), dNodes.push_back(datatree.AddTimes(dargs.at(i),
datatree.AddFirstDerivExternalFunctionNode(symb_id, arguments, i+1))); datatree.AddFirstDerivExternalFunction(symb_id, arguments, i+1)));
expr_t theDeriv = datatree.Zero; expr_t theDeriv = datatree.Zero;
for (vector<expr_t>::const_iterator it = dNodes.begin(); it != dNodes.end(); it++) for (vector<expr_t>::const_iterator it = dNodes.begin(); it != dNodes.end(); it++)
...@@ -4322,7 +4331,7 @@ ExternalFunctionNode::composeDerivatives(const vector<expr_t> &dargs) ...@@ -4322,7 +4331,7 @@ ExternalFunctionNode::composeDerivatives(const vector<expr_t> &dargs)
} }
expr_t expr_t
ExternalFunctionNode::getChainRuleDerivative(int deriv_id, const map<int, expr_t> &recursive_variables) AbstractExternalFunctionNode::getChainRuleDerivative(int deriv_id, const map<int, expr_t> &recursive_variables)
{ {
assert(datatree.external_functions_table.getNargs(symb_id) > 0); assert(datatree.external_functions_table.getNargs(symb_id) > 0);
vector<expr_t> dargs; vector<expr_t> dargs;
...@@ -4341,7 +4350,7 @@ ExternalFunctionNode::computeTemporaryTerms(map<expr_t, int> &reference_count, ...@@ -4341,7 +4350,7 @@ ExternalFunctionNode::computeTemporaryTerms(map<expr_t, int> &reference_count,
} }
void void
ExternalFunctionNode::writeExternalFunctionArguments(ostream &output, ExprNodeOutputType output_type, AbstractExternalFunctionNode::writeExternalFunctionArguments(ostream &output, ExprNodeOutputType output_type,
const temporary_terms_t &temporary_terms, const temporary_terms_t &temporary_terms,
deriv_node_temp_terms_t &tef_terms) const deriv_node_temp_terms_t &tef_terms) const
{ {
...@@ -4356,7 +4365,7 @@ ExternalFunctionNode::writeExternalFunctionArguments(ostream &output, ExprNodeOu ...@@ -4356,7 +4365,7 @@ ExternalFunctionNode::writeExternalFunctionArguments(ostream &output, ExprNodeOu
} }
void void
ExternalFunctionNode::writePrhs(ostream &output, ExprNodeOutputType output_type, AbstractExternalFunctionNode::writePrhs(ostream &output, ExprNodeOutputType output_type,
const temporary_terms_t &temporary_terms, const temporary_terms_t &temporary_terms,
deriv_node_temp_terms_t &tef_terms, const string &ending) const deriv_node_temp_terms_t &tef_terms, const string &ending) const
{ {
...@@ -4376,9 +4385,12 @@ ExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType output_typ ...@@ -4376,9 +4385,12 @@ ExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType output_typ
const temporary_terms_t &temporary_terms, const temporary_terms_t &temporary_terms,
deriv_node_temp_terms_t &tef_terms) const deriv_node_temp_terms_t &tef_terms) const
{ {
if (output_type == oMatlabOutsideModel || output_type == oSteadyStateFile) if (output_type == oMatlabOutsideModel || output_type == oSteadyStateFile
|| IS_LATEX(output_type))
{ {
output << datatree.symbol_table.getName(symb_id) << "("; string name = IS_LATEX(output_type) ? datatree.symbol_table.getTeXName(symb_id)
: datatree.symbol_table.getName(symb_id);
output << name << "(";
writeExternalFunctionArguments(output, output_type, temporary_terms, tef_terms); writeExternalFunctionArguments(output, output_type, temporary_terms, tef_terms);
output << ")"; output << ")";
return; return;
...@@ -4400,7 +4412,7 @@ ExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType output_typ ...@@ -4400,7 +4412,7 @@ ExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType output_typ
} }
unsigned int unsigned int
ExternalFunctionNode::compileExternalFunctionArguments(ostream &CompileCode, unsigned int &instruction_number, AbstractExternalFunctionNode::compileExternalFunctionArguments(ostream &CompileCode, unsigned int &instruction_number,
bool lhs_rhs, const temporary_terms_t &temporary_terms, bool lhs_rhs, const temporary_terms_t &temporary_terms,
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
deriv_node_temp_terms_t &tef_terms) const deriv_node_temp_terms_t &tef_terms) const
...@@ -4591,7 +4603,7 @@ ExternalFunctionNode::computeTemporaryTerms(map<expr_t, int> &reference_count, ...@@ -4591,7 +4603,7 @@ ExternalFunctionNode::computeTemporaryTerms(map<expr_t, int> &reference_count,
} }
void void
ExternalFunctionNode::collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const AbstractExternalFunctionNode::collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const
{ {
for (vector<expr_t>::const_iterator it = arguments.begin(); for (vector<expr_t>::const_iterator it = arguments.begin();
it != arguments.end(); it++) it != arguments.end(); it++)
...@@ -4599,9 +4611,9 @@ ExternalFunctionNode::collectDynamicVariables(SymbolType type_arg, set<pair<int, ...@@ -4599,9 +4611,9 @@ ExternalFunctionNode::collectDynamicVariables(SymbolType type_arg, set<pair<int,
} }
void void
ExternalFunctionNode::collectTemporary_terms(const temporary_terms_t &temporary_terms, temporary_terms_inuse_t &temporary_terms_inuse, int Curr_Block) const AbstractExternalFunctionNode::collectTemporary_terms(const temporary_terms_t &temporary_terms, temporary_terms_inuse_t &temporary_terms_inuse, int Curr_Block) const
{ {
temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<ExternalFunctionNode *>(this)); temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<AbstractExternalFunctionNode *>(this));
if (it != temporary_terms.end()) if (it != temporary_terms.end())
temporary_terms_inuse.insert(idx); temporary_terms_inuse.insert(idx);
else else
...@@ -4613,13 +4625,13 @@ ExternalFunctionNode::collectTemporary_terms(const temporary_terms_t &temporary_ ...@@ -4613,13 +4625,13 @@ ExternalFunctionNode::collectTemporary_terms(const temporary_terms_t &temporary_
} }
double double
ExternalFunctionNode::eval(const eval_context_t &eval_context) const throw (EvalException, EvalExternalFunctionException) AbstractExternalFunctionNode::eval(const eval_context_t &eval_context) const throw (EvalException, EvalExternalFunctionException)
{ {
throw EvalExternalFunctionException(); throw EvalExternalFunctionException();
} }
pair<int, expr_t> pair<int, expr_t>
ExternalFunctionNode::normalizeEquation(int var_endo, vector<pair<int, pair<expr_t, expr_t> > > &List_of_Op_RHS) const AbstractExternalFunctionNode::normalizeEquation(int var_endo, vector<pair<int, pair<expr_t, expr_t> > > &List_of_Op_RHS) const
{ {
vector<pair<bool, expr_t> > V_arguments; vector<pair<bool, expr_t> > V_arguments;
vector<expr_t> V_expr_t; vector<expr_t> V_expr_t;
...@@ -4658,7 +4670,7 @@ ExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const ...@@ -4658,7 +4670,7 @@ ExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const
} }
int int
ExternalFunctionNode::maxEndoLead() const AbstractExternalFunctionNode::maxEndoLead() const
{ {
int val = 0; int val = 0;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (vector<expr_t>::const_iterator it = arguments.begin();
...@@ -4668,7 +4680,7 @@ ExternalFunctionNode::maxEndoLead() const ...@@ -4668,7 +4680,7 @@ ExternalFunctionNode::maxEndoLead() const
} }
int int
ExternalFunctionNode::maxExoLead() const AbstractExternalFunctionNode::maxExoLead() const
{ {
int val = 0; int val = 0;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (vector<expr_t>::const_iterator it = arguments.begin();
...@@ -4678,7 +4690,7 @@ ExternalFunctionNode::maxExoLead() const ...@@ -4678,7 +4690,7 @@ ExternalFunctionNode::maxExoLead() const
} }
int int
ExternalFunctionNode::maxEndoLag() const AbstractExternalFunctionNode::maxEndoLag() const
{ {
int val = 0; int val = 0;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (vector<expr_t>::const_iterator it = arguments.begin();
...@@ -4688,7 +4700,7 @@ ExternalFunctionNode::maxEndoLag() const ...@@ -4688,7 +4700,7 @@ ExternalFunctionNode::maxEndoLag() const
} }
int int
ExternalFunctionNode::maxExoLag() const AbstractExternalFunctionNode::maxExoLag() const
{ {
int val = 0; int val = 0;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (vector<expr_t>::const_iterator it = arguments.begin();
...@@ -4698,7 +4710,7 @@ ExternalFunctionNode::maxExoLag() const ...@@ -4698,7 +4710,7 @@ ExternalFunctionNode::maxExoLag() const
} }
int int
ExternalFunctionNode::maxLead() const AbstractExternalFunctionNode::maxLead() const
{ {
int val = 0; int val = 0;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (vector<expr_t>::const_iterator it = arguments.begin();
...@@ -4708,7 +4720,7 @@ ExternalFunctionNode::maxLead() const ...@@ -4708,7 +4720,7 @@ ExternalFunctionNode::maxLead() const
} }
expr_t expr_t
ExternalFunctionNode::decreaseLeadsLags(int n) const AbstractExternalFunctionNode::decreaseLeadsLags(int n) const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++)
...@@ -4717,7 +4729,7 @@ ExternalFunctionNode::decreaseLeadsLags(int n) const ...@@ -4717,7 +4729,7 @@ ExternalFunctionNode::decreaseLeadsLags(int n) const
} }
expr_t expr_t
ExternalFunctionNode::decreaseLeadsLagsPredeterminedVariables() const AbstractExternalFunctionNode::decreaseLeadsLagsPredeterminedVariables() const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++)
...@@ -4726,7 +4738,7 @@ ExternalFunctionNode::decreaseLeadsLagsPredeterminedVariables() const ...@@ -4726,7 +4738,7 @@ ExternalFunctionNode::decreaseLeadsLagsPredeterminedVariables() const
} }
expr_t expr_t
ExternalFunctionNode::substituteEndoLeadGreaterThanTwo(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const AbstractExternalFunctionNode::substituteEndoLeadGreaterThanTwo(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++)
...@@ -4735,7 +4747,7 @@ ExternalFunctionNode::substituteEndoLeadGreaterThanTwo(subst_table_t &subst_tabl ...@@ -4735,7 +4747,7 @@ ExternalFunctionNode::substituteEndoLeadGreaterThanTwo(subst_table_t &subst_tabl
} }
expr_t expr_t
ExternalFunctionNode::substituteEndoLagGreaterThanTwo(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const AbstractExternalFunctionNode::substituteEndoLagGreaterThanTwo(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++)
...@@ -4744,7 +4756,7 @@ ExternalFunctionNode::substituteEndoLagGreaterThanTwo(subst_table_t &subst_table ...@@ -4744,7 +4756,7 @@ ExternalFunctionNode::substituteEndoLagGreaterThanTwo(subst_table_t &subst_table
} }
expr_t expr_t
ExternalFunctionNode::substituteExoLead(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const AbstractExternalFunctionNode::substituteExoLead(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++)
...@@ -4753,7 +4765,7 @@ ExternalFunctionNode::substituteExoLead(subst_table_t &subst_table, vector<Binar ...@@ -4753,7 +4765,7 @@ ExternalFunctionNode::substituteExoLead(subst_table_t &subst_table, vector<Binar
} }
expr_t expr_t
ExternalFunctionNode::substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const AbstractExternalFunctionNode::substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++)
...@@ -4762,7 +4774,7 @@ ExternalFunctionNode::substituteExoLag(subst_table_t &subst_table, vector<Binary ...@@ -4762,7 +4774,7 @@ ExternalFunctionNode::substituteExoLag(subst_table_t &subst_table, vector<Binary
} }
expr_t expr_t
ExternalFunctionNode::substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const AbstractExternalFunctionNode::substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++)
...@@ -4771,7 +4783,7 @@ ExternalFunctionNode::substituteExpectation(subst_table_t &subst_table, vector<B ...@@ -4771,7 +4783,7 @@ ExternalFunctionNode::substituteExpectation(subst_table_t &subst_table, vector<B
} }
expr_t expr_t
ExternalFunctionNode::differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const AbstractExternalFunctionNode::differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++)
...@@ -4786,7 +4798,7 @@ ExternalFunctionNode::buildSimilarExternalFunctionNode(vector<expr_t> &alt_args, ...@@ -4786,7 +4798,7 @@ ExternalFunctionNode::buildSimilarExternalFunctionNode(vector<expr_t> &alt_args,
} }
bool bool
ExternalFunctionNode::alreadyWrittenAsTefTerm(int the_symb_id, deriv_node_temp_terms_t &tef_terms) const AbstractExternalFunctionNode::alreadyWrittenAsTefTerm(int the_symb_id, deriv_node_temp_terms_t &tef_terms) const
{ {
deriv_node_temp_terms_t::const_iterator it = tef_terms.find(make_pair(the_symb_id, arguments)); deriv_node_temp_terms_t::const_iterator it = tef_terms.find(make_pair(the_symb_id, arguments));
if (it != tef_terms.end()) if (it != tef_terms.end())
...@@ -4795,7 +4807,7 @@ ExternalFunctionNode::alreadyWrittenAsTefTerm(int the_symb_id, deriv_node_temp_t ...@@ -4795,7 +4807,7 @@ ExternalFunctionNode::alreadyWrittenAsTefTerm(int the_symb_id, deriv_node_temp_t
} }
int int
ExternalFunctionNode::getIndxInTefTerms(int the_symb_id, deriv_node_temp_terms_t &tef_terms) const throw (UnknownFunctionNameAndArgs) AbstractExternalFunctionNode::getIndxInTefTerms(int the_symb_id, deriv_node_temp_terms_t &tef_terms) const throw (UnknownFunctionNameAndArgs)
{ {
deriv_node_temp_terms_t::const_iterator it = tef_terms.find(make_pair(the_symb_id, arguments)); deriv_node_temp_terms_t::const_iterator it = tef_terms.find(make_pair(the_symb_id, arguments));
if (it != tef_terms.end()) if (it != tef_terms.end())
...@@ -4804,19 +4816,19 @@ ExternalFunctionNode::getIndxInTefTerms(int the_symb_id, deriv_node_temp_terms_t ...@@ -4804,19 +4816,19 @@ ExternalFunctionNode::getIndxInTefTerms(int the_symb_id, deriv_node_temp_terms_t
} }
bool bool
ExternalFunctionNode::isNumConstNodeEqualTo(double value) const AbstractExternalFunctionNode::isNumConstNodeEqualTo(double value) const
{ {
return false; return false;
} }
bool bool
ExternalFunctionNode::isVariableNodeEqualTo(SymbolType type_arg, int variable_id, int lag_arg) const AbstractExternalFunctionNode::isVariableNodeEqualTo(SymbolType type_arg, int variable_id, int lag_arg) const
{ {
return false; return false;
} }
bool bool
ExternalFunctionNode::containsEndogenous(void) const AbstractExternalFunctionNode::containsEndogenous(void) const
{ {
bool result = false; bool result = false;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++)
...@@ -4825,7 +4837,7 @@ ExternalFunctionNode::containsEndogenous(void) const ...@@ -4825,7 +4837,7 @@ ExternalFunctionNode::containsEndogenous(void) const
} }
expr_t expr_t
ExternalFunctionNode::replaceTrendVar() const AbstractExternalFunctionNode::replaceTrendVar() const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++)
...@@ -4834,7 +4846,7 @@ ExternalFunctionNode::replaceTrendVar() const ...@@ -4834,7 +4846,7 @@ ExternalFunctionNode::replaceTrendVar() const
} }
expr_t expr_t
ExternalFunctionNode::detrend(int symb_id, bool log_trend, expr_t trend) const AbstractExternalFunctionNode::detrend(int symb_id, bool log_trend, expr_t trend) const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++)
...@@ -4843,7 +4855,7 @@ ExternalFunctionNode::detrend(int symb_id, bool log_trend, expr_t trend) const ...@@ -4843,7 +4855,7 @@ ExternalFunctionNode::detrend(int symb_id, bool log_trend, expr_t trend) const
} }
expr_t expr_t
ExternalFunctionNode::removeTrendLeadLag(map<int, expr_t> trend_symbols_map) const AbstractExternalFunctionNode::removeTrendLeadLag(map<int, expr_t> trend_symbols_map) const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++)
...@@ -4852,7 +4864,7 @@ ExternalFunctionNode::removeTrendLeadLag(map<int, expr_t> trend_symbols_map) con ...@@ -4852,7 +4864,7 @@ ExternalFunctionNode::removeTrendLeadLag(map<int, expr_t> trend_symbols_map) con
} }
bool bool
ExternalFunctionNode::isInStaticForm() const AbstractExternalFunctionNode::isInStaticForm() const
{ {
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); ++it) for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); ++it)
if (!(*it)->isInStaticForm()) if (!(*it)->isInStaticForm())
...@@ -4865,7 +4877,7 @@ FirstDerivExternalFunctionNode::FirstDerivExternalFunctionNode(DataTree &datatre ...@@ -4865,7 +4877,7 @@ FirstDerivExternalFunctionNode::FirstDerivExternalFunctionNode(DataTree &datatre
int top_level_symb_id_arg, int top_level_symb_id_arg,
const vector<expr_t> &arguments_arg, const vector<expr_t> &arguments_arg,
int inputIndex_arg) : int inputIndex_arg) :
ExternalFunctionNode(datatree_arg, top_level_symb_id_arg, arguments_arg), AbstractExternalFunctionNode(datatree_arg, top_level_symb_id_arg, arguments_arg),
inputIndex(inputIndex_arg) inputIndex(inputIndex_arg)
{ {
// Add myself to the first derivative external function map // Add myself to the first derivative external function map
...@@ -4901,7 +4913,7 @@ FirstDerivExternalFunctionNode::composeDerivatives(const vector<expr_t> &dargs) ...@@ -4901,7 +4913,7 @@ FirstDerivExternalFunctionNode::composeDerivatives(const vector<expr_t> &dargs)
for (int i = 0; i < (int) dargs.size(); i++) for (int i = 0; i < (int) dargs.size(); i++)
if (dargs.at(i) != 0) if (dargs.at(i) != 0)
dNodes.push_back(datatree.AddTimes(dargs.at(i), dNodes.push_back(datatree.AddTimes(dargs.at(i),
datatree.AddSecondDerivExternalFunctionNode(symb_id, arguments, inputIndex, i+1))); datatree.AddSecondDerivExternalFunction(symb_id, arguments, inputIndex, i+1)));
expr_t theDeriv = datatree.Zero; expr_t theDeriv = datatree.Zero;
for (vector<expr_t>::const_iterator it = dNodes.begin(); it != dNodes.end(); it++) for (vector<expr_t>::const_iterator it = dNodes.begin(); it != dNodes.end(); it++)
theDeriv = datatree.AddPlus(theDeriv, *it); theDeriv = datatree.AddPlus(theDeriv, *it);
...@@ -4915,6 +4927,15 @@ FirstDerivExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType ...@@ -4915,6 +4927,15 @@ FirstDerivExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType
{ {
assert(output_type != oMatlabOutsideModel); assert(output_type != oMatlabOutsideModel);
if (IS_LATEX(output_type))
{
output << "\\frac{\\partial " << datatree.symbol_table.getTeXName(symb_id)
<< "}{\\partial " << inputIndex << "}(";
writeExternalFunctionArguments(output, output_type, temporary_terms, tef_terms);
output << ")";
return;
}
// If current node is a temporary term // If current node is a temporary term
temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<FirstDerivExternalFunctionNode *>(this)); temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<FirstDerivExternalFunctionNode *>(this));
if (it != temporary_terms.end()) if (it != temporary_terms.end())
...@@ -4995,7 +5016,17 @@ FirstDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Exp ...@@ -4995,7 +5016,17 @@ FirstDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Exp
int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id); int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id);
assert(first_deriv_symb_id != eExtFunSetButNoNameProvided); assert(first_deriv_symb_id != eExtFunSetButNoNameProvided);
if (first_deriv_symb_id == symb_id || alreadyWrittenAsTefTerm(first_deriv_symb_id, tef_terms)) /* For a node with derivs provided by the user function, call the method
on the non-derived node */
if (first_deriv_symb_id == symb_id)
{
expr_t parent = datatree.AddExternalFunction(symb_id, arguments);
parent->writeExternalFunctionOutput(output, output_type, temporary_terms,
tef_terms);
return;
}
if (alreadyWrittenAsTefTerm(first_deriv_symb_id, tef_terms))
return; return;
if (IS_C(output_type)) if (IS_C(output_type))
...@@ -5124,12 +5155,40 @@ FirstDerivExternalFunctionNode::compileExternalFunctionOutput(ostream &CompileCo ...@@ -5124,12 +5155,40 @@ FirstDerivExternalFunctionNode::compileExternalFunctionOutput(ostream &CompileCo
} }
} }
expr_t
FirstDerivExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const
{
vector<expr_t> dynamic_arguments;
for (vector<expr_t>::const_iterator it = arguments.begin();
it != arguments.end(); it++)
dynamic_arguments.push_back((*it)->cloneDynamic(dynamic_datatree));
return dynamic_datatree.AddFirstDerivExternalFunction(symb_id, dynamic_arguments,
inputIndex);
}
expr_t
FirstDerivExternalFunctionNode::buildSimilarExternalFunctionNode(vector<expr_t> &alt_args, DataTree &alt_datatree) const
{
return alt_datatree.AddFirstDerivExternalFunction(symb_id, alt_args, inputIndex);
}
expr_t
FirstDerivExternalFunctionNode::toStatic(DataTree &static_datatree) const
{
vector<expr_t> static_arguments;
for (vector<expr_t>::const_iterator it = arguments.begin();
it != arguments.end(); it++)
static_arguments.push_back((*it)->toStatic(static_datatree));
return static_datatree.AddFirstDerivExternalFunction(symb_id, static_arguments,
inputIndex);
}
SecondDerivExternalFunctionNode::SecondDerivExternalFunctionNode(DataTree &datatree_arg, SecondDerivExternalFunctionNode::SecondDerivExternalFunctionNode(DataTree &datatree_arg,
int top_level_symb_id_arg, int top_level_symb_id_arg,
const vector<expr_t> &arguments_arg, const vector<expr_t> &arguments_arg,
int inputIndex1_arg, int inputIndex1_arg,
int inputIndex2_arg) : int inputIndex2_arg) :
ExternalFunctionNode(datatree_arg, top_level_symb_id_arg, arguments_arg), AbstractExternalFunctionNode(datatree_arg, top_level_symb_id_arg, arguments_arg),
inputIndex1(inputIndex1_arg), inputIndex1(inputIndex1_arg),
inputIndex2(inputIndex2_arg) inputIndex2(inputIndex2_arg)
{ {
...@@ -5160,7 +5219,8 @@ SecondDerivExternalFunctionNode::computeTemporaryTerms(map<expr_t, int> &referen ...@@ -5160,7 +5219,8 @@ SecondDerivExternalFunctionNode::computeTemporaryTerms(map<expr_t, int> &referen
} }
expr_t expr_t
SecondDerivExternalFunctionNode::computeDerivative(int deriv_id) SecondDerivExternalFunctionNode::composeDerivatives(const vector<expr_t> &dargs)
{ {
cerr << "ERROR: third order derivatives of external functions are not implemented" << endl; cerr << "ERROR: third order derivatives of external functions are not implemented" << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
...@@ -5173,6 +5233,15 @@ SecondDerivExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType ...@@ -5173,6 +5233,15 @@ SecondDerivExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType
{ {
assert(output_type != oMatlabOutsideModel); assert(output_type != oMatlabOutsideModel);
if (IS_LATEX(output_type))
{
output << "\\frac{\\partial^2 " << datatree.symbol_table.getTeXName(symb_id)
<< "}{\\partial " << inputIndex1 << "\\partial " << inputIndex2 << "}(";
writeExternalFunctionArguments(output, output_type, temporary_terms, tef_terms);
output << ")";
return;
}
// If current node is a temporary term // If current node is a temporary term
temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<SecondDerivExternalFunctionNode *>(this)); temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<SecondDerivExternalFunctionNode *>(this));
if (it != temporary_terms.end()) if (it != temporary_terms.end())
...@@ -5229,8 +5298,17 @@ SecondDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Ex ...@@ -5229,8 +5298,17 @@ SecondDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Ex
int second_deriv_symb_id = datatree.external_functions_table.getSecondDerivSymbID(symb_id); int second_deriv_symb_id = datatree.external_functions_table.getSecondDerivSymbID(symb_id);
assert(second_deriv_symb_id != eExtFunSetButNoNameProvided); assert(second_deriv_symb_id != eExtFunSetButNoNameProvided);
if (alreadyWrittenAsTefTerm(second_deriv_symb_id, tef_terms) /* For a node with derivs provided by the user function, call the method
|| second_deriv_symb_id == symb_id) on the non-derived node */
if (second_deriv_symb_id == symb_id)
{
expr_t parent = datatree.AddExternalFunction(symb_id, arguments);
parent->writeExternalFunctionOutput(output, output_type, temporary_terms,
tef_terms);
return;
}
if (alreadyWrittenAsTefTerm(second_deriv_symb_id, tef_terms))
return; return;
if (IS_C(output_type)) if (IS_C(output_type))
...@@ -5316,3 +5394,51 @@ SecondDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Ex ...@@ -5316,3 +5394,51 @@ SecondDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Ex
output << ");" << endl; output << ");" << endl;
} }
} }
expr_t
SecondDerivExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const
{
vector<expr_t> dynamic_arguments;
for (vector<expr_t>::const_iterator it = arguments.begin();
it != arguments.end(); it++)
dynamic_arguments.push_back((*it)->cloneDynamic(dynamic_datatree));
return dynamic_datatree.AddSecondDerivExternalFunction(symb_id, dynamic_arguments,
inputIndex1, inputIndex2);
}
expr_t
SecondDerivExternalFunctionNode::buildSimilarExternalFunctionNode(vector<expr_t> &alt_args, DataTree &alt_datatree) const
{
return alt_datatree.AddSecondDerivExternalFunction(symb_id, alt_args, inputIndex1, inputIndex2);
}
expr_t
SecondDerivExternalFunctionNode::toStatic(DataTree &static_datatree) const
{
vector<expr_t> static_arguments;
for (vector<expr_t>::const_iterator it = arguments.begin();
it != arguments.end(); it++)
static_arguments.push_back((*it)->toStatic(static_datatree));
return static_datatree.AddSecondDerivExternalFunction(symb_id, static_arguments,
inputIndex1, inputIndex2);
}
void
SecondDerivExternalFunctionNode::compile(ostream &CompileCode, unsigned int &instruction_number,
bool lhs_rhs, const temporary_terms_t &temporary_terms,
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
deriv_node_temp_terms_t &tef_terms) const
{
cerr << "SecondDerivExternalFunctionNode::compile: not implemented." << endl;
exit(EXIT_FAILURE);
}
void
SecondDerivExternalFunctionNode::compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
bool lhs_rhs, const temporary_terms_t &temporary_terms,
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
deriv_node_temp_terms_t &tef_terms) const
{
cerr << "SecondDerivExternalFunctionNode::compileExternalFunctionOutput: not implemented." << endl;
exit(EXIT_FAILURE);
}
/* /*
* Copyright (C) 2007-2013 Dynare Team * Copyright (C) 2007-2014 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
...@@ -20,13 +20,13 @@ ...@@ -20,13 +20,13 @@
#ifndef _EXPR_NODE_HH #ifndef _EXPR_NODE_HH
#define _EXPR_NODE_HH #define _EXPR_NODE_HH
using namespace std;
#include <set> #include <set>
#include <map> #include <map>
#include <vector> #include <vector>
#include <ostream> #include <ostream>
using namespace std;
#include "SymbolTable.hh" #include "SymbolTable.hh"
#include "CodeInterpreter.hh" #include "CodeInterpreter.hh"
#include "ExternalFunctionsTable.hh" #include "ExternalFunctionsTable.hh"
...@@ -121,7 +121,7 @@ class ExprNode ...@@ -121,7 +121,7 @@ class ExprNode
friend class UnaryOpNode; friend class UnaryOpNode;
friend class BinaryOpNode; friend class BinaryOpNode;
friend class TrinaryOpNode; friend class TrinaryOpNode;
friend class ExternalFunctionNode; friend class AbstractExternalFunctionNode;
private: private:
//! Computes derivative w.r. to a derivation ID (but doesn't store it in derivatives map) //! Computes derivative w.r. to a derivation ID (but doesn't store it in derivatives map)
/*! You shoud use getDerivative() to get the benefit of symbolic a priori and of caching */ /*! You shoud use getDerivative() to get the benefit of symbolic a priori and of caching */
...@@ -767,11 +767,11 @@ public: ...@@ -767,11 +767,11 @@ public:
}; };
//! External function node //! External function node
class ExternalFunctionNode : public ExprNode class AbstractExternalFunctionNode : public ExprNode
{ {
private: private:
virtual expr_t computeDerivative(int deriv_id); virtual expr_t computeDerivative(int deriv_id);
virtual expr_t composeDerivatives(const vector<expr_t> &dargs); virtual expr_t composeDerivatives(const vector<expr_t> &dargs) = 0;
protected: protected:
//! Thrown when trying to access an unknown entry in external_function_node_map //! Thrown when trying to access an unknown entry in external_function_node_map
class UnknownFunctionNameAndArgs class UnknownFunctionNameAndArgs
...@@ -786,24 +786,24 @@ protected: ...@@ -786,24 +786,24 @@ protected:
//! Helper function to write output arguments of any given external function //! Helper function to write output arguments of any given external function
void writeExternalFunctionArguments(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const; void writeExternalFunctionArguments(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
public: public:
ExternalFunctionNode(DataTree &datatree_arg, int symb_id_arg, AbstractExternalFunctionNode(DataTree &datatree_arg, int symb_id_arg,
const vector<expr_t> &arguments_arg); const vector<expr_t> &arguments_arg);
virtual void prepareForDerivation(); virtual void prepareForDerivation();
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const; virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const = 0;
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const; virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const = 0;
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type, virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
const temporary_terms_t &temporary_terms, const temporary_terms_t &temporary_terms,
deriv_node_temp_terms_t &tef_terms) const; deriv_node_temp_terms_t &tef_terms) const = 0;
virtual void compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number, virtual void compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
bool lhs_rhs, const temporary_terms_t &temporary_terms, bool lhs_rhs, const temporary_terms_t &temporary_terms,
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
deriv_node_temp_terms_t &tef_terms) const; deriv_node_temp_terms_t &tef_terms) const = 0;
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, virtual void computeTemporaryTerms(map<expr_t, int> &reference_count,
temporary_terms_t &temporary_terms, temporary_terms_t &temporary_terms,
map<expr_t, pair<int, int> > &first_occurence, map<expr_t, pair<int, int> > &first_occurence,
int Curr_block, int Curr_block,
vector< vector<temporary_terms_t> > &v_temporary_terms, vector< vector<temporary_terms_t> > &v_temporary_terms,
int equation) const; int equation) const = 0;
virtual void collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const; virtual void collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
virtual void collectTemporary_terms(const temporary_terms_t &temporary_terms, temporary_terms_inuse_t &temporary_terms_inuse, int Curr_Block) const; virtual void collectTemporary_terms(const temporary_terms_t &temporary_terms, temporary_terms_inuse_t &temporary_terms_inuse, int Curr_Block) const;
virtual double eval(const eval_context_t &eval_context) const throw (EvalException, EvalExternalFunctionException); virtual double eval(const eval_context_t &eval_context) const throw (EvalException, EvalExternalFunctionException);
...@@ -812,8 +812,8 @@ public: ...@@ -812,8 +812,8 @@ public:
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
deriv_node_temp_terms_t &tef_terms) const; deriv_node_temp_terms_t &tef_terms) const;
virtual void compile(ostream &CompileCode, unsigned int &instruction_number, bool lhs_rhs, const temporary_terms_t &temporary_terms, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic, deriv_node_temp_terms_t &tef_terms) const; virtual void compile(ostream &CompileCode, unsigned int &instruction_number, bool lhs_rhs, const temporary_terms_t &temporary_terms, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic, deriv_node_temp_terms_t &tef_terms) const = 0;
virtual expr_t toStatic(DataTree &static_datatree) const; virtual expr_t toStatic(DataTree &static_datatree) const = 0;
virtual pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<pair<int, pair<expr_t, expr_t> > > &List_of_Op_RHS) const; virtual pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<pair<int, pair<expr_t, expr_t> > > &List_of_Op_RHS) const;
virtual expr_t getChainRuleDerivative(int deriv_id, const map<int, expr_t> &recursive_variables); virtual expr_t getChainRuleDerivative(int deriv_id, const map<int, expr_t> &recursive_variables);
virtual int maxEndoLead() const; virtual int maxEndoLead() const;
...@@ -827,7 +827,7 @@ public: ...@@ -827,7 +827,7 @@ public:
virtual expr_t substituteExoLead(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const; virtual expr_t substituteExoLead(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const;
virtual expr_t substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const; virtual expr_t substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
virtual expr_t substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const; virtual expr_t substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const;
virtual expr_t buildSimilarExternalFunctionNode(vector<expr_t> &alt_args, DataTree &alt_datatree) const; virtual expr_t buildSimilarExternalFunctionNode(vector<expr_t> &alt_args, DataTree &alt_datatree) const = 0;
virtual expr_t decreaseLeadsLagsPredeterminedVariables() const; virtual expr_t decreaseLeadsLagsPredeterminedVariables() const;
virtual expr_t differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const; virtual expr_t differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
virtual bool isNumConstNodeEqualTo(double value) const; virtual bool isNumConstNodeEqualTo(double value) const;
...@@ -836,12 +836,40 @@ public: ...@@ -836,12 +836,40 @@ public:
virtual void writePrhs(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms, const string &ending) const; virtual void writePrhs(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms, const string &ending) const;
virtual expr_t replaceTrendVar() const; virtual expr_t replaceTrendVar() const;
virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const; virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const;
virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const = 0;
virtual expr_t removeTrendLeadLag(map<int, expr_t> trend_symbols_map) const; virtual expr_t removeTrendLeadLag(map<int, expr_t> trend_symbols_map) const;
virtual bool isInStaticForm() const; virtual bool isInStaticForm() const;
}; };
class FirstDerivExternalFunctionNode : public ExternalFunctionNode class ExternalFunctionNode : public AbstractExternalFunctionNode
{
private:
virtual expr_t composeDerivatives(const vector<expr_t> &dargs);
public:
ExternalFunctionNode(DataTree &datatree_arg, int symb_id_arg,
const vector<expr_t> &arguments_arg);
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
const temporary_terms_t &temporary_terms,
deriv_node_temp_terms_t &tef_terms) const;
virtual void compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
bool lhs_rhs, const temporary_terms_t &temporary_terms,
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
deriv_node_temp_terms_t &tef_terms) const;
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count,
temporary_terms_t &temporary_terms,
map<expr_t, pair<int, int> > &first_occurence,
int Curr_block,
vector< vector<temporary_terms_t> > &v_temporary_terms,
int equation) const;
virtual void compile(ostream &CompileCode, unsigned int &instruction_number, bool lhs_rhs, const temporary_terms_t &temporary_terms, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic, deriv_node_temp_terms_t &tef_terms) const;
virtual expr_t toStatic(DataTree &static_datatree) const;
virtual expr_t buildSimilarExternalFunctionNode(vector<expr_t> &alt_args, DataTree &alt_datatree) const;
virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const;
};
class FirstDerivExternalFunctionNode : public AbstractExternalFunctionNode
{ {
private: private:
const int inputIndex; const int inputIndex;
...@@ -870,14 +898,17 @@ public: ...@@ -870,14 +898,17 @@ public:
bool lhs_rhs, const temporary_terms_t &temporary_terms, bool lhs_rhs, const temporary_terms_t &temporary_terms,
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
deriv_node_temp_terms_t &tef_terms) const; deriv_node_temp_terms_t &tef_terms) const;
virtual expr_t toStatic(DataTree &static_datatree) const;
virtual expr_t buildSimilarExternalFunctionNode(vector<expr_t> &alt_args, DataTree &alt_datatree) const;
virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const;
}; };
class SecondDerivExternalFunctionNode : public ExternalFunctionNode class SecondDerivExternalFunctionNode : public AbstractExternalFunctionNode
{ {
private: private:
const int inputIndex1; const int inputIndex1;
const int inputIndex2; const int inputIndex2;
virtual expr_t computeDerivative(int deriv_id); virtual expr_t composeDerivatives(const vector<expr_t> &dargs);
public: public:
SecondDerivExternalFunctionNode(DataTree &datatree_arg, SecondDerivExternalFunctionNode(DataTree &datatree_arg,
int top_level_symb_id_arg, int top_level_symb_id_arg,
...@@ -892,9 +923,20 @@ public: ...@@ -892,9 +923,20 @@ public:
vector< vector<temporary_terms_t> > &v_temporary_terms, vector< vector<temporary_terms_t> > &v_temporary_terms,
int equation) const; int equation) const;
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const; virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
virtual void compile(ostream &CompileCode, unsigned int &instruction_number,
bool lhs_rhs, const temporary_terms_t &temporary_terms,
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
deriv_node_temp_terms_t &tef_terms) const;
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type, virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
const temporary_terms_t &temporary_terms, const temporary_terms_t &temporary_terms,
deriv_node_temp_terms_t &tef_terms) const; deriv_node_temp_terms_t &tef_terms) const;
virtual void compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
bool lhs_rhs, const temporary_terms_t &temporary_terms,
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
deriv_node_temp_terms_t &tef_terms) const;
virtual expr_t toStatic(DataTree &static_datatree) const;
virtual expr_t buildSimilarExternalFunctionNode(vector<expr_t> &alt_args, DataTree &alt_datatree) const;
virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const;
}; };
#endif #endif
...@@ -2,7 +2,7 @@ SUBDIRS = macro ...@@ -2,7 +2,7 @@ SUBDIRS = macro
BUILT_SOURCES = DynareBison.hh stack.hh position.hh location.hh DynareBison.cc DynareFlex.cc FlexLexer.h BUILT_SOURCES = DynareBison.hh stack.hh position.hh location.hh DynareBison.cc DynareFlex.cc FlexLexer.h
matlabdir = $(libdir)/matlab matlabdir = $(pkglibdir)/matlab
matlab_PROGRAMS = dynare_m matlab_PROGRAMS = dynare_m
...@@ -79,3 +79,6 @@ clean-local: ...@@ -79,3 +79,6 @@ clean-local:
rm -rf doc/html/ rm -rf doc/html/
EXTRA_DIST = $(BUILT_SOURCES) Doxyfile EXTRA_DIST = $(BUILT_SOURCES) Doxyfile
install-exec-local:
$(MKDIR_P) $(DESTDIR)$(pkglibdir)/matlab
...@@ -289,7 +289,7 @@ ModFile::checkPass() ...@@ -289,7 +289,7 @@ ModFile::checkPass()
// Check if some exogenous is not used in the model block // Check if some exogenous is not used in the model block
set<int> unusedExo = dynamic_model.findUnusedExogenous(); set<int> unusedExo = dynamic_model.findUnusedExogenous();
if (unusedExo.size() > 1) if (unusedExo.size() > 0)
{ {
warnings << "WARNING: some exogenous ("; warnings << "WARNING: some exogenous (";
for (set<int>::const_iterator it = unusedExo.begin(); for (set<int>::const_iterator it = unusedExo.begin();
...@@ -419,6 +419,12 @@ ModFile::transformPass(bool nostrict) ...@@ -419,6 +419,12 @@ ModFile::transformPass(bool nostrict)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (mod_file_struct.identification_present && symbol_table.exo_det_nbr() > 0)
{
cerr << "ERROR: identification is incompatible with deterministic exogenous variables" << endl;
exit(EXIT_FAILURE);
}
if (!mod_file_struct.ramsey_policy_present) if (!mod_file_struct.ramsey_policy_present)
cout << "Found " << dynamic_model.equation_number() << " equation(s)." << endl; cout << "Found " << dynamic_model.equation_number() << " equation(s)." << endl;
else else
...@@ -588,6 +594,9 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool no_log, b ...@@ -588,6 +594,9 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool no_log, b
mOutputFile << "M_.H = 0;" << endl mOutputFile << "M_.H = 0;" << endl
<< "M_.Correlation_matrix_ME = 1;" << endl; << "M_.Correlation_matrix_ME = 1;" << endl;
// May be later modified by a shocks block
mOutputFile << "M_.sigma_e_is_diagonal = 1;" << endl;
if (linear == 1) if (linear == 1)
mOutputFile << "options_.linear = 1;" << endl; mOutputFile << "options_.linear = 1;" << endl;
...@@ -681,14 +690,31 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool no_log, b ...@@ -681,14 +690,31 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool no_log, b
#else #else
# ifdef __linux__ # ifdef __linux__
// MATLAB/Linux // MATLAB/Linux
mOutputFile << " eval('mex -O LDFLAGS=''-pthread -shared -Wl,--no-undefined'' " << basename << "_dynamic.c " << basename << "_dynamic_mex.c')" << endl mOutputFile << " if matlab_ver_less_than('8.3')" << endl
<< " eval('mex -O LDFLAGS=''-pthread -shared -Wl,--no-undefined'' " << basename << "_static.c "<< basename << "_static_mex.c')" << endl; << " eval('mex -O LDFLAGS=''-pthread -shared -Wl,--no-undefined'' " << basename << "_dynamic.c " << basename << "_dynamic_mex.c')" << endl
<< " eval('mex -O LDFLAGS=''-pthread -shared -Wl,--no-undefined'' " << basename << "_static.c "<< basename << "_static_mex.c')" << endl
<< " else" << endl
<< " eval('mex -O LINKEXPORT='''' " << basename << "_dynamic.c " << basename << "_dynamic_mex.c')" << endl
<< " eval('mex -O LINKEXPORT='''' " << basename << "_static.c "<< basename << "_static_mex.c')" << endl
<< " end" << endl;
# else // MacOS # else // MacOS
// MATLAB/MacOS // MATLAB/MacOS
mOutputFile << " eval('mex -O LDFLAGS=''-Wl,-twolevel_namespace -undefined error -arch \\$ARCHS -Wl,-syslibroot,\\$SDKROOT -mmacosx-version-min=\\$MACOSX_DEPLOYMENT_TARGET -bundle'' " mOutputFile << " if matlab_ver_less_than('8.3')" << endl
<< " if matlab_ver_less_than('8.1')" << endl
<< " eval('mex -O LDFLAGS=''-Wl,-twolevel_namespace -undefined error -arch \\$ARCHS -Wl,-syslibroot,\\$SDKROOT -mmacosx-version-min=\\$MACOSX_DEPLOYMENT_TARGET -bundle'' "
<< basename << "_dynamic.c " << basename << "_dynamic_mex.c')" << endl << basename << "_dynamic.c " << basename << "_dynamic_mex.c')" << endl
<< " eval('mex -O LDFLAGS=''-Wl,-twolevel_namespace -undefined error -arch \\$ARCHS -Wl,-syslibroot,\\$SDKROOT -mmacosx-version-min=\\$MACOSX_DEPLOYMENT_TARGET -bundle'' " << " eval('mex -O LDFLAGS=''-Wl,-twolevel_namespace -undefined error -arch \\$ARCHS -Wl,-syslibroot,\\$SDKROOT -mmacosx-version-min=\\$MACOSX_DEPLOYMENT_TARGET -bundle'' "
<< basename << "_static.c " << basename << "_static_mex.c')" << endl; << basename << "_static.c " << basename << "_static_mex.c')" << endl
<< " else" << endl
<< " eval('mex -O LDFLAGS=''-Wl,-twolevel_namespace -undefined error -arch \\$ARCHS -Wl,-syslibroot,\\$MW_SDKROOT -mmacosx-version-min=\\$MACOSX_DEPLOYMENT_TARGET -bundle'' "
<< basename << "_dynamic.c " << basename << "_dynamic_mex.c')" << endl
<< " eval('mex -O LDFLAGS=''-Wl,-twolevel_namespace -undefined error -arch \\$ARCHS -Wl,-syslibroot,\\$MW_SDKROOT -mmacosx-version-min=\\$MACOSX_DEPLOYMENT_TARGET -bundle'' "
<< basename << "_static.c " << basename << "_static_mex.c')" << endl
<< " end" << endl
<< " else" << endl
<< " eval('mex -O LINKEXPORT='''' " << basename << "_dynamic.c " << basename << "_dynamic_mex.c')" << endl
<< " eval('mex -O LINKEXPORT='''' " << basename << "_static.c "<< basename << "_static_mex.c')" << endl
<< " end" << endl;
# endif # endif
#endif #endif
mOutputFile << "else" << endl // Octave mOutputFile << "else" << endl // Octave
......
...@@ -207,9 +207,18 @@ ModelTree::computeNonSingularNormalization(jacob_map_t &contemporaneous_jacobian ...@@ -207,9 +207,18 @@ ModelTree::computeNonSingularNormalization(jacob_map_t &contemporaneous_jacobian
dynamic_jacobian[make_pair(0, make_pair(it->first.first, it->first.second))] = 0; dynamic_jacobian[make_pair(0, make_pair(it->first.first, it->first.second))] = 0;
if (contemporaneous_jacobian.find(make_pair(it->first.first, it->first.second)) == contemporaneous_jacobian.end()) if (contemporaneous_jacobian.find(make_pair(it->first.first, it->first.second)) == contemporaneous_jacobian.end())
contemporaneous_jacobian[make_pair(it->first.first, it->first.second)] = 0; contemporaneous_jacobian[make_pair(it->first.first, it->first.second)] = 0;
try
{
if (first_derivatives.find(make_pair(it->first.first, getDerivID(symbol_table.getID(eEndogenous, it->first.second), 0))) == first_derivatives.end()) if (first_derivatives.find(make_pair(it->first.first, getDerivID(symbol_table.getID(eEndogenous, it->first.second), 0))) == first_derivatives.end())
first_derivatives[make_pair(it->first.first, getDerivID(symbol_table.getID(eEndogenous, it->first.second), 0))] = Zero; first_derivatives[make_pair(it->first.first, getDerivID(symbol_table.getID(eEndogenous, it->first.second), 0))] = Zero;
} }
catch(DataTree::UnknownDerivIDException &e)
{
cerr << "The variable " << symbol_table.getName(symbol_table.getID(eEndogenous, it->first.second))
<< " does not appear at the current period (i.e. with no lead and no lag); this case is not handled by the 'block' option of the 'model' block." << endl;
exit(EXIT_FAILURE);
}
}
} }
} }
...@@ -1113,7 +1122,7 @@ ModelTree::writeTemporaryTerms(const temporary_terms_t &tt, ostream &output, ...@@ -1113,7 +1122,7 @@ ModelTree::writeTemporaryTerms(const temporary_terms_t &tt, ostream &output,
for (temporary_terms_t::const_iterator it = tt.begin(); for (temporary_terms_t::const_iterator it = tt.begin();
it != tt.end(); it++) it != tt.end(); it++)
{ {
if (dynamic_cast<ExternalFunctionNode *>(*it) != NULL) if (dynamic_cast<AbstractExternalFunctionNode *>(*it) != NULL)
(*it)->writeExternalFunctionOutput(output, output_type, tt2, tef_terms); (*it)->writeExternalFunctionOutput(output, output_type, tt2, tef_terms);
if (IS_C(output_type)) if (IS_C(output_type))
...@@ -1144,7 +1153,7 @@ ModelTree::compileTemporaryTerms(ostream &code_file, unsigned int &instruction_n ...@@ -1144,7 +1153,7 @@ ModelTree::compileTemporaryTerms(ostream &code_file, unsigned int &instruction_n
for (temporary_terms_t::const_iterator it = tt.begin(); for (temporary_terms_t::const_iterator it = tt.begin();
it != tt.end(); it++) it != tt.end(); it++)
{ {
if (dynamic_cast<ExternalFunctionNode *>(*it) != NULL) if (dynamic_cast<AbstractExternalFunctionNode *>(*it) != NULL)
{ {
(*it)->compileExternalFunctionOutput(code_file, instruction_number, false, tt2, map_idx, dynamic, steady_dynamic, tef_terms); (*it)->compileExternalFunctionOutput(code_file, instruction_number, false, tt2, map_idx, dynamic, steady_dynamic, tef_terms);
} }
......
/* /*
* Copyright (C) 2003-2013 Dynare Team * Copyright (C) 2003-2014 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
...@@ -269,7 +269,7 @@ HistValStatement::writeOutput(ostream &output, const string &basename) const ...@@ -269,7 +269,7 @@ HistValStatement::writeOutput(ostream &output, const string &basename) const
output << "%" << endl output << "%" << endl
<< "% HISTVAL instructions" << endl << "% HISTVAL instructions" << endl
<< "%" << endl << "%" << endl
<< "M_.endo_histval = zeros(M_.endo_nbr,M_.maximum_lag);" << endl; << "M_.endo_histval = zeros(M_.endo_nbr,M_.maximum_endo_lag);" << endl;
for (hist_values_t::const_iterator it = hist_values.begin(); for (hist_values_t::const_iterator it = hist_values.begin();
it != hist_values.end(); it++) it != hist_values.end(); it++)
...@@ -305,7 +305,7 @@ HistValStatement::writeOutput(ostream &output, const string &basename) const ...@@ -305,7 +305,7 @@ HistValStatement::writeOutput(ostream &output, const string &basename) const
int tsid = symbol_table.getTypeSpecificID(symb_id) + 1; int tsid = symbol_table.getTypeSpecificID(symb_id) + 1;
if (type == eEndogenous) if (type == eEndogenous)
output << "M_.endo_histval( " << tsid << ", M_.maximum_lag + " << lag << ") = "; output << "M_.endo_histval( " << tsid << ", M_.maximum_endo_lag + " << lag << ") = ";
else if (type == eExogenous) else if (type == eExogenous)
output << "oo_.exo_simul( M_.maximum_lag + " << lag << ", " << tsid << " ) = "; output << "oo_.exo_simul( M_.maximum_lag + " << lag << ", " << tsid << " ) = ";
else if (type != eExogenousDet) else if (type != eExogenousDet)
......
...@@ -138,7 +138,9 @@ ParsingDriver::declare_symbol(const string *name, SymbolType type, const string ...@@ -138,7 +138,9 @@ ParsingDriver::declare_symbol(const string *name, SymbolType type, const string
if (tex_name == NULL && long_name == NULL) if (tex_name == NULL && long_name == NULL)
mod_file->symbol_table.addSymbol(*name, type); mod_file->symbol_table.addSymbol(*name, type);
else else
if (long_name == NULL) if (tex_name == NULL)
mod_file->symbol_table.createTexNameAndAddSymbolWithLongName(*name, type, *long_name);
else if (long_name == NULL)
mod_file->symbol_table.addSymbol(*name, type, *tex_name); mod_file->symbol_table.addSymbol(*name, type, *tex_name);
else else
mod_file->symbol_table.addSymbol(*name, type, *tex_name, *long_name); mod_file->symbol_table.addSymbol(*name, type, *tex_name, *long_name);
...@@ -313,7 +315,7 @@ ParsingDriver::add_model_variable(int symb_id, int lag) ...@@ -313,7 +315,7 @@ ParsingDriver::add_model_variable(int symb_id, int lag)
error("Variable " + mod_file->symbol_table.getName(symb_id) + " not allowed inside model declaration. Its scope is only outside model."); error("Variable " + mod_file->symbol_table.getName(symb_id) + " not allowed inside model declaration. Its scope is only outside model.");
if (type == eExternalFunction) if (type == eExternalFunction)
error("Symbol " + mod_file->symbol_table.getName(symb_id) + " is a function name external to Dynare. It cannot be used inside model."); error("Symbol " + mod_file->symbol_table.getName(symb_id) + " is a function name external to Dynare. It cannot be used like a variable without input argument inside model.");
if (type == eModelLocalVariable && lag != 0) if (type == eModelLocalVariable && lag != 0)
error("Model local variable " + mod_file->symbol_table.getName(symb_id) + " cannot be given a lead or a lag."); error("Model local variable " + mod_file->symbol_table.getName(symb_id) + " cannot be given a lead or a lag.");
...@@ -321,6 +323,9 @@ ParsingDriver::add_model_variable(int symb_id, int lag) ...@@ -321,6 +323,9 @@ ParsingDriver::add_model_variable(int symb_id, int lag)
if (dynamic_cast<StaticModel *>(model_tree) != NULL && lag != 0) if (dynamic_cast<StaticModel *>(model_tree) != NULL && lag != 0)
error("Leads and lags on variables are forbidden in 'planner_objective'."); error("Leads and lags on variables are forbidden in 'planner_objective'.");
if (dynamic_cast<StaticModel *>(model_tree) != NULL && type == eModelLocalVariable)
error("Model local variable " + mod_file->symbol_table.getName(symb_id) + " cannot be used in 'planner_objective'.");
// It makes sense to allow a lead/lag on parameters: during steady state calibration, endogenous and parameters can be swapped // It makes sense to allow a lead/lag on parameters: during steady state calibration, endogenous and parameters can be swapped
return model_tree->AddVariable(symb_id, lag); return model_tree->AddVariable(symb_id, lag);
} }
...@@ -340,6 +345,9 @@ ParsingDriver::add_expression_variable(string *name) ...@@ -340,6 +345,9 @@ ParsingDriver::add_expression_variable(string *name)
|| mod_file->symbol_table.getType(*name) == eLogTrend) || mod_file->symbol_table.getType(*name) == eLogTrend)
error("Variable " + *name + " not allowed outside model declaration, because it is a trend variable."); error("Variable " + *name + " not allowed outside model declaration, because it is a trend variable.");
if (mod_file->symbol_table.getType(*name) == eExternalFunction)
error("Symbol '" + *name + "' is the name of a MATLAB/Octave function, and cannot be used as a variable.");
int symb_id = mod_file->symbol_table.getID(*name); int symb_id = mod_file->symbol_table.getID(*name);
expr_t id = data_tree->AddVariable(symb_id); expr_t id = data_tree->AddVariable(symb_id);
...@@ -350,13 +358,16 @@ ParsingDriver::add_expression_variable(string *name) ...@@ -350,13 +358,16 @@ ParsingDriver::add_expression_variable(string *name)
void void
ParsingDriver::declare_nonstationary_var(string *name, string *tex_name, string *long_name) ParsingDriver::declare_nonstationary_var(string *name, string *tex_name, string *long_name)
{ {
if (tex_name != NULL) if (tex_name == NULL && long_name == NULL)
if (long_name != NULL) declare_endogenous(new string(*name));
declare_endogenous(new string(*name), new string(*tex_name), new string(*long_name));
else else
if (tex_name == NULL)
declare_endogenous(new string(*name), NULL, new string(*long_name));
else if (long_name == NULL)
declare_endogenous(new string(*name), new string(*tex_name)); declare_endogenous(new string(*name), new string(*tex_name));
else else
declare_endogenous(new string(*name)); declare_endogenous(new string(*name), new string(*tex_name), new string(*long_name));
declared_nonstationary_vars.push_back(mod_file->symbol_table.getID(*name)); declared_nonstationary_vars.push_back(mod_file->symbol_table.getID(*name));
mod_file->nonstationary_variables = true; mod_file->nonstationary_variables = true;
delete name; delete name;
...@@ -665,12 +676,10 @@ ParsingDriver::add_det_shock(string *var, bool conditional_forecast) ...@@ -665,12 +676,10 @@ ParsingDriver::add_det_shock(string *var, bool conditional_forecast)
v.push_back(dse); v.push_back(dse);
} }
det_shocks[symb_id].first = v; det_shocks[symb_id] = v;
det_shocks[symb_id].second = det_shocks_expectation_pf;
det_shocks_periods.clear(); det_shocks_periods.clear();
det_shocks_values.clear(); det_shocks_values.clear();
det_shocks_expectation_pf = false;
delete var; delete var;
} }
...@@ -790,12 +799,6 @@ ParsingDriver::add_value(string *v) ...@@ -790,12 +799,6 @@ ParsingDriver::add_value(string *v)
det_shocks_values.push_back(id); det_shocks_values.push_back(id);
} }
void
ParsingDriver::add_expectation_pf(bool pf)
{
det_shocks_expectation_pf = pf;
}
void void
ParsingDriver::begin_svar_identification() ParsingDriver::begin_svar_identification()
{ {
...@@ -1174,8 +1177,7 @@ ParsingDriver::add_in_symbol_list(string *tmp_var) ...@@ -1174,8 +1177,7 @@ ParsingDriver::add_in_symbol_list(string *tmp_var)
void void
ParsingDriver::rplot() ParsingDriver::rplot()
{ {
mod_file->addStatement(new RplotStatement(symbol_list, options_list)); mod_file->addStatement(new RplotStatement(symbol_list));
options_list.clear();
symbol_list.clear(); symbol_list.clear();
} }
...@@ -1214,8 +1216,23 @@ ParsingDriver::add_estimated_params_element() ...@@ -1214,8 +1216,23 @@ ParsingDriver::add_estimated_params_element()
if (estim_params.name != "dsge_prior_weight") if (estim_params.name != "dsge_prior_weight")
{ {
check_symbol_existence(estim_params.name); check_symbol_existence(estim_params.name);
if (estim_params.name2.size() > 0) SymbolType type = mod_file->symbol_table.getType(estim_params.name);
switch (estim_params.type)
{
case 1:
if (type != eEndogenous && type != eExogenous)
error(estim_params.name + " must be an endogenous or an exogenous variable");
break;
case 2:
check_symbol_is_parameter(&estim_params.name);
break;
case 3:
check_symbol_existence(estim_params.name2); check_symbol_existence(estim_params.name2);
SymbolType type2 = mod_file->symbol_table.getType(estim_params.name2);
if ((type != eEndogenous && type != eExogenous) || type != type2)
error(estim_params.name + " and " + estim_params.name2 + " must either be both endogenous variables or both exogenous");
break;
}
} }
estim_params_list.push_back(estim_params); estim_params_list.push_back(estim_params);
estim_params.init(*data_tree); estim_params.init(*data_tree);
...@@ -2439,7 +2456,8 @@ ParsingDriver::add_model_var_or_external_function(string *function_name, bool in ...@@ -2439,7 +2456,8 @@ ParsingDriver::add_model_var_or_external_function(string *function_name, bool in
{ // e.g. this function has already been referenced (either ad hoc or through the external_function() statement { // e.g. this function has already been referenced (either ad hoc or through the external_function() statement
// => check that the information matches previously declared info // => check that the information matches previously declared info
int symb_id = mod_file->symbol_table.getID(*function_name); int symb_id = mod_file->symbol_table.getID(*function_name);
assert(mod_file->external_functions_table.exists(symb_id)); if (!mod_file->external_functions_table.exists(symb_id))
error("Using a derivative of an external function (" + *function_name + ") in the model block is currently not allowed.");
if (in_model_block) if (in_model_block)
if (mod_file->external_functions_table.getNargs(symb_id) == eExtFunNotSet) if (mod_file->external_functions_table.getNargs(symb_id) == eExtFunNotSet)
......
...@@ -134,8 +134,6 @@ private: ...@@ -134,8 +134,6 @@ private:
vector<pair<int, int> > det_shocks_periods; vector<pair<int, int> > det_shocks_periods;
//! Temporary storage for values of deterministic shocks //! Temporary storage for values of deterministic shocks
vector<expr_t> det_shocks_values; vector<expr_t> det_shocks_values;
//! Temporary storage for perfect foresight of deterministic shocks in conditional forecast
bool det_shocks_expectation_pf;
//! Temporary storage for variances of shocks //! Temporary storage for variances of shocks
ShocksStatement::var_and_std_shocks_t var_shocks; ShocksStatement::var_and_std_shocks_t var_shocks;
//! Temporary storage for standard errors of shocks //! Temporary storage for standard errors of shocks
...@@ -347,8 +345,6 @@ public: ...@@ -347,8 +345,6 @@ public:
//! Adds a deterministic shock value //! Adds a deterministic shock value
/*! \param v a string containing a (possibly negative) numeric constant */ /*! \param v a string containing a (possibly negative) numeric constant */
void add_value(string *v); void add_value(string *v);
//! Adds a expectation type for conditional forecast with deterministic simulation
void add_expectation_pf(bool pf);
//! Writes a Sigma_e block //! Writes a Sigma_e block
void do_sigma_e(); void do_sigma_e();
//! Ends row of Sigma_e block //! Ends row of Sigma_e block
......
...@@ -44,11 +44,11 @@ AbstractShocksStatement::writeDetShocks(ostream &output) const ...@@ -44,11 +44,11 @@ AbstractShocksStatement::writeDetShocks(ostream &output) const
bool exo_det = (symbol_table.getType(it->first) == eExogenousDet); bool exo_det = (symbol_table.getType(it->first) == eExogenousDet);
int set_shocks_index = ((int) mshocks) + 2 * ((int) exo_det); int set_shocks_index = ((int) mshocks) + 2 * ((int) exo_det);
for (size_t i = 0; i < it->second.first.size(); i++) for (size_t i = 0; i < it->second.size(); i++)
{ {
const int &period1 = it->second.first[i].period1; const int &period1 = it->second[i].period1;
const int &period2 = it->second.first[i].period2; const int &period2 = it->second[i].period2;
const expr_t value = it->second.first[i].value; const expr_t value = it->second[i].value;
if (period1 == period2) if (period1 == period2)
{ {
...@@ -99,10 +99,12 @@ ShocksStatement::writeOutput(ostream &output, const string &basename) const ...@@ -99,10 +99,12 @@ ShocksStatement::writeOutput(ostream &output, const string &basename) const
writeDetShocks(output); writeDetShocks(output);
writeVarAndStdShocks(output); writeVarAndStdShocks(output);
writeCovarAndCorrShocks(output); writeCovarAndCorrShocks(output);
/* M_.sigma_e_is_diagonal is initialized to 1 by ModFile.cc. If there are no
off-diagonal elements, then we don't reset it to 1, since there might be
previous shocks blocks with off-diagonal elements. */
if (covar_shocks.size()+corr_shocks.size() > 0) if (covar_shocks.size()+corr_shocks.size() > 0)
output << "M_.sigma_e_is_diagonal = 0;" << endl; output << "M_.sigma_e_is_diagonal = 0;" << endl;
else
output << "M_.sigma_e_is_diagonal = 1;" << endl;
} }
void void
...@@ -339,7 +341,7 @@ ConditionalForecastPathsStatement::checkPass(ModFileStructure &mod_file_struct, ...@@ -339,7 +341,7 @@ ConditionalForecastPathsStatement::checkPass(ModFileStructure &mod_file_struct,
it != paths.end(); it++) it != paths.end(); it++)
{ {
int this_path_length = 0; int this_path_length = 0;
const vector<AbstractShocksStatement::DetShockElement> &elems = it->second.first; const vector<AbstractShocksStatement::DetShockElement> &elems = it->second;
for (int i = 0; i < (int) elems.size(); i++) for (int i = 0; i < (int) elems.size(); i++)
// Period1 < Period2, as enforced in ParsingDriver::add_period() // Period1 < Period2, as enforced in ParsingDriver::add_period()
this_path_length = max(this_path_length, elems[i].period2); this_path_length = max(this_path_length, elems[i].period2);
...@@ -368,16 +370,14 @@ ConditionalForecastPathsStatement::writeOutput(ostream &output, const string &ba ...@@ -368,16 +370,14 @@ ConditionalForecastPathsStatement::writeOutput(ostream &output, const string &ba
if (it == paths.begin()) if (it == paths.begin())
{ {
output << "constrained_vars_ = " << it->first +1 << ";" << endl; output << "constrained_vars_ = " << it->first +1 << ";" << endl;
output << "constrained_perfect_foresight_ = " << it->second.second << ";" << endl;
} }
else else
{ {
output << "constrained_vars_ = [constrained_vars_; " << it->first +1 << "];" << endl; output << "constrained_vars_ = [constrained_vars_; " << it->first +1 << "];" << endl;
output << "constrained_perfect_foresight_ = [constrained_perfect_foresight_; " << it->second.second << "];" << endl;
} }
const vector<AbstractShocksStatement::DetShockElement> &elems = it->second.first; const vector<AbstractShocksStatement::DetShockElement> &elems = it->second;
for (int i = 0; i < (int) elems.size(); i++) for (int i = 0; i < (int) elems.size(); i++)
for (int j = elems[i].period1; j <= elems[i].period2; j++) for (int j = elems[i].period1; j <= elems[i].period2; j++)
{ {
......
...@@ -41,7 +41,7 @@ public: ...@@ -41,7 +41,7 @@ public:
}; };
//The boolean element indicates if the shock is a surprise (false) or a perfect foresight (true) shock. //The boolean element indicates if the shock is a surprise (false) or a perfect foresight (true) shock.
//This boolean is used only in case of conditional forecast with extended path method (simulation_type = deterministic). //This boolean is used only in case of conditional forecast with extended path method (simulation_type = deterministic).
typedef map<int, pair< vector<DetShockElement>, bool> > det_shocks_t; typedef map<int, vector<DetShockElement> > det_shocks_t;
protected: protected:
//! Is this statement a "mshocks" statement ? (instead of a "shocks" statement) //! Is this statement a "mshocks" statement ? (instead of a "shocks" statement)
const bool mshocks; const bool mshocks;
......
...@@ -49,7 +49,8 @@ ModFileStructure::ModFileStructure() : ...@@ -49,7 +49,8 @@ ModFileStructure::ModFileStructure() :
bayesian_irf_present(false), bayesian_irf_present(false),
estimation_data_statement_present(false), estimation_data_statement_present(false),
last_markov_switching_chain(0), last_markov_switching_chain(0),
calib_smoother_present(false) calib_smoother_present(false),
estim_params_use_calib(false)
{ {
} }
...@@ -77,7 +78,7 @@ NativeStatement::writeOutput(ostream &output, const string &basename) const ...@@ -77,7 +78,7 @@ NativeStatement::writeOutput(ostream &output, const string &basename) const
{ {
using namespace boost::xpressive; using namespace boost::xpressive;
string date_regex = "(-?\\d+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4]\\d|5[0-2])))"; string date_regex = "(-?\\d+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4]\\d|5[0-2])))";
sregex regex_lookbehind = sregex::compile("(?<!\\$|\\d|[a-zA-Z]|\\')" + date_regex); sregex regex_lookbehind = sregex::compile("(?<!\\$|\\d|[a-zA-Z_]|\\')" + date_regex);
sregex regex_dollar = sregex::compile("(\\$)"+date_regex); sregex regex_dollar = sregex::compile("(\\$)"+date_regex);
string ns = regex_replace(native_statement, regex_lookbehind, "dates('$&')"); string ns = regex_replace(native_statement, regex_lookbehind, "dates('$&')");
......
...@@ -98,6 +98,8 @@ public: ...@@ -98,6 +98,8 @@ public:
int last_markov_switching_chain; int last_markov_switching_chain;
//! Whether a calib_smoother statement is present //! Whether a calib_smoother statement is present
bool calib_smoother_present; bool calib_smoother_present;
//! Whether there is an estimated_params_init with use_calibration
bool estim_params_use_calib;
//! Set of parameters used within shocks blocks, inside the expressions //! Set of parameters used within shocks blocks, inside the expressions
//! defining the values of covariances (stored as symbol ids) //! defining the values of covariances (stored as symbol ids)
set<int> parameters_within_shocks_values; set<int> parameters_within_shocks_values;
......
/* /*
* Copyright (C) 2003-2012 Dynare Team * Copyright (C) 2003-2014 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
...@@ -286,7 +286,7 @@ StaticModel::writeModelEquationsOrdered_M(const string &static_basename) const ...@@ -286,7 +286,7 @@ StaticModel::writeModelEquationsOrdered_M(const string &static_basename) const
for (temporary_terms_t::const_iterator it = v_temporary_terms[block][i].begin(); for (temporary_terms_t::const_iterator it = v_temporary_terms[block][i].begin();
it != v_temporary_terms[block][i].end(); it++) it != v_temporary_terms[block][i].end(); it++)
{ {
if (dynamic_cast<ExternalFunctionNode *>(*it) != NULL) if (dynamic_cast<AbstractExternalFunctionNode *>(*it) != NULL)
(*it)->writeExternalFunctionOutput(output, local_output_type, tt2, tef_terms); (*it)->writeExternalFunctionOutput(output, local_output_type, tt2, tef_terms);
output << " " << sps; output << " " << sps;
...@@ -658,7 +658,7 @@ StaticModel::writeModelEquationsCode_Block(const string file_name, const string ...@@ -658,7 +658,7 @@ StaticModel::writeModelEquationsCode_Block(const string file_name, const string
for (temporary_terms_t::const_iterator it = v_temporary_terms[block][i].begin(); for (temporary_terms_t::const_iterator it = v_temporary_terms[block][i].begin();
it != v_temporary_terms[block][i].end(); it++) it != v_temporary_terms[block][i].end(); it++)
{ {
if (dynamic_cast<ExternalFunctionNode *>(*it) != NULL) if (dynamic_cast<AbstractExternalFunctionNode *>(*it) != NULL)
(*it)->compileExternalFunctionOutput(code_file, instruction_number, false, tt2, map_idx, false, false, tef_terms); (*it)->compileExternalFunctionOutput(code_file, instruction_number, false, tt2, map_idx, false, false, tef_terms);
FNUMEXPR_ fnumexpr(TemporaryTerm, (int) (map_idx.find((*it)->idx)->second)); FNUMEXPR_ fnumexpr(TemporaryTerm, (int) (map_idx.find((*it)->idx)->second));
...@@ -851,7 +851,7 @@ StaticModel::writeModelEquationsCode_Block(const string file_name, const string ...@@ -851,7 +851,7 @@ StaticModel::writeModelEquationsCode_Block(const string file_name, const string
for (temporary_terms_t::const_iterator it = v_temporary_terms_local[block][i].begin(); for (temporary_terms_t::const_iterator it = v_temporary_terms_local[block][i].begin();
it != v_temporary_terms_local[block][i].end(); it++) it != v_temporary_terms_local[block][i].end(); it++)
{ {
if (dynamic_cast<ExternalFunctionNode *>(*it) != NULL) if (dynamic_cast<AbstractExternalFunctionNode *>(*it) != NULL)
(*it)->compileExternalFunctionOutput(code_file, instruction_number, false, tt3, map_idx2[block], false, false, tef_terms2); (*it)->compileExternalFunctionOutput(code_file, instruction_number, false, tt3, map_idx2[block], false, false, tef_terms2);
FNUMEXPR_ fnumexpr(TemporaryTerm, (int) (map_idx2[block].find((*it)->idx)->second)); FNUMEXPR_ fnumexpr(TemporaryTerm, (int) (map_idx2[block].find((*it)->idx)->second));
...@@ -1155,11 +1155,11 @@ StaticModel::writeStaticMFile(const string &func_name) const ...@@ -1155,11 +1155,11 @@ StaticModel::writeStaticMFile(const string &func_name) const
<< "% residual [M_.endo_nbr by 1] double vector of residuals of the static model equations " << endl << "% residual [M_.endo_nbr by 1] double vector of residuals of the static model equations " << endl
<< "% in order of declaration of the equations" << endl << "% in order of declaration of the equations" << endl
<< "% g1 [M_.endo_nbr by M_.endo_nbr] double Jacobian matrix of the static model equations;" << endl << "% g1 [M_.endo_nbr by M_.endo_nbr] double Jacobian matrix of the static model equations;" << endl
<< "% columns: equations in order of declaration" << endl << "% columns: variables in declaration order" << endl
<< "% rows: variables in declaration order" << endl << "% rows: equations in order of declaration" << endl
<< "% g2 [M_.endo_nbr by (M_.endo_nbr)^2] double Hessian matrix of the static model equations;" << endl << "% g2 [M_.endo_nbr by (M_.endo_nbr)^2] double Hessian matrix of the static model equations;" << endl
<< "% columns: equations in order of declaration" << endl << "% columns: variables in declaration order" << endl
<< "% rows: variables in declaration order" << endl << "% rows: equations in order of declaration" << endl
<< "%" << endl << "%" << endl
<< "%" << endl << "%" << endl
<< "% Warning : this file is generated automatically by Dynare" << endl << "% Warning : this file is generated automatically by Dynare" << endl
......
...@@ -71,16 +71,30 @@ SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_na ...@@ -71,16 +71,30 @@ SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_na
int int
SymbolTable::addSymbol(const string &name, SymbolType type) throw (AlreadyDeclaredException, FrozenException) SymbolTable::addSymbol(const string &name, SymbolType type) throw (AlreadyDeclaredException, FrozenException)
{
string tex_name;
return addSymbol(name, type, construct_tex_name(name, tex_name));
}
int
SymbolTable::createTexNameAndAddSymbolWithLongName(const string &name, SymbolType type, const string &long_name) throw (AlreadyDeclaredException, FrozenException)
{
string tex_name;
return addSymbol(name, type, construct_tex_name(name, tex_name), long_name);
}
string &
SymbolTable::construct_tex_name(const string &name, string &tex_name)
{ {
// Construct "tex_name" by prepending an antislash to all underscores in "name" // Construct "tex_name" by prepending an antislash to all underscores in "name"
string tex_name = name; tex_name = name;
size_t pos = 0; size_t pos = 0;
while ((pos = tex_name.find('_', pos)) != string::npos) while ((pos = tex_name.find('_', pos)) != string::npos)
{ {
tex_name.insert(pos, "\\"); tex_name.insert(pos, "\\");
pos += 2; pos += 2;
} }
return addSymbol(name, type, tex_name); return tex_name;
} }
void void
...@@ -249,7 +263,7 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException) ...@@ -249,7 +263,7 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
<< "M_.aux_vars(" << i+1 << ").orig_lead_lag = " << aux_vars[i].get_orig_lead_lag() << ";" << endl; << "M_.aux_vars(" << i+1 << ").orig_lead_lag = " << aux_vars[i].get_orig_lead_lag() << ";" << endl;
break; break;
case avMultiplier: case avMultiplier:
output << "M_.aux_vars(" << i+1 << ").eq_nbr = '" << aux_vars[i].get_equation_number_for_multiplier() << "';" << endl; output << "M_.aux_vars(" << i+1 << ").eq_nbr = '" << aux_vars[i].get_equation_number_for_multiplier() + 1 << "';" << endl;
break; break;
case avDiffForward: case avDiffForward:
output << "M_.aux_vars(" << i+1 << ").orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id())+1 << ";" << endl; output << "M_.aux_vars(" << i+1 << ").orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id())+1 << ";" << endl;
......
...@@ -191,6 +191,12 @@ public: ...@@ -191,6 +191,12 @@ public:
//! Add a symbol without its TeX name (will be equal to its name) //! Add a symbol without its TeX name (will be equal to its name)
/*! Returns the symbol ID */ /*! Returns the symbol ID */
int addSymbol(const string &name, SymbolType type) throw (AlreadyDeclaredException, FrozenException); int addSymbol(const string &name, SymbolType type) throw (AlreadyDeclaredException, FrozenException);
//! Tmp addSymbol function that creates a tex_name and declares a symbol
//! when the name and long_name are passed
/*! Returns the symbol ID */
int createTexNameAndAddSymbolWithLongName(const string &name, SymbolType type, const string &long_name) throw (AlreadyDeclaredException, FrozenException);
//! Create a tex_name based on the variable name
string &construct_tex_name(const string &name, string &tex_name);
//! Adds an auxiliary variable for endogenous with lead >= 2 //! Adds an auxiliary variable for endogenous with lead >= 2
/*! /*!
\param[in] index Used to construct the variable name \param[in] index Used to construct the variable name
......