Merge branch 'master' into ecb-master

Fixed conflicts:
	preprocessor/DynareBison.yy
	preprocessor/Statement.hh
issue#70
Stéphane Adjemian (Scylla) 2017-08-31 12:09:43 +02:00
commit 9b8961d26e
16 changed files with 160 additions and 20 deletions

View File

@ -2640,6 +2640,29 @@ WriteLatexOriginalModelStatement::writeJsonOutput(ostream &output) const
output << "{\"statementName\": \"write_latex_original_model\"}";
}
WriteLatexSteadyStateModelStatement::WriteLatexSteadyStateModelStatement(const SteadyStateModel &steady_state_model_arg) :
steady_state_model(steady_state_model_arg)
{
}
void
WriteLatexSteadyStateModelStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
{
mod_file_struct.write_latex_steady_state_model_present = true;
}
void
WriteLatexSteadyStateModelStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
{
steady_state_model.writeLatexSteadyStateFile(basename);
}
void
WriteLatexSteadyStateModelStatement::writeJsonOutput(ostream &output) const
{
output << "{\"statementName\": \"write_latex_steady_state_model\"}";
}
ShockDecompositionStatement::ShockDecompositionStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg) :
symbol_list(symbol_list_arg),

View File

@ -27,6 +27,7 @@
#include "Statement.hh"
#include "StaticModel.hh"
#include "DynamicModel.hh"
#include "SteadyStateModel.hh"
class SteadyStatement : public Statement
{
@ -678,6 +679,17 @@ public:
virtual void writeJsonOutput(ostream &output) const;
};
class WriteLatexSteadyStateModelStatement : public Statement
{
private:
const SteadyStateModel &steady_state_model;
public:
WriteLatexSteadyStateModelStatement(const SteadyStateModel &steady_state_model_arg);
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
virtual void writeJsonOutput(ostream &output) const;
};
class ShockDecompositionStatement : public Statement
{
private:

View File

@ -129,8 +129,8 @@ class ParsingDriver;
%token TEX RAMSEY_MODEL RAMSEY_POLICY RAMSEY_CONSTRAINTS PLANNER_DISCOUNT DISCRETIONARY_POLICY DISCRETIONARY_TOL
%token <string_val> TEX_NAME
%token UNIFORM_PDF UNIT_ROOT_VARS USE_DLL USEAUTOCORR GSA_SAMPLE_FILE USE_UNIVARIATE_FILTERS_IF_SINGULARITY_IS_DETECTED
%token VALUES VAR VAREXO VAREXO_DET VAROBS VAREXOBS PREDETERMINED_VARIABLES VAR_EXPECTATION PLOT_SHOCK_DECOMPOSITION MODEL_LOCAL_VARIABLE
%token WRITE_LATEX_DYNAMIC_MODEL WRITE_LATEX_STATIC_MODEL WRITE_LATEX_ORIGINAL_MODEL CROSSEQUATIONS COVARIANCE
%token VALUES VAR VAREXO VAREXO_DET VAROBS VAREXOBS PREDETERMINED_VARIABLES VAR_EXPECATATION PLOT_SHOCK_DECOMPOSITION MODEL_LOCAL_VARIABLE
%token WRITE_LATEX_DYNAMIC_MODEL WRITE_LATEX_STATIC_MODEL WRITE_LATEX_ORIGINAL_MODEL CROSSEQUATIONS COVARIANCE WRITE_LATEX_STEADY_STATE_MODEL
%token XLS_SHEET XLS_RANGE LMMCP OCCBIN BANDPASS_FILTER COLORMAP VAR_MODEL QOQ YOY AOA
%left COMMA
%left EQUAL_EQUAL EXCLAMATION_EQUAL
@ -265,6 +265,7 @@ statement : parameters
| write_latex_dynamic_model
| write_latex_static_model
| write_latex_original_model
| write_latex_steady_state_model
| shock_decomposition
| realtime_shock_decomposition
| plot_shock_decomposition
@ -2277,6 +2278,10 @@ write_latex_original_model : WRITE_LATEX_ORIGINAL_MODEL ';'
{ driver.write_latex_original_model(true); }
;
write_latex_steady_state_model : WRITE_LATEX_STEADY_STATE_MODEL ';'
{ driver.write_latex_steady_state_model(); }
;
shock_decomposition : SHOCK_DECOMPOSITION ';'
{driver.shock_decomposition(); }
| SHOCK_DECOMPOSITION '(' shock_decomposition_options_list ')' ';'

View File

@ -133,6 +133,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
<INITIAL>write_latex_dynamic_model {BEGIN DYNARE_STATEMENT; return token::WRITE_LATEX_DYNAMIC_MODEL;}
<INITIAL>write_latex_static_model {BEGIN DYNARE_STATEMENT; return token::WRITE_LATEX_STATIC_MODEL;}
<INITIAL>write_latex_original_model {BEGIN DYNARE_STATEMENT; return token::WRITE_LATEX_ORIGINAL_MODEL;}
<INITIAL>write_latex_steady_state_model {BEGIN DYNARE_STATEMENT; return token::WRITE_LATEX_STEADY_STATE_MODEL;}
<INITIAL>steady {BEGIN DYNARE_STATEMENT; return token::STEADY;}
<INITIAL>check {BEGIN DYNARE_STATEMENT; return token::CHECK;}

View File

@ -39,7 +39,7 @@
void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear_global,
bool no_tmp_terms, bool no_log, bool no_warn, bool warn_uninit, bool console,
bool nograph, bool nointeractive, bool parallel, ConfigFile &config_file,
WarningConsolidation &warnings_arg, bool nostrict, bool check_model_changes,
WarningConsolidation &warnings_arg, bool nostrict, bool stochastic, bool check_model_changes,
bool minimal_workspace, bool compute_xrefs, FileOutputType output_mode,
LanguageOutputType lang, int params_derivs_order
#if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__)
@ -57,7 +57,7 @@ usage()
{
cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [onlyclearglobals] [savemacro[=macro_file]] [onlymacro] [nolinemacro] [notmpterms] [nolog] [warn_uninit]"
<< " [console] [nograph] [nointeractive] [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_slave_open_mode] [parallel_test]"
<< " [-D<variable>[=<value>]] [-I/path] [nostrict] [fast] [minimal_workspace] [compute_xrefs] [output=dynamic|first|second|third] [language=C|C++|julia]"
<< " [-D<variable>[=<value>]] [-I/path] [nostrict] [stochastic] [fast] [minimal_workspace] [compute_xrefs] [output=dynamic|first|second|third] [language=C|C++|julia]"
<< " [params_derivs_order=0|1|2]"
#if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__)
<< " [cygwin] [msvc] [mingw]"
@ -109,6 +109,7 @@ main(int argc, char **argv)
bool parallel_slave_open_mode = false;
bool parallel_test = false;
bool nostrict = false;
bool stochastic = false;
bool check_model_changes = false;
bool minimal_workspace = false;
bool compute_xrefs = false;
@ -197,6 +198,8 @@ main(int argc, char **argv)
parallel_test = true;
else if (!strcmp(argv[arg], "nostrict"))
nostrict = true;
else if (!strcmp(argv[arg], "stochastic"))
stochastic = true;
else if (!strcmp(argv[arg], "fast"))
check_model_changes = true;
else if (!strcmp(argv[arg], "minimal_workspace"))
@ -365,7 +368,7 @@ main(int argc, char **argv)
// Do the rest
main2(macro_output, basename, debug, clear_all, clear_global,
no_tmp_terms, no_log, no_warn, warn_uninit, console, nograph, nointeractive,
parallel, config_file, warnings, nostrict, check_model_changes, minimal_workspace,
parallel, config_file, warnings, nostrict, stochastic, check_model_changes, minimal_workspace,
compute_xrefs, output_mode, language, params_derivs_order
#if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__)
, cygwin, msvc, mingw

View File

@ -28,7 +28,7 @@ void
main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear_global,
bool no_tmp_terms, bool no_log, bool no_warn, bool warn_uninit, bool console,
bool nograph, bool nointeractive, bool parallel, ConfigFile &config_file,
WarningConsolidation &warnings, bool nostrict, bool check_model_changes,
WarningConsolidation &warnings, bool nostrict, bool stochastic, bool check_model_changes,
bool minimal_workspace, bool compute_xrefs, FileOutputType output_mode,
LanguageOutputType language, int params_derivs_order
#if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__)
@ -45,12 +45,12 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson);
// Run checking pass
mod_file->checkPass(nostrict);
mod_file->checkPass(nostrict, stochastic);
if (json == checkpass)
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson);
// Perform transformations on the model (creation of auxiliary vars and equations)
mod_file->transformPass(nostrict, compute_xrefs || json == transformpass);
mod_file->transformPass(nostrict, stochastic, compute_xrefs || json == transformpass);
if (json == transformpass)
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson);

View File

@ -107,14 +107,21 @@ ModFile::addStatementAtFront(Statement *st)
}
void
ModFile::checkPass(bool nostrict)
ModFile::checkPass(bool nostrict, bool stochastic)
{
for (vector<Statement *>::iterator it = statements.begin();
it != statements.end(); it++)
(*it)->checkPass(mod_file_struct, warnings);
// Check the steady state block
steady_state_model.checkPass(mod_file_struct.ramsey_model_present, warnings);
steady_state_model.checkPass(mod_file_struct, warnings);
if (mod_file_struct.write_latex_steady_state_model_present &&
!mod_file_struct.steady_state_model_present)
{
cerr << "ERROR: You cannot have a write_latex_steady_state_model statement without a steady_state_model block." << endl;
exit(EXIT_FAILURE);
}
// If order option has not been set, default to 2
if (!mod_file_struct.order_option)
@ -129,7 +136,8 @@ ModFile::checkPass(bool nostrict)
|| mod_file_struct.osr_present
|| mod_file_struct.ramsey_policy_present
|| mod_file_struct.discretionary_policy_present
|| mod_file_struct.calib_smoother_present;
|| mod_file_struct.calib_smoother_present
|| stochastic;
// Allow empty model only when doing a standalone BVAR estimation
if (dynamic_model.equation_number() == 0
@ -332,7 +340,7 @@ ModFile::checkPass(bool nostrict)
}
void
ModFile::transformPass(bool nostrict, bool compute_xrefs)
ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs)
{
// Save the original model (must be done before any model transformations by preprocessor)
// - except adl and diff which we always want expanded
@ -410,7 +418,8 @@ ModFile::transformPass(bool nostrict, bool compute_xrefs)
|| mod_file_struct.osr_present
|| mod_file_struct.ramsey_policy_present
|| mod_file_struct.discretionary_policy_present
|| mod_file_struct.calib_smoother_present)
|| mod_file_struct.calib_smoother_present
|| stochastic )
{
// In stochastic models, create auxiliary vars for leads and lags greater than 2, on both endos and exos
dynamic_model.substituteEndoLeadGreaterThanTwo(false);

View File

@ -131,10 +131,10 @@ public:
void evalAllExpressions(bool warn_uninit);
//! Do some checking and fills mod_file_struct
/*! \todo add check for number of equations and endogenous if ramsey_policy is present */
void checkPass(bool nostrict);
void checkPass(bool nostrict, bool stochastic);
//! Perform some transformations on the model (creation of auxiliary vars and equations)
/*! \param compute_xrefs if true, equation cross references will be computed */
void transformPass(bool nostrict, bool compute_xrefs);
void transformPass(bool nostrict, bool stochastic, bool compute_xrefs);
//! Execute computations
/*! \param no_tmp_terms if true, no temporary terms will be computed in the static and dynamic files */
/*! \param params_derivs_order compute this order of derivs wrt parameters */

View File

@ -2175,6 +2175,12 @@ ParsingDriver::write_latex_original_model(bool write_equation_tags)
mod_file->addStatement(new WriteLatexOriginalModelStatement(mod_file->original_model, write_equation_tags));
}
void
ParsingDriver::write_latex_steady_state_model()
{
mod_file->addStatement(new WriteLatexSteadyStateModelStatement(mod_file->steady_state_model));
}
void
ParsingDriver::bvar_density(string *maxnlags)
{

View File

@ -596,6 +596,8 @@ public:
void write_latex_static_model(bool write_equation_tags);
//! Adds a write_latex_original_model statement
void write_latex_original_model(bool write_equation_tags);
//! Adds a write_latex_steady_state_model statement
void write_latex_steady_state_model();
//! BVAR marginal density
void bvar_density(string *maxnlags);
//! BVAR forecast

View File

@ -59,7 +59,9 @@ ModFileStructure::ModFileStructure() :
ms_dsge_present(false),
occbin_option(false),
orig_eq_nbr(0),
ramsey_eq_nbr(0)
ramsey_eq_nbr(0),
steady_state_model_present(false),
write_latex_steady_state_model_present(false)
{
}

View File

@ -119,6 +119,10 @@ public:
int orig_eq_nbr;
//! Stores the number of equations added to the Ramsey model
int ramsey_eq_nbr;
//! Whether there was a steady_state_model block
bool steady_state_model_present;
//! Whether there is a write_latex_steady_state_model statement present
bool write_latex_steady_state_model_present;
};
class Statement

View File

@ -2173,6 +2173,23 @@ StaticModel::writeAuxVarRecursiveDefinitions(ostream &output, ExprNodeOutputType
}
}
void
StaticModel::writeLatexAuxVarRecursiveDefinitions(ostream &output) const
{
deriv_node_temp_terms_t tef_terms;
temporary_terms_t temporary_terms;
for (int i = 0; i < (int) aux_equations.size(); i++)
if (dynamic_cast<ExprNode *>(aux_equations[i])->containsExternalFunction())
dynamic_cast<ExprNode *>(aux_equations[i])->writeExternalFunctionOutput(output, oLatexStaticModel,
temporary_terms, tef_terms);
for (int i = 0; i < (int) aux_equations.size(); i++)
{
output << "\\begin{dmath}" << endl;
dynamic_cast<ExprNode *>(aux_equations[i]->substituteStaticAuxiliaryDefinition())->writeOutput(output, oLatexStaticModel);
output << endl << "\\end{dmath}" << endl;
}
}
void
StaticModel::writeParamsDerivativesFile(const string &basename, bool julia) const
{

View File

@ -191,6 +191,7 @@ public:
//! Writes definition of the auxiliary variables in a .m or .jl file
void writeSetAuxiliaryVariables(const string &basename, const bool julia) const;
void writeAuxVarRecursiveDefinitions(ostream &output, ExprNodeOutputType output_type) const;
void writeLatexAuxVarRecursiveDefinitions(ostream &output) const;
//! To ensure that no exogenous is present in the planner objective
//! See #1264

View File

@ -56,11 +56,12 @@ SteadyStateModel::addMultipleDefinitions(const vector<int> &symb_ids, expr_t exp
}
void
SteadyStateModel::checkPass(bool ramsey_model, WarningConsolidation &warnings) const
SteadyStateModel::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) const
{
if (def_table.size() == 0)
return;
mod_file_struct.steady_state_model_present = true;
vector<int> so_far_defined;
for (size_t i = 0; i < def_table.size(); i++)
@ -74,7 +75,7 @@ SteadyStateModel::checkPass(bool ramsey_model, WarningConsolidation &warnings) c
warnings << "WARNING: in the 'steady_state_model' block, variable '" << symbol_table.getName(symb_ids[j]) << "' is declared twice" << endl;
// Check that expression has no undefined symbol
if (!ramsey_model)
if (!mod_file_struct.ramsey_model_present)
{
set<int> used_symbols;
const expr_t &expr = def_table[i].second;
@ -104,6 +105,57 @@ SteadyStateModel::checkPass(bool ramsey_model, WarningConsolidation &warnings) c
}
}
void
SteadyStateModel::writeLatexSteadyStateFile(const string &basename) const
{
ofstream output, content_output;
string filename = basename + "_steady_state.tex";
string content_basename = basename + "_steady_state_content";
string content_filename = content_basename + ".tex";
output.open(filename.c_str(), ios::out | ios::binary);
if (!output.is_open())
{
cerr << "ERROR: Can't open file " << filename << " for writing" << endl;
exit(EXIT_FAILURE);
}
content_output.open(content_filename.c_str(), ios::out | ios::binary);
if (!content_output.is_open())
{
cerr << "ERROR: Can't open file " << content_filename << " for writing" << endl;
exit(EXIT_FAILURE);
}
output << "\\documentclass[10pt,a4paper]{article}" << endl
<< "\\usepackage[landscape]{geometry}" << endl
<< "\\usepackage{fullpage}" << endl
<< "\\usepackage{amsfonts}" << endl
<< "\\usepackage{breqn}" << endl
<< "\\begin{document}" << endl
<< "\\footnotesize" << endl;
for (vector<pair<vector<int>, expr_t> >::const_iterator it = def_table.begin();
it != def_table.end(); it++)
for (vector<int>::const_iterator it1 = it->first.begin(); it1 != it->first.end(); it1++)
{
int id = *it1;
expr_t value = it->second;
content_output << "\\begin{dmath}" << endl
<< symbol_table.getTeXName(id) << " = ";
value->writeOutput(content_output, oLatexStaticModel);
content_output << endl << "\\end{dmath}" << endl;
}
static_model.writeLatexAuxVarRecursiveDefinitions(content_output);
output << "\\include{" << content_basename << "}" << endl
<< "\\end{document}" << endl;
output.close();
content_output.close();
}
void
SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_model, bool julia) const
{

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2015 Dynare Team
* Copyright (C) 2010-2017 Dynare Team
*
* This file is part of Dynare.
*
@ -21,6 +21,7 @@
#define _STEADY_STATE_MODEL_HH
#include "DataTree.hh"
#include "Statement.hh"
#include "StaticModel.hh"
#include "WarningConsolidation.hh"
@ -43,13 +44,15 @@ public:
/*!
\param[in] ramsey_model Is there a Ramsey model in the MOD file? If yes, then disable the check on the recursivity of the declarations
*/
void checkPass(bool ramsey_model, WarningConsolidation &warnings) const;
void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) const;
//! Write the steady state file
/*!
\param[in] ramsey_model Is there a Ramsey model in the MOD file? If yes, then use the "ys" in argument of the steady state file as initial values
*/
void writeSteadyStateFile(const string &basename, bool ramsey_model, bool julia) const;
void writeSteadyStateFileC(const string &basename, bool ramsey_model) const;
//! Writes LaTeX file with the equations of the dynamic model (for the steady state model)
void writeLatexSteadyStateFile(const string &basename) const;
};
#endif