From 5a3504012637b12a7e00539373b95fca6a904e8e Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Fri, 17 Mar 2017 10:07:13 +0100 Subject: [PATCH 01/26] Make sure block-decomposed model returns with correct error code if Inf or NaN is encountered Missing from 5f85d3a2005ae1d2b3650776cc33830967721159 where only residual was set to error code. If oo_.deterministic_simulation.status is not set to 0, model will erroneously be considered as solved and homotopy will not be triggered. --- DynamicModel.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/DynamicModel.cc b/DynamicModel.cc index b914eff6..cc3dcf1c 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -2002,6 +2002,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri mDynamicModelFile << " tmp = y(:,M_.block_structure.block(" << block + 1 << ").variable);\n"; mDynamicModelFile << " if any(isnan(tmp) | isinf(tmp))\n"; mDynamicModelFile << " disp(['Inf or Nan value during the evaluation of block " << block <<"']);\n"; + mDynamicModelFile << " oo_.deterministic_simulation.status = 0;\n"; mDynamicModelFile << " oo_.deterministic_simulation.error = 100;\n"; mDynamicModelFile << " varargout{1} = oo_;\n"; mDynamicModelFile << " return;\n"; @@ -2029,6 +2030,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri mDynamicModelFile << " tmp = y(:,M_.block_structure.block(" << block + 1 << ").variable);\n"; mDynamicModelFile << " if any(isnan(tmp) | isinf(tmp))\n"; mDynamicModelFile << " disp(['Inf or Nan value during the evaluation of block " << block <<"']);\n"; + mDynamicModelFile << " oo_.deterministic_simulation.status = 0;\n"; mDynamicModelFile << " oo_.deterministic_simulation.error = 100;\n"; mDynamicModelFile << " varargout{1} = oo_;\n"; mDynamicModelFile << " return;\n"; @@ -2060,6 +2062,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri mDynamicModelFile << " tmp = y(:,M_.block_structure.block(" << block + 1 << ").variable);\n"; mDynamicModelFile << " if any(isnan(tmp) | isinf(tmp))\n"; mDynamicModelFile << " disp(['Inf or Nan value during the resolution of block " << block <<"']);\n"; + mDynamicModelFile << " oo_.deterministic_simulation.status = 0;\n"; mDynamicModelFile << " oo_.deterministic_simulation.error = 100;\n"; mDynamicModelFile << " varargout{1} = oo_;\n"; mDynamicModelFile << " return;\n"; @@ -2092,6 +2095,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri mDynamicModelFile << " tmp = y(:,M_.block_structure.block(" << block + 1 << ").variable);\n"; mDynamicModelFile << " if any(isnan(tmp) | isinf(tmp))\n"; mDynamicModelFile << " disp(['Inf or Nan value during the resolution of block " << block <<"']);\n"; + mDynamicModelFile << " oo_.deterministic_simulation.status = 0;\n"; mDynamicModelFile << " oo_.deterministic_simulation.error = 100;\n"; mDynamicModelFile << " varargout{1} = oo_;\n"; mDynamicModelFile << " return;\n"; @@ -2124,6 +2128,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri mDynamicModelFile << " tmp = y(:,M_.block_structure.block(" << block + 1 << ").variable);\n"; mDynamicModelFile << " if any(isnan(tmp) | isinf(tmp))\n"; mDynamicModelFile << " disp(['Inf or Nan value during the resolution of block " << block <<"']);\n"; + mDynamicModelFile << " oo_.deterministic_simulation.status = 0;\n"; mDynamicModelFile << " oo_.deterministic_simulation.error = 100;\n"; mDynamicModelFile << " varargout{1} = oo_;\n"; mDynamicModelFile << " return;\n"; From 8c595e3298f556734cb0bdf9be2eedb8d079a114 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Mon, 9 Jan 2017 18:10:15 +0100 Subject: [PATCH 02/26] evaluate_smoother.m: pass updated M_.params and oo_ back to base workspace Closes #1373 --- ComputingTasks.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index a05727d3..200249f7 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1662,7 +1662,7 @@ ShockDecompositionStatement::writeOutput(ostream &output, const string &basename { options_list.writeOutput(output); symbol_list.writeOutput("var_list_", output); - output << "oo_ = shock_decomposition(M_,oo_,options_,var_list_,bayestopt_,estim_params_);" << endl; + output << "[oo_,M_]= shock_decomposition(M_,oo_,options_,var_list_,bayestopt_,estim_params_);" << endl; } ConditionalForecastStatement::ConditionalForecastStatement(const OptionsList &options_list_arg) : @@ -3191,7 +3191,7 @@ CalibSmootherStatement::writeOutput(ostream &output, const string &basename, boo symbol_list.writeOutput("var_list_", output); output << "options_.smoother = 1;" << endl; output << "options_.order = 1;" << endl; - output << "[oo_,options_,bayestopt_]=evaluate_smoother('calibration',var_list_,M_,oo_,options_,bayestopt_,estim_params_);" << endl; + output << "[oo_,M_,options_,bayestopt_]=evaluate_smoother('calibration',var_list_,M_,oo_,options_,bayestopt_,estim_params_);" << endl; } ExtendedPathStatement::ExtendedPathStatement(const OptionsList &options_list_arg) From bc5ac82612aa2bfd2c50273d236e13c74596dde0 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 21 Mar 2017 11:22:15 +0100 Subject: [PATCH 03/26] preprocessor: add init_state option to shock_decomposition --- DynareBison.yy | 6 ++++-- DynareFlex.ll | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/DynareBison.yy b/DynareBison.yy index 7f6d2883..8c5f9704 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2016 Dynare Team + * Copyright (C) 2003-2017 Dynare Team * * This file is part of Dynare. * @@ -113,7 +113,7 @@ class ParsingDriver; %token CPF_WEIGHTS AMISANOTRISTANI MURRAYJONESPARSLOW %token FILTER_ALGORITHM PROPOSAL_APPROXIMATION CUBATURE UNSCENTED MONTECARLO DISTRIBUTION_APPROXIMATION %token NAME -%token USE_PENALIZED_OBJECTIVE_FOR_HESSIAN +%token USE_PENALIZED_OBJECTIVE_FOR_HESSIAN INIT_STATE %token NAN_CONSTANT NO_STATIC NOBS NOCONSTANT NODISPLAY NOCORR NODIAGNOSTIC NOFUNCTIONS NO_HOMOTOPY %token NOGRAPH POSTERIOR_NOGRAPH POSTERIOR_GRAPH NOMOMENTS NOPRINT NORMAL_PDF SAVE_DRAWS %token OBSERVATION_TRENDS OPTIM OPTIM_WEIGHTS ORDER OSR OSR_PARAMS MAX_DIM_COVA_GROUP ADVANCED OUTFILE OUTVARS OVERWRITE @@ -2494,6 +2494,7 @@ shock_decomposition_option : o_parameter_set | o_shock_decomposition_nograph | o_first_obs | o_nobs + | o_init_state ; homotopy_setup: HOMOTOPY_SETUP ';' homotopy_list END ';' @@ -2832,6 +2833,7 @@ o_posterior_nograph : POSTERIOR_NOGRAPH { driver.option_num("no_graph.posterior", "0"); } ; o_shock_decomposition_nograph : NOGRAPH { driver.option_num("no_graph.shock_decomposition", "1"); } +o_init_state : INIT_STATE EQUAL INT_NUMBER { driver.option_num("init_state", $3); }; o_nodisplay : NODISPLAY { driver.option_num("nodisplay","1"); }; o_graph_format : GRAPH_FORMAT EQUAL allowed_graph_formats { driver.process_graph_format_option(); } diff --git a/DynareFlex.ll b/DynareFlex.ll index e1e0aa4c..ae99fe73 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2016 Dynare Team + * Copyright (C) 2003-2017 Dynare Team * * This file is part of Dynare. * @@ -570,6 +570,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 controlled_varexo {return token::CONTROLLED_VAREXO; } parameter_set {return token::PARAMETER_SET; } +init_state {return token::INIT_STATE; } prior_mode {return token::PRIOR_MODE; } prior_mean {return token::PRIOR_MEAN; } posterior_mode {return token::POSTERIOR_MODE; } From ea450d425413c6c54dbd423dbe965cf1e963c253 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 21 Mar 2017 14:07:30 +0100 Subject: [PATCH 04/26] preprocessor: fix bug introduced in a4eb8d6b91b3b9d5c0293b78be0678c52c4395a4 --- DynareBison.yy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DynareBison.yy b/DynareBison.yy index 8c5f9704..5fcd49ae 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -2833,7 +2833,7 @@ o_posterior_nograph : POSTERIOR_NOGRAPH { driver.option_num("no_graph.posterior", "0"); } ; o_shock_decomposition_nograph : NOGRAPH { driver.option_num("no_graph.shock_decomposition", "1"); } -o_init_state : INIT_STATE EQUAL INT_NUMBER { driver.option_num("init_state", $3); }; +o_init_state : INIT_STATE EQUAL INT_NUMBER { driver.option_num("shock_decomp.init_state", $3); }; o_nodisplay : NODISPLAY { driver.option_num("nodisplay","1"); }; o_graph_format : GRAPH_FORMAT EQUAL allowed_graph_formats { driver.process_graph_format_option(); } From d2dfb65602adfe58acb96c1e66f9eb6e5c5362af Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 21 Mar 2017 14:58:15 +0100 Subject: [PATCH 05/26] preprocessor: add realtime_shock_decomposition statement. #1406 --- ComputingTasks.cc | 16 ++++++++++++++++ ComputingTasks.hh | 12 +++++++++++- DynareBison.yy | 34 ++++++++++++++++++++++++++++++++-- DynareFlex.ll | 2 ++ ParsingDriver.cc | 10 +++++++++- ParsingDriver.hh | 4 +++- 6 files changed, 73 insertions(+), 5 deletions(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 200249f7..cfc3b59b 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1665,6 +1665,22 @@ ShockDecompositionStatement::writeOutput(ostream &output, const string &basename output << "[oo_,M_]= shock_decomposition(M_,oo_,options_,var_list_,bayestopt_,estim_params_);" << endl; } +RealtimeShockDecompositionStatement::RealtimeShockDecompositionStatement(const SymbolList &symbol_list_arg, + const OptionsList &options_list_arg) : + symbol_list(symbol_list_arg), + options_list(options_list_arg) +{ +} + +void +RealtimeShockDecompositionStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const +{ + options_list.writeOutput(output); + symbol_list.writeOutput("var_list_", output); + output << "oo_ = realtime_shock_decomposition(M_,oo_,options_,var_list_,bayestopt_,estim_params_);" << endl; +} + + ConditionalForecastStatement::ConditionalForecastStatement(const OptionsList &options_list_arg) : options_list(options_list_arg) { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index a62a02b3..e74211f7 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2016 Dynare Team + * Copyright (C) 2003-2017 Dynare Team * * This file is part of Dynare. * @@ -586,6 +586,16 @@ public: virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; +class RealtimeShockDecompositionStatement : public Statement +{ +private: + const SymbolList symbol_list; + const OptionsList options_list; +public: + RealtimeShockDecompositionStatement(const SymbolList &symbol_list_arg, + const OptionsList &options_list_arg); + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; +}; class ConditionalForecastStatement : public Statement { private: diff --git a/DynareBison.yy b/DynareBison.yy index 5fcd49ae..246c8dda 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -125,7 +125,7 @@ class ParsingDriver; %token RELATIVE_IRF REPLIC SIMUL_REPLIC RPLOT SAVE_PARAMS_AND_STEADY_STATE PARAMETER_UNCERTAINTY %token SHOCKS SHOCK_DECOMPOSITION SHOCK_GROUPS USE_SHOCK_GROUPS SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED ENDOGENOUS_TERMINAL_PERIOD %token SMOOTHER SMOOTHER2HISTVAL SQUARE_ROOT_SOLVER STACK_SOLVE_ALGO STEADY_STATE_MODEL SOLVE_ALGO SOLVER_PERIODS ROBUST_LIN_SOLVE -%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 REALTIME_SHOCK_DECOMPOSITION %token TEX RAMSEY_MODEL RAMSEY_POLICY RAMSEY_CONSTRAINTS PLANNER_DISCOUNT DISCRETIONARY_POLICY DISCRETIONARY_TOL %token TEX_NAME %token UNIFORM_PDF UNIT_ROOT_VARS USE_DLL USEAUTOCORR GSA_SAMPLE_FILE USE_UNIVARIATE_FILTERS_IF_SINGULARITY_IS_DETECTED @@ -171,7 +171,7 @@ class ParsingDriver; %token ADAPTIVE_MH_DRAWS THINNING_FACTOR COEFFICIENTS_PRIOR_HYPERPARAMETERS %token CONVERGENCE_STARTING_VALUE CONVERGENCE_ENDING_VALUE CONVERGENCE_INCREMENT_VALUE %token MAX_ITERATIONS_STARTING_VALUE MAX_ITERATIONS_INCREMENT_VALUE MAX_BLOCK_ITERATIONS -%token MAX_REPEATED_OPTIMIZATION_RUNS FUNCTION_CONVERGENCE_CRITERION +%token MAX_REPEATED_OPTIMIZATION_RUNS FUNCTION_CONVERGENCE_CRITERION SAVE_REALTIME %token PARAMETER_CONVERGENCE_CRITERION NUMBER_OF_LARGE_PERTURBATIONS NUMBER_OF_SMALL_PERTURBATIONS %token NUMBER_OF_POSTERIOR_DRAWS_AFTER_PERTURBATION MAX_NUMBER_OF_STAGES %token RANDOM_FUNCTION_CONVERGENCE_CRITERION RANDOM_PARAMETER_CONVERGENCE_CRITERION @@ -261,6 +261,7 @@ statement : parameters | write_latex_static_model | write_latex_original_model | shock_decomposition + | realtime_shock_decomposition | conditional_forecast | conditional_forecast_paths | plot_conditional_forecast @@ -2128,6 +2129,16 @@ shock_decomposition : SHOCK_DECOMPOSITION ';' { driver.shock_decomposition(); } ; +realtime_shock_decomposition : REALTIME_SHOCK_DECOMPOSITION ';' + {driver.realtime_shock_decomposition(); } + | REALTIME_SHOCK_DECOMPOSITION '(' realtime_shock_decomposition_options_list ')' ';' + { driver.realtime_shock_decomposition(); } + | REALTIME_SHOCK_DECOMPOSITION symbol_list ';' + { driver.realtime_shock_decomposition(); } + | REALTIME_SHOCK_DECOMPOSITION '(' realtime_shock_decomposition_options_list ')' symbol_list ';' + { driver.realtime_shock_decomposition(); } + ; + bvar_prior_option : o_bvar_prior_tau | o_bvar_prior_decay | o_bvar_prior_lambda @@ -2497,6 +2508,22 @@ shock_decomposition_option : o_parameter_set | o_init_state ; +realtime_shock_decomposition_options_list : realtime_shock_decomposition_option COMMA realtime_shock_decomposition_options_list + | realtime_shock_decomposition_option + ; + +realtime_shock_decomposition_option : o_parameter_set + | o_datafile + | o_first_obs + | o_nobs + | o_use_shock_groups + | o_colormap + | o_shock_decomposition_nograph + | o_shock_decomposition_presample + | o_shock_decomposition_forecast + | o_save_realtime + ; + homotopy_setup: HOMOTOPY_SETUP ';' homotopy_list END ';' { driver.end_homotopy();}; @@ -2834,6 +2861,9 @@ o_posterior_nograph : POSTERIOR_NOGRAPH ; o_shock_decomposition_nograph : NOGRAPH { driver.option_num("no_graph.shock_decomposition", "1"); } o_init_state : INIT_STATE EQUAL INT_NUMBER { driver.option_num("shock_decomp.init_state", $3); }; +o_shock_decomposition_presample : PRESAMPLE EQUAL INT_NUMBER { driver.option_num("shock_decomp.presample", $3); }; +o_shock_decomposition_forecast : FORECAST EQUAL INT_NUMBER { driver.option_num("shock_decomp.forecast", $3); }; +o_save_realtime : SAVE_REALTIME EQUAL vec_int { driver.option_vec_int("shock_decomp.save_realtime", $3); }; o_nodisplay : NODISPLAY { driver.option_num("nodisplay","1"); }; o_graph_format : GRAPH_FORMAT EQUAL allowed_graph_formats { driver.process_graph_format_option(); } diff --git a/DynareFlex.ll b/DynareFlex.ll index ae99fe73..c8d1accd 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -150,6 +150,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 histval_file {BEGIN DYNARE_STATEMENT; return token::HISTVAL_FILE;} forecast {BEGIN DYNARE_STATEMENT; return token::FORECAST;} shock_decomposition {BEGIN DYNARE_STATEMENT; return token::SHOCK_DECOMPOSITION;} +realtime_shock_decomposition {BEGIN DYNARE_STATEMENT; return token::REALTIME_SHOCK_DECOMPOSITION;} sbvar {BEGIN DYNARE_STATEMENT; return token::SBVAR;} ms_estimation {BEGIN DYNARE_STATEMENT; return token::MS_ESTIMATION;} ms_simulation {BEGIN DYNARE_STATEMENT; return token::MS_SIMULATION;} @@ -571,6 +572,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 controlled_varexo {return token::CONTROLLED_VAREXO; } parameter_set {return token::PARAMETER_SET; } init_state {return token::INIT_STATE; } +save_realtime {return token::SAVE_REALTIME;} prior_mode {return token::PRIOR_MODE; } prior_mean {return token::PRIOR_MEAN; } posterior_mode {return token::POSTERIOR_MODE; } diff --git a/ParsingDriver.cc b/ParsingDriver.cc index 23e2018c..dc7953ce 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2016 Dynare Team + * Copyright (C) 2003-2017 Dynare Team * * This file is part of Dynare. * @@ -2125,6 +2125,14 @@ ParsingDriver::shock_decomposition() options_list.clear(); } +void +ParsingDriver::realtime_shock_decomposition() +{ + mod_file->addStatement(new RealtimeShockDecompositionStatement(symbol_list, options_list)); + symbol_list.clear(); + options_list.clear(); +} + void ParsingDriver::conditional_forecast() { diff --git a/ParsingDriver.hh b/ParsingDriver.hh index 8eb7ba6d..28385563 100644 --- a/ParsingDriver.hh +++ b/ParsingDriver.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2016 Dynare Team + * Copyright (C) 2003-2017 Dynare Team * * This file is part of Dynare. * @@ -590,6 +590,8 @@ public: void markov_switching(); //! Shock decomposition void shock_decomposition(); + //! Realtime Shock decomposition + void realtime_shock_decomposition(); //! Conditional forecast statement void conditional_forecast(); //! Conditional forecast paths block From 59322da2a7dcba4d6d9dd60f4fb17c12677f9f81 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 22 Mar 2017 11:30:35 +0100 Subject: [PATCH 06/26] preprocessor: add plot_shock_decomposition command. closes #1406 --- ComputingTasks.cc | 15 +++++++++++ ComputingTasks.hh | 14 +++++++++- DynareBison.yy | 68 ++++++++++++++++++++++++++++++++++++++++++----- DynareFlex.ll | 13 +++++++++ ParsingDriver.cc | 15 +++++++++++ ParsingDriver.hh | 4 +++ 6 files changed, 121 insertions(+), 8 deletions(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index cfc3b59b..d91d04c1 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1680,6 +1680,21 @@ RealtimeShockDecompositionStatement::writeOutput(ostream &output, const string & output << "oo_ = realtime_shock_decomposition(M_,oo_,options_,var_list_,bayestopt_,estim_params_);" << endl; } +PlotShockDecompositionStatement::PlotShockDecompositionStatement(const SymbolList &symbol_list_arg, + const OptionsList &options_list_arg) : + symbol_list(symbol_list_arg), + options_list(options_list_arg) +{ +} + +void +PlotShockDecompositionStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const +{ + output << "options_ = set_default_plot_shock_decomposition_options(options_);" << endl; + options_list.writeOutput(output); + symbol_list.writeOutput("var_list_", output); + output << "plot_shock_decomposition(M_, oo_, options_, var_list_);" << endl; +} ConditionalForecastStatement::ConditionalForecastStatement(const OptionsList &options_list_arg) : options_list(options_list_arg) diff --git a/ComputingTasks.hh b/ComputingTasks.hh index e74211f7..41da6098 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -593,9 +593,21 @@ private: const OptionsList options_list; public: RealtimeShockDecompositionStatement(const SymbolList &symbol_list_arg, - const OptionsList &options_list_arg); + const OptionsList &options_list_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; + +class PlotShockDecompositionStatement : public Statement +{ +private: + const SymbolList symbol_list; + const OptionsList options_list; +public: + PlotShockDecompositionStatement(const SymbolList &symbol_list_arg, + const OptionsList &options_list_arg); + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; +}; + class ConditionalForecastStatement : public Statement { private: diff --git a/DynareBison.yy b/DynareBison.yy index 246c8dda..8c2b9106 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -86,10 +86,10 @@ class ParsingDriver; %token AIM_SOLVER ANALYTIC_DERIVATION ANALYTIC_DERIVATION_MODE AR AUTOCORR POSTERIOR_SAMPLING_METHOD %token BAYESIAN_IRF BETA_PDF BLOCK USE_CALIBRATION SILENT_OPTIMIZER -%token BVAR_DENSITY BVAR_FORECAST NODECOMPOSITION DR_DISPLAY_TOL HUGE_NUMBER -%token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA -%token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN -%token BVAR_REPLIC BYTECODE ALL_VALUES_REQUIRED PROPOSAL_DISTRIBUTION +%token BVAR_DENSITY BVAR_FORECAST NODECOMPOSITION DR_DISPLAY_TOL HUGE_NUMBER FIG_NAME WRITE_XLS +%token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA INTERACTIVE SCREEN_SHOCKS STEADYSTATE +%token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN DETAIL_PLOT TYPE +%token BVAR_REPLIC BYTECODE ALL_VALUES_REQUIRED PROPOSAL_DISTRIBUTION REALTIME VINTAGE %token CALIB_SMOOTHER CHANGE_TYPE CHECK CONDITIONAL_FORECAST CONDITIONAL_FORECAST_PATHS CONF_SIG CONSTANT CONTROLLED_VAREXO CORR COVAR CUTOFF CYCLE_REDUCTION LOGARITHMIC_REDUCTION %token CONSIDER_ALL_ENDOGENOUS CONSIDER_ONLY_OBSERVED %token DATAFILE FILE SERIES DOUBLING DR_CYCLE_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_MAXITER DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE CALIBRATION DIFFERENTIATE_FORWARD_VARS @@ -129,9 +129,9 @@ class ParsingDriver; %token TEX RAMSEY_MODEL RAMSEY_POLICY RAMSEY_CONSTRAINTS PLANNER_DISCOUNT DISCRETIONARY_POLICY DISCRETIONARY_TOL %token 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 PREDETERMINED_VARIABLES +%token VALUES VAR VAREXO VAREXO_DET VAROBS PREDETERMINED_VARIABLES PLOT_SHOCK_DECOMPOSITION %token WRITE_LATEX_DYNAMIC_MODEL WRITE_LATEX_STATIC_MODEL WRITE_LATEX_ORIGINAL_MODEL -%token XLS_SHEET XLS_RANGE LMMCP OCCBIN BANDPASS_FILTER COLORMAP +%token XLS_SHEET XLS_RANGE LMMCP OCCBIN BANDPASS_FILTER COLORMAP QOQ YOY AOA %left COMMA %left EQUAL_EQUAL EXCLAMATION_EQUAL %left LESS GREATER LESS_EQUAL GREATER_EQUAL @@ -262,6 +262,7 @@ statement : parameters | write_latex_original_model | shock_decomposition | realtime_shock_decomposition + | plot_shock_decomposition | conditional_forecast | conditional_forecast_paths | plot_conditional_forecast @@ -2139,6 +2140,16 @@ realtime_shock_decomposition : REALTIME_SHOCK_DECOMPOSITION ';' { driver.realtime_shock_decomposition(); } ; +plot_shock_decomposition : PLOT_SHOCK_DECOMPOSITION ';' + {driver.plot_shock_decomposition(); } + | PLOT_SHOCK_DECOMPOSITION '(' plot_shock_decomposition_options_list ')' ';' + { driver.plot_shock_decomposition(); } + | PLOT_SHOCK_DECOMPOSITION symbol_list ';' + { driver.plot_shock_decomposition(); } + | PLOT_SHOCK_DECOMPOSITION '(' plot_shock_decomposition_options_list ')' symbol_list ';' + { driver.plot_shock_decomposition(); } + ; + bvar_prior_option : o_bvar_prior_tau | o_bvar_prior_decay | o_bvar_prior_lambda @@ -2524,6 +2535,25 @@ realtime_shock_decomposition_option : o_parameter_set | o_save_realtime ; +plot_shock_decomposition_options_list : plot_shock_decomposition_option COMMA plot_shock_decomposition_options_list + | plot_shock_decomposition_option + ; + +plot_shock_decomposition_option : o_psd_use_shock_groups + | o_psd_colormap + | o_psd_nodisplay + | o_psd_graph_format + | o_psd_detail_plot + | o_psd_interactive + | o_psd_screen_shocks + | o_psd_steadystate + | o_psd_type + | o_psd_fig_name + | o_psd_write_xls + | o_psd_realtime + | o_psd_vintage + ; + homotopy_setup: HOMOTOPY_SETUP ';' homotopy_list END ';' { driver.end_homotopy();}; @@ -2865,11 +2895,17 @@ o_shock_decomposition_presample : PRESAMPLE EQUAL INT_NUMBER { driver.option_num o_shock_decomposition_forecast : FORECAST EQUAL INT_NUMBER { driver.option_num("shock_decomp.forecast", $3); }; o_save_realtime : SAVE_REALTIME EQUAL vec_int { driver.option_vec_int("shock_decomp.save_realtime", $3); }; o_nodisplay : NODISPLAY { driver.option_num("nodisplay","1"); }; +o_psd_nodisplay : NODISPLAY { driver.option_num("plot_shock_decomp.nodisplay","1"); }; o_graph_format : GRAPH_FORMAT EQUAL allowed_graph_formats { driver.process_graph_format_option(); } | GRAPH_FORMAT EQUAL '(' list_allowed_graph_formats ')' { driver.process_graph_format_option(); } ; +o_psd_graph_format : GRAPH_FORMAT EQUAL allowed_graph_formats + { driver.plot_shock_decomp_process_graph_format_option(); } + | GRAPH_FORMAT EQUAL '(' list_allowed_graph_formats ')' + { driver.plot_shock_decomp_process_graph_format_option(); } + ; allowed_graph_formats : EPS { driver.add_graph_format("eps"); } | FIG @@ -2975,7 +3011,21 @@ o_dr : DR EQUAL CYCLE_REDUCTION {driver.option_num("dr_cycle_reduction", "1"); } o_dr_cycle_reduction_tol : DR_CYCLE_REDUCTION_TOL EQUAL non_negative_number {driver.option_num("dr_cycle_reduction_tol",$3);}; o_dr_logarithmic_reduction_tol : DR_LOGARITHMIC_REDUCTION_TOL EQUAL non_negative_number {driver.option_num("dr_logarithmic_reduction_tol",$3);}; o_dr_logarithmic_reduction_maxiter : DR_LOGARITHMIC_REDUCTION_MAXITER EQUAL INT_NUMBER {driver.option_num("dr_logarithmic_reduction_maxiter",$3);}; - +o_psd_detail_plot : DETAIL_PLOT { driver.option_num("plot_shock_decomp.detail_plot", "1"); }; +o_psd_interactive : INTERACTIVE { driver.option_num("plot_shock_decomp.interactive", "1"); }; +o_psd_screen_shocks : SCREEN_SHOCKS { driver.option_num("plot_shock_decomp.screen_shocks", "1"); }; +o_psd_steadystate : STEADYSTATE EQUAL INT_NUMBER { driver.option_num("plot_shock_decomp.steadystate", $3); }; +o_psd_fig_name : FIG_NAME EQUAL filename { driver.option_str("plot_shock_decomp.fig_name", $3); }; +o_psd_type : TYPE EQUAL QOQ + { driver.option_str("plot_shock_decomp.type", "qoq"); } + | TYPE EQUAL YOY + { driver.option_str("plot_shock_decomp.type", "qoq"); } + | TYPE EQUAL AOA + { driver.option_str("plot_shock_decomp.type", "qoq"); } + ; +o_psd_write_xls : WRITE_XLS { driver.option_num("plot_shock_decomp.write_xls", "1"); }; +o_psd_realtime : REALTIME EQUAL INT_NUMBER { driver.option_num("plot_shock_decomp.realtime", $3); }; +o_psd_vintage : VINTAGE EQUAL INT_NUMBER { driver.option_num("plot_shock_decomp.vintage", $3); }; o_bvar_prior_tau : BVAR_PRIOR_TAU EQUAL signed_number { driver.option_num("bvar_prior_tau", $3); }; o_bvar_prior_decay : BVAR_PRIOR_DECAY EQUAL non_negative_number { driver.option_num("bvar_prior_decay", $3); }; o_bvar_prior_lambda : BVAR_PRIOR_LAMBDA EQUAL signed_number { driver.option_num("bvar_prior_lambda", $3); }; @@ -3285,7 +3335,11 @@ o_sampling_draws : SAMPLING_DRAWS EQUAL INT_NUMBER { driver.option_num("sampling o_use_shock_groups : USE_SHOCK_GROUPS { driver.option_str("use_shock_groups","default"); } | USE_SHOCK_GROUPS EQUAL symbol { driver.option_str("use_shock_groups", $3); } ; +o_psd_use_shock_groups : USE_SHOCK_GROUPS { driver.option_str("plot_shock_decomp.use_shock_groups","default"); } + | USE_SHOCK_GROUPS EQUAL symbol { driver.option_str("plot_shock_decomp.use_shock_groups", $3); } + ; o_colormap : COLORMAP EQUAL symbol { driver.option_num("colormap",$3); }; +o_psd_colormap : COLORMAP EQUAL symbol { driver.option_num("plot_shock_decomp.colormap",$3); }; range : symbol ':' symbol { diff --git a/DynareFlex.ll b/DynareFlex.ll index c8d1accd..59eac989 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -151,6 +151,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 forecast {BEGIN DYNARE_STATEMENT; return token::FORECAST;} shock_decomposition {BEGIN DYNARE_STATEMENT; return token::SHOCK_DECOMPOSITION;} realtime_shock_decomposition {BEGIN DYNARE_STATEMENT; return token::REALTIME_SHOCK_DECOMPOSITION;} +plot_shock_decomposition {BEGIN DYNARE_STATEMENT; return token::PLOT_SHOCK_DECOMPOSITION;} sbvar {BEGIN DYNARE_STATEMENT; return token::SBVAR;} ms_estimation {BEGIN DYNARE_STATEMENT; return token::MS_ESTIMATION;} ms_simulation {BEGIN DYNARE_STATEMENT; return token::MS_SIMULATION;} @@ -573,6 +574,18 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 parameter_set {return token::PARAMETER_SET; } init_state {return token::INIT_STATE; } save_realtime {return token::SAVE_REALTIME;} +detail_plot {return token::DETAIL_PLOT;} +interactive {return token::INTERACTIVE;} +screen_shocks {return token::SCREEN_SHOCKS;} +steadystate {return token::STEADYSTATE;} +type {return token::TYPE;} +qoq {return token::QOQ; } +yoy {return token::YOY; } +aoa {return token::AOA; } +fig_name {return token::FIG_NAME;} +write_xls {return token::WRITE_XLS;} +realtime {return token::REALTIME;} +vintage {return token::VINTAGE;} prior_mode {return token::PRIOR_MODE; } prior_mean {return token::PRIOR_MEAN; } posterior_mode {return token::POSTERIOR_MODE; } diff --git a/ParsingDriver.cc b/ParsingDriver.cc index dc7953ce..e0df6128 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -2133,6 +2133,14 @@ ParsingDriver::realtime_shock_decomposition() options_list.clear(); } +void +ParsingDriver::plot_shock_decomposition() +{ + mod_file->addStatement(new PlotShockDecompositionStatement(symbol_list, options_list)); + symbol_list.clear(); + options_list.clear(); +} + void ParsingDriver::conditional_forecast() { @@ -2815,6 +2823,13 @@ ParsingDriver::process_graph_format_option() graph_formats.clear(); } +void +ParsingDriver::plot_shock_decomp_process_graph_format_option() +{ + options_list.symbol_list_options["plot_shock_decomp.graph_format"] = graph_formats; + graph_formats.clear(); +} + void ParsingDriver::model_diagnostics() { diff --git a/ParsingDriver.hh b/ParsingDriver.hh index 28385563..29b9c321 100644 --- a/ParsingDriver.hh +++ b/ParsingDriver.hh @@ -592,6 +592,8 @@ public: void shock_decomposition(); //! Realtime Shock decomposition void realtime_shock_decomposition(); + //! Plot Shock decomposition + void plot_shock_decomposition(); //! Conditional forecast statement void conditional_forecast(); //! Conditional forecast paths block @@ -722,6 +724,8 @@ public: void add_graph_format(const string &name); //! Add the graph_format option to the OptionsList structure void process_graph_format_option(); + //! Add the graph_format option to the plot_shock_decomp substructure of the OptionsList structure + void plot_shock_decomp_process_graph_format_option(); //! Model diagnostics void model_diagnostics(); //! Processing the parallel_local_files option From 5fb2ba6f7c8a16162b2192687c27fdb2d42e678a Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 28 Mar 2017 12:15:00 +0200 Subject: [PATCH 07/26] plot_shock_decomposition: remove argument to steadystate option --- DynareBison.yy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DynareBison.yy b/DynareBison.yy index 8c2b9106..10361cdb 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -3014,7 +3014,7 @@ o_dr_logarithmic_reduction_maxiter : DR_LOGARITHMIC_REDUCTION_MAXITER EQUAL INT_ o_psd_detail_plot : DETAIL_PLOT { driver.option_num("plot_shock_decomp.detail_plot", "1"); }; o_psd_interactive : INTERACTIVE { driver.option_num("plot_shock_decomp.interactive", "1"); }; o_psd_screen_shocks : SCREEN_SHOCKS { driver.option_num("plot_shock_decomp.screen_shocks", "1"); }; -o_psd_steadystate : STEADYSTATE EQUAL INT_NUMBER { driver.option_num("plot_shock_decomp.steadystate", $3); }; +o_psd_steadystate : STEADYSTATE { driver.option_num("plot_shock_decomp.steadystate", "1"); }; o_psd_fig_name : FIG_NAME EQUAL filename { driver.option_str("plot_shock_decomp.fig_name", $3); }; o_psd_type : TYPE EQUAL QOQ { driver.option_str("plot_shock_decomp.type", "qoq"); } From ddcad84f13037ae1e3d8b58ae66bd3c8f7b50d62 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 28 Mar 2017 23:06:03 +0200 Subject: [PATCH 08/26] Clarify error message if model-local variable was already used on RHS --- ParsingDriver.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ParsingDriver.cc b/ParsingDriver.cc index e0df6128..d370979e 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -2233,7 +2233,7 @@ ParsingDriver::declare_and_init_model_local_variable(string *name, expr_t rhs) // It can have already been declared in a steady_state_model block, check that it is indeed a ModelLocalVariable symb_id = mod_file->symbol_table.getID(*name); if (mod_file->symbol_table.getType(symb_id) != eModelLocalVariable) - error(*name + " has wrong type, you cannot use it within as left-hand side of a pound ('#') expression"); + error(*name + " has wrong type or was already used on the right-hand side. You cannot use it on the left-hand side of a pound ('#') expression"); } try From bc9a619d8a8c4e5eba975808d8619dd23c69b544 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 31 Mar 2017 12:50:17 +0200 Subject: [PATCH 09/26] preprocessor: initial_condition_decomposition front end. closes #1425 --- ComputingTasks.cc | 16 ++++++++++++++++ ComputingTasks.hh | 11 +++++++++++ DynareBison.yy | 39 +++++++++++++++++++++++++++++++++++++-- DynareFlex.ll | 3 +++ ParsingDriver.cc | 8 ++++++++ ParsingDriver.hh | 2 ++ 6 files changed, 77 insertions(+), 2 deletions(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index d91d04c1..21b2dd75 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1696,6 +1696,22 @@ PlotShockDecompositionStatement::writeOutput(ostream &output, const string &base output << "plot_shock_decomposition(M_, oo_, options_, var_list_);" << endl; } +InitialConditionDecompositionStatement::InitialConditionDecompositionStatement(const SymbolList &symbol_list_arg, + const OptionsList &options_list_arg) : + symbol_list(symbol_list_arg), + options_list(options_list_arg) +{ +} + +void +InitialConditionDecompositionStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const +{ + output << "options_ = set_default_initial_condition_decomposition_options(options_);" << endl; + options_list.writeOutput(output); + symbol_list.writeOutput("var_list_", output); + output << "initial_condition_decomposition(M_, oo_, options_, var_list_, bayestopt_, estim_params_);" << endl; +} + ConditionalForecastStatement::ConditionalForecastStatement(const OptionsList &options_list_arg) : options_list(options_list_arg) { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 41da6098..596738c2 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -608,6 +608,17 @@ public: virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; +class InitialConditionDecompositionStatement : public Statement +{ +private: + const SymbolList symbol_list; + const OptionsList options_list; +public: + InitialConditionDecompositionStatement(const SymbolList &symbol_list_arg, + const OptionsList &options_list_arg); + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; +}; + class ConditionalForecastStatement : public Statement { private: diff --git a/DynareBison.yy b/DynareBison.yy index 10361cdb..6eea69bc 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -91,7 +91,7 @@ class ParsingDriver; %token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN DETAIL_PLOT TYPE %token BVAR_REPLIC BYTECODE ALL_VALUES_REQUIRED PROPOSAL_DISTRIBUTION REALTIME VINTAGE %token CALIB_SMOOTHER CHANGE_TYPE CHECK CONDITIONAL_FORECAST CONDITIONAL_FORECAST_PATHS CONF_SIG CONSTANT CONTROLLED_VAREXO CORR COVAR CUTOFF CYCLE_REDUCTION LOGARITHMIC_REDUCTION -%token CONSIDER_ALL_ENDOGENOUS CONSIDER_ONLY_OBSERVED +%token CONSIDER_ALL_ENDOGENOUS CONSIDER_ONLY_OBSERVED INITIAL_CONDITION_DECOMPOSITION %token DATAFILE FILE SERIES 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 FILENAME DIRNAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS LAST_OBS SET_TIME OSR_PARAMS_BOUNDS KEEP_KALMAN_ALGO_IF_SINGULARITY_IS_DETECTED @@ -103,7 +103,7 @@ class ParsingDriver; %token IDENTIFICATION INF_CONSTANT INITVAL INITVAL_FILE BOUNDS JSCALE INIT INFILE INVARS %token INT_NUMBER %token INV_GAMMA_PDF INV_GAMMA1_PDF INV_GAMMA2_PDF IRF IRF_SHOCKS IRF_PLOT_THRESHOLD IRF_CALIBRATION -%token FAST_KALMAN_FILTER KALMAN_ALGO KALMAN_TOL DIFFUSE_KALMAN_TOL SUBSAMPLES OPTIONS TOLF TOLX +%token FAST_KALMAN_FILTER KALMAN_ALGO KALMAN_TOL DIFFUSE_KALMAN_TOL SUBSAMPLES OPTIONS TOLF TOLX PLOT_INIT_DATE PLOT_END_DATE %token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_IDENT_FILES LOAD_MH_FILE LOAD_RESULTS_AFTER_LOAD_MH LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR LOGDATA LYAPUNOV LINEAR_APPROXIMATION %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_CONF_SIG MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER POSTERIOR_MAX_SUBSAMPLE_DRAWS MIN MINIMAL_SOLVING_PERIODS @@ -263,6 +263,7 @@ statement : parameters | shock_decomposition | realtime_shock_decomposition | plot_shock_decomposition + | initial_condition_decomposition | conditional_forecast | conditional_forecast_paths | plot_conditional_forecast @@ -2150,6 +2151,16 @@ plot_shock_decomposition : PLOT_SHOCK_DECOMPOSITION ';' { driver.plot_shock_decomposition(); } ; +initial_condition_decomposition : INITIAL_CONDITION_DECOMPOSITION ';' + {driver.initial_condition_decomposition(); } + | INITIAL_CONDITION_DECOMPOSITION '(' initial_condition_decomposition_options_list ')' ';' + { driver.initial_condition_decomposition(); } + | INITIAL_CONDITION_DECOMPOSITION symbol_list ';' + { driver.initial_condition_decomposition(); } + | INITIAL_CONDITION_DECOMPOSITION '(' initial_condition_decomposition_options_list ')' symbol_list ';' + { driver.initial_condition_decomposition(); } + ; + bvar_prior_option : o_bvar_prior_tau | o_bvar_prior_decay | o_bvar_prior_lambda @@ -2554,6 +2565,18 @@ plot_shock_decomposition_option : o_psd_use_shock_groups | o_psd_vintage ; +initial_condition_decomposition_options_list : initial_condition_decomposition_option COMMA initial_condition_decomposition_options_list + | initial_condition_decomposition_option + ; + +initial_condition_decomposition_option : o_icd_type + | o_icd_detail_plot + | o_icd_steadystate + | o_icd_write_xls + | o_icd_plot_init_date + | o_icd_plot_end_date + ; + homotopy_setup: HOMOTOPY_SETUP ';' homotopy_list END ';' { driver.end_homotopy();}; @@ -3012,9 +3035,11 @@ o_dr_cycle_reduction_tol : DR_CYCLE_REDUCTION_TOL EQUAL non_negative_number {dri o_dr_logarithmic_reduction_tol : DR_LOGARITHMIC_REDUCTION_TOL EQUAL non_negative_number {driver.option_num("dr_logarithmic_reduction_tol",$3);}; o_dr_logarithmic_reduction_maxiter : DR_LOGARITHMIC_REDUCTION_MAXITER EQUAL INT_NUMBER {driver.option_num("dr_logarithmic_reduction_maxiter",$3);}; o_psd_detail_plot : DETAIL_PLOT { driver.option_num("plot_shock_decomp.detail_plot", "1"); }; +o_icd_detail_plot : DETAIL_PLOT { driver.option_num("initial_condition_decomp.detail_plot", "1"); }; o_psd_interactive : INTERACTIVE { driver.option_num("plot_shock_decomp.interactive", "1"); }; o_psd_screen_shocks : SCREEN_SHOCKS { driver.option_num("plot_shock_decomp.screen_shocks", "1"); }; o_psd_steadystate : STEADYSTATE { driver.option_num("plot_shock_decomp.steadystate", "1"); }; +o_icd_steadystate : STEADYSTATE { driver.option_num("initial_condition_decomp.steadystate", "1"); }; o_psd_fig_name : FIG_NAME EQUAL filename { driver.option_str("plot_shock_decomp.fig_name", $3); }; o_psd_type : TYPE EQUAL QOQ { driver.option_str("plot_shock_decomp.type", "qoq"); } @@ -3023,6 +3048,16 @@ o_psd_type : TYPE EQUAL QOQ | TYPE EQUAL AOA { driver.option_str("plot_shock_decomp.type", "qoq"); } ; +o_icd_type : TYPE EQUAL QOQ + { driver.option_str("initial_condition_decomp.type", "qoq"); } + | TYPE EQUAL YOY + { driver.option_str("initial_condition_decomp.type", "qoq"); } + | TYPE EQUAL AOA + { driver.option_str("initial_condition_decomp.type", "qoq"); } + ; +o_icd_plot_init_date : PLOT_INIT_DATE EQUAL date_expr { driver.option_date("initial_condition_decomp.plot_init_date", $3); } ; +o_icd_plot_end_date : PLOT_END_DATE EQUAL date_expr { driver.option_date("initial_condition_decomp.plot_end_date", $3); } ; +o_icd_write_xls : WRITE_XLS { driver.option_num("initial_condition_decomp.write_xls", "1"); }; o_psd_write_xls : WRITE_XLS { driver.option_num("plot_shock_decomp.write_xls", "1"); }; o_psd_realtime : REALTIME EQUAL INT_NUMBER { driver.option_num("plot_shock_decomp.realtime", $3); }; o_psd_vintage : VINTAGE EQUAL INT_NUMBER { driver.option_num("plot_shock_decomp.vintage", $3); }; diff --git a/DynareFlex.ll b/DynareFlex.ll index 59eac989..299d31ed 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -152,6 +152,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 shock_decomposition {BEGIN DYNARE_STATEMENT; return token::SHOCK_DECOMPOSITION;} realtime_shock_decomposition {BEGIN DYNARE_STATEMENT; return token::REALTIME_SHOCK_DECOMPOSITION;} plot_shock_decomposition {BEGIN DYNARE_STATEMENT; return token::PLOT_SHOCK_DECOMPOSITION;} +initial_condition_decomposition {BEGIN DYNARE_STATEMENT; return token::INITIAL_CONDITION_DECOMPOSITION;} sbvar {BEGIN DYNARE_STATEMENT; return token::SBVAR;} ms_estimation {BEGIN DYNARE_STATEMENT; return token::MS_ESTIMATION;} ms_simulation {BEGIN DYNARE_STATEMENT; return token::MS_SIMULATION;} @@ -375,6 +376,8 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 indxscalesstates {return token::INDXSCALESSTATES;} fixed_point {return token::FIXED_POINT;} doubling {return token::DOUBLING;} +plot_init_date {return token::PLOT_INIT_DATE;} +plot_end_date {return token::PLOT_END_DATE;} square_root_solver {return token::SQUARE_ROOT_SOLVER;} cycle_reduction {return token::CYCLE_REDUCTION;} logarithmic_reduction {return token::LOGARITHMIC_REDUCTION;} diff --git a/ParsingDriver.cc b/ParsingDriver.cc index d370979e..c0f47291 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -2141,6 +2141,14 @@ ParsingDriver::plot_shock_decomposition() options_list.clear(); } +void +ParsingDriver::initial_condition_decomposition() +{ + mod_file->addStatement(new InitialConditionDecompositionStatement(symbol_list, options_list)); + symbol_list.clear(); + options_list.clear(); +} + void ParsingDriver::conditional_forecast() { diff --git a/ParsingDriver.hh b/ParsingDriver.hh index 29b9c321..bc9729ff 100644 --- a/ParsingDriver.hh +++ b/ParsingDriver.hh @@ -594,6 +594,8 @@ public: void realtime_shock_decomposition(); //! Plot Shock decomposition void plot_shock_decomposition(); + //! Initial Condition decomposition + void initial_condition_decomposition(); //! Conditional forecast statement void conditional_forecast(); //! Conditional forecast paths block From 5be4206092733e3442f98217eb1c6777fa811ab1 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 31 Mar 2017 14:38:44 +0200 Subject: [PATCH 10/26] preprocessor: add options plot_init_date and plot_end_date to plot_shock_decomposition --- DynareBison.yy | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DynareBison.yy b/DynareBison.yy index 6eea69bc..e5f71d66 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -2563,6 +2563,8 @@ plot_shock_decomposition_option : o_psd_use_shock_groups | o_psd_write_xls | o_psd_realtime | o_psd_vintage + | o_psd_plot_init_date + | o_psd_plot_end_date ; initial_condition_decomposition_options_list : initial_condition_decomposition_option COMMA initial_condition_decomposition_options_list @@ -3057,6 +3059,8 @@ o_icd_type : TYPE EQUAL QOQ ; o_icd_plot_init_date : PLOT_INIT_DATE EQUAL date_expr { driver.option_date("initial_condition_decomp.plot_init_date", $3); } ; o_icd_plot_end_date : PLOT_END_DATE EQUAL date_expr { driver.option_date("initial_condition_decomp.plot_end_date", $3); } ; +o_psd_plot_init_date : PLOT_INIT_DATE EQUAL date_expr { driver.option_date("plot_shock_decomp.plot_init_date", $3); } ; +o_psd_plot_end_date : PLOT_END_DATE EQUAL date_expr { driver.option_date("plot_shock_decomp.plot_end_date", $3); } ; o_icd_write_xls : WRITE_XLS { driver.option_num("initial_condition_decomp.write_xls", "1"); }; o_psd_write_xls : WRITE_XLS { driver.option_num("plot_shock_decomp.write_xls", "1"); }; o_psd_realtime : REALTIME EQUAL INT_NUMBER { driver.option_num("plot_shock_decomp.realtime", $3); }; From f9a803f4a925b182e03fd49d953853cab4ac9dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Sun, 2 Apr 2017 18:37:45 +0200 Subject: [PATCH 11/26] Added option nonlinear_filter_initialization. Default value is 1 (initialization with the ergodic variance of the reduced form solution of the model approximated at order one). If the model has unit roots, the user must use `nonlinear_filter_initialization=3`, which select an identity matrix for the initial covariance matrix of the state variables. A side effect of this option is to temporarily change the value of options_.qz_criterium to a value above one (ie 1+1e-6) so that the unit roots are not rejected. If the model has unit roots and if the and if the option nonlinear_filter_initialization has a value less than 3, the evaluation of the likelihood will fail, because by default the unit root is counted as an unstable root. --- DynareBison.yy | 4 +++- DynareFlex.ll | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/DynareBison.yy b/DynareBison.yy index e5f71d66..c495801a 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -111,7 +111,7 @@ class ParsingDriver; %token MODEL_DIAGNOSTICS MODIFIEDHARMONICMEAN MOMENTS_VARENDO CONTEMPORANEOUS_CORRELATION DIFFUSE_FILTER SUB_DRAWS TAPER_STEPS GEWEKE_INTERVAL RAFTERY_LEWIS_QRS RAFTERY_LEWIS_DIAGNOSTICS MCMC_JUMPING_COVARIANCE MOMENT_CALIBRATION %token NUMBER_OF_PARTICLES RESAMPLING SYSTEMATIC GENERIC RESAMPLING_THRESHOLD RESAMPLING_METHOD KITAGAWA STRATIFIED SMOOTH %token CPF_WEIGHTS AMISANOTRISTANI MURRAYJONESPARSLOW -%token FILTER_ALGORITHM PROPOSAL_APPROXIMATION CUBATURE UNSCENTED MONTECARLO DISTRIBUTION_APPROXIMATION +%token NONLINEAR_FILTER_INITIALIZATION FILTER_ALGORITHM PROPOSAL_APPROXIMATION CUBATURE UNSCENTED MONTECARLO DISTRIBUTION_APPROXIMATION %token NAME %token USE_PENALIZED_OBJECTIVE_FOR_HESSIAN INIT_STATE %token NAN_CONSTANT NO_STATIC NOBS NOCONSTANT NODISPLAY NOCORR NODIAGNOSTIC NOFUNCTIONS NO_HOMOTOPY @@ -1818,6 +1818,7 @@ estimation_options : o_datafile | o_resampling_threshold | o_resampling_method | o_filter_algorithm + | o_nonlinear_filter_initialization | o_cpf_weights | o_proposal_approximation | o_distribution_approximation @@ -3085,6 +3086,7 @@ o_resampling_method : RESAMPLING_METHOD EQUAL KITAGAWA {driver.option_num("parti o_cpf_weights : CPF_WEIGHTS EQUAL AMISANOTRISTANI {driver.option_num("particle.cpf_weights_method.amisanotristani", "1"); driver.option_num("particle.cpf_weights_method.murrayjonesparslow", "0"); } | CPF_WEIGHTS EQUAL MURRAYJONESPARSLOW {driver.option_num("particle.cpf_weights_method.amisanotristani", "0"); driver.option_num("particle.cpf_weights_method.murrayjonesparslow", "1"); }; o_filter_algorithm : FILTER_ALGORITHM EQUAL symbol { driver.option_str("particle.filter_algorithm", $3); }; +o_nonlinear_filter_initialization : NONLINEAR_FILTER_INITIALIZATION EQUAL INT_NUMBER { driver.option_num("particle.initialization", $3); }; o_proposal_approximation : PROPOSAL_APPROXIMATION EQUAL CUBATURE {driver.option_num("particle.proposal_approximation.cubature", "1"); driver.option_num("particle.proposal_approximation.unscented", "0"); driver.option_num("particle.proposal_approximation.montecarlo", "0");} | PROPOSAL_APPROXIMATION EQUAL UNSCENTED {driver.option_num("particle.proposal_approximation.cubature", "0"); driver.option_num("particle.proposal_approximation.unscented", "1"); driver.option_num("particle.proposal_approximation.montecarlo", "0");} | PROPOSAL_APPROXIMATION EQUAL MONTECARLO {driver.option_num("particle.proposal_approximation.cubature", "0"); driver.option_num("particle.proposal_approximation.unscented", "0"); driver.option_num("particle.proposal_approximation.montecarlo", "1");} ; diff --git a/DynareFlex.ll b/DynareFlex.ll index 299d31ed..0a1588c5 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -398,6 +398,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 amisanotristani {return token::AMISANOTRISTANI;} murrayjonesparslow {return token::MURRAYJONESPARSLOW;} filter_algorithm {return token::FILTER_ALGORITHM;} +nonlinear_filter_initialization {return token::NONLINEAR_FILTER_INITIALIZATION;} proposal_approximation {return token::PROPOSAL_APPROXIMATION;} cubature {return token::CUBATURE;} unscented {return token::UNSCENTED;} From 7c09ae7f3de092a2d3b87113d6dd836736d2845d Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 3 Apr 2017 15:23:01 +0200 Subject: [PATCH 12/26] preprocessor: remove unused filed histval_present from mod_file_struct --- NumericalInitialization.cc | 4 +--- Statement.cc | 3 +-- Statement.hh | 5 +---- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index 3bbd803e..aa7a2502 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2016 Dynare Team + * Copyright (C) 2003-2017 Dynare Team * * This file is part of Dynare. * @@ -279,8 +279,6 @@ HistValStatement::HistValStatement(const hist_values_t &hist_values_arg, void HistValStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) { - mod_file_struct.histval_present = true; - if (all_values_required) { set unused_endo = symbol_table.getEndogenous(); diff --git a/Statement.cc b/Statement.cc index 887603b6..d43d1144 100644 --- a/Statement.cc +++ b/Statement.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2015 Dynare Team + * Copyright (C) 2006-2017 Dynare Team * * This file is part of Dynare. * @@ -40,7 +40,6 @@ ModFileStructure::ModFileStructure() : identification_present(false), estimation_analytic_derivation(false), partial_information(false), - histval_present(false), k_order_solver(false), calibrated_measurement_errors(false), dsge_prior_weight_in_estimated_params(false), diff --git a/Statement.hh b/Statement.hh index 311260b0..adfbdd6a 100644 --- a/Statement.hh +++ b/Statement.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2015 Dynare Team + * Copyright (C) 2006-2017 Dynare Team * * This file is part of Dynare. * @@ -72,9 +72,6 @@ public: bool estimation_analytic_derivation; //! Whether the option partial_information is given to stoch_simul/estimation/osr/ramsey_policy bool partial_information; - //! Whether a histval bloc is present - /*! Used for the workaround for trac ticket #157 */ - bool histval_present; //! Whether the "k_order_solver" option is used (explictly, or implicitly if order >= 3) bool k_order_solver; //! Whether there is a calibrated measurement error From 053407314dc791e14f6cdbf3ab812dae590f08af Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 4 Apr 2017 15:28:27 +0200 Subject: [PATCH 13/26] preprocessor: add option to write equation tags in latex output. closes #477 --- ComputingTasks.cc | 7 ++++--- ComputingTasks.hh | 3 ++- DynamicModel.cc | 4 ++-- DynamicModel.hh | 4 ++-- DynareBison.yy | 6 ++++-- DynareFlex.ll | 1 + ModelTree.cc | 13 ++++++++++++- ModelTree.hh | 2 +- ParsingDriver.cc | 4 ++-- ParsingDriver.hh | 2 +- 10 files changed, 31 insertions(+), 15 deletions(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 21b2dd75..d441eca1 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1617,15 +1617,16 @@ IdentificationStatement::writeOutput(ostream &output, const string &basename, bo output << "dynare_identification(options_ident);" << endl; } -WriteLatexDynamicModelStatement::WriteLatexDynamicModelStatement(const DynamicModel &dynamic_model_arg) : - dynamic_model(dynamic_model_arg) +WriteLatexDynamicModelStatement::WriteLatexDynamicModelStatement(const DynamicModel &dynamic_model_arg, bool write_equation_tags_arg) : + dynamic_model(dynamic_model_arg), + write_equation_tags(write_equation_tags_arg) { } void WriteLatexDynamicModelStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { - dynamic_model.writeLatexFile(basename); + dynamic_model.writeLatexFile(basename, write_equation_tags); } WriteLatexStaticModelStatement::WriteLatexStaticModelStatement(const StaticModel &static_model_arg) : diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 596738c2..8319bd89 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -552,8 +552,9 @@ class WriteLatexDynamicModelStatement : public Statement { private: const DynamicModel &dynamic_model; + const bool write_equation_tags; public: - WriteLatexDynamicModelStatement(const DynamicModel &dynamic_model_arg); + WriteLatexDynamicModelStatement(const DynamicModel &dynamic_model_arg, bool write_equation_tags_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; diff --git a/DynamicModel.cc b/DynamicModel.cc index cc3dcf1c..212cec56 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -4378,9 +4378,9 @@ DynamicModel::writeChainRuleDerivative(ostream &output, int eqr, int varr, int l } void -DynamicModel::writeLatexFile(const string &basename) const +DynamicModel::writeLatexFile(const string &basename, const bool write_equation_tags) const { - writeLatexModelFile(basename + "_dynamic", oLatexDynamicModel); + writeLatexModelFile(basename + "_dynamic", oLatexDynamicModel, write_equation_tags); } void diff --git a/DynamicModel.hh b/DynamicModel.hh index 7f0177fb..7988a365 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2016 Dynare Team + * Copyright (C) 2003-2017 Dynare Team * * This file is part of Dynare. * @@ -278,7 +278,7 @@ public: size_t dynamicOnlyEquationsNbr() const; //! Writes LaTeX file with the equations of the dynamic model - void writeLatexFile(const string &basename) const; + void writeLatexFile(const string &basename, const bool write_equation_tags) const; //! Writes LaTeX file with the equations of the dynamic model (for the original model) void writeLatexOriginalFile(const string &basename) const; diff --git a/DynareBison.yy b/DynareBison.yy index c495801a..7c918a1d 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -110,7 +110,7 @@ class ParsingDriver; %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 CONTEMPORANEOUS_CORRELATION DIFFUSE_FILTER SUB_DRAWS TAPER_STEPS GEWEKE_INTERVAL RAFTERY_LEWIS_QRS RAFTERY_LEWIS_DIAGNOSTICS MCMC_JUMPING_COVARIANCE MOMENT_CALIBRATION %token NUMBER_OF_PARTICLES RESAMPLING SYSTEMATIC GENERIC RESAMPLING_THRESHOLD RESAMPLING_METHOD KITAGAWA STRATIFIED SMOOTH -%token CPF_WEIGHTS AMISANOTRISTANI MURRAYJONESPARSLOW +%token CPF_WEIGHTS AMISANOTRISTANI MURRAYJONESPARSLOW WRITE_EQUATION_TAGS %token NONLINEAR_FILTER_INITIALIZATION FILTER_ALGORITHM PROPOSAL_APPROXIMATION CUBATURE UNSCENTED MONTECARLO DISTRIBUTION_APPROXIMATION %token NAME %token USE_PENALIZED_OBJECTIVE_FOR_HESSIAN INIT_STATE @@ -2111,7 +2111,9 @@ ramsey_policy_options : stoch_simul_primary_options ; write_latex_dynamic_model : WRITE_LATEX_DYNAMIC_MODEL ';' - { driver.write_latex_dynamic_model(); } + { driver.write_latex_dynamic_model(false); } + | WRITE_LATEX_DYNAMIC_MODEL '(' WRITE_EQUATION_TAGS ')' ';' + { driver.write_latex_dynamic_model(true); } ; write_latex_static_model : WRITE_LATEX_STATIC_MODEL ';' diff --git a/DynareFlex.ll b/DynareFlex.ll index 0a1588c5..262d7a35 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -465,6 +465,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 yylval->string_val = new string(yytext); return token::ABAND; } +write_equation_tags {return token::WRITE_EQUATION_TAGS;} indxap {return token::INDXAP;} apband {return token::APBAND;} indximf {return token::INDXIMF;} diff --git a/ModelTree.cc b/ModelTree.cc index 0b88c298..deec8b72 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -1529,7 +1529,7 @@ ModelTree::Write_Inf_To_Bin_File(const string &basename, } void -ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output_type) const +ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output_type, const bool write_equation_tags) const { ofstream output, content_output; string filename = basename + ".tex"; @@ -1575,6 +1575,17 @@ ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output { content_output << "\\begin{dmath}" << endl << "% Equation " << eq+1 << endl; + if (write_equation_tags) + for (vector > >::const_iterator iteqt = equation_tags.begin(); + iteqt != equation_tags.end(); iteqt++) + if (iteqt->first == eq) + { + content_output << "[\\textrm{" << iteqt->second.first << "}"; + if (!empty(iteqt->second.second)) + content_output << " = \\textrm{``" << iteqt->second.second << "''}"; + content_output << "]"; + } + // Here it is necessary to cast to superclass ExprNode, otherwise the overloaded writeOutput() method is not found dynamic_cast(equations[eq])->writeOutput(content_output, output_type); content_output << endl << "\\end{dmath}" << endl; diff --git a/ModelTree.hh b/ModelTree.hh index b87debf1..1de07d4b 100644 --- a/ModelTree.hh +++ b/ModelTree.hh @@ -196,7 +196,7 @@ protected: void compileModelEquations(ostream &code_file, unsigned int &instruction_number, const temporary_terms_t &tt, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic) const; //! Writes LaTeX model file - void writeLatexModelFile(const string &basename, ExprNodeOutputType output_type) const; + void writeLatexModelFile(const string &basename, ExprNodeOutputType output_type, const bool write_equation_tags = false) const; //! Sparse matrix of double to store the values of the Jacobian /*! First index is equation number, second index is endogenous type specific ID */ diff --git a/ParsingDriver.cc b/ParsingDriver.cc index c0f47291..bce54085 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -1963,9 +1963,9 @@ ParsingDriver::discretionary_policy() } void -ParsingDriver::write_latex_dynamic_model() +ParsingDriver::write_latex_dynamic_model(bool write_equation_tags) { - mod_file->addStatement(new WriteLatexDynamicModelStatement(mod_file->dynamic_model)); + mod_file->addStatement(new WriteLatexDynamicModelStatement(mod_file->dynamic_model, write_equation_tags)); } void diff --git a/ParsingDriver.hh b/ParsingDriver.hh index bc9729ff..b25105f4 100644 --- a/ParsingDriver.hh +++ b/ParsingDriver.hh @@ -559,7 +559,7 @@ public: //! Discretionary policy statement void discretionary_policy(); //! Adds a write_latex_dynamic_model statement - void write_latex_dynamic_model(); + void write_latex_dynamic_model(bool write_equation_tags); //! Adds a write_latex_static_model statement void write_latex_static_model(); //! Adds a write_latex_original_model statement From 5021601b5b88af63a80a2da0f1362a0dacebe35b Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 5 Apr 2017 10:28:37 +0200 Subject: [PATCH 14/26] preprocessor: move equation tags out of dmath mode, include all equation tags in one set of brackets, allow equation tags to be interpreted as latex, modify manual and test accordingly. #477 --- ModelTree.cc | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/ModelTree.cc b/ModelTree.cc index deec8b72..ed5ecdbe 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -1573,19 +1573,31 @@ ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output for (int eq = 0; eq < (int) equations.size(); eq++) { - content_output << "\\begin{dmath}" << endl - << "% Equation " << eq+1 << endl; + content_output << "% Equation " << eq + 1 << endl; + bool wrote_eq_tag = false; if (write_equation_tags) - for (vector > >::const_iterator iteqt = equation_tags.begin(); - iteqt != equation_tags.end(); iteqt++) - if (iteqt->first == eq) - { - content_output << "[\\textrm{" << iteqt->second.first << "}"; - if (!empty(iteqt->second.second)) - content_output << " = \\textrm{``" << iteqt->second.second << "''}"; - content_output << "]"; - } + { + for (vector > >::const_iterator iteqt = equation_tags.begin(); + iteqt != equation_tags.end(); iteqt++) + if (iteqt->first == eq) + { + if (!wrote_eq_tag) + content_output << "\\noindent["; + else + content_output << ", "; + content_output << iteqt->second.first; + + if (!empty(iteqt->second.second)) + content_output << "= `" << iteqt->second.second << "'"; + + wrote_eq_tag = true; + } + } + if (wrote_eq_tag) + content_output << "]"; + + content_output << "\\begin{dmath}" << endl; // Here it is necessary to cast to superclass ExprNode, otherwise the overloaded writeOutput() method is not found dynamic_cast(equations[eq])->writeOutput(content_output, output_type); content_output << endl << "\\end{dmath}" << endl; From c74dac7e737713ada50d8cc384be9beaa695410a Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 5 Apr 2017 11:07:34 +0200 Subject: [PATCH 15/26] preprocessor: add warning for potential non-linearities in model declared linear. #1404 --- ModFile.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ModFile.cc b/ModFile.cc index 5719d019..6d993d11 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -277,6 +277,19 @@ ModFile::checkPass(bool nostrict) || dynamic_model.isBinaryOpUsed(oDifferent))) warnings << "WARNING: you are using a function (max, min, abs, sign) or an operator (<, >, <=, >=, ==, !=) which is unsuitable for a stochastic context; see the reference manual, section about \"Expressions\", for more details." << endl; + if (linear && + (dynamic_model.isUnaryOpUsed(oSign) + || dynamic_model.isUnaryOpUsed(oAbs) + || dynamic_model.isBinaryOpUsed(oMax) + || dynamic_model.isBinaryOpUsed(oMin) + || dynamic_model.isBinaryOpUsed(oGreater) + || dynamic_model.isBinaryOpUsed(oLess) + || dynamic_model.isBinaryOpUsed(oGreaterEqual) + || dynamic_model.isBinaryOpUsed(oLessEqual) + || dynamic_model.isBinaryOpUsed(oEqualEqual) + || dynamic_model.isBinaryOpUsed(oDifferent))) + warnings << "WARNING: you have declared your model 'linear' but you are using a function (max, min, abs, sign) or an operator (<, >, <=, >=, ==, !=) which potentially makes it non-linear." << endl; + // Test if some estimated parameters are used within the values of shocks // statements (see issue #469) set parameters_intersect; From 8db01545705455111389d9ead487bf2384c0fe6d Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 6 Apr 2017 08:41:12 +0200 Subject: [PATCH 16/26] Fix typo in error message --- ModFile.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ModFile.cc b/ModFile.cc index 6d993d11..629d4b42 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -144,7 +144,7 @@ ModFile::checkPass(bool nostrict) if ((mod_file_struct.ramsey_model_present || mod_file_struct.ramsey_policy_present) && mod_file_struct.discretionary_policy_present) { - cerr << "ERROR: You cannot use the discretionary_policy command when you use either rasmey_model or ramsey_policy and vice versa" << endl; + cerr << "ERROR: You cannot use the discretionary_policy command when you use either ramsey_model or ramsey_policy and vice versa" << endl; exit(EXIT_FAILURE); } From a85cc7b451f0439ecab1f3ee5e0efcc7b5b48d74 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 20 Apr 2017 18:41:28 +0200 Subject: [PATCH 17/26] preprocessor: change trend test to warning. #1389 --- DynamicModel.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index 212cec56..32e3f384 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -4104,11 +4104,11 @@ DynamicModel::testTrendDerivativesEqualToZero(const eval_context_t &eval_context double nearZero = testeq->getDerivative(endogit->second)->eval(eval_context); // eval d F / d Trend d Endog if (fabs(nearZero) > ZERO_BAND) { - cerr << "ERROR: trends not compatible with balanced growth path; the second-order cross partial of equation " << eq + 1 << " (line " + cerr << "WARNING: trends not compatible with balanced growth path; the second-order cross partial of equation " << eq + 1 << " (line " << equations_lineno[eq] << ") w.r.t. trend variable " << symbol_table.getName(it->first.first) << " and endogenous variable " << symbol_table.getName(endogit->first.first) << " is not null. " << endl; - exit(EXIT_FAILURE); + // Changed to warning. See discussion in #1389 } } } From bac51e0a0e010d8e520dc50affd77a14f12fd599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Wed, 26 Apr 2017 18:22:03 +0200 Subject: [PATCH 18/26] Added option rescale_prediction_error_covariance. --- DynareBison.yy | 4 +++- DynareFlex.ll | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/DynareBison.yy b/DynareBison.yy index 7c918a1d..7d79c163 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -113,7 +113,7 @@ class ParsingDriver; %token CPF_WEIGHTS AMISANOTRISTANI MURRAYJONESPARSLOW WRITE_EQUATION_TAGS %token NONLINEAR_FILTER_INITIALIZATION FILTER_ALGORITHM PROPOSAL_APPROXIMATION CUBATURE UNSCENTED MONTECARLO DISTRIBUTION_APPROXIMATION %token NAME -%token USE_PENALIZED_OBJECTIVE_FOR_HESSIAN INIT_STATE +%token USE_PENALIZED_OBJECTIVE_FOR_HESSIAN INIT_STATE RESCALE_PREDICTION_ERROR_COVARIANCE %token NAN_CONSTANT NO_STATIC NOBS NOCONSTANT NODISPLAY NOCORR NODIAGNOSTIC NOFUNCTIONS NO_HOMOTOPY %token NOGRAPH POSTERIOR_NOGRAPH POSTERIOR_GRAPH NOMOMENTS NOPRINT NORMAL_PDF SAVE_DRAWS %token OBSERVATION_TRENDS OPTIM OPTIM_WEIGHTS ORDER OSR OSR_PARAMS MAX_DIM_COVA_GROUP ADVANCED OUTFILE OUTVARS OVERWRITE @@ -1831,6 +1831,7 @@ estimation_options : o_datafile | o_posterior_sampler_options | o_keep_kalman_algo_if_singularity_is_detected | o_use_penalized_objective_for_hessian + | o_rescale_prediction_error_covariance ; list_optim_option : QUOTED_STRING COMMA QUOTED_STRING @@ -3359,6 +3360,7 @@ o_mcmc_jumping_covariance : MCMC_JUMPING_COVARIANCE EQUAL HESSIAN | MCMC_JUMPING_COVARIANCE EQUAL filename { driver.option_str("MCMC_jumping_covariance", $3); } ; +o_rescale_prediction_error_covariance : RESCALE_PREDICTION_ERROR_COVARIANCE { driver.option_num("rescale_prediction_error_covariance", "true"); }; o_use_penalized_objective_for_hessian : USE_PENALIZED_OBJECTIVE_FOR_HESSIAN { driver.option_num("hessian.use_penalized_objective","true"); }; o_irf_plot_threshold : IRF_PLOT_THRESHOLD EQUAL non_negative_number { driver.option_num("impulse_responses.plot_threshold", $3); }; o_dr_display_tol : DR_DISPLAY_TOL EQUAL non_negative_number { driver.option_num("dr_display_tol", $3); }; diff --git a/DynareFlex.ll b/DynareFlex.ll index 262d7a35..7f04aacd 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -406,6 +406,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 distribution_approximation {return token::DISTRIBUTION_APPROXIMATION;} proposal_distribution {return token::PROPOSAL_DISTRIBUTION;} no_posterior_kernel_density {return token::NO_POSTERIOR_KERNEL_DENSITY;} +rescale_prediction_error_covariance {return token::RESCALE_PREDICTION_ERROR_COVARIANCE;} use_penalized_objective_for_hessian {return token::USE_PENALIZED_OBJECTIVE_FOR_HESSIAN;} alpha { From ec6756db0e0086360b4a5db79d2d876f741d61c2 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 27 Apr 2017 11:08:17 +0200 Subject: [PATCH 19/26] Remove redundant ksstat option Closes #1431 --- DynareBison.yy | 4 +--- DynareFlex.ll | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/DynareBison.yy b/DynareBison.yy index 7c918a1d..640ad465 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -143,7 +143,7 @@ class ParsingDriver; %token ASINH ACOSH ATANH SQRT NORMCDF NORMPDF STEADY_STATE EXPECTATION /* GSA analysis */ %token DYNARE_SENSITIVITY MORRIS STAB REDFORM PPRIOR PRIOR_RANGE PPOST ILPTAU MORRIS_NLIV -%token MORRIS_NTRA NSAM LOAD_REDFORM LOAD_RMSE LOAD_STAB ALPHA2_STAB KSSTAT LOGTRANS_REDFORM THRESHOLD_REDFORM +%token MORRIS_NTRA NSAM LOAD_REDFORM LOAD_RMSE LOAD_STAB ALPHA2_STAB LOGTRANS_REDFORM THRESHOLD_REDFORM %token KSSTAT_REDFORM ALPHA2_REDFORM NAMENDO NAMLAGENDO NAMEXO RMSE LIK_ONLY VAR_RMSE PFILT_RMSE ISTART_RMSE %token ALPHA_RMSE ALPHA2_RMSE /* end of GSA analysis*/ @@ -2480,7 +2480,6 @@ dynare_sensitivity_option : o_gsa_identification | o_gsa_load_rmse | o_gsa_load_stab | o_gsa_alpha2_stab - | o_gsa_ksstat | o_gsa_logtrans_redform | o_gsa_ksstat_redform | o_gsa_alpha2_redform @@ -3112,7 +3111,6 @@ o_gsa_load_redform : LOAD_REDFORM EQUAL INT_NUMBER { driver.option_num("load_red o_gsa_load_rmse : LOAD_RMSE EQUAL INT_NUMBER { driver.option_num("load_rmse", $3); }; o_gsa_load_stab : LOAD_STAB EQUAL INT_NUMBER { driver.option_num("load_stab", $3); }; o_gsa_alpha2_stab : ALPHA2_STAB EQUAL non_negative_number { driver.option_num("alpha2_stab", $3); }; -o_gsa_ksstat : KSSTAT EQUAL non_negative_number { driver.option_num("ksstat", $3); }; o_gsa_logtrans_redform : LOGTRANS_REDFORM EQUAL INT_NUMBER { driver.option_num("logtrans_redform", $3); }; o_gsa_threshold_redform : THRESHOLD_REDFORM EQUAL vec_value_w_inf { driver.option_num("threshold_redform",$3); }; o_gsa_ksstat_redform : KSSTAT_REDFORM EQUAL non_negative_number { driver.option_num("ksstat_redform", $3); }; diff --git a/DynareFlex.ll b/DynareFlex.ll index 262d7a35..b0620ab7 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -800,7 +800,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 load_rmse {return token::LOAD_RMSE;} load_stab {return token::LOAD_STAB;} alpha2_stab {return token::ALPHA2_STAB;} -ksstat {return token::KSSTAT;} logtrans_redform {return token::LOGTRANS_REDFORM;} threshold_redform {return token::THRESHOLD_REDFORM;} ksstat_redform {return token::KSSTAT_REDFORM;} From 031a798a962f5163152cc09c86ac5d4680e4e7ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Tue, 16 May 2017 14:11:15 +0200 Subject: [PATCH 20/26] Fixed copyright notices. --- CodeInterpreter.hh | 2 +- ExternalFunctionsTable.cc | 2 +- ExternalFunctionsTable.hh | 2 +- SymbolList.hh | 2 +- macro/MacroValue.cc | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CodeInterpreter.hh b/CodeInterpreter.hh index ad41b0ed..ed695fc2 100644 --- a/CodeInterpreter.hh +++ b/CodeInterpreter.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2015 Dynare Team + * Copyright (C) 2007-2016 Dynare Team * * This file is part of Dynare. * diff --git a/ExternalFunctionsTable.cc b/ExternalFunctionsTable.cc index 8554d830..eb4ab00c 100644 --- a/ExternalFunctionsTable.cc +++ b/ExternalFunctionsTable.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011 Dynare Team + * Copyright (C) 2010-2015 Dynare Team * * This file is part of Dynare. * diff --git a/ExternalFunctionsTable.hh b/ExternalFunctionsTable.hh index aa4b02cd..42d18391 100644 --- a/ExternalFunctionsTable.hh +++ b/ExternalFunctionsTable.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011 Dynare Team + * Copyright (C) 2010-2015 Dynare Team * * This file is part of Dynare. * diff --git a/SymbolList.hh b/SymbolList.hh index 82f0b794..cbb51cab 100644 --- a/SymbolList.hh +++ b/SymbolList.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2011 Dynare Team + * Copyright (C) 2003-2014 Dynare Team * * This file is part of Dynare. * diff --git a/macro/MacroValue.cc b/macro/MacroValue.cc index 3dfab323..b20beb5d 100644 --- a/macro/MacroValue.cc +++ b/macro/MacroValue.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2013 Dynare Team + * Copyright (C) 2008-2014 Dynare Team * * This file is part of Dynare. * From d2b7503e1c74ce9627944321d3219295cc6425a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Tue, 16 May 2017 16:30:27 +0200 Subject: [PATCH 21/26] Fixed indentation of c/h/cc/hh files. --- CodeInterpreter.hh | 27 +- ComputingTasks.cc | 317 ++++++++++---------- ComputingTasks.hh | 25 +- ConfigFile.cc | 79 +++-- ConfigFile.hh | 14 +- DataTree.hh | 3 +- DynamicModel.cc | 416 +++++++++++++------------- DynamicModel.hh | 15 +- DynareMain.cc | 54 ++-- DynareMain2.cc | 4 +- ExprNode.cc | 51 ++-- ExprNode.hh | 559 ++++++++++++++++++----------------- ExtendedPreprocessorTypes.hh | 6 +- MinimumFeedbackSet.cc | 2 +- ModFile.cc | 236 ++++++++------- ModFile.hh | 8 +- ModelTree.cc | 78 ++--- ModelTree.hh | 15 +- ParsingDriver.cc | 121 ++++---- ParsingDriver.hh | 24 +- Shocks.cc | 14 +- Shocks.hh | 2 +- Statement.cc | 9 +- Statement.hh | 5 +- StaticModel.cc | 44 ++- StaticModel.hh | 6 +- SteadyStateModel.cc | 12 +- SymbolList.hh | 12 +- SymbolTable.cc | 119 ++++---- SymbolTable.hh | 48 ++- WarningConsolidation.cc | 13 +- WarningConsolidation.hh | 26 +- macro/MacroDriver.cc | 6 +- macro/MacroDriver.hh | 5 +- macro/MacroValue.hh | 18 +- 35 files changed, 1231 insertions(+), 1162 deletions(-) diff --git a/CodeInterpreter.hh b/CodeInterpreter.hh index ed695fc2..7be9a056 100644 --- a/CodeInterpreter.hh +++ b/CodeInterpreter.hh @@ -228,15 +228,15 @@ enum TrinaryOpcode }; enum external_function_type -{ - ExternalFunctionWithoutDerivative, - ExternalFunctionWithFirstDerivative, - ExternalFunctionWithFirstandSecondDerivative, - ExternalFunctionNumericalFirstDerivative, - ExternalFunctionFirstDerivative, - ExternalFunctionNumericalSecondDerivative, - ExternalFunctionSecondDerivative -}; + { + ExternalFunctionWithoutDerivative, + ExternalFunctionWithFirstDerivative, + ExternalFunctionWithFirstandSecondDerivative, + ExternalFunctionNumericalFirstDerivative, + ExternalFunctionFirstDerivative, + ExternalFunctionNumericalSecondDerivative, + ExternalFunctionSecondDerivative + }; enum PriorDistributions { @@ -1451,9 +1451,9 @@ public: exogenous = vector(exogenous_arg); other_endogenous = vector(other_endogenous_arg); is_linear = is_linear_arg; endo_nbr = endo_nbr_arg; Max_Lag = Max_Lag_arg; Max_Lead = Max_Lead_arg; u_count_int = u_count_int_arg; - nb_col_jacob = nb_col_jacob_arg; - det_exo_size = det_exo_size_arg; nb_col_det_exo_jacob = nb_col_det_exo_jacob_arg; - exo_size = exo_size_arg; nb_col_exo_jacob = nb_col_exo_jacob_arg; + nb_col_jacob = nb_col_jacob_arg; + det_exo_size = det_exo_size_arg; nb_col_det_exo_jacob = nb_col_det_exo_jacob_arg; + exo_size = exo_size_arg; nb_col_exo_jacob = nb_col_exo_jacob_arg; other_endo_size = other_endo_size_arg; nb_col_other_endo_jacob = nb_col_other_endo_jacob_arg; }; inline @@ -1467,7 +1467,7 @@ public: is_linear = is_linear_arg; endo_nbr = endo_nbr_arg; Max_Lag = Max_Lag_arg; Max_Lead = Max_Lead_arg; u_count_int = u_count_int_arg; nb_col_jacob = nb_col_jacob_arg; det_exo_size = 0; exo_size = 0; other_endo_size = 0; - nb_col_det_exo_jacob = 0;nb_col_exo_jacob = 0;nb_col_other_endo_jacob = 0; + nb_col_det_exo_jacob = 0; nb_col_exo_jacob = 0; nb_col_other_endo_jacob = 0; } inline unsigned int get_size() @@ -2025,4 +2025,3 @@ public: #endif #pragma pack(pop) #endif - diff --git a/ComputingTasks.cc b/ComputingTasks.cc index d441eca1..859770dc 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -150,11 +150,11 @@ PriorPosteriorFunctionStatement::checkPass(ModFileStructure &mod_file_struct, Wa { OptionsList::string_options_t::const_iterator it2 = options_list.string_options.find("function"); if (it2 == options_list.string_options.end() || it2->second.empty()) - { - cerr << "ERROR: both the prior_function and posterior_function commands require the 'function' argument" - << endl; - exit(EXIT_FAILURE); - } + { + cerr << "ERROR: both the prior_function and posterior_function commands require the 'function' argument" + << endl; + exit(EXIT_FAILURE); + } } void @@ -163,7 +163,7 @@ PriorPosteriorFunctionStatement::writeOutput(ostream &output, const string &base options_list.writeOutput(output); string type = "posterior"; if (prior_func) - type = "prior"; + type = "prior"; output << "oo_ = execute_prior_posterior_function(" << "'" << options_list.string_options.find("function")->second << "', " @@ -202,14 +202,14 @@ StochSimulStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli it = options_list.num_options.find("hp_filter"); OptionsList::num_options_t::const_iterator it1 = options_list.num_options.find("bandpass.indicator"); OptionsList::num_options_t::const_iterator it2 = options_list.num_options.find("one_sided_hp_filter"); - if ((it != options_list.num_options.end() && it1 != options_list.num_options.end()) || - (it != options_list.num_options.end() && it2 != options_list.num_options.end()) || - (it1 != options_list.num_options.end() && it2 != options_list.num_options.end())) - { - cerr << "ERROR: stoch_simul: can only use one of hp, one-sided hp, and bandpass filters" - << endl; - exit(EXIT_FAILURE); - } + if ((it != options_list.num_options.end() && it1 != options_list.num_options.end()) + || (it != options_list.num_options.end() && it2 != options_list.num_options.end()) + || (it1 != options_list.num_options.end() && it2 != options_list.num_options.end())) + { + cerr << "ERROR: stoch_simul: can only use one of hp, one-sided hp, and bandpass filters" + << endl; + exit(EXIT_FAILURE); + } } void @@ -243,7 +243,7 @@ ForecastStatement::writeOutput(ostream &output, const string &basename, bool min } RamseyModelStatement::RamseyModelStatement(const SymbolList &symbol_list_arg, - const OptionsList &options_list_arg) : + const OptionsList &options_list_arg) : symbol_list(symbol_list_arg), options_list(options_list_arg) { @@ -307,7 +307,7 @@ RamseyConstraintsStatement::RamseyConstraintsStatement(const constraints_t &cons void RamseyConstraintsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) { - if ((mod_file_struct.ramsey_model_present != true) || ( mod_file_struct.ramsey_policy_present != true)) + if ((mod_file_struct.ramsey_model_present != true) || (mod_file_struct.ramsey_policy_present != true)) cerr << "ramsey_constraints: can only be used with ramsey_model or ramsey_policy" << endl; } @@ -318,26 +318,26 @@ RamseyConstraintsStatement::writeOutput(ostream &output, const string &basename, for (RamseyConstraintsStatement::constraints_t::const_iterator it = constraints.begin(); it != constraints.end(); ++it) { if (it != constraints.begin()) - output << ", "; + output << ", "; output << "{" << it->endo + 1 << ", '"; - switch(it->code) - { - case oLess: - output << '<'; - break; - case oGreater: - output << '>'; - break; - case oLessEqual: - output << "<="; - break; - case oGreaterEqual: - output << ">="; - break; - default: - cerr << "Ramsey constraints: this shouldn't happen." << endl; - exit(EXIT_FAILURE); - } + switch (it->code) + { + case oLess: + output << '<'; + break; + case oGreater: + output << '>'; + break; + case oLessEqual: + output << "<="; + break; + case oGreaterEqual: + output << ">="; + break; + default: + cerr << "Ramsey constraints: this shouldn't happen." << endl; + exit(EXIT_FAILURE); + } output << "', '"; it->expression->writeOutput(output); output << "'}" << endl; @@ -416,7 +416,7 @@ RamseyPolicyStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso { // ramsey_model_present indicates that the model is augmented with the FOC of the planner problem mod_file_struct.ramsey_model_present = true; - // ramsey_policy_present indicates that ramsey_policy instruction for computation of first order approximation + // ramsey_policy_present indicates that ramsey_policy instruction for computation of first order approximation // of a stochastic Ramsey problem if present in the *.mod file mod_file_struct.ramsey_policy_present = true; @@ -490,7 +490,7 @@ RamseyPolicyStatement::writeOutput(ostream &output, const string &basename, bool } DiscretionaryPolicyStatement::DiscretionaryPolicyStatement(const SymbolList &symbol_list_arg, - const OptionsList &options_list_arg) : + const OptionsList &options_list_arg) : symbol_list(symbol_list_arg), options_list(options_list_arg) { @@ -566,16 +566,16 @@ EstimationStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli if (it != options_list.num_options.end()) { int order = atoi(it->second.c_str()); - + if (order > 2) { cerr << "ERROR: order > 2 is not supported in estimation" << endl; exit(EXIT_FAILURE); } - + mod_file_struct.order_option = max(mod_file_struct.order_option, order); } - + // Fill in mod_file_struct.partial_information it = options_list.num_options.find("partial_information"); if (it != options_list.num_options.end() && it->second == "1") @@ -588,8 +588,8 @@ EstimationStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli it = options_list.num_options.find("dsge_var"); if (it != options_list.num_options.end()) - // Fill in mod_file_struct.dsge_var_calibrated - mod_file_struct.dsge_var_calibrated = it->second; + // Fill in mod_file_struct.dsge_var_calibrated + mod_file_struct.dsge_var_calibrated = it->second; // Fill in mod_file_struct.dsge_var_estimated OptionsList::string_options_t::const_iterator it_str = options_list.string_options.find("dsge_var"); @@ -618,15 +618,15 @@ EstimationStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli exit(EXIT_FAILURE); } - if (options_list.string_options.find("datafile") == options_list.string_options.end() && - !mod_file_struct.estimation_data_statement_present) + if (options_list.string_options.find("datafile") == options_list.string_options.end() + && !mod_file_struct.estimation_data_statement_present) { cerr << "ERROR: The estimation statement requires a data file to be supplied via the datafile option." << endl; exit(EXIT_FAILURE); } - if (options_list.string_options.find("mode_file") != options_list.string_options.end() && - mod_file_struct.estim_params_use_calib) + if (options_list.string_options.find("mode_file") != options_list.string_options.end() + && mod_file_struct.estim_params_use_calib) { cerr << "ERROR: The mode_file option of the estimation statement is incompatible with the use_calibration option of the estimated_params_init block." << endl; exit(EXIT_FAILURE); @@ -686,7 +686,7 @@ DynareSensitivityStatement::writeOutput(ostream &output, const string &basename, OptionsList::string_options_t::const_iterator it2 = options_list.string_options.find("graph_format"); if (it2 != options_list.string_options.end()) output << "options_.graph_format = '" << it2->second << "';" << endl; - + output << "dynare_sensitivity(options_gsa);" << endl; } @@ -710,7 +710,7 @@ void UnitRootVarsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "options_.diffuse_filter = 1;" << endl - << "options_.steadystate.nocheck = 1;" << endl; + << "options_.steadystate.nocheck = 1;" << endl; } PeriodsStatement::PeriodsStatement(int periods_arg) : periods(periods_arg) @@ -1369,8 +1369,8 @@ MSSBVAREstimationStatement::checkPass(ModFileStructure &mod_file_struct, Warning mod_file_struct.bvar_present = true; if (options_list.num_options.find("ms.create_init") == options_list.num_options.end()) - if (options_list.string_options.find("datafile") == options_list.string_options.end() || - options_list.num_options.find("ms.initial_year") == options_list.num_options.end()) + if (options_list.string_options.find("datafile") == options_list.string_options.end() + || options_list.num_options.find("ms.initial_year") == options_list.num_options.end()) { cerr << "ERROR: If you do not pass no_create_init to ms_estimation, " << "you must pass the datafile and initial_year options." << endl; @@ -1462,7 +1462,7 @@ MSSBVARComputeProbabilitiesStatement::writeOutput(ostream &output, const string } MSSBVARIrfStatement::MSSBVARIrfStatement(const SymbolList &symbol_list_arg, - const OptionsList &options_list_arg) : + const OptionsList &options_list_arg) : symbol_list(symbol_list_arg), options_list(options_list_arg) { @@ -1489,14 +1489,14 @@ MSSBVARIrfStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli if (it != options_list.num_options.end()) filtered_probabilities_present = true; - if ((filtered_probabilities_present && regime_present) || - (filtered_probabilities_present && regimes_present) || - (regimes_present && regime_present)) - { - cerr << "ERROR: You may only pass one of regime, regimes and " - << "filtered_probabilities to ms_irf" << endl; - exit(EXIT_FAILURE); - } + if ((filtered_probabilities_present && regime_present) + || (filtered_probabilities_present && regimes_present) + || (regimes_present && regime_present)) + { + cerr << "ERROR: You may only pass one of regime, regimes and " + << "filtered_probabilities to ms_irf" << endl; + exit(EXIT_FAILURE); + } } void @@ -1560,14 +1560,14 @@ MSSBVARVarianceDecompositionStatement::checkPass(ModFileStructure &mod_file_stru if (it != options_list.num_options.end()) filtered_probabilities_present = true; - if ((filtered_probabilities_present && regime_present) || - (filtered_probabilities_present && regimes_present) || - (regimes_present && regime_present)) - { - cerr << "ERROR: You may only pass one of regime, regimes and " - << "filtered_probabilities to ms_variance_decomposition" << endl; - exit(EXIT_FAILURE); - } + if ((filtered_probabilities_present && regime_present) + || (filtered_probabilities_present && regimes_present) + || (regimes_present && regime_present)) + { + cerr << "ERROR: You may only pass one of regime, regimes and " + << "filtered_probabilities to ms_variance_decomposition" << endl; + exit(EXIT_FAILURE); + } } void @@ -1831,19 +1831,19 @@ SvarIdentificationStatement::writeOutput(ostream &output, const string &basename for (svar_identification_restrictions_t::const_iterator it = restrictions.begin(); it != restrictions.end(); it++) { assert(it->lag >= 0); - if (it->lag == 0) + if (it->lag == 0) output << "options_.ms.Qi{" << it->equation << "}(" << it->restriction_nbr << ", " << it->variable + 1 << ") = "; - else - { - int col = (it->lag-1)*n+it->variable+1; - if (col > k) + else + { + int col = (it->lag-1)*n+it->variable+1; + if (col > k) { cerr << "ERROR: lag =" << it->lag << ", num endog vars = " << n << "current endog var index = " << it->variable << ". Index " << "out of bounds. If the above does not represent a logical error, please report this to the Dyanre Team." << endl; exit(EXIT_FAILURE); } - output << "options_.ms.Ri{" << it->equation << "}(" << it->restriction_nbr << ", " << col << ") = "; - } + output << "options_.ms.Ri{" << it->equation << "}(" << it->restriction_nbr << ", " << col << ") = "; + } it->value->writeOutput(output); output << ";" << endl; } @@ -1858,21 +1858,21 @@ MarkovSwitchingStatement::MarkovSwitchingStatement(const OptionsList &options_li if (it_num != options_list.num_options.end()) { using namespace boost; - OptionsList::num_options_t::const_iterator it_num_regimes = - options_list.num_options.find("ms.number_of_regimes"); + OptionsList::num_options_t::const_iterator it_num_regimes + = options_list.num_options.find("ms.number_of_regimes"); assert(it_num_regimes != options_list.num_options.end()); int num_regimes = lexical_cast< int >(it_num_regimes->second); vector tokenizedRestrictions; split(tokenizedRestrictions, it_num->second, is_any_of("["), token_compress_on); for (vector::iterator it = tokenizedRestrictions.begin(); - it != tokenizedRestrictions.end(); it++ ) + it != tokenizedRestrictions.end(); it++) if (it->size() > 0) { vector restriction; split(restriction, *it, is_any_of("], ")); for (vector::iterator it1 = restriction.begin(); - it1 != restriction.end(); ) + it1 != restriction.end();) if (it1->empty()) restriction.erase(it1); else @@ -1941,16 +1941,16 @@ MarkovSwitchingStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo if (it_num != options_list.num_options.end()) { using namespace boost; - OptionsList::num_options_t::const_iterator it_num_regimes = - options_list.num_options.find("ms.number_of_regimes"); + OptionsList::num_options_t::const_iterator it_num_regimes + = options_list.num_options.find("ms.number_of_regimes"); assert(it_num_regimes != options_list.num_options.end()); int num_regimes = lexical_cast< int >(it_num_regimes->second); - vector col_trans_prob_sum (num_regimes, 0); - vector row_trans_prob_sum (num_regimes, 0); - vector all_restrictions_in_row (num_regimes, true); - vector all_restrictions_in_col (num_regimes, true); - for (int row=0; row col_trans_prob_sum(num_regimes, 0); + vector row_trans_prob_sum(num_regimes, 0); + vector all_restrictions_in_row(num_regimes, true); + vector all_restrictions_in_col(num_regimes, true); + for (int row = 0; row < num_regimes; row++) + for (int col = 0; col < num_regimes; col++) if (restriction_map.find(make_pair(row+1, col+1)) != restriction_map.end()) { row_trans_prob_sum[row] += restriction_map[make_pair(row+1, col+1)]; @@ -1962,41 +1962,41 @@ MarkovSwitchingStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo all_restrictions_in_col[col] = false; } - for (int i=0; i= 1.0) { - cerr << "ERROR: When all transitions probabilities are specified for a certain " - << "regime, they must sum to 1" << endl; + cerr << "ERROR: When transition probabilites are not specified for every regime, " + << "their sum must be < 1" << endl; exit(EXIT_FAILURE); } - } - else - if (row_trans_prob_sum[i] >= 1.0) - { - cerr << "ERROR: When transition probabilites are not specified for every regime, " - << "their sum must be < 1" << endl; - exit(EXIT_FAILURE); - } - if (all_restrictions_in_col[i]) - { - if (col_trans_prob_sum[i] != 1.0) + if (all_restrictions_in_col[i]) + { + if (col_trans_prob_sum[i] != 1.0) + { + cerr << "ERROR: When all transitions probabilities are specified for a certain " + << "regime, they must sum to 1" << endl; + exit(EXIT_FAILURE); + } + } + else + if (col_trans_prob_sum[i] >= 1.0) { - cerr << "ERROR: When all transitions probabilities are specified for a certain " - << "regime, they must sum to 1" << endl; + cerr << "ERROR: When transition probabilites are not specified for every regime, " + << "their sum must be < 1" << endl; exit(EXIT_FAILURE); } - } - else - if (col_trans_prob_sum[i] >= 1.0) - { - cerr << "ERROR: When transition probabilites are not specified for every regime, " - << "their sum must be < 1" << endl; - exit(EXIT_FAILURE); - } } } @@ -2033,7 +2033,7 @@ MarkovSwitchingStatement::writeOutput(ostream &output, const string &basename, b } int restrictions_index = 0; - for (itR=restriction_map.begin(); itR != restriction_map.end(); itR++) + for (itR = restriction_map.begin(); itR != restriction_map.end(); itR++) output << "options_.ms.ms_chain(" << itChain->second << ").restrictions(" << ++restrictions_index << ") = {[" << itR->first.first << ", " << itR->first.second << ", " << itR->second << "]};" << endl; @@ -2044,8 +2044,8 @@ MarkovSwitchingStatement::writeCOutput(ostream &output, const string &basename) { output << endl; - OptionsList::num_options_t::const_iterator it = - options_list.num_options.find("ms.chain"); + OptionsList::num_options_t::const_iterator it + = options_list.num_options.find("ms.chain"); assert(it != options_list.num_options.end()); output << "chain = " << it->second << ";" << endl; @@ -2067,17 +2067,17 @@ MarkovSwitchingStatement::writeCOutput(ostream &output, const string &basename) vector tokenizedDomain; split(tokenizedDomain, it->second, is_any_of("[ ]"), token_compress_on); for (vector::iterator itvs = tokenizedDomain.begin(); - itvs != tokenizedDomain.end(); itvs++ ) + itvs != tokenizedDomain.end(); itvs++) if (!itvs->empty()) output << "duration.push_back(" << *itvs << ");" << endl; - OptionsList::symbol_list_options_t::const_iterator itsl = - options_list.symbol_list_options.find("ms.parameters"); + OptionsList::symbol_list_options_t::const_iterator itsl + = options_list.symbol_list_options.find("ms.parameters"); assert(itsl != options_list.symbol_list_options.end()); vector parameters = itsl->second.get_symbols(); output << "parameters.clear();" << endl; for (vector::iterator itp = parameters.begin(); - itp != parameters.end(); itp++ ) + itp != parameters.end(); itp++) output << "parameters.push_back(param_names[\"" << *itp << "\"]);" << endl; output << "restriction_map.clear();" << endl; @@ -2104,13 +2104,13 @@ SvarStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation it2 = options_list.string_options.find("ms.constants"); assert((it0 != options_list.string_options.end() && it1 == options_list.string_options.end() - && it2 == options_list.string_options.end()) || - (it0 == options_list.string_options.end() - && it1 != options_list.string_options.end() - && it2 == options_list.string_options.end()) || - (it0 == options_list.string_options.end() - && it1 == options_list.string_options.end() - && it2 != options_list.string_options.end())); + && it2 == options_list.string_options.end()) + || (it0 == options_list.string_options.end() + && it1 != options_list.string_options.end() + && it2 == options_list.string_options.end()) + || (it0 == options_list.string_options.end() + && it1 == options_list.string_options.end() + && it2 != options_list.string_options.end())); } void @@ -2193,15 +2193,15 @@ EstimationDataStatement::checkPass(ModFileStructure &mod_file_struct, WarningCon exit(EXIT_FAILURE); } - if ((options_list.string_options.find("file") == options_list.string_options.end()) && - (options_list.string_options.find("series") == options_list.string_options.end())) + if ((options_list.string_options.find("file") == options_list.string_options.end()) + && (options_list.string_options.find("series") == options_list.string_options.end())) { cerr << "ERROR: The file or series option must be passed to the data statement." << endl; exit(EXIT_FAILURE); } - if ((options_list.string_options.find("file") != options_list.string_options.end()) && - (options_list.string_options.find("series") != options_list.string_options.end())) + if ((options_list.string_options.find("file") != options_list.string_options.end()) + && (options_list.string_options.find("series") != options_list.string_options.end())) { cerr << "ERROR: The file and series options cannot be used simultaneously in the data statement." << endl; exit(EXIT_FAILURE); @@ -2373,8 +2373,8 @@ JointPriorStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli exit(EXIT_FAILURE); } - if (options_list.num_options.find("mean") == options_list.num_options.end() && - options_list.num_options.find("mode") == options_list.num_options.end()) + if (options_list.num_options.find("mean") == options_list.num_options.end() + && options_list.num_options.find("mode") == options_list.num_options.end()) { cerr << "ERROR: You must pass at least one of mean and mode to the prior statement." << endl; exit(EXIT_FAILURE); @@ -2397,13 +2397,13 @@ JointPriorStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli void JointPriorStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { - for (vector::const_iterator it = joint_parameters.begin() ; it != joint_parameters.end(); it++) + for (vector::const_iterator it = joint_parameters.begin(); it != joint_parameters.end(); it++) output << "eifind = get_new_or_existing_ei_index('joint_parameter_prior_index', '" << *it << "', '');" << endl << "estimation_info.joint_parameter_prior_index(eifind) = {'" << *it << "'};" << endl; output << "key = {["; - for (vector::const_iterator it = joint_parameters.begin() ; it != joint_parameters.end(); it++) + for (vector::const_iterator it = joint_parameters.begin(); it != joint_parameters.end(); it++) output << "get_new_or_existing_ei_index('joint_parameter_prior_index', '" << *it << "', '') ..." << endl << " "; output << "]};" << endl; @@ -2444,18 +2444,17 @@ JointPriorStatement::writeOutputHelper(ostream &output, const string &field, con { OptionsList::num_options_t::const_iterator itn = options_list.num_options.find(field); output << lhs_field << "." << field << " = {"; - if (field=="variance") + if (field == "variance") output << "{"; if (itn != options_list.num_options.end()) output << itn->second; else output << "{}"; - if (field=="variance") + if (field == "variance") output << "}"; output << "};" << endl; } - BasicPriorStatement::~BasicPriorStatement() { } @@ -2482,16 +2481,16 @@ BasicPriorStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli exit(EXIT_FAILURE); } - if (options_list.num_options.find("mean") == options_list.num_options.end() && - options_list.num_options.find("mode") == options_list.num_options.end()) + if (options_list.num_options.find("mean") == options_list.num_options.end() + && options_list.num_options.find("mode") == options_list.num_options.end()) { cerr << "ERROR: You must pass at least one of mean and mode to the prior statement." << endl; exit(EXIT_FAILURE); } OptionsList::num_options_t::const_iterator it_stdev = options_list.num_options.find("stdev"); - if ((it_stdev == options_list.num_options.end() && variance == NULL) || - (it_stdev != options_list.num_options.end() && variance != NULL)) + if ((it_stdev == options_list.num_options.end() && variance == NULL) + || (it_stdev != options_list.num_options.end() && variance != NULL)) { cerr << "ERROR: You must pass exactly one of stdev and variance to the prior statement." << endl; exit(EXIT_FAILURE); @@ -2598,7 +2597,7 @@ BasicPriorStatement::writeCDomain(ostream &output) const vector tokenizedDomain; split(tokenizedDomain, it_num->second, is_any_of("[ ]"), token_compress_on); for (vector::iterator it = tokenizedDomain.begin(); - it != tokenizedDomain.end(); it++ ) + it != tokenizedDomain.end(); it++) if (!it->empty()) output << "domain.push_back(" << *it << ");" << endl; } @@ -2621,28 +2620,28 @@ BasicPriorStatement::writeCShape(ostream &output) const switch (prior_shape) { case eBeta: - output << "\"beta\";" << endl; + output << "\"beta\";" << endl; break; case eGamma: - output << "\"gamma\";" << endl; + output << "\"gamma\";" << endl; break; case eNormal: - output << "\"normal\";" << endl; + output << "\"normal\";" << endl; break; case eInvGamma: - output << "\"inv_gamma\";" << endl; + output << "\"inv_gamma\";" << endl; break; case eUniform: - output << "\"uniform\";" << endl; + output << "\"uniform\";" << endl; break; case eInvGamma2: - output << "\"inv_gamma2\";" << endl; + output << "\"inv_gamma2\";" << endl; break; case eDirichlet: - output << "\"dirichlet\";" << endl; + output << "\"dirichlet\";" << endl; break; case eWeibull: - output << "\"weibull\";" << endl; + output << "\"weibull\";" << endl; break; case eNoShape: assert(prior_shape != eNoShape); @@ -2689,7 +2688,7 @@ StdPriorStatement::StdPriorStatement(const string &name_arg, const PriorDistributions &prior_shape_arg, const expr_t &variance_arg, const OptionsList &options_list_arg, - const SymbolTable &symbol_table_arg ) : + const SymbolTable &symbol_table_arg) : BasicPriorStatement(name_arg, subsample_name_arg, prior_shape_arg, variance_arg, options_list_arg), symbol_table(symbol_table_arg) { @@ -2738,7 +2737,7 @@ CorrPriorStatement::CorrPriorStatement(const string &name_arg1, const string &na const PriorDistributions &prior_shape_arg, const expr_t &variance_arg, const OptionsList &options_list_arg, - const SymbolTable &symbol_table_arg ) : + const SymbolTable &symbol_table_arg) : BasicPriorStatement(name_arg1, subsample_name_arg, prior_shape_arg, variance_arg, options_list_arg), name1(name_arg2), symbol_table(symbol_table_arg) @@ -2829,8 +2828,8 @@ PriorEqualStatement::PriorEqualStatement(const string &to_declaration_type_arg, void PriorEqualStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) { - if ((to_declaration_type != "par" && to_declaration_type != "std" && to_declaration_type != "corr") || - (from_declaration_type != "par" && from_declaration_type != "std" && from_declaration_type != "corr")) + if ((to_declaration_type != "par" && to_declaration_type != "std" && to_declaration_type != "corr") + || (from_declaration_type != "par" && from_declaration_type != "std" && from_declaration_type != "corr")) { cerr << "Internal Dynare Error" << endl; exit(EXIT_FAILURE); @@ -2861,7 +2860,6 @@ PriorEqualStatement::writeOutput(ostream &output, const string &basename, bool m else get_base_name(symbol_table.getType(from_name1), rhs_field); - if (to_declaration_type == "corr") lhs_field += "_corr"; @@ -3014,7 +3012,7 @@ OptionsStatement::writeCOutput(ostream &output, const string &basename) StdOptionsStatement::StdOptionsStatement(const string &name_arg, const string &subsample_name_arg, const OptionsList &options_list_arg, - const SymbolTable &symbol_table_arg ) : + const SymbolTable &symbol_table_arg) : BasicOptionsStatement(name_arg, subsample_name_arg, options_list_arg), symbol_table(symbol_table_arg) { @@ -3056,7 +3054,7 @@ StdOptionsStatement::writeCOutput(ostream &output, const string &basename) CorrOptionsStatement::CorrOptionsStatement(const string &name_arg1, const string &name_arg2, const string &subsample_name_arg, const OptionsList &options_list_arg, - const SymbolTable &symbol_table_arg ) : + const SymbolTable &symbol_table_arg) : BasicOptionsStatement(name_arg1, subsample_name_arg, options_list_arg), name1(name_arg2), symbol_table(symbol_table_arg) @@ -3141,8 +3139,8 @@ OptionsEqualStatement::OptionsEqualStatement(const string &to_declaration_type_a void OptionsEqualStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) { - if ((to_declaration_type != "par" && to_declaration_type != "std" && to_declaration_type != "corr") || - (from_declaration_type != "par" && from_declaration_type != "std" && from_declaration_type != "corr")) + if ((to_declaration_type != "par" && to_declaration_type != "std" && to_declaration_type != "corr") + || (from_declaration_type != "par" && from_declaration_type != "std" && from_declaration_type != "corr")) { cerr << "Internal Dynare Error" << endl; exit(EXIT_FAILURE); @@ -3173,7 +3171,6 @@ OptionsEqualStatement::writeOutput(ostream &output, const string &basename, bool else get_base_name(symbol_table.getType(from_name1), rhs_field); - if (to_declaration_type == "corr") lhs_field += "_corr"; diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 8319bd89..c36eb155 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -128,7 +128,7 @@ private: const OptionsList options_list; public: RamseyModelStatement(const SymbolList &symbol_list_arg, - const OptionsList &options_list_arg); + const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; @@ -136,11 +136,12 @@ public: class RamseyConstraintsStatement : public Statement { public: - struct Constraint { + struct Constraint + { int endo; BinaryOpcode code; expr_t expression; - }; + }; typedef vector constraints_t; private: const constraints_t constraints; @@ -173,7 +174,7 @@ private: const OptionsList options_list; public: DiscretionaryPolicyStatement(const SymbolList &symbol_list_arg, - const OptionsList &options_list_arg); + const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; @@ -423,7 +424,8 @@ public: /*! \param model_tree_arg the model tree used to store the objective function. It is owned by the PlannerObjectiveStatement, and will be deleted by its destructor */ PlannerObjectiveStatement(StaticModel *model_tree_arg); - virtual ~PlannerObjectiveStatement(); + virtual + ~PlannerObjectiveStatement(); /*! \todo check there are only endogenous variables at the current period in the objective (no exogenous, no lead/lag) */ virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); @@ -513,7 +515,7 @@ private: const OptionsList options_list; public: MSSBVARIrfStatement(const SymbolList &symbol_list_arg, - const OptionsList &options_list_arg); + const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; @@ -673,7 +675,7 @@ public: int lag; int variable; expr_t value; - }; + }; typedef vector< svar_identification_restriction > svar_identification_restrictions_t; private: @@ -687,7 +689,7 @@ public: SvarIdentificationStatement(const svar_identification_restrictions_t &restrictions_arg, const bool &upper_cholesky_present_arg, const bool &lower_cholesky_present_arg, - const bool &constants_exclusion_present_arg, + const bool &constants_exclusion_present_arg, const SymbolTable &symbol_table_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; @@ -792,11 +794,11 @@ public: void writeOutputHelper(ostream &output, const string &field, const string &lhs_field) const; }; - class BasicPriorStatement : public Statement { public: - virtual ~BasicPriorStatement(); + virtual + ~BasicPriorStatement(); protected: const string name; const string subsample_name; @@ -899,7 +901,8 @@ public: class BasicOptionsStatement : public Statement { public: - virtual ~BasicOptionsStatement(); + virtual + ~BasicOptionsStatement(); protected: const string name; const string subsample_name; diff --git a/ConfigFile.cc b/ConfigFile.cc index d1fbd8b7..36a1faa7 100644 --- a/ConfigFile.cc +++ b/ConfigFile.cc @@ -102,7 +102,7 @@ ConfigFile::getConfigFileInfo(const string &config_file) if (config_file.empty()) { - string defaultConfigFile (""); + string defaultConfigFile(""); // Test OS and try to open default file #if defined(_WIN32) || defined(__CYGWIN32__) if (getenv("APPDATA") == NULL) @@ -122,42 +122,41 @@ ConfigFile::getConfigFileInfo(const string &config_file) defaultConfigFile += "\\dynare.ini"; } #else - if (getenv("HOME") == NULL) - { - if (parallel || parallel_test) - cerr << "ERROR: "; - else - cerr << "WARNING: "; - cerr << "HOME environment variable not found." << endl; - if (parallel || parallel_test) - exit(EXIT_FAILURE); - } - else - { - defaultConfigFile += getenv("HOME"); - defaultConfigFile += "/.dynare"; - } -#endif - configFile = new ifstream(defaultConfigFile.c_str(), fstream::in); - if (!configFile->is_open()) + if (getenv("HOME") == NULL) + { if (parallel || parallel_test) - { - cerr << "ERROR: Could not open the default config file (" << defaultConfigFile << ")" << endl; - exit(EXIT_FAILURE); - } + cerr << "ERROR: "; else - return; - } - else - { - configFile = new ifstream(config_file.c_str(), fstream::in); - if (!configFile->is_open()) + cerr << "WARNING: "; + cerr << "HOME environment variable not found." << endl; + if (parallel || parallel_test) + exit(EXIT_FAILURE); + } + else + { + defaultConfigFile += getenv("HOME"); + defaultConfigFile += "/.dynare"; + } +#endif + configFile = new ifstream(defaultConfigFile.c_str(), fstream::in); + if (!configFile->is_open()) + if (parallel || parallel_test) { - cerr << "ERROR: Couldn't open file " << config_file << endl;; + cerr << "ERROR: Could not open the default config file (" << defaultConfigFile << ")" << endl; exit(EXIT_FAILURE); } - } - + else + return; + } + else + { + configFile = new ifstream(config_file.c_str(), fstream::in); + if (!configFile->is_open()) + { + cerr << "ERROR: Couldn't open file " << config_file << endl;; + exit(EXIT_FAILURE); + } + } string name, computerName, port, userName, password, remoteDrive, remoteDirectory, dynarePath, matlabOctavePath, operatingSystem, @@ -271,7 +270,7 @@ ConfigFile::getConfigFileInfo(const string &config_file) vector tokenizedPath; split(tokenizedPath, tokenizedLine.back(), is_any_of(":"), token_compress_on); for (vector::iterator it = tokenizedPath.begin(); - it != tokenizedPath.end(); it++ ) + it != tokenizedPath.end(); it++) if (!it->empty()) { trim(*it); @@ -375,7 +374,7 @@ ConfigFile::getConfigFileInfo(const string &config_file) for (tokenizer >::iterator it = tokens.begin(); it != tokens.end(); it++) { - string token (*it); + string token(*it); if (token.compare("(") == 0) { begin_weight = true; @@ -525,10 +524,10 @@ void ConfigFile::checkPass(WarningConsolidation &warnings) const { bool global_init_file_declared = false; - for (vector::const_iterator it = hooks.begin() ; it != hooks.end(); it++) + for (vector::const_iterator it = hooks.begin(); it != hooks.end(); it++) { const map hookmap = (*it)->get_hooks(); - for (map ::const_iterator mapit = hookmap.begin() ; mapit != hookmap.end(); mapit++) + for (map ::const_iterator mapit = hookmap.begin(); mapit != hookmap.end(); mapit++) if (mapit->first.compare("global_init_file") == 0) if (global_init_file_declared == true) { @@ -686,10 +685,10 @@ vector ConfigFile::getIncludePaths() const { vector include_paths; - for (vector::const_iterator it = paths.begin() ; it != paths.end(); it++) + for (vector::const_iterator it = paths.begin(); it != paths.end(); it++) { map > pathmap = (*it)->get_paths(); - for (map >::const_iterator mapit = pathmap.begin() ; mapit != pathmap.end(); mapit++) + for (map >::const_iterator mapit = pathmap.begin(); mapit != pathmap.end(); mapit++) for (vector::const_iterator vecit = mapit->second.begin(); vecit != mapit->second.end(); vecit++) include_paths.push_back(*vecit); } @@ -699,10 +698,10 @@ ConfigFile::getIncludePaths() const void ConfigFile::writeHooks(ostream &output) const { - for (vector::const_iterator it = hooks.begin() ; it != hooks.end(); it++) + for (vector::const_iterator it = hooks.begin(); it != hooks.end(); it++) { map hookmap = (*it)->get_hooks(); - for (map ::const_iterator mapit = hookmap.begin() ; mapit != hookmap.end(); mapit++) + for (map ::const_iterator mapit = hookmap.begin(); mapit != hookmap.end(); mapit++) output << "options_." << mapit->first << " = '" << mapit->second << "';" << endl; } } diff --git a/ConfigFile.hh b/ConfigFile.hh index 3c761753..e054922f 100644 --- a/ConfigFile.hh +++ b/ConfigFile.hh @@ -37,18 +37,26 @@ public: private: map hooks; public: - inline mapget_hooks() { return hooks; }; + inline map + get_hooks() + { + return hooks; + }; }; class Path { public: - Path(vector &includepath_arg); + Path(vector &includepath_arg); ~Path(); private: map > paths; public: - inline map >get_paths() { return paths; }; + inline map > + get_paths() + { + return paths; + }; }; class SlaveNode diff --git a/DataTree.hh b/DataTree.hh index 83e59471..d7a1de5d 100644 --- a/DataTree.hh +++ b/DataTree.hh @@ -104,7 +104,8 @@ private: public: DataTree(SymbolTable &symbol_table_arg, NumericalConstants &num_constants_arg, ExternalFunctionsTable &external_functions_table_arg); - virtual ~DataTree(); + virtual + ~DataTree(); //! Some predefined constants expr_t Zero, One, Two, MinusOne, NaN, Infinity, MinusInfinity, Pi; diff --git a/DynamicModel.cc b/DynamicModel.cc index 32e3f384..6ade5651 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -881,7 +881,7 @@ DynamicModel::writeModelEquationsCode(string &file_name, const string &bin_basen count_col_det_exo++; } } - + FBEGINBLOCK_ fbeginblock(symbol_table.endo_nbr(), simulation_type, 0, @@ -1140,30 +1140,30 @@ DynamicModel::writeModelEquationsCode_Block(string &file_name, const string &bin for (var_t::const_iterator it1 = it->second.begin(); it1 != it->second.end(); it1++) { count_col_det_exo++; - if (find (exo_det.begin(), exo_det.end(), *it1) == exo_det.end()) + if (find(exo_det.begin(), exo_det.end(), *it1) == exo_det.end()) exo_det.push_back(*it1); } - + unsigned int count_col_exo = 0; vector exo; for (lag_var_t::const_iterator it = exo_block[block].begin(); it != exo_block[block].end(); it++) for (var_t::const_iterator it1 = it->second.begin(); it1 != it->second.end(); it1++) { count_col_exo++; - if (find (exo.begin(), exo.end(), *it1) == exo.end()) + if (find(exo.begin(), exo.end(), *it1) == exo.end()) exo.push_back(*it1); } - + vector other_endo; unsigned int count_col_other_endo = 0; for (lag_var_t::const_iterator it = other_endo_block[block].begin(); it != other_endo_block[block].end(); it++) for (var_t::const_iterator it1 = it->second.begin(); it1 != it->second.end(); it1++) { count_col_other_endo++; - if (find (other_endo.begin(), other_endo.end(), *it1) == other_endo.end()) - other_endo.push_back(*it1); + if (find(other_endo.begin(), other_endo.end(), *it1) == other_endo.end()) + other_endo.push_back(*it1); } - + FBEGINBLOCK_ fbeginblock(block_mfs, simulation_type, getBlockFirstEquation(block), @@ -1187,7 +1187,7 @@ DynamicModel::writeModelEquationsCode_Block(string &file_name, const string &bin other_endo ); fbeginblock.write(code_file, instruction_number); - + // The equations for (i = 0; i < (int) block_size; i++) { @@ -1202,10 +1202,10 @@ DynamicModel::writeModelEquationsCode_Block(string &file_name, const string &bin if (dynamic_cast(*it) != NULL) (*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)); fnumexpr.write(code_file, instruction_number); (*it)->compile(code_file, instruction_number, false, tt2, map_idx, true, false, tef_terms); - FSTPT_ fstpt((int) (map_idx.find((*it)->idx)->second)); + FSTPT_ fstpt((int)(map_idx.find((*it)->idx)->second)); fstpt.write(code_file, instruction_number); // Insert current node into tt2 tt2.insert(*it); @@ -1543,7 +1543,7 @@ DynamicModel::writeDynamicMFile(const string &dynamic_basename) const << "% Outputs:" << 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 - << "% Dynare may prepend auxiliary equations, see M_.aux_vars" << endl + << "% Dynare may prepend auxiliary equations, see M_.aux_vars" << endl << "% g1 [M_.endo_nbr by #dynamic variables] double Jacobian matrix of the dynamic model equations;" << endl << "% rows: equations in order of declaration" << endl << "% columns: variables in order stored in M_.lead_lag_incidence followed by the ones in M_.exo_names" << endl @@ -1554,7 +1554,7 @@ DynamicModel::writeDynamicMFile(const string &dynamic_basename) const << "% rows: equations in order of declaration" << endl << "% columns: variables in order stored in M_.lead_lag_incidence followed by the ones in M_.exo_names" << endl << "%" << endl - << "%" << endl + << "%" << endl << "% Warning : this file is generated automatically by Dynare" << endl << "% from model file (.mod)" << endl << endl; @@ -1959,11 +1959,11 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri << " else" << endl << " mthd='UNKNOWN';" << endl << " end;" << endl - << " if options_.verbosity" << endl + << " if options_.verbosity" << endl << " printline(41)" << endl << " disp(sprintf('MODEL SIMULATION (method=%s):',mthd))" << endl - << " skipline()" << endl - << " end" << endl + << " skipline()" << endl + << " end" << endl << " periods=options_.periods;" << endl << " maxit_=options_.simul.maxit;" << endl << " solve_tolf=options_.solve_tolf;" << endl @@ -2000,7 +2000,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri mDynamicModelFile << " g1=[];g2=[];g3=[];\n"; mDynamicModelFile << " y=" << dynamic_basename << "_" << block + 1 << "(y, x, params, steady_state, 0, y_kmin, periods);\n"; mDynamicModelFile << " tmp = y(:,M_.block_structure.block(" << block + 1 << ").variable);\n"; - mDynamicModelFile << " if any(isnan(tmp) | isinf(tmp))\n"; + mDynamicModelFile << " if any(isnan(tmp) | isinf(tmp))\n"; mDynamicModelFile << " disp(['Inf or Nan value during the evaluation of block " << block <<"']);\n"; mDynamicModelFile << " oo_.deterministic_simulation.status = 0;\n"; mDynamicModelFile << " oo_.deterministic_simulation.error = 100;\n"; @@ -2375,7 +2375,7 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia << jacobian_output.str() << endl - // Initialize g2 matrix + // Initialize g2 matrix << "if nargout >= 3," << endl << " %" << endl << " % Hessian matrix" << endl @@ -2565,17 +2565,17 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de output << modstruct << "lead_lag_incidence = ["; // Loop on endogenous variables - int nstatic = 0, - nfwrd = 0, - npred = 0, - nboth = 0; + int nstatic = 0, + nfwrd = 0, + npred = 0, + nboth = 0; for (int endoID = 0; endoID < symbol_table.endo_nbr(); endoID++) { output << endl; - int sstatic = 1, - sfwrd = 0, - spred = 0, - sboth = 0; + int sstatic = 1, + sfwrd = 0, + spred = 0, + sboth = 0; // Loop on periods for (int lag = -max_endo_lag; lag <= max_endo_lead; lag++) { @@ -2771,29 +2771,29 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de i++; } output << "];\n"; - + //vector inter_state_var; output << "block_structure.block(" << block+1 << ").tm1 = zeros(" << i << ", " << state_var.size() << ");\n"; int count_other_endogenous = 1; for (set::const_iterator it_other_endogenous = other_endogenous.begin(); it_other_endogenous != other_endogenous.end(); it_other_endogenous++) { - for (vector::const_iterator it=state_var.begin(); it != state_var.end(); it++) + for (vector::const_iterator it = state_var.begin(); it != state_var.end(); it++) { //cout << "block = " << block+1 << " state_var = " << *it << " it_other_endogenous=" << *it_other_endogenous + 1 << "\n"; if (*it == *it_other_endogenous + 1) { - output << "block_structure.block(" << block+1 << ").tm1(" - << count_other_endogenous << ", " + output << "block_structure.block(" << block+1 << ").tm1(" + << count_other_endogenous << ", " << it - state_var.begin()+1 << ") = 1;\n"; - /*output << "block_structure.block(" << block+1 << ").tm1(" - << it - state_var.begin()+1 << ", " - << count_other_endogenous << ") = 1;\n";*/ + /*output << "block_structure.block(" << block+1 << ").tm1(" + << it - state_var.begin()+1 << ", " + << count_other_endogenous << ") = 1;\n";*/ //cout << "=>\n"; } } count_other_endogenous++; } - + output << "block_structure.block(" << block+1 << ").other_endo_nbr = " << i << ";\n"; tmp_s.str(""); @@ -2820,10 +2820,10 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de } else if (lag == 0) { - if (find( local_state_var.begin(), local_state_var.end(), getBlockVariableID(block, it->first.second.first)+1) == local_state_var.end()) + if (find(local_state_var.begin(), local_state_var.end(), getBlockVariableID(block, it->first.second.first)+1) == local_state_var.end()) { - local_stat_var.push_back(getBlockVariableID(block, it->first.second.first)+1); - n_static++; + local_stat_var.push_back(getBlockVariableID(block, it->first.second.first)+1); + n_static++; } } else @@ -2835,7 +2835,7 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de } else { - if (find(local_stat_var.begin(), local_stat_var.end(),getBlockVariableID(block, it->first.second.first)+1) != local_stat_var.end()) + if (find(local_stat_var.begin(), local_stat_var.end(), getBlockVariableID(block, it->first.second.first)+1) != local_stat_var.end()) n_static--; n_forward++; } @@ -2855,13 +2855,13 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de tmp_s.str(""); } vector inter_state_var; - for (vector::const_iterator it_l=local_state_var.begin(); it_l != local_state_var.end(); it_l++) - for (vector::const_iterator it=state_var.begin(); it != state_var.end(); it++) + for (vector::const_iterator it_l = local_state_var.begin(); it_l != local_state_var.end(); it_l++) + for (vector::const_iterator it = state_var.begin(); it != state_var.end(); it++) if (*it == *it_l) inter_state_var.push_back(it - state_var.begin()+1); output << "block_structure.block(" << block+1 << ").sorted_col_dr_ghx = ["; - for (vector::const_iterator it=inter_state_var.begin(); it != inter_state_var.end(); it++) - output << *it << " "; + for (vector::const_iterator it = inter_state_var.begin(); it != inter_state_var.end(); it++) + output << *it << " "; output << "];\n"; count_lead_lag_incidence = 0; output << "block_structure.block(" << block+1 << ").lead_lag_incidence_other = [];\n"; @@ -2906,10 +2906,10 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de output << "];\n"; vector variable_inv_reordered(nb_endo); - for (int i = 0; i< nb_endo; i++) + for (int i = 0; i < nb_endo; i++) variable_inv_reordered[variable_reordered[i]] = i; - - for (vector::const_iterator it=state_var.begin(); it != state_var.end(); it++) + + for (vector::const_iterator it = state_var.begin(); it != state_var.end(); it++) state_equ.push_back(equation_reordered[variable_inv_reordered[*it - 1]]+1); map >, int> lag_row_incidence; @@ -2962,11 +2962,11 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de i_nz_state_var[i] = n; unsigned int lp = n_obs; - for (unsigned int block = 0; block < nb_blocks; block++) + for (unsigned int block = 0; block < nb_blocks; block++) { int block_size = getBlockSize(block); int nze = 0; - + for (int i = 0; i < block_size; i++) { int var = getBlockVariableID(block, i); @@ -2985,22 +2985,21 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de vector::const_iterator it_state_equ = find(state_equ.begin(), state_equ.end(), getBlockEquationID(block, it->first.first)+1); if (it_state_equ != state_equ.end()) row_state_var_incidence.insert(make_pair(it_state_equ - state_equ.begin(), it_state_var - state_var.begin())); - } - - + } + } /*tmp_block_endo_derivative[make_pair(it->second.first, make_pair(it->first.second, it->first.first))] = it->second.second; - if (block == 0) - { - - vector::const_iterator it_state_equ = find(state_equ.begin(), state_equ.end(), getBlockEquationID(block, i)+1); - if (it_state_equ != state_equ.end()) - { - cout << "row_state_var_incidence[make_pair([" << *it_state_equ << "] " << it_state_equ - state_equ.begin() << ", [" << *it_state_var << "] " << it_state_var - state_var.begin() << ")] = 1;\n"; - row_state_var_incidence.insert(make_pair(it_state_equ - state_equ.begin(), it_state_var - state_var.begin())); - } - }*/ - set >::const_iterator row_state_var_incidence_it = row_state_var_incidence.begin(); + if (block == 0) + { + + vector::const_iterator it_state_equ = find(state_equ.begin(), state_equ.end(), getBlockEquationID(block, i)+1); + if (it_state_equ != state_equ.end()) + { + cout << "row_state_var_incidence[make_pair([" << *it_state_equ << "] " << it_state_equ - state_equ.begin() << ", [" << *it_state_var << "] " << it_state_var - state_var.begin() << ")] = 1;\n"; + row_state_var_incidence.insert(make_pair(it_state_equ - state_equ.begin(), it_state_var - state_var.begin())); + } + }*/ + set >::const_iterator row_state_var_incidence_it = row_state_var_incidence.begin(); bool diag = true; int nb_diag_r = 0; while (row_state_var_incidence_it != row_state_var_incidence.end() && diag) @@ -3013,12 +3012,12 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de if (equ != row_state_var_incidence_it->first) nb_diag_r++; } - + } - set > col_state_var_incidence; - for(set >::const_iterator row_state_var_incidence_it = row_state_var_incidence.begin();row_state_var_incidence_it != row_state_var_incidence.end(); row_state_var_incidence_it++) + set > col_state_var_incidence; + for (set >::const_iterator row_state_var_incidence_it = row_state_var_incidence.begin(); row_state_var_incidence_it != row_state_var_incidence.end(); row_state_var_incidence_it++) col_state_var_incidence.insert(make_pair(row_state_var_incidence_it->second, row_state_var_incidence_it->first)); - set >::const_iterator col_state_var_incidence_it = col_state_var_incidence.begin(); + set >::const_iterator col_state_var_incidence_it = col_state_var_incidence.begin(); diag = true; int nb_diag_c = 0; while (col_state_var_incidence_it != col_state_var_incidence.end() && diag) @@ -3032,13 +3031,13 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de nb_diag_c++; } } - nb_diag = min( nb_diag_r, nb_diag_c); + nb_diag = min(nb_diag_r, nb_diag_c); row_state_var_incidence.clear(); col_state_var_incidence.clear(); } for (int i = 0; i < nze; i++) - i_nz_state_var[lp + i] = lp + nze; - lp += nze; + i_nz_state_var[lp + i] = lp + nze; + lp += nze; } output << modstruct << "nz_state_var = ["; for (unsigned int i = 0; i < lp; i++) @@ -3046,8 +3045,7 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de output << "];" << endl; output << modstruct << "n_diag = " << nb_diag << ";" << endl; KF_index_file.write(reinterpret_cast(&nb_diag), sizeof(nb_diag)); - - + typedef pair > index_KF; vector v_index_KF; for (int i = 0; i < n; i++) @@ -3055,7 +3053,7 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de for (int j = n_obs; j < n; j++) { int j1 = j - n_obs; - int j1_n_state = j1 * n_state - n_obs ; + int j1_n_state = j1 * n_state - n_obs; if ((i < n_obs) || (i >= nb_diag + n_obs) || (j1 >= nb_diag)) for (int k = n_obs; k < i_nz_state_var[i]; k++) { @@ -3064,14 +3062,14 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de } int size_v_index_KF = v_index_KF.size(); - KF_index_file.write(reinterpret_cast(&size_v_index_KF), sizeof(size_v_index_KF)); + KF_index_file.write(reinterpret_cast(&size_v_index_KF), sizeof(size_v_index_KF)); for (vector::iterator it = v_index_KF.begin(); it != v_index_KF.end(); it++) KF_index_file.write(reinterpret_cast(&(*it)), sizeof(index_KF)); vector v_index_KF_2; int n_n_obs = n * n_obs; for (int i = 0; i < n; i++) - //i = 0; + //i = 0; for (int j = i; j < n; j++) { if ((i < n_obs) || (i >= nb_diag + n_obs) || (j < n_obs) || (j >= nb_diag + n_obs)) @@ -3083,16 +3081,16 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de } int size_v_index_KF_2 = v_index_KF_2.size(); - KF_index_file.write(reinterpret_cast(&size_v_index_KF_2), sizeof(size_v_index_KF_2)); + KF_index_file.write(reinterpret_cast(&size_v_index_KF_2), sizeof(size_v_index_KF_2)); for (vector::iterator it = v_index_KF_2.begin(); it != v_index_KF_2.end(); it++) - KF_index_file.write(reinterpret_cast(&(*it)), sizeof(index_KF)); + KF_index_file.write(reinterpret_cast(&(*it)), sizeof(index_KF)); KF_index_file.close(); } - output << modstruct << "state_var = ["; + output << modstruct << "state_var = ["; - for (vector::const_iterator it=state_var.begin(); it != state_var.end(); it++) - output << *it << " "; - output << "];" << endl; + for (vector::const_iterator it = state_var.begin(); it != state_var.end(); it++) + output << *it << " "; + output << "];" << endl; } // Writing initialization for some other variables @@ -3106,21 +3104,21 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de output << modstruct << "maximum_endo_lag = " << max_endo_lag << ";" << endl << modstruct << "maximum_endo_lead = " << max_endo_lead << ";" << endl - << outstruct << "steady_state = zeros(" << symbol_table.endo_nbr() << (julia ? ")" : ", 1);" ) << endl; + << outstruct << "steady_state = zeros(" << symbol_table.endo_nbr() << (julia ? ")" : ", 1);") << endl; output << modstruct << "maximum_exo_lag = " << max_exo_lag << ";" << endl << modstruct << "maximum_exo_lead = " << max_exo_lead << ";" << endl - << outstruct << "exo_steady_state = zeros(" << symbol_table.exo_nbr() << (julia ? ")" : ", 1);" ) << endl; + << outstruct << "exo_steady_state = zeros(" << symbol_table.exo_nbr() << (julia ? ")" : ", 1);") << endl; if (symbol_table.exo_det_nbr()) { output << modstruct << "maximum_exo_det_lag = " << max_exo_det_lag << ";" << endl << modstruct << "maximum_exo_det_lead = " << max_exo_det_lead << ";" << endl - << outstruct << "exo_det_steady_state = zeros(" << symbol_table.exo_det_nbr() << (julia ? ")" : ", 1);" ) << endl; + << outstruct << "exo_det_steady_state = zeros(" << symbol_table.exo_det_nbr() << (julia ? ")" : ", 1);") << endl; } output << modstruct << "params = " << (julia ? "fill(NaN, " : "NaN(") - << symbol_table.param_nbr() << (julia ? ")" : ", 1);" ) << endl; + << symbol_table.param_nbr() << (julia ? ")" : ", 1);") << endl; if (compute_xrefs) writeXrefs(output); @@ -3128,7 +3126,7 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de // Write number of non-zero derivatives // Use -1 if the derivatives have not been computed output << modstruct << (julia ? "nnzderivatives" : "NNZDerivatives") - << " = [" << NNZDerivatives[0] << "; "; + << " = [" << NNZDerivatives[0] << "; "; if (order > 1) output << NNZDerivatives[1] << "; "; else @@ -3174,7 +3172,7 @@ DynamicModel::computingPass(bool jacobianExo, bool hessian, bool thirdDerivative assert(jacobianExo || !(hessian || thirdDerivatives || paramsDerivsOrder)); initializeVariablesAndEquations(); - + // Prepare for derivation computeDerivIDs(); @@ -3537,7 +3535,7 @@ DynamicModel::collect_block_first_order_derivatives() int var = symbol_table.getTypeSpecificID(getSymbIDByDerivID(it2->first.second)); int lag = getLagByDerivID(it2->first.second); int block_eq = equation_2_block[eq]; - int block_var=0; + int block_var = 0; derivative_t tmp_derivative; lag_var_t lag_var; switch (getTypeByDerivID(it2->first.second)) @@ -4483,7 +4481,6 @@ DynamicModel::substituteLeadLagInternal(aux_var_t type, bool deterministic_model equations[i] = substeq; } - // Substitute in aux_equations // Without this loop, the auxiliary equations in equations // will diverge from those in aux_equations @@ -4683,7 +4680,7 @@ DynamicModel::fillEvalContext(eval_context_t &eval_context) const vector trendVars = symbol_table.getTrendVarIds(); for (vector ::const_iterator it = trendVars.begin(); it != trendVars.end(); it++) - eval_context[*it] = 2; //not <= 0 bc of log, not 1 bc of powers + eval_context[*it] = 2; //not <= 0 bc of log, not 1 bc of powers } bool @@ -4729,7 +4726,7 @@ DynamicModel::dynamicOnlyEquationsNbr() const } #ifndef PRIVATE_BUFFER_SIZE -#define PRIVATE_BUFFER_SIZE 1024 +# define PRIVATE_BUFFER_SIZE 1024 #endif bool @@ -4790,10 +4787,10 @@ DynamicModel::isChecksumMatching(const string &basename) const } char private_buffer[PRIVATE_BUFFER_SIZE]; - while(buffer) + while (buffer) { - buffer.get(private_buffer,PRIVATE_BUFFER_SIZE); - result.process_bytes(private_buffer,strlen(private_buffer)); + buffer.get(private_buffer, PRIVATE_BUFFER_SIZE); + result.process_bytes(private_buffer, strlen(private_buffer)); } bool basename_dir_exists = false; @@ -4805,8 +4802,8 @@ DynamicModel::isChecksumMatching(const string &basename) const if (r < 0) if (errno != EEXIST) { - perror("ERROR"); - exit(EXIT_FAILURE); + perror("ERROR"); + exit(EXIT_FAILURE); } else basename_dir_exists = true; @@ -4821,25 +4818,25 @@ DynamicModel::isChecksumMatching(const string &basename) const { checksum_file.open(filename.c_str(), ios::in | ios::binary); if (checksum_file.is_open()) - { - checksum_file >> old_checksum; - checksum_file.close(); - } + { + checksum_file >> old_checksum; + checksum_file.close(); + } } // write new checksum file if none or different from old checksum if (old_checksum != result.checksum()) - { - checksum_file.open(filename.c_str(), ios::out | ios::binary); - if (!checksum_file.is_open()) - { - cerr << "ERROR: Can't open file " << filename << endl; - exit(EXIT_FAILURE); - } - checksum_file << result.checksum(); - checksum_file.close(); - return false; - } - + { + checksum_file.open(filename.c_str(), ios::out | ios::binary); + if (!checksum_file.is_open()) + { + cerr << "ERROR: Can't open file " << filename << endl; + exit(EXIT_FAILURE); + } + checksum_file << result.checksum(); + checksum_file.close(); + return false; + } + return true; } @@ -4853,26 +4850,26 @@ DynamicModel::writeCOutput(ostream &output, const string &basename, bool block_d { // Loop on periods for (int lag = 0; lag <= 2; lag++) - { - lag_presence[lag] = 1; + { + lag_presence[lag] = 1; try { getDerivID(symbol_table.getID(eEndogenous, endoID), lag-1); } catch (UnknownDerivIDException &e) { - lag_presence[lag] = 0; + lag_presence[lag] = 0; } } if (lag_presence[0] == 1) - if (lag_presence[2] == 1) - zeta_mixed.push_back(endoID); - else - zeta_back.push_back(endoID); + if (lag_presence[2] == 1) + zeta_mixed.push_back(endoID); + else + zeta_back.push_back(endoID); else if (lag_presence[2] == 1) - zeta_fwrd.push_back(endoID); + zeta_fwrd.push_back(endoID); else - zeta_static.push_back(endoID); + zeta_static.push_back(endoID); } output << "size_t nstatic = " << zeta_static.size() << ";" << endl @@ -4882,8 +4879,8 @@ DynamicModel::writeCOutput(ostream &output, const string &basename, bool block_d output << "size_t zeta_static[" << zeta_static.size() << "] = {"; for (vector::iterator i = zeta_static.begin(); i != zeta_static.end(); ++i) { - if ( i != zeta_static.begin() ) - output << ","; + if (i != zeta_static.begin()) + output << ","; output << *i; } output << "};" << endl; @@ -4891,8 +4888,8 @@ DynamicModel::writeCOutput(ostream &output, const string &basename, bool block_d output << "size_t zeta_back[" << zeta_back.size() << "] = {"; for (vector::iterator i = zeta_back.begin(); i != zeta_back.end(); ++i) { - if ( i != zeta_back.begin() ) - output << ","; + if (i != zeta_back.begin()) + output << ","; output << *i; } output << "};" << endl; @@ -4900,8 +4897,8 @@ DynamicModel::writeCOutput(ostream &output, const string &basename, bool block_d output << "size_t zeta_fwrd[" << zeta_fwrd.size() << "] = {"; for (vector::iterator i = zeta_fwrd.begin(); i != zeta_fwrd.end(); ++i) { - if ( i != zeta_fwrd.begin() ) - output << ","; + if (i != zeta_fwrd.begin()) + output << ","; output << *i; } output << "};" << endl; @@ -4909,8 +4906,8 @@ DynamicModel::writeCOutput(ostream &output, const string &basename, bool block_d output << "size_t zeta_mixed[" << zeta_mixed.size() << "] = {"; for (vector::iterator i = zeta_mixed.begin(); i != zeta_mixed.end(); ++i) { - if ( i != zeta_mixed.begin() ) - output << ","; + if (i != zeta_mixed.begin()) + output << ","; output << *i; } output << "};" << endl; @@ -4930,8 +4927,8 @@ DynamicModel::writeCOutput(ostream &output, const string &basename, bool block_d output << NNZDerivatives[0] << "," << NNZDerivatives[1] << "," << NNZDerivatives[2] << "};" << endl; break; default: - cerr << "Order larger than 3 not implemented" << endl; - exit(EXIT_FAILURE); + cerr << "Order larger than 3 not implemented" << endl; + exit(EXIT_FAILURE); } } @@ -4983,7 +4980,7 @@ DynamicModel::writeResidualsC(const string &basename, bool cuda) const << endl << " /* Residual equations */" << endl << model_output.str() - << "}" << endl; + << "}" << endl; writePowerDeriv(mDynamicModelFile); writeNormcdf(mDynamicModelFile); @@ -5095,7 +5092,6 @@ DynamicModel::writeFirstDerivativesC_csr(const string &basename, bool cuda) cons // this is always empty here, but needed by d1->writeOutput deriv_node_temp_terms_t tef_terms; - // Indexing derivatives in column order vector D; for (first_derivatives_t::const_iterator it = first_derivatives.begin(); @@ -5108,35 +5104,35 @@ DynamicModel::writeFirstDerivativesC_csr(const string &basename, bool cuda) cons SymbolType type = getTypeByDerivID(dynvar); int tsid = symbol_table.getTypeSpecificID(symb_id); int col_id; - switch(type) - { - case eEndogenous: - col_id = tsid+(lag+1)*symbol_table.endo_nbr(); - break; - case eExogenous: - col_id = tsid+3*symbol_table.endo_nbr(); - break; - case eExogenousDet: - col_id = tsid+3*symbol_table.endo_nbr()+symbol_table.exo_nbr(); - break; - default: - std::cerr << "This case shouldn't happen" << std::endl; - exit(EXIT_FAILURE); - } - derivative deriv(col_id + eq*cols_nbr,col_id,eq,it->second); + switch (type) + { + case eEndogenous: + col_id = tsid+(lag+1)*symbol_table.endo_nbr(); + break; + case eExogenous: + col_id = tsid+3*symbol_table.endo_nbr(); + break; + case eExogenousDet: + col_id = tsid+3*symbol_table.endo_nbr()+symbol_table.exo_nbr(); + break; + default: + std::cerr << "This case shouldn't happen" << std::endl; + exit(EXIT_FAILURE); + } + derivative deriv(col_id + eq *cols_nbr, col_id, eq, it->second); D.push_back(deriv); } - sort(D.begin(), D.end(), derivative_less_than() ); + sort(D.begin(), D.end(), derivative_less_than()); // writing sparse Jacobian vector row_ptr(equations.size()); - fill(row_ptr.begin(),row_ptr.end(),0.0); + fill(row_ptr.begin(), row_ptr.end(), 0.0); int k = 0; - for(vector::const_iterator it = D.begin(); it != D.end(); ++it) + for (vector::const_iterator it = D.begin(); it != D.end(); ++it) { row_ptr[it->row_nbr]++; mDynamicModelFile << "col_ptr[" << k << "] " - << "=" << it->col_nbr << ";" << endl; + << "=" << it->col_nbr << ";" << endl; mDynamicModelFile << "value[" << k << "] = "; // oCstaticModel makes reference to the static variables it->value->writeOutput(mDynamicModelFile, oCDynamic2Model, temporary_terms, tef_terms); @@ -5147,20 +5143,20 @@ DynamicModel::writeFirstDerivativesC_csr(const string &basename, bool cuda) cons // row_ptr must point to the relative address of the first element of the row int cumsum = 0; mDynamicModelFile << "int row_ptr_data[" << row_ptr.size() + 1 << "] = { 0"; - for (vector::iterator it=row_ptr.begin(); it != row_ptr.end(); ++it) + for (vector::iterator it = row_ptr.begin(); it != row_ptr.end(); ++it) { cumsum += *it; mDynamicModelFile << ", " << cumsum; } mDynamicModelFile << "};" << endl - << "int i;" << endl - << "for (i=0; i < " << row_ptr.size() + 1 << "; i++) row_ptr[i] = row_ptr_data[i];" << endl; + << "int i;" << endl + << "for (i=0; i < " << row_ptr.size() + 1 << "; i++) row_ptr[i] = row_ptr_data[i];" << endl; mDynamicModelFile << "}" << endl; mDynamicModelFile.close(); } - void +void DynamicModel::writeSecondDerivativesC_csr(const string &basename, bool cuda) const { @@ -5216,26 +5212,26 @@ DynamicModel::writeSecondDerivativesC_csr(const string &basename, bool cuda) con int col_nb = id1 * dynJacobianColsNbr + id2; - derivative deriv(col_nb + eq*hessianColsNbr,col_nb,eq,it->second); + derivative deriv(col_nb + eq *hessianColsNbr, col_nb, eq, it->second); D.push_back(deriv); if (id1 != id2) - { - col_nb = id2 * dynJacobianColsNbr + id1; - derivative deriv(col_nb + eq*hessianColsNbr,col_nb,eq,it->second); - D.push_back(deriv); - } + { + col_nb = id2 * dynJacobianColsNbr + id1; + derivative deriv(col_nb + eq *hessianColsNbr, col_nb, eq, it->second); + D.push_back(deriv); + } } - sort(D.begin(), D.end(), derivative_less_than() ); + sort(D.begin(), D.end(), derivative_less_than()); // Writing Hessian vector row_ptr(equations.size()); - fill(row_ptr.begin(),row_ptr.end(),0.0); + fill(row_ptr.begin(), row_ptr.end(), 0.0); int k = 0; - for(vector::const_iterator it = D.begin(); it != D.end(); ++it) + for (vector::const_iterator it = D.begin(); it != D.end(); ++it) { row_ptr[it->row_nbr]++; mDynamicModelFile << "col_ptr[" << k << "] " - << "=" << it->col_nbr << ";" << endl; + << "=" << it->col_nbr << ";" << endl; mDynamicModelFile << "value[" << k << "] = "; // oCstaticModel makes reference to the static variables it->value->writeOutput(mDynamicModelFile, oCStaticModel, temporary_terms, tef_terms); @@ -5246,7 +5242,7 @@ DynamicModel::writeSecondDerivativesC_csr(const string &basename, bool cuda) con // row_ptr must point to the relative address of the first element of the row int cumsum = 0; mDynamicModelFile << "row_ptr = [ 0"; - for (vector::iterator it=row_ptr.begin(); it != row_ptr.end(); ++it) + for (vector::iterator it = row_ptr.begin(); it != row_ptr.end(); ++it) { cumsum += *it; mDynamicModelFile << ", " << cumsum; @@ -5319,55 +5315,55 @@ DynamicModel::writeThirdDerivativesC_csr(const string &basename, bool cuda) cons vector cols; long unsigned int col_nb = id1 * hessianColsNbr + id2 * dynJacobianColsNbr + id3; int thirdDColsNbr = hessianColsNbr*dynJacobianColsNbr; - derivative deriv(col_nb + eq*thirdDColsNbr,col_nb,eq,it->second); + derivative deriv(col_nb + eq *thirdDColsNbr, col_nb, eq, it->second); D.push_back(deriv); cols.push_back(col_nb); col_nb = id1 * hessianColsNbr + id3 * dynJacobianColsNbr + id2; - if (find(cols.begin(),cols.end(),col_nb) == cols.end()) - { - derivative deriv(col_nb + eq*thirdDerivativesColsNbr,col_nb,eq,it->second); - D.push_back(deriv); - cols.push_back(col_nb); - } + if (find(cols.begin(), cols.end(), col_nb) == cols.end()) + { + derivative deriv(col_nb + eq *thirdDerivativesColsNbr, col_nb, eq, it->second); + D.push_back(deriv); + cols.push_back(col_nb); + } col_nb = id2 * hessianColsNbr + id1 * dynJacobianColsNbr + id3; - if (find(cols.begin(),cols.end(),col_nb) == cols.end()) - { - derivative deriv(col_nb + eq*thirdDerivativesColsNbr,col_nb,eq,it->second); - D.push_back(deriv); - cols.push_back(col_nb); - } + if (find(cols.begin(), cols.end(), col_nb) == cols.end()) + { + derivative deriv(col_nb + eq *thirdDerivativesColsNbr, col_nb, eq, it->second); + D.push_back(deriv); + cols.push_back(col_nb); + } col_nb = id2 * hessianColsNbr + id3 * dynJacobianColsNbr + id1; - if (find(cols.begin(),cols.end(),col_nb) == cols.end()) - { - derivative deriv(col_nb + eq*thirdDerivativesColsNbr,col_nb,eq,it->second); - D.push_back(deriv); - cols.push_back(col_nb); - } + if (find(cols.begin(), cols.end(), col_nb) == cols.end()) + { + derivative deriv(col_nb + eq *thirdDerivativesColsNbr, col_nb, eq, it->second); + D.push_back(deriv); + cols.push_back(col_nb); + } col_nb = id3 * hessianColsNbr + id1 * dynJacobianColsNbr + id2; - if (find(cols.begin(),cols.end(),col_nb) == cols.end()) - { - derivative deriv(col_nb + eq*thirdDerivativesColsNbr,col_nb,eq,it->second); - D.push_back(deriv); - cols.push_back(col_nb); - } + if (find(cols.begin(), cols.end(), col_nb) == cols.end()) + { + derivative deriv(col_nb + eq *thirdDerivativesColsNbr, col_nb, eq, it->second); + D.push_back(deriv); + cols.push_back(col_nb); + } col_nb = id3 * hessianColsNbr + id2 * dynJacobianColsNbr + id1; - if (find(cols.begin(),cols.end(),col_nb) == cols.end()) - { - derivative deriv(col_nb + eq*thirdDerivativesColsNbr,col_nb,eq,it->second); - D.push_back(deriv); - } + if (find(cols.begin(), cols.end(), col_nb) == cols.end()) + { + derivative deriv(col_nb + eq *thirdDerivativesColsNbr, col_nb, eq, it->second); + D.push_back(deriv); + } } - sort(D.begin(), D.end(), derivative_less_than() ); + sort(D.begin(), D.end(), derivative_less_than()); vector row_ptr(equations.size()); - fill(row_ptr.begin(),row_ptr.end(),0.0); + fill(row_ptr.begin(), row_ptr.end(), 0.0); int k = 0; - for(vector::const_iterator it = D.begin(); it != D.end(); ++it) + for (vector::const_iterator it = D.begin(); it != D.end(); ++it) { row_ptr[it->row_nbr]++; mDynamicModelFile << "col_ptr[" << k << "] " - << "=" << it->col_nbr << ";" << endl; + << "=" << it->col_nbr << ";" << endl; mDynamicModelFile << "value[" << k << "] = "; // oCstaticModel makes reference to the static variables it->value->writeOutput(mDynamicModelFile, oCStaticModel, temporary_terms, tef_terms); @@ -5378,7 +5374,7 @@ DynamicModel::writeThirdDerivativesC_csr(const string &basename, bool cuda) cons // row_ptr must point to the relative address of the first element of the row int cumsum = 0; mDynamicModelFile << "row_ptr = [ 0"; - for (vector::iterator it=row_ptr.begin(); it != row_ptr.end(); ++it) + for (vector::iterator it = row_ptr.begin(); it != row_ptr.end(); ++it) { cumsum += *it; mDynamicModelFile << ", " << cumsum; @@ -5402,26 +5398,26 @@ DynamicModel::writeCCOutput(ostream &output, const string &basename, bool block_ { // Loop on periods for (int lag = 0; lag <= 2; lag++) - { - lag_presence[lag] = 1; + { + lag_presence[lag] = 1; try { getDerivID(symbol_table.getID(eEndogenous, endoID), lag-1); } catch (UnknownDerivIDException &e) { - lag_presence[lag] = 0; + lag_presence[lag] = 0; } } if (lag_presence[0] == 1) - if (lag_presence[2] == 1) - output << "zeta_mixed.push_back(" << endoID << ");" << endl; - else - output << "zeta_back.push_back(" << endoID << ");" << endl; + if (lag_presence[2] == 1) + output << "zeta_mixed.push_back(" << endoID << ");" << endl; + else + output << "zeta_back.push_back(" << endoID << ");" << endl; else if (lag_presence[2] == 1) - output << "zeta_fwrd.push_back(" << endoID << ");" << endl; + output << "zeta_fwrd.push_back(" << endoID << ");" << endl; else - output << "zeta_static.push_back(" << endoID << ");" << endl; + output << "zeta_static.push_back(" << endoID << ");" << endl; } output << "nstatic = zeta_static.size();" << endl diff --git a/DynamicModel.hh b/DynamicModel.hh index 7988a365..c66cbdd5 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -273,7 +273,7 @@ public: //! Returns number of static only equations size_t staticOnlyEquationsNbr() const; - + //! Returns number of dynamic only equations size_t dynamicOnlyEquationsNbr() const; @@ -325,7 +325,7 @@ public: //! Transforms the model by creating aux vars for the diff of forward vars /*! If subset is empty, does the transformation for all fwrd vars; otherwise - restrict it to the vars in subset */ + restrict it to the vars in subset */ void differentiateForwardVars(const vector &subset); //! Fills eval context with values of model local variables and auxiliary variables @@ -523,7 +523,7 @@ DynamicModel::checkHessianZero() const return second_derivatives.empty(); } -//! Classes to re-order derivatives for various sparse storage formats +//! Classes to re-order derivatives for various sparse storage formats class derivative { public: @@ -531,14 +531,17 @@ public: long unsigned int col_nbr; unsigned int row_nbr; expr_t value; - derivative(long unsigned int arg1, long unsigned int arg2, int arg3, expr_t arg4): - linear_address(arg1), col_nbr(arg2), row_nbr(arg3), value(arg4) {}; + derivative(long unsigned int arg1, long unsigned int arg2, int arg3, expr_t arg4) : + linear_address(arg1), col_nbr(arg2), row_nbr(arg3), value(arg4) + { + }; }; class derivative_less_than { public: - bool operator()(const derivative & d1, const derivative & d2) const + bool + operator()(const derivative &d1, const derivative &d2) const { return d1.linear_address < d2.linear_address; } diff --git a/DynareMain.cc b/DynareMain.cc index adbb1b68..51fa7767 100644 --- a/DynareMain.cc +++ b/DynareMain.cc @@ -124,8 +124,8 @@ main(int argc, char **argv) clear_all = false; else if (strlen(argv[arg]) >= 19 && !strncmp(argv[arg], "params_derivs_order", 19)) { - if (strlen(argv[arg]) >= 22 || argv[arg][19] != '=' || - !(argv[arg][20] == '0' || argv[arg][20] == '1' || argv[arg][20] == '2')) + if (strlen(argv[arg]) >= 22 || argv[arg][19] != '=' + || !(argv[arg][20] == '0' || argv[arg][20] == '1' || argv[arg][20] == '2')) { cerr << "Incorrect syntax for params_derivs_order option" << endl; usage(); @@ -222,12 +222,12 @@ main(int argc, char **argv) size_t equal_index = string(argv[arg]).find('='); if (equal_index != string::npos) { - string key = string(argv[arg]).erase(equal_index).erase(0,2); + string key = string(argv[arg]).erase(equal_index).erase(0, 2); defines[key] = string(argv[arg]).erase(0, equal_index+1); } else { - string key = string(argv[arg]).erase(0,2); + string key = string(argv[arg]).erase(0, 2); defines[key] = "1"; } } @@ -239,36 +239,36 @@ main(int argc, char **argv) << "must not be separated from -I by whitespace." << endl; usage(); } - path.push_back(string(argv[arg]).erase(0,2)); + path.push_back(string(argv[arg]).erase(0, 2)); } else if (strlen(argv[arg]) >= 6 && !strncmp(argv[arg], "output", 6)) { - if (strlen(argv[arg]) <= 7 || argv[arg][6] != '=') - { - cerr << "Incorrect syntax for ouput option" << endl; - usage(); - } - if (strlen(argv[arg]) == 14 && !strncmp(argv[arg] + 7, "dynamic", 7)) - output_mode = dynamic; - else if (strlen(argv[arg]) == 12 && !strncmp(argv[arg] + 7, "first", 5)) - output_mode = first; - else if (strlen(argv[arg]) == 13 && !strncmp(argv[arg] + 7, "second", 6)) - output_mode = second; - else if (strlen(argv[arg]) == 12 && !strncmp(argv[arg] + 7, "third", 5)) - output_mode = third; - else - { - cerr << "Incorrect syntax for ouput option" << endl; - usage(); + if (strlen(argv[arg]) <= 7 || argv[arg][6] != '=') + { + cerr << "Incorrect syntax for ouput option" << endl; + usage(); + } + if (strlen(argv[arg]) == 14 && !strncmp(argv[arg] + 7, "dynamic", 7)) + output_mode = dynamic; + else if (strlen(argv[arg]) == 12 && !strncmp(argv[arg] + 7, "first", 5)) + output_mode = first; + else if (strlen(argv[arg]) == 13 && !strncmp(argv[arg] + 7, "second", 6)) + output_mode = second; + else if (strlen(argv[arg]) == 12 && !strncmp(argv[arg] + 7, "third", 5)) + output_mode = third; + else + { + cerr << "Incorrect syntax for ouput option" << endl; + usage(); } } else if (strlen(argv[arg]) >= 8 && !strncmp(argv[arg], "language", 8)) { - if (strlen(argv[arg]) <= 9 || argv[arg][8] != '=') - { - cerr << "Incorrect syntax for language option" << endl; - usage(); - } + if (strlen(argv[arg]) <= 9 || argv[arg][8] != '=') + { + cerr << "Incorrect syntax for language option" << endl; + usage(); + } if (strlen(argv[arg]) == 14 && !strncmp(argv[arg] + 9, "julia", 5)) language = julia; diff --git a/DynareMain2.cc b/DynareMain2.cc index b5d1e006..dc9420ca 100644 --- a/DynareMain2.cc +++ b/DynareMain2.cc @@ -60,9 +60,9 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear mod_file->writeOutputFiles(basename, clear_all, clear_global, no_log, no_warn, console, nograph, nointeractive, config_file, check_model_changes, minimal_workspace, compute_xrefs #if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__) - , cygwin, msvc, mingw + , cygwin, msvc, mingw #endif - ); + ); delete mod_file; diff --git a/ExprNode.cc b/ExprNode.cc index 4d723fa7..2aa85568 100644 --- a/ExprNode.cc +++ b/ExprNode.cc @@ -100,7 +100,7 @@ ExprNode::collectVariables(SymbolType type, set &result) const set > symbs_lags; collectDynamicVariables(type, symbs_lags); transform(symbs_lags.begin(), symbs_lags.end(), inserter(result, result.begin()), - boost::bind(&pair::first,_1)); + boost::bind(&pair::first, _1)); } void @@ -514,7 +514,6 @@ NumConstNode::substituteStaticAuxiliaryVariable() const return const_cast(this); } - VariableNode::VariableNode(DataTree &datatree_arg, int symb_id_arg, int lag_arg) : ExprNode(datatree_arg), symb_id(symb_id_arg), @@ -864,7 +863,7 @@ VariableNode::substituteStaticAuxiliaryVariable() const } return const_cast(this); } - + double VariableNode::eval(const eval_context_t &eval_context) const throw (EvalException, EvalExternalFunctionException) { @@ -973,17 +972,17 @@ VariableNode::collectDynamicVariables(SymbolType type_arg, set > pair VariableNode::normalizeEquation(int var_endo, vector > > &List_of_Op_RHS) const { - /* The equation has to be normalized with respect to the current endogenous variable ascribed to it. - The two input arguments are : - - The ID of the endogenous variable associated to the equation. - - The list of operators and operands needed to normalize the equation* - - The pair returned by NormalizeEquation is composed of - - a flag indicating if the expression returned contains (flag = 1) or not (flag = 0) - the endogenous variable related to the equation. - If the expression contains more than one occurence of the associated endogenous variable, - the flag is equal to 2. - - an expression equal to the RHS if flag = 0 and equal to NULL elsewhere + /* The equation has to be normalized with respect to the current endogenous variable ascribed to it. + The two input arguments are : + - The ID of the endogenous variable associated to the equation. + - The list of operators and operands needed to normalize the equation* + + The pair returned by NormalizeEquation is composed of + - a flag indicating if the expression returned contains (flag = 1) or not (flag = 0) + the endogenous variable related to the equation. + If the expression contains more than one occurence of the associated endogenous variable, + the flag is equal to 2. + - an expression equal to the RHS if flag = 0 and equal to NULL elsewhere */ if (type == eEndogenous) { @@ -1461,7 +1460,7 @@ VariableNode::removeTrendLeadLag(map trend_symbols_map) const expr_t noTrendLeadLagNode = new VariableNode(datatree, it->first, 0); bool log_trend = get_type() == eLogTrend; expr_t trend = it->second; - + if (get_lag() > 0) { expr_t growthFactorSequence = trend->decreaseLeadsLags(-1); @@ -2166,9 +2165,9 @@ UnaryOpNode::normalizeEquation(int var_endo, vector expr_t UnaryOpNode::substituteExpectation(subst_table_t &subst_table, vector &neweqs, bool partial_information_model) const { - if (op_code==oExpectation) + if (op_code == oExpectation) { subst_table_t::iterator it = subst_table.find(const_cast(this)); if (it != subst_table.end()) @@ -3336,7 +3335,7 @@ BinaryOpNode::Compute_RHS(expr_t arg1, expr_t arg2, int op, int op_type) const pair BinaryOpNode::normalizeEquation(int var_endo, vector > > &List_of_Op_RHS) const { - /* Checks if the current value of the endogenous variable related to the equation + /* Checks if the current value of the endogenous variable related to the equation is present in the arguments of the binary operator. */ vector > > List_of_Op_RHS1, List_of_Op_RHS2; int is_endogenous_present_1, is_endogenous_present_2; @@ -3349,17 +3348,17 @@ BinaryOpNode::normalizeEquation(int var_endo, vectornormalizeEquation(var_endo, List_of_Op_RHS2); is_endogenous_present_2 = res.first; expr_t_2 = res.second; - + /* If the two expressions contains the current value of the endogenous variable associated to the equation the equation could not be normalized and the process is given-up.*/ if (is_endogenous_present_1 == 2 || is_endogenous_present_2 == 2) return (make_pair(2, (expr_t) NULL)); else if (is_endogenous_present_1 && is_endogenous_present_2) return (make_pair(2, (expr_t) NULL)); - else if (is_endogenous_present_1) /*If the current values of the endogenous variable associated to the equation + else if (is_endogenous_present_1) /*If the current values of the endogenous variable associated to the equation is present only in the first operand of the expression, we try to normalize the equation*/ { - if (op_code == oEqual) /* The end of the normalization process : + if (op_code == oEqual) /* The end of the normalization process : All the operations needed to normalize the equation are applied. */ { pair > it; @@ -3374,7 +3373,7 @@ BinaryOpNode::normalizeEquation(int var_endo, vector &subset, subst_table_t &subst_table, vector &neweqs) const { @@ -4483,7 +4481,6 @@ TrinaryOpNode::substituteExpectation(subst_table_t &subst_table, vector &subset, subst_table_t &subst_table, vector &neweqs) const { diff --git a/ExprNode.hh b/ExprNode.hh index e784c60d..6bf7bc2e 100644 --- a/ExprNode.hh +++ b/ExprNode.hh @@ -89,16 +89,16 @@ enum ExprNodeOutputType || (output_type) == oMatlabDynamicSparseSteadyStateOperator \ || (output_type) == oSteadyStateFile) -#define IS_JULIA(output_type) ((output_type) == oJuliaStaticModel \ - || (output_type) == oJuliaDynamicModel \ +#define IS_JULIA(output_type) ((output_type) == oJuliaStaticModel \ + || (output_type) == oJuliaDynamicModel \ || (output_type) == oJuliaDynamicSteadyStateOperator \ || (output_type) == oJuliaSteadyStateFile) -#define IS_C(output_type) ((output_type) == oCDynamicModel \ - || (output_type) == oCDynamic2Model \ - || (output_type) == oCStaticModel \ - || (output_type) == oCDynamicSteadyStateOperator \ - || (output_type) == oCSteadyStateFile) +#define IS_C(output_type) ((output_type) == oCDynamicModel \ + || (output_type) == oCDynamic2Model \ + || (output_type) == oCStaticModel \ + || (output_type) == oCDynamicSteadyStateOperator \ + || (output_type) == oCSteadyStateFile) #define IS_LATEX(output_type) ((output_type) == oLatexStaticModel \ || (output_type) == oLatexDynamicModel \ @@ -122,334 +122,335 @@ enum ExprNodeOutputType #define MIN_COST(is_matlab) ((is_matlab) ? MIN_COST_MATLAB : MIN_COST_C) //! Base class for expression nodes -class ExprNode -{ - friend class DataTree; - friend class DynamicModel; - friend class StaticModel; - friend class ModelTree; - friend struct ExprNodeLess; - friend class NumConstNode; - friend class VariableNode; - friend class UnaryOpNode; - friend class BinaryOpNode; - friend class TrinaryOpNode; - friend class AbstractExternalFunctionNode; -private: - //! 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 */ - virtual expr_t computeDerivative(int deriv_id) = 0; + class ExprNode + { + friend class DataTree; + friend class DynamicModel; + friend class StaticModel; + friend class ModelTree; + friend struct ExprNodeLess; + friend class NumConstNode; + friend class VariableNode; + friend class UnaryOpNode; + friend class BinaryOpNode; + friend class TrinaryOpNode; + friend class AbstractExternalFunctionNode; + private: + //! 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 */ + virtual expr_t computeDerivative(int deriv_id) = 0; -protected: - //! Reference to the enclosing DataTree - DataTree &datatree; + protected: + //! Reference to the enclosing DataTree + DataTree &datatree; - //! Index number - int idx; + //! Index number + int idx; - //! Is the data member non_null_derivatives initialized ? - bool preparedForDerivation; + //! Is the data member non_null_derivatives initialized ? + bool preparedForDerivation; - //! Set of derivation IDs with respect to which the derivative is potentially non-null - set non_null_derivatives; + //! Set of derivation IDs with respect to which the derivative is potentially non-null + set non_null_derivatives; - //! Used for caching of first order derivatives (when non-null) - map derivatives; + //! Used for caching of first order derivatives (when non-null) + map derivatives; - //! Cost of computing current node - /*! Nodes included in temporary_terms are considered having a null cost */ - virtual int cost(int cost, bool is_matlab) const; - virtual int cost(const temporary_terms_t &temporary_terms, bool is_matlab) const; - virtual int cost(const map &temp_terms_map, bool is_matlab) const; + //! Cost of computing current node + /*! Nodes included in temporary_terms are considered having a null cost */ + virtual int cost(int cost, bool is_matlab) const; + virtual int cost(const temporary_terms_t &temporary_terms, bool is_matlab) const; + virtual int cost(const map &temp_terms_map, bool is_matlab) const; - //! For creating equation cross references - struct EquationInfo - { - set > param; - set > endo; - set > exo; - set > exo_det; - }; + //! For creating equation cross references + struct EquationInfo + { + set > param; + set > endo; + set > exo; + set > exo_det; + }; -public: - ExprNode(DataTree &datatree_arg); - virtual ~ExprNode(); + public: + ExprNode(DataTree &datatree_arg); + virtual + ~ExprNode(); - //! Initializes data member non_null_derivatives - virtual void prepareForDerivation() = 0; + //! Initializes data member non_null_derivatives + virtual void prepareForDerivation() = 0; - //! Returns derivative w.r. to derivation ID - /*! Uses a symbolic a priori to pre-detect null derivatives, and caches the result for other derivatives (to avoid computing it several times) - For an equal node, returns the derivative of lhs minus rhs */ - expr_t getDerivative(int deriv_id); + //! Returns derivative w.r. to derivation ID + /*! Uses a symbolic a priori to pre-detect null derivatives, and caches the result for other derivatives (to avoid computing it several times) + For an equal node, returns the derivative of lhs minus rhs */ + expr_t getDerivative(int deriv_id); - //! Computes derivatives by applying the chain rule for some variables - /*! - \param deriv_id The derivation ID with respect to which we are derivating - \param recursive_variables Contains the derivation ID for which chain rules must be applied. Keys are derivation IDs, values are equations of the form x=f(y) where x is the key variable and x doesn't appear in y - */ - virtual expr_t getChainRuleDerivative(int deriv_id, const map &recursive_variables) = 0; + //! Computes derivatives by applying the chain rule for some variables + /*! + \param deriv_id The derivation ID with respect to which we are derivating + \param recursive_variables Contains the derivation ID for which chain rules must be applied. Keys are derivation IDs, values are equations of the form x=f(y) where x is the key variable and x doesn't appear in y + */ + virtual expr_t getChainRuleDerivative(int deriv_id, const map &recursive_variables) = 0; - //! Returns precedence of node - /*! Equals 100 for constants, variables, unary ops, and temporary terms */ - virtual int precedence(ExprNodeOutputType output_t, const temporary_terms_t &temporary_terms) const; + //! Returns precedence of node + /*! Equals 100 for constants, variables, unary ops, and temporary terms */ + virtual int precedence(ExprNodeOutputType output_t, const temporary_terms_t &temporary_terms) const; - //! Fills temporary_terms set, using reference counts - /*! A node will be marked as a temporary term if it is referenced at least two times (i.e. has at least two parents), and has a computing cost (multiplied by reference count) greater to datatree.min_cost */ - virtual void computeTemporaryTerms(map > &reference_count, - map &temp_terms_map, - bool is_matlab, NodeTreeReference tr) const; + //! Fills temporary_terms set, using reference counts + /*! A node will be marked as a temporary term if it is referenced at least two times (i.e. has at least two parents), and has a computing cost (multiplied by reference count) greater to datatree.min_cost */ + virtual void computeTemporaryTerms(map > &reference_count, + map &temp_terms_map, + bool is_matlab, NodeTreeReference tr) const; - //! Writes output of node, using a Txxx notation for nodes in temporary_terms, and specifiying the set of already written external functions - /*! - \param[in] output the output stream - \param[in] output_type the type of output (MATLAB, C, LaTeX...) - \param[in] temporary_terms the nodes that are marked as temporary terms - \param[in,out] tef_terms the set of already written external function nodes - */ - virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const = 0; + //! Writes output of node, using a Txxx notation for nodes in temporary_terms, and specifiying the set of already written external functions + /*! + \param[in] output the output stream + \param[in] output_type the type of output (MATLAB, C, LaTeX...) + \param[in] temporary_terms the nodes that are marked as temporary terms + \param[in,out] tef_terms the set of already written external function nodes + */ + virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const = 0; - //! returns true if the expr node contains an external function - virtual bool containsExternalFunction() const = 0; + //! returns true if the expr node contains an external function + virtual bool containsExternalFunction() const = 0; - //! Writes output of node (with no temporary terms and with "outside model" output type) - void writeOutput(ostream &output) const; + //! Writes output of node (with no temporary terms and with "outside model" output type) + void writeOutput(ostream &output) const; - //! Writes output of node (with no temporary terms) - void writeOutput(ostream &output, ExprNodeOutputType output_type) const; + //! Writes output of node (with no temporary terms) + void writeOutput(ostream &output, ExprNodeOutputType output_type) const; - //! Writes output of node, using a Txxx notation for nodes in temporary_terms - void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const; + //! Writes output of node, using a Txxx notation for nodes in temporary_terms + void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const; - //! Writes the output for an external function, ensuring that the external function is called as few times as possible using temporary terms - virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type, - const temporary_terms_t &temporary_terms, - deriv_node_temp_terms_t &tef_terms) const; + //! Writes the output for an external function, ensuring that the external function is called as few times as possible using temporary terms + 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 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; - //! Computes the set of all variables of a given symbol type in the expression (with information on lags) - /*! - Variables are stored as integer pairs of the form (symb_id, lag). - They are added to the set given in argument. - Note that model local variables are substituted by their expression in the computation - (and added if type_arg = ModelLocalVariable). - */ - virtual void collectDynamicVariables(SymbolType type_arg, set > &result) const = 0; + //! Computes the set of all variables of a given symbol type in the expression (with information on lags) + /*! + Variables are stored as integer pairs of the form (symb_id, lag). + They are added to the set given in argument. + Note that model local variables are substituted by their expression in the computation + (and added if type_arg = ModelLocalVariable). + */ + virtual void collectDynamicVariables(SymbolType type_arg, set > &result) const = 0; - //! Computes the set of all variables of a given symbol type in the expression (without information on lags) - /*! - Variables are stored as symb_id. - They are added to the set given in argument. - Note that model local variables are substituted by their expression in the computation - (and added if type_arg = ModelLocalVariable). - */ - void collectVariables(SymbolType type_arg, set &result) const; + //! Computes the set of all variables of a given symbol type in the expression (without information on lags) + /*! + Variables are stored as symb_id. + They are added to the set given in argument. + Note that model local variables are substituted by their expression in the computation + (and added if type_arg = ModelLocalVariable). + */ + void collectVariables(SymbolType type_arg, set &result) const; - //! Computes the set of endogenous variables in the expression - /*! - Endogenous are stored as integer pairs of the form (type_specific_id, lag). - They are added to the set given in argument. - Note that model local variables are substituted by their expression in the computation. - */ - virtual void collectEndogenous(set > &result) const; + //! Computes the set of endogenous variables in the expression + /*! + Endogenous are stored as integer pairs of the form (type_specific_id, lag). + They are added to the set given in argument. + Note that model local variables are substituted by their expression in the computation. + */ + virtual void collectEndogenous(set > &result) const; - //! Computes the set of exogenous variables in the expression - /*! - Exogenous are stored as integer pairs of the form (type_specific_id, lag). - They are added to the set given in argument. - Note that model local variables are substituted by their expression in the computation. - */ - virtual void collectExogenous(set > &result) const; + //! Computes the set of exogenous variables in the expression + /*! + Exogenous are stored as integer pairs of the form (type_specific_id, lag). + They are added to the set given in argument. + Note that model local variables are substituted by their expression in the computation. + */ + virtual void collectExogenous(set > &result) const; - virtual void collectTemporary_terms(const temporary_terms_t &temporary_terms, temporary_terms_inuse_t &temporary_terms_inuse, int Curr_Block) const = 0; + virtual void collectTemporary_terms(const temporary_terms_t &temporary_terms, temporary_terms_inuse_t &temporary_terms_inuse, int Curr_Block) const = 0; - virtual void computeTemporaryTerms(map &reference_count, - temporary_terms_t &temporary_terms, - map > &first_occurence, - int Curr_block, - vector< vector > &v_temporary_terms, - int equation) const; + virtual void computeTemporaryTerms(map &reference_count, + temporary_terms_t &temporary_terms, + map > &first_occurence, + int Curr_block, + vector< vector > &v_temporary_terms, + int equation) const; - class EvalException + class EvalException - { - }; + { + }; - class EvalExternalFunctionException : public EvalException + class EvalExternalFunctionException : public EvalException - { - }; + { + }; - virtual double eval(const eval_context_t &eval_context) const throw (EvalException, EvalExternalFunctionException) = 0; - 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; - 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) const; - //! Creates a static version of this node - /*! - This method duplicates the current node by creating a similar node from which all leads/lags have been stripped, - adds the result in the static_datatree argument (and not in the original datatree), and returns it. - */ - virtual expr_t toStatic(DataTree &static_datatree) const = 0; + virtual double eval(const eval_context_t &eval_context) const throw (EvalException, EvalExternalFunctionException) = 0; + 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; + 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) const; + //! Creates a static version of this node + /*! + This method duplicates the current node by creating a similar node from which all leads/lags have been stripped, + adds the result in the static_datatree argument (and not in the original datatree), and returns it. + */ + virtual expr_t toStatic(DataTree &static_datatree) const = 0; - /*! - Compute cross references for equations - */ - // virtual void computeXrefs(set ¶m, set &endo, set &exo, set &exo_det) const = 0; - virtual void computeXrefs(EquationInfo &ei) const = 0; - //! Try to normalize an equation linear in its endogenous variable - virtual pair normalizeEquation(int symb_id_endo, vector > > &List_of_Op_RHS) const = 0; + /*! + Compute cross references for equations + */ + // virtual void computeXrefs(set ¶m, set &endo, set &exo, set &exo_det) const = 0; + virtual void computeXrefs(EquationInfo &ei) const = 0; + //! Try to normalize an equation linear in its endogenous variable + virtual pair normalizeEquation(int symb_id_endo, vector > > &List_of_Op_RHS) const = 0; - //! Returns the maximum lead of endogenous in this expression - /*! Always returns a non-negative value */ - virtual int maxEndoLead() const = 0; + //! Returns the maximum lead of endogenous in this expression + /*! Always returns a non-negative value */ + virtual int maxEndoLead() const = 0; - //! Returns the maximum lead of exogenous in this expression - /*! Always returns a non-negative value */ - virtual int maxExoLead() const = 0; + //! Returns the maximum lead of exogenous in this expression + /*! Always returns a non-negative value */ + virtual int maxExoLead() const = 0; - //! Returns the maximum lag of endogenous in this expression - /*! Always returns a non-negative value */ - virtual int maxEndoLag() const = 0; + //! Returns the maximum lag of endogenous in this expression + /*! Always returns a non-negative value */ + virtual int maxEndoLag() const = 0; - //! Returns the maximum lag of exogenous in this expression - /*! Always returns a non-negative value */ - virtual int maxExoLag() const = 0; + //! Returns the maximum lag of exogenous in this expression + /*! Always returns a non-negative value */ + virtual int maxExoLag() const = 0; - //! Returns the relative period of the most forward term in this expression - /*! A negative value means that the expression contains only lagged variables */ - virtual int maxLead() const = 0; + //! Returns the relative period of the most forward term in this expression + /*! A negative value means that the expression contains only lagged variables */ + virtual int maxLead() const = 0; - //! Returns a new expression where all the leads/lags have been shifted backwards by the same amount - /*! - Only acts on endogenous, exogenous, exogenous det - \param[in] n The number of lags by which to shift - \return The same expression except that leads/lags have been shifted backwards - */ - virtual expr_t decreaseLeadsLags(int n) const = 0; + //! Returns a new expression where all the leads/lags have been shifted backwards by the same amount + /*! + Only acts on endogenous, exogenous, exogenous det + \param[in] n The number of lags by which to shift + \return The same expression except that leads/lags have been shifted backwards + */ + virtual expr_t decreaseLeadsLags(int n) const = 0; - //! Type for the substitution map used in the process of creating auxiliary vars for leads >= 2 - typedef map subst_table_t; + //! Type for the substitution map used in the process of creating auxiliary vars for leads >= 2 + typedef map subst_table_t; - //! Creates auxiliary endo lead variables corresponding to this expression - /*! - If maximum endogenous lead >= 3, this method will also create intermediary auxiliary var, and will add the equations of the form aux1 = aux2(+1) to the substitution table. - \pre This expression is assumed to have maximum endogenous lead >= 2 - \param[in,out] subst_table The table to which new auxiliary variables and their correspondance will be added - \param[out] neweqs Equations to be added to the model to match the creation of auxiliary variables. - \return The new variable node corresponding to the current expression - */ - VariableNode *createEndoLeadAuxiliaryVarForMyself(subst_table_t &subst_table, vector &neweqs) const; + //! Creates auxiliary endo lead variables corresponding to this expression + /*! + If maximum endogenous lead >= 3, this method will also create intermediary auxiliary var, and will add the equations of the form aux1 = aux2(+1) to the substitution table. + \pre This expression is assumed to have maximum endogenous lead >= 2 + \param[in,out] subst_table The table to which new auxiliary variables and their correspondance will be added + \param[out] neweqs Equations to be added to the model to match the creation of auxiliary variables. + \return The new variable node corresponding to the current expression + */ + VariableNode *createEndoLeadAuxiliaryVarForMyself(subst_table_t &subst_table, vector &neweqs) const; - //! Creates auxiliary exo lead variables corresponding to this expression - /*! - If maximum exogenous lead >= 2, this method will also create intermediary auxiliary var, and will add the equations of the form aux1 = aux2(+1) to the substitution table. - \pre This expression is assumed to have maximum exogenous lead >= 1 - \param[in,out] subst_table The table to which new auxiliary variables and their correspondance will be added - \param[out] neweqs Equations to be added to the model to match the creation of auxiliary variables. - \return The new variable node corresponding to the current expression - */ - VariableNode *createExoLeadAuxiliaryVarForMyself(subst_table_t &subst_table, vector &neweqs) const; + //! Creates auxiliary exo lead variables corresponding to this expression + /*! + If maximum exogenous lead >= 2, this method will also create intermediary auxiliary var, and will add the equations of the form aux1 = aux2(+1) to the substitution table. + \pre This expression is assumed to have maximum exogenous lead >= 1 + \param[in,out] subst_table The table to which new auxiliary variables and their correspondance will be added + \param[out] neweqs Equations to be added to the model to match the creation of auxiliary variables. + \return The new variable node corresponding to the current expression + */ + VariableNode *createExoLeadAuxiliaryVarForMyself(subst_table_t &subst_table, vector &neweqs) const; - //! Constructs a new expression where sub-expressions with max endo lead >= 2 have been replaced by auxiliary variables - /*! - \param[in,out] subst_table Map used to store expressions that have already be substituted and their corresponding variable, in order to avoid creating two auxiliary variables for the same sub-expr. - \param[out] neweqs Equations to be added to the model to match the creation of auxiliary variables. + //! Constructs a new expression where sub-expressions with max endo lead >= 2 have been replaced by auxiliary variables + /*! + \param[in,out] subst_table Map used to store expressions that have already be substituted and their corresponding variable, in order to avoid creating two auxiliary variables for the same sub-expr. + \param[out] neweqs Equations to be added to the model to match the creation of auxiliary variables. - If the method detects a sub-expr which needs to be substituted, two cases are possible: - - if this expr is in the table, then it will use the corresponding variable and return the substituted expression - - if this expr is not in the table, then it will create an auxiliary endogenous variable, add the substitution in the table and return the substituted expression + If the method detects a sub-expr which needs to be substituted, two cases are possible: + - if this expr is in the table, then it will use the corresponding variable and return the substituted expression + - if this expr is not in the table, then it will create an auxiliary endogenous variable, add the substitution in the table and return the substituted expression - \return A new equivalent expression where sub-expressions with max endo lead >= 2 have been replaced by auxiliary variables - */ - virtual expr_t substituteEndoLeadGreaterThanTwo(subst_table_t &subst_table, vector &neweqs, bool deterministic_model) const = 0; + \return A new equivalent expression where sub-expressions with max endo lead >= 2 have been replaced by auxiliary variables + */ + virtual expr_t substituteEndoLeadGreaterThanTwo(subst_table_t &subst_table, vector &neweqs, bool deterministic_model) const = 0; - //! Constructs a new expression where endo variables with max endo lag >= 2 have been replaced by auxiliary variables - /*! - \param[in,out] subst_table Map used to store expressions that have already be substituted and their corresponding variable, in order to avoid creating two auxiliary variables for the same sub-expr. - \param[out] neweqs Equations to be added to the model to match the creation of auxiliary variables. - */ - virtual expr_t substituteEndoLagGreaterThanTwo(subst_table_t &subst_table, vector &neweqs) const = 0; + //! Constructs a new expression where endo variables with max endo lag >= 2 have been replaced by auxiliary variables + /*! + \param[in,out] subst_table Map used to store expressions that have already be substituted and their corresponding variable, in order to avoid creating two auxiliary variables for the same sub-expr. + \param[out] neweqs Equations to be added to the model to match the creation of auxiliary variables. + */ + virtual expr_t substituteEndoLagGreaterThanTwo(subst_table_t &subst_table, vector &neweqs) const = 0; - //! Constructs a new expression where exogenous variables with a lead have been replaced by auxiliary variables - /*! - \param[in,out] subst_table Map used to store expressions that have already be substituted and their corresponding variable, in order to avoid creating two auxiliary variables for the same sub-expr. - \param[out] neweqs Equations to be added to the model to match the creation of auxiliary variables. - */ - virtual expr_t substituteExoLead(subst_table_t &subst_table, vector &neweqs, bool deterministic_model) const = 0; - //! Constructs a new expression where exogenous variables with a lag have been replaced by auxiliary variables - /*! - \param[in,out] subst_table Map used to store expressions that have already be substituted and their corresponding variable, in order to avoid creating two auxiliary variables for the same sub-expr. - \param[out] neweqs Equations to be added to the model to match the creation of auxiliary variables. - */ - virtual expr_t substituteExoLag(subst_table_t &subst_table, vector &neweqs) const = 0; + //! Constructs a new expression where exogenous variables with a lead have been replaced by auxiliary variables + /*! + \param[in,out] subst_table Map used to store expressions that have already be substituted and their corresponding variable, in order to avoid creating two auxiliary variables for the same sub-expr. + \param[out] neweqs Equations to be added to the model to match the creation of auxiliary variables. + */ + virtual expr_t substituteExoLead(subst_table_t &subst_table, vector &neweqs, bool deterministic_model) const = 0; + //! Constructs a new expression where exogenous variables with a lag have been replaced by auxiliary variables + /*! + \param[in,out] subst_table Map used to store expressions that have already be substituted and their corresponding variable, in order to avoid creating two auxiliary variables for the same sub-expr. + \param[out] neweqs Equations to be added to the model to match the creation of auxiliary variables. + */ + virtual expr_t substituteExoLag(subst_table_t &subst_table, vector &neweqs) const = 0; - //! Constructs a new expression where the expectation operator has been replaced by auxiliary variables - /*! - \param[in,out] subst_table Map used to store expressions that have already be substituted and their corresponding variable, in order to avoid creating two auxiliary variables for the same sub-expr. - \param[out] neweqs Equations to be added to the model to match the creation of auxiliary variables. - \param[in] partial_information_model Are we substituting in a partial information model? - */ - virtual expr_t substituteExpectation(subst_table_t &subst_table, vector &neweqs, bool partial_information_model) const = 0; + //! Constructs a new expression where the expectation operator has been replaced by auxiliary variables + /*! + \param[in,out] subst_table Map used to store expressions that have already be substituted and their corresponding variable, in order to avoid creating two auxiliary variables for the same sub-expr. + \param[out] neweqs Equations to be added to the model to match the creation of auxiliary variables. + \param[in] partial_information_model Are we substituting in a partial information model? + */ + virtual expr_t substituteExpectation(subst_table_t &subst_table, vector &neweqs, bool partial_information_model) const = 0; - virtual expr_t decreaseLeadsLagsPredeterminedVariables() const = 0; + virtual expr_t decreaseLeadsLagsPredeterminedVariables() const = 0; - //! Constructs a new expression where forward variables (supposed to be at most in t+1) have been replaced by themselves at t, plus a new aux var representing their (time) differentiate - /*! - \param[in] subset variables to which to limit the transformation; transform - all fwrd vars if empty - \param[in,out] subst_table Map used to store mapping between a given - forward variable and the aux var that contains its differentiate - \param[out] neweqs Equations to be added to the model to match the creation of auxiliary variables. - */ - virtual expr_t differentiateForwardVars(const vector &subset, subst_table_t &subst_table, vector &neweqs) const = 0; + //! Constructs a new expression where forward variables (supposed to be at most in t+1) have been replaced by themselves at t, plus a new aux var representing their (time) differentiate + /*! + \param[in] subset variables to which to limit the transformation; transform + all fwrd vars if empty + \param[in,out] subst_table Map used to store mapping between a given + forward variable and the aux var that contains its differentiate + \param[out] neweqs Equations to be added to the model to match the creation of auxiliary variables. + */ + virtual expr_t differentiateForwardVars(const vector &subset, subst_table_t &subst_table, vector &neweqs) const = 0; - //! Return true if the nodeID is a numerical constant equal to value and false otherwise - /*! - \param[in] value of the numerical constante - \param[out] the boolean equal to true if NodeId is a constant equal to value - */ - virtual bool isNumConstNodeEqualTo(double value) const = 0; + //! Return true if the nodeID is a numerical constant equal to value and false otherwise + /*! + \param[in] value of the numerical constante + \param[out] the boolean equal to true if NodeId is a constant equal to value + */ + virtual bool isNumConstNodeEqualTo(double value) const = 0; - //! Returns true if the expression contains one or several endogenous variable - virtual bool containsEndogenous(void) const = 0; + //! Returns true if the expression contains one or several endogenous variable + virtual bool containsEndogenous(void) const = 0; - //! Returns true if the expression contains one or several exogenous variable - virtual bool containsExogenous() const = 0; + //! Returns true if the expression contains one or several exogenous variable + virtual bool containsExogenous() const = 0; - //! Return true if the nodeID is a variable withe a type equal to type_arg, a specific variable id aqual to varfiable_id and a lag equal to lag_arg and false otherwise - /*! - \param[in] the type (type_arg), specifique variable id (variable_id and the lag (lag_arg) - \param[out] the boolean equal to true if NodeId is the variable - */ - virtual bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, int lag_arg) const = 0; + //! Return true if the nodeID is a variable withe a type equal to type_arg, a specific variable id aqual to varfiable_id and a lag equal to lag_arg and false otherwise + /*! + \param[in] the type (type_arg), specifique variable id (variable_id and the lag (lag_arg) + \param[out] the boolean equal to true if NodeId is the variable + */ + virtual bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, int lag_arg) const = 0; - //! Replaces the Trend var with datatree.One - virtual expr_t replaceTrendVar() const = 0; + //! Replaces the Trend var with datatree.One + virtual expr_t replaceTrendVar() const = 0; - //! Constructs a new expression where the variable indicated by symb_id has been detrended - /*! - \param[in] symb_id indicating the variable to be detrended - \param[in] log_trend indicates if the trend is in log - \param[in] trend indicating the trend - \return the new binary op pointing to a detrended variable - */ - virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const = 0; + //! Constructs a new expression where the variable indicated by symb_id has been detrended + /*! + \param[in] symb_id indicating the variable to be detrended + \param[in] log_trend indicates if the trend is in log + \param[in] trend indicating the trend + \return the new binary op pointing to a detrended variable + */ + virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const = 0; - //! Add ExprNodes to the provided datatree - virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const = 0; + //! Add ExprNodes to the provided datatree + virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const = 0; - //! Move a trend variable with lag/lead to time t by dividing/multiplying by its growth factor - virtual expr_t removeTrendLeadLag(map trend_symbols_map) const = 0; + //! Move a trend variable with lag/lead to time t by dividing/multiplying by its growth factor + virtual expr_t removeTrendLeadLag(map trend_symbols_map) const = 0; - //! Returns true if the expression is in static form (no lead, no lag, no expectation, no STEADY_STATE) - virtual bool isInStaticForm() const = 0; + //! Returns true if the expression is in static form (no lead, no lag, no expectation, no STEADY_STATE) + virtual bool isInStaticForm() const = 0; - //! Substitute auxiliary variables by their expression in static model - virtual expr_t substituteStaticAuxiliaryVariable() const = 0; -}; + //! Substitute auxiliary variables by their expression in static model + virtual expr_t substituteStaticAuxiliaryVariable() const = 0; + }; //! Object used to compare two nodes (using their indexes) struct ExprNodeLess @@ -550,7 +551,11 @@ public: { return symb_id; }; - int get_lag() const { return lag; }; + int + get_lag() const + { + return lag; + }; virtual pair normalizeEquation(int symb_id_endo, vector > > &List_of_Op_RHS) const; virtual expr_t getChainRuleDerivative(int deriv_id, const map &recursive_variables); virtual int maxEndoLead() const; diff --git a/ExtendedPreprocessorTypes.hh b/ExtendedPreprocessorTypes.hh index e0a955f2..4c6869a3 100644 --- a/ExtendedPreprocessorTypes.hh +++ b/ExtendedPreprocessorTypes.hh @@ -24,9 +24,9 @@ enum FileOutputType { none, // outputs files for Matlab/Octave processing dynamic, // outputs _dynamic.* and related files - first, // outputs _first_derivatives.* and related files - second, // outputs _first_derivatives.*, _second_derivatives.* and related files - third, // outputs _first_derivatives.*, _second_derivatives.*, _third_derivatives.* and related files + first, // outputs _first_derivatives.* and related files + second, // outputs _first_derivatives.*, _second_derivatives.* and related files + third, // outputs _first_derivatives.*, _second_derivatives.*, _third_derivatives.* and related files }; enum LanguageOutputType diff --git a/MinimumFeedbackSet.cc b/MinimumFeedbackSet.cc index 479c8f22..a84a994a 100644 --- a/MinimumFeedbackSet.cc +++ b/MinimumFeedbackSet.cc @@ -175,7 +175,7 @@ namespace MFS if (in_degree(vertex, G) > 0 && out_degree(vertex, G) > 0) for (tie(it_in, in_end) = in_edges(vertex, G); it_in != in_end; ++it_in) for (tie(it_out, out_end) = out_edges(vertex, G); it_out != out_end; ++it_out) - if (source(*it_in, G) == target(*it_out, G) && source(*it_in, G) != target(*it_in, G)) // not a loop + if (source(*it_in, G) == target(*it_out, G) && source(*it_in, G) != target(*it_in, G)) // not a loop Doublet.push_back(source(*it_in, G)); return Doublet; } diff --git a/ModFile.cc b/ModFile.cc index 629d4b42..a10d1308 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -39,7 +39,7 @@ ModFile::ModFile(WarningConsolidation &warnings_arg) orig_ramsey_dynamic_model(symbol_table, num_constants, external_functions_table), static_model(symbol_table, num_constants, external_functions_table), steady_state_model(symbol_table, num_constants, external_functions_table, static_model), - linear(false), block(false), byte_code(false), use_dll(false), no_static(false), + linear(false), block(false), byte_code(false), use_dll(false), no_static(false), differentiate_forward_vars(false), nonstationary_variables(false), param_used_with_lead_lag(false), warnings(warnings_arg) { @@ -148,10 +148,10 @@ ModFile::checkPass(bool nostrict) exit(EXIT_FAILURE); } - if (((mod_file_struct.ramsey_model_present || mod_file_struct.discretionary_policy_present) + if (((mod_file_struct.ramsey_model_present || mod_file_struct.discretionary_policy_present) && !mod_file_struct.planner_objective_present) || (!(mod_file_struct.ramsey_model_present || mod_file_struct.discretionary_policy_present) - && mod_file_struct.planner_objective_present)) + && mod_file_struct.planner_objective_present)) { cerr << "ERROR: A planner_objective statement must be used with a ramsey_model, a ramsey_policy or a discretionary_policy statement and vice versa." << endl; exit(EXIT_FAILURE); @@ -256,38 +256,38 @@ ModFile::checkPass(bool nostrict) cerr << "ERROR: the number of equations marked [static] must be equal to the number of equations marked [dynamic]" << endl; exit(EXIT_FAILURE); } - - if (dynamic_model.staticOnlyEquationsNbr() > 0 && - (mod_file_struct.ramsey_model_present || mod_file_struct.discretionary_policy_present)) + + if (dynamic_model.staticOnlyEquationsNbr() > 0 + && (mod_file_struct.ramsey_model_present || mod_file_struct.discretionary_policy_present)) { cerr << "ERROR: marking equations as [static] or [dynamic] is not possible with ramsey_model, ramsey_policy or discretionary_policy" << endl; exit(EXIT_FAILURE); } - if (stochastic_statement_present && - (dynamic_model.isUnaryOpUsed(oSign) - || dynamic_model.isUnaryOpUsed(oAbs) - || dynamic_model.isBinaryOpUsed(oMax) - || dynamic_model.isBinaryOpUsed(oMin) - || dynamic_model.isBinaryOpUsed(oGreater) - || dynamic_model.isBinaryOpUsed(oLess) - || dynamic_model.isBinaryOpUsed(oGreaterEqual) - || dynamic_model.isBinaryOpUsed(oLessEqual) - || dynamic_model.isBinaryOpUsed(oEqualEqual) - || dynamic_model.isBinaryOpUsed(oDifferent))) + if (stochastic_statement_present + && (dynamic_model.isUnaryOpUsed(oSign) + || dynamic_model.isUnaryOpUsed(oAbs) + || dynamic_model.isBinaryOpUsed(oMax) + || dynamic_model.isBinaryOpUsed(oMin) + || dynamic_model.isBinaryOpUsed(oGreater) + || dynamic_model.isBinaryOpUsed(oLess) + || dynamic_model.isBinaryOpUsed(oGreaterEqual) + || dynamic_model.isBinaryOpUsed(oLessEqual) + || dynamic_model.isBinaryOpUsed(oEqualEqual) + || dynamic_model.isBinaryOpUsed(oDifferent))) warnings << "WARNING: you are using a function (max, min, abs, sign) or an operator (<, >, <=, >=, ==, !=) which is unsuitable for a stochastic context; see the reference manual, section about \"Expressions\", for more details." << endl; - if (linear && - (dynamic_model.isUnaryOpUsed(oSign) - || dynamic_model.isUnaryOpUsed(oAbs) - || dynamic_model.isBinaryOpUsed(oMax) - || dynamic_model.isBinaryOpUsed(oMin) - || dynamic_model.isBinaryOpUsed(oGreater) - || dynamic_model.isBinaryOpUsed(oLess) - || dynamic_model.isBinaryOpUsed(oGreaterEqual) - || dynamic_model.isBinaryOpUsed(oLessEqual) - || dynamic_model.isBinaryOpUsed(oEqualEqual) - || dynamic_model.isBinaryOpUsed(oDifferent))) + if (linear + && (dynamic_model.isUnaryOpUsed(oSign) + || dynamic_model.isUnaryOpUsed(oAbs) + || dynamic_model.isBinaryOpUsed(oMax) + || dynamic_model.isBinaryOpUsed(oMin) + || dynamic_model.isBinaryOpUsed(oGreater) + || dynamic_model.isBinaryOpUsed(oLess) + || dynamic_model.isBinaryOpUsed(oGreaterEqual) + || dynamic_model.isBinaryOpUsed(oLessEqual) + || dynamic_model.isBinaryOpUsed(oEqualEqual) + || dynamic_model.isBinaryOpUsed(oDifferent))) warnings << "WARNING: you have declared your model 'linear' but you are using a function (max, min, abs, sign) or an operator (<, >, <=, >=, ==, !=) which potentially makes it non-linear." << endl; // Test if some estimated parameters are used within the values of shocks @@ -302,7 +302,7 @@ ModFile::checkPass(bool nostrict) { cerr << "ERROR: some estimated parameters ("; for (set::const_iterator it = parameters_intersect.begin(); - it != parameters_intersect.end(); ) + it != parameters_intersect.end();) { cerr << symbol_table.getName(*it); if (++it != parameters_intersect.end()) @@ -376,7 +376,7 @@ ModFile::transformPass(bool nostrict, bool compute_xrefs) /* clone the model then clone the new equations back to the original because we have to call computeDerivIDs (in computeRamseyPolicyFOCs and computingPass) - */ + */ if (linear) dynamic_model.cloneDynamic(orig_ramsey_dynamic_model); dynamic_model.cloneDynamic(ramsey_FOC_equations_dynamic_model); @@ -510,64 +510,64 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output, int params_deri // Compute static model and its derivatives dynamic_model.toStatic(static_model); if (!no_static) - { - if (mod_file_struct.stoch_simul_present - || mod_file_struct.estimation_present || mod_file_struct.osr_present - || mod_file_struct.ramsey_model_present || mod_file_struct.identification_present - || mod_file_struct.calib_smoother_present) - static_model.set_cutoff_to_zero(); + { + if (mod_file_struct.stoch_simul_present + || mod_file_struct.estimation_present || mod_file_struct.osr_present + || mod_file_struct.ramsey_model_present || mod_file_struct.identification_present + || mod_file_struct.calib_smoother_present) + static_model.set_cutoff_to_zero(); - const bool static_hessian = mod_file_struct.identification_present - || mod_file_struct.estimation_analytic_derivation; + const bool static_hessian = mod_file_struct.identification_present + || mod_file_struct.estimation_analytic_derivation; int paramsDerivsOrder = 0; if (mod_file_struct.identification_present || mod_file_struct.estimation_analytic_derivation) paramsDerivsOrder = params_derivs_order; - static_model.computingPass(global_eval_context, no_tmp_terms, static_hessian, - false, paramsDerivsOrder, block, byte_code); - } + static_model.computingPass(global_eval_context, no_tmp_terms, static_hessian, + false, paramsDerivsOrder, block, byte_code); + } // Set things to compute for dynamic model if (mod_file_struct.perfect_foresight_solver_present || mod_file_struct.check_present - || mod_file_struct.stoch_simul_present - || mod_file_struct.estimation_present || mod_file_struct.osr_present - || mod_file_struct.ramsey_model_present || mod_file_struct.identification_present - || mod_file_struct.calib_smoother_present) - { - if (mod_file_struct.perfect_foresight_solver_present) - dynamic_model.computingPass(true, false, false, none, global_eval_context, no_tmp_terms, block, use_dll, byte_code); - else - { - if (mod_file_struct.stoch_simul_present - || mod_file_struct.estimation_present || mod_file_struct.osr_present - || mod_file_struct.ramsey_model_present || mod_file_struct.identification_present - || mod_file_struct.calib_smoother_present) - dynamic_model.set_cutoff_to_zero(); - if (mod_file_struct.order_option < 1 || mod_file_struct.order_option > 3) - { - cerr << "ERROR: Incorrect order option..." << endl; - exit(EXIT_FAILURE); - } - bool hessian = mod_file_struct.order_option >= 2 - || mod_file_struct.identification_present - || mod_file_struct.estimation_analytic_derivation - || linear - || output == second - || output == third; - bool thirdDerivatives = mod_file_struct.order_option == 3 - || mod_file_struct.estimation_analytic_derivation - || output == third; - int paramsDerivsOrder = 0; - if (mod_file_struct.identification_present || mod_file_struct.estimation_analytic_derivation) - paramsDerivsOrder = params_derivs_order; - dynamic_model.computingPass(true, hessian, thirdDerivatives, paramsDerivsOrder, global_eval_context, no_tmp_terms, block, use_dll, byte_code); - if (linear && mod_file_struct.ramsey_model_present) - orig_ramsey_dynamic_model.computingPass(true, true, false, paramsDerivsOrder, global_eval_context, no_tmp_terms, block, use_dll, byte_code); - } - } - else // No computing task requested, compute derivatives up to 2nd order by default - dynamic_model.computingPass(true, true, false, none, global_eval_context, no_tmp_terms, block, use_dll, byte_code); + || mod_file_struct.stoch_simul_present + || mod_file_struct.estimation_present || mod_file_struct.osr_present + || mod_file_struct.ramsey_model_present || mod_file_struct.identification_present + || mod_file_struct.calib_smoother_present) + { + if (mod_file_struct.perfect_foresight_solver_present) + dynamic_model.computingPass(true, false, false, none, global_eval_context, no_tmp_terms, block, use_dll, byte_code); + else + { + if (mod_file_struct.stoch_simul_present + || mod_file_struct.estimation_present || mod_file_struct.osr_present + || mod_file_struct.ramsey_model_present || mod_file_struct.identification_present + || mod_file_struct.calib_smoother_present) + dynamic_model.set_cutoff_to_zero(); + if (mod_file_struct.order_option < 1 || mod_file_struct.order_option > 3) + { + cerr << "ERROR: Incorrect order option..." << endl; + exit(EXIT_FAILURE); + } + bool hessian = mod_file_struct.order_option >= 2 + || mod_file_struct.identification_present + || mod_file_struct.estimation_analytic_derivation + || linear + || output == second + || output == third; + bool thirdDerivatives = mod_file_struct.order_option == 3 + || mod_file_struct.estimation_analytic_derivation + || output == third; + int paramsDerivsOrder = 0; + if (mod_file_struct.identification_present || mod_file_struct.estimation_analytic_derivation) + paramsDerivsOrder = params_derivs_order; + dynamic_model.computingPass(true, hessian, thirdDerivatives, paramsDerivsOrder, global_eval_context, no_tmp_terms, block, use_dll, byte_code); + if (linear && mod_file_struct.ramsey_model_present) + orig_ramsey_dynamic_model.computingPass(true, true, false, paramsDerivsOrder, global_eval_context, no_tmp_terms, block, use_dll, byte_code); + } + } + else // No computing task requested, compute derivatives up to 2nd order by default + dynamic_model.computingPass(true, true, false, none, global_eval_context, no_tmp_terms, block, use_dll, byte_code); - if ((linear && !mod_file_struct.ramsey_model_present && !dynamic_model.checkHessianZero()) || - (linear && mod_file_struct.ramsey_model_present && !orig_ramsey_dynamic_model.checkHessianZero())) + if ((linear && !mod_file_struct.ramsey_model_present && !dynamic_model.checkHessianZero()) + || (linear && mod_file_struct.ramsey_model_present && !orig_ramsey_dynamic_model.checkHessianZero())) { map eqs; if (mod_file_struct.ramsey_model_present) @@ -633,18 +633,18 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo if (clear_all) mOutputFile << "if isoctave || matlab_ver_less_than('8.6')" << endl << " clear all" << endl - << "else" << endl - << " clearvars -global" << endl - << " clear_persistent_variables(fileparts(which('dynare')), false)" << endl - << "end" << endl; + << "else" << endl + << " clearvars -global" << endl + << " clear_persistent_variables(fileparts(which('dynare')), false)" << endl + << "end" << endl; else if (clear_global) mOutputFile << "clear M_ options_ oo_ estim_params_ bayestopt_ dataset_ dataset_info estimation_info ys0_ ex0_;" << endl; mOutputFile << "tic0 = tic;" << endl - << "% Save empty dates and dseries objects in memory." << endl - << "dates('initialize');" << endl - << "dseries('initialize');" << endl - << "% Define global variables." << endl + << "% Save empty dates and dseries objects in memory." << endl + << "dates('initialize');" << endl + << "dseries('initialize');" << endl + << "% Define global variables." << endl << "global M_ options_ oo_ estim_params_ bayestopt_ dataset_ dataset_info estimation_info ys0_ ex0_" << endl << "options_ = [];" << endl << "M_.fname = '" << basename << "';" << endl @@ -734,7 +734,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo bool hasModelChanged = !dynamic_model.isChecksumMatching(basename); if (!check_model_changes) hasModelChanged = true; - + if (hasModelChanged) { // Erase possible remnants of previous runs @@ -749,7 +749,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo unlink((basename + "_steadystate2.m").c_str()); unlink((basename + "_set_auxiliary_variables.m").c_str()); } - + if (!use_dll) { mOutputFile << "erase_compiled_function('" + basename + "_static');" << endl; @@ -757,7 +757,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo } #if defined(_WIN32) || defined(__CYGWIN32__) -#if (defined(_MSC_VER) && _MSC_VER < 1700) +# if (defined(_MSC_VER) && _MSC_VER < 1700) // If using USE_DLL with MSVC 10.0 or earlier, check that the user didn't use a function not supported by the compiler (because MSVC <= 10.0 doesn't comply with C99 standard) if (use_dll && msvc) { @@ -777,7 +777,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo exit(EXIT_FAILURE); } } -#endif +# endif #endif // Compile the dynamic MEX file for use_dll option @@ -787,10 +787,10 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo #if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__) if (msvc) // MATLAB/Windows + Microsoft Visual C++ - mOutputFile << "dyn_mex('msvc', '" << basename << "', " << !check_model_changes << ")" << endl; + mOutputFile << "dyn_mex('msvc', '" << basename << "', " << !check_model_changes << ")" << endl; else if (cygwin) // MATLAB/Windows + Cygwin g++ - mOutputFile << "dyn_mex('cygwin', '" << basename << "', " << !check_model_changes << ")" << endl; + mOutputFile << "dyn_mex('cygwin', '" << basename << "', " << !check_model_changes << ")" << endl; else if (mingw) // MATLAB/Windows + MinGW g++ mOutputFile << "dyn_mex('mingw', '" << basename << "', " << !check_model_changes << ")" << endl; @@ -868,7 +868,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo config_file.writeEndParallel(mOutputFile); mOutputFile << endl << endl - << "disp(['Total computing time : ' dynsec2hms(toc(tic0)) ]);" << endl; + << "disp(['Total computing time : ' dynsec2hms(toc(tic0)) ]);" << endl; if (!no_warn) { @@ -879,7 +879,6 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo << " disp('Note: warning(s) encountered in MATLAB/Octave code')" << endl << "end" << endl; } - if (!no_log) mOutputFile << "diary off" << endl; @@ -890,16 +889,16 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo { // Create static and dynamic files if (dynamic_model.equation_number() > 0) - { - if (!no_static) - { - static_model.writeStaticFile(basename, block, byte_code, use_dll, false); - static_model.writeParamsDerivativesFile(basename, false); - } + { + if (!no_static) + { + static_model.writeStaticFile(basename, block, byte_code, use_dll, false); + static_model.writeParamsDerivativesFile(basename, false); + } - dynamic_model.writeDynamicFile(basename, block, byte_code, use_dll, mod_file_struct.order_option, false); - dynamic_model.writeParamsDerivativesFile(basename, false); - } + dynamic_model.writeDynamicFile(basename, block, byte_code, use_dll, mod_file_struct.order_option, false); + dynamic_model.writeParamsDerivativesFile(basename, false); + } // Create steady state file steady_state_model.writeSteadyStateFile(basename, mod_file_struct.ramsey_model_present, false); @@ -911,7 +910,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo void ModFile::writeExternalFiles(const string &basename, FileOutputType output, LanguageOutputType language) const { - switch(language) + switch (language) { case c: writeExternalFilesC(basename, output); @@ -939,7 +938,6 @@ ModFile::writeExternalFilesC(const string &basename, FileOutputType output) cons if (!no_static) static_model.writeStaticFile(basename, false, false, true, false); - // static_model.writeStaticCFile(basename, block, byte_code, use_dll); // static_model.writeParamsDerivativesFileC(basename, cuda); // static_model.writeAuxVarInitvalC(mOutputFile, oMatlabOutsideModel, cuda); @@ -952,8 +950,8 @@ ModFile::writeExternalFilesC(const string &basename, FileOutputType output) cons dynamic_model.writeSecondDerivativesC_csr(basename, cuda); else if (output == third) { - dynamic_model.writeSecondDerivativesC_csr(basename, cuda); - dynamic_model.writeThirdDerivativesC_csr(basename, cuda); + dynamic_model.writeSecondDerivativesC_csr(basename, cuda); + dynamic_model.writeThirdDerivativesC_csr(basename, cuda); } } @@ -997,7 +995,7 @@ ModFile::writeModelC(const string &basename) const // Print statements for (vector::const_iterator it = statements.begin(); it != statements.end(); it++) - (*it)->writeCOutput(mDriverCFile, basename); + (*it)->writeCOutput(mDriverCFile, basename); mDriverCFile << "} DynareInfo;" << endl; mDriverCFile.close(); @@ -1057,8 +1055,8 @@ ModFile::writeExternalFilesCC(const string &basename, FileOutputType output) con dynamic_model.writeSecondDerivativesC_csr(basename, cuda); else if (output == third) { - dynamic_model.writeSecondDerivativesC_csr(basename, cuda); - dynamic_model.writeThirdDerivativesC_csr(basename, cuda); + dynamic_model.writeSecondDerivativesC_csr(basename, cuda); + dynamic_model.writeThirdDerivativesC_csr(basename, cuda); } } @@ -1102,7 +1100,7 @@ ModFile::writeModelCC(const string &basename) const // Print statements for (vector::const_iterator it = statements.begin(); it != statements.end(); it++) - (*it)->writeCOutput(mDriverCFile, basename); + (*it)->writeCOutput(mDriverCFile, basename); mDriverCFile << "};" << endl; mDriverCFile.close(); @@ -1178,7 +1176,7 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output) << "if isfile(\"" << basename << "SteadyState2.jl" "\")" << endl << " using " << basename << "SteadyState2" << endl << "end" << endl << endl - << "export model_, options_, oo_" << endl; + << "export model_, options_, oo_" << endl; // Write Output jlOutputFile << endl @@ -1236,9 +1234,9 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output) steady_state_model.writeSteadyStateFile(basename, mod_file_struct.ramsey_model_present, true); // Print statements (includes parameter values) - for (vector::const_iterator it = statements.begin(); - it != statements.end(); it++) - (*it)->writeJuliaOutput(jlOutputFile, basename); + for (vector::const_iterator it = statements.begin(); + it != statements.end(); it++) + (*it)->writeJuliaOutput(jlOutputFile, basename); jlOutputFile << "model_.static = " << basename << "Static.static!" << endl << "model_.dynamic = " << basename << "Dynamic.dynamic!" << endl @@ -1258,7 +1256,7 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output) << " using " << basename << "DynamicParamsDerivs" << endl << " model_.dynamic_params_derivs = " << basename << "DynamicParamsDerivs.params_derivs" << endl << "end" << endl - << "end" << endl; + << "end" << endl; jlOutputFile.close(); cout << "done" << endl; } diff --git a/ModFile.hh b/ModFile.hh index 68df1adf..a4812471 100644 --- a/ModFile.hh +++ b/ModFile.hh @@ -41,7 +41,7 @@ using namespace std; // for checksum computation #ifndef PRIVATE_BUFFER_SIZE -#define PRIVATE_BUFFER_SIZE 1024 +# define PRIVATE_BUFFER_SIZE 1024 #endif //! The abstract representation of a "mod" file @@ -91,9 +91,9 @@ public: bool differentiate_forward_vars; /*! If the 'differentiate_forward_vars' option is used, contains the set of - endogenous with respect to which to do the transformation; - if empty, means that the transformation must be applied to all endos - with a lead */ + endogenous with respect to which to do the transformation; + if empty, means that the transformation must be applied to all endos + with a lead */ vector differentiate_forward_vars_subset; //! Are nonstationary variables present ? diff --git a/ModelTree.cc b/ModelTree.cc index ed5ecdbe..9bfb30ea 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -212,7 +212,7 @@ ModelTree::computeNonSingularNormalization(jacob_map_t &contemporaneous_jacobian 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; } - catch(DataTree::UnknownDerivIDException &e) + 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; @@ -332,19 +332,19 @@ ModelTree::computePrologueAndEpilogue(const jacob_map_t &static_jacobian_arg, ve eq2endo[*it] = i; equation_reordered[i] = i; variable_reordered[*it] = i; - } - if (cutoff == 0) - { + } + if (cutoff == 0) + { set > endo; for (int i = 0; i < n; i++) - { + { endo.clear(); - equations[i]->collectEndogenous(endo); - for (set >::const_iterator it = endo.begin(); it != endo.end(); it++) - IM[i * n + endo2eq[it->first]] = true; - } - } - else + equations[i]->collectEndogenous(endo); + for (set >::const_iterator it = endo.begin(); it != endo.end(); it++) + IM[i * n + endo2eq[it->first]] = true; + } + } + else for (jacob_map_t::const_iterator it = static_jacobian_arg.begin(); it != static_jacobian_arg.end(); it++) IM[it->first.first * n + endo2eq[it->first.second]] = true; bool something_has_been_done = true; @@ -546,22 +546,22 @@ ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(const jacob { reverse_equation_reordered[equation_reordered[i]] = i; reverse_variable_reordered[variable_reordered[i]] = i; - } - jacob_map_t tmp_normalized_contemporaneous_jacobian; - if (cutoff == 0) - { + } + jacob_map_t tmp_normalized_contemporaneous_jacobian; + if (cutoff == 0) + { set > endo; for (int i = 0; i < nb_var; i++) - { + { endo.clear(); - equations[i]->collectEndogenous(endo); - for (set >::const_iterator it = endo.begin(); it != endo.end(); it++) - tmp_normalized_contemporaneous_jacobian[make_pair(i, it->first)] = 1; + equations[i]->collectEndogenous(endo); + for (set >::const_iterator it = endo.begin(); it != endo.end(); it++) + tmp_normalized_contemporaneous_jacobian[make_pair(i, it->first)] = 1; - } - } - else - tmp_normalized_contemporaneous_jacobian = static_jacobian; + } + } + else + tmp_normalized_contemporaneous_jacobian = static_jacobian; for (jacob_map_t::const_iterator it = tmp_normalized_contemporaneous_jacobian.begin(); it != tmp_normalized_contemporaneous_jacobian.end(); it++) if (reverse_equation_reordered[it->first.first] >= (int) prologue && reverse_equation_reordered[it->first.first] < (int) (nb_var - epilogue) && reverse_variable_reordered[it->first.second] >= (int) prologue && reverse_variable_reordered[it->first.second] < (int) (nb_var - epilogue) @@ -887,7 +887,7 @@ ModelTree::reduceBlocksAndTypeDetermination(const dynamic_jacob_map_t &dynamic_j int c_Size = (block_type_size_mfs[block_type_size_mfs.size()-1]).second.first; int first_equation = (block_type_size_mfs[block_type_size_mfs.size()-1]).first.second; if (c_Size > 0 && ((prev_Type == EVALUATE_FORWARD && Simulation_Type == EVALUATE_FORWARD && !is_lead) - || (prev_Type == EVALUATE_BACKWARD && Simulation_Type == EVALUATE_BACKWARD && !is_lag))) + || (prev_Type == EVALUATE_BACKWARD && Simulation_Type == EVALUATE_BACKWARD && !is_lag))) { for (int j = first_equation; j < first_equation+c_Size; j++) { @@ -1125,10 +1125,10 @@ ModelTree::computeTemporaryTerms(bool is_matlab) temporary_terms_g2.clear(); temporary_terms_g3.clear(); map temp_terms_map; - temp_terms_map[eResiduals]=temporary_terms_res; - temp_terms_map[eFirstDeriv]=temporary_terms_g1; - temp_terms_map[eSecondDeriv]=temporary_terms_g2; - temp_terms_map[eThirdDeriv]=temporary_terms_g3; + temp_terms_map[eResiduals] = temporary_terms_res; + temp_terms_map[eFirstDeriv] = temporary_terms_g1; + temp_terms_map[eSecondDeriv] = temporary_terms_g2; + temp_terms_map[eThirdDeriv] = temporary_terms_g3; for (vector::iterator it = equations.begin(); it != equations.end(); it++) @@ -1332,17 +1332,17 @@ ModelTree::compileTemporaryTerms(ostream &code_file, unsigned int &instruction_n (*it)->compileExternalFunctionOutput(code_file, instruction_number, false, tt2, map_idx, dynamic, steady_dynamic, tef_terms); } - FNUMEXPR_ fnumexpr(TemporaryTerm, (int) (map_idx.find((*it)->idx)->second)); + FNUMEXPR_ fnumexpr(TemporaryTerm, (int)(map_idx.find((*it)->idx)->second)); fnumexpr.write(code_file, instruction_number); (*it)->compile(code_file, instruction_number, false, tt2, map_idx, dynamic, steady_dynamic, tef_terms); if (dynamic) { - FSTPT_ fstpt((int) (map_idx.find((*it)->idx)->second)); + FSTPT_ fstpt((int)(map_idx.find((*it)->idx)->second)); fstpt.write(code_file, instruction_number); } else { - FSTPST_ fstpst((int) (map_idx.find((*it)->idx)->second)); + FSTPST_ fstpst((int)(map_idx.find((*it)->idx)->second)); fstpst.write(code_file, instruction_number); } // Insert current node into tt2 @@ -1577,7 +1577,7 @@ ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output bool wrote_eq_tag = false; if (write_equation_tags) { - for (vector > >::const_iterator iteqt = equation_tags.begin(); + for (vector > >::const_iterator iteqt = equation_tags.begin(); iteqt != equation_tags.end(); iteqt++) if (iteqt->first == eq) { @@ -1792,11 +1792,11 @@ ModelTree::computeParamsDerivativesTemporaryTerms() map > reference_count; params_derivs_temporary_terms.clear(); map temp_terms_map; - temp_terms_map[eResidualsParamsDeriv]=params_derivs_temporary_terms_res; - temp_terms_map[eJacobianParamsDeriv]=params_derivs_temporary_terms_g1; - temp_terms_map[eResidualsParamsSecondDeriv]=params_derivs_temporary_terms_res2; - temp_terms_map[eJacobianParamsSecondDeriv]=params_derivs_temporary_terms_g12; - temp_terms_map[eHessianParamsDeriv]=params_derivs_temporary_terms_g2; + temp_terms_map[eResidualsParamsDeriv] = params_derivs_temporary_terms_res; + temp_terms_map[eJacobianParamsDeriv] = params_derivs_temporary_terms_g1; + temp_terms_map[eResidualsParamsSecondDeriv] = params_derivs_temporary_terms_res2; + temp_terms_map[eJacobianParamsSecondDeriv] = params_derivs_temporary_terms_g12; + temp_terms_map[eHessianParamsDeriv] = params_derivs_temporary_terms_g2; for (first_derivatives_t::iterator it = residuals_params_derivatives.begin(); it != residuals_params_derivatives.end(); it++) @@ -1839,9 +1839,9 @@ ModelTree::computeParamsDerivativesTemporaryTerms() params_derivs_temporary_terms_g2 = temp_terms_map[eHessianParamsDeriv]; } -bool ModelTree::isNonstationary(int symb_id) const +bool +ModelTree::isNonstationary(int symb_id) const { return (nonstationary_symbols_map.find(symb_id) != nonstationary_symbols_map.end()); } - diff --git a/ModelTree.hh b/ModelTree.hh index 1de07d4b..f3c34836 100644 --- a/ModelTree.hh +++ b/ModelTree.hh @@ -128,7 +128,6 @@ protected: */ third_derivatives_t hessian_params_derivatives; - //! Temporary terms for the static/dynamic file (those which will be noted Txxxx) temporary_terms_t temporary_terms; temporary_terms_t temporary_terms_res; @@ -144,7 +143,6 @@ protected: temporary_terms_t params_derivs_temporary_terms_g12; temporary_terms_t params_derivs_temporary_terms_g2; - //! Trend variables and their growth factors map trend_symbols_map; @@ -177,7 +175,7 @@ protected: void computeTemporaryTerms(bool is_matlab); //! Computes temporary terms for the file containing parameters derivatives void computeParamsDerivativesTemporaryTerms(); -//! Writes temporary terms + //! Writes temporary terms void writeTemporaryTerms(const temporary_terms_t &tt, const temporary_terms_t &ttm1, ostream &output, ExprNodeOutputType output_type, deriv_node_temp_terms_t &tef_terms) const; //! Compiles temporary terms void compileTemporaryTerms(ostream &code_file, unsigned int &instruction_number, const temporary_terms_t &tt, map_idx_t map_idx, bool dynamic, bool steady_dynamic) const; @@ -268,11 +266,12 @@ protected: virtual unsigned int getBlockMaxLag(int block_number) const = 0; //! Return the maximum lead in a block virtual unsigned int getBlockMaxLead(int block_number) const = 0; - inline void setBlockLeadLag(int block, int max_lag, int max_lead) - { - block_lag_lead[block] = make_pair(max_lag, max_lead); - }; - + inline void + setBlockLeadLag(int block, int max_lag, int max_lead) + { + block_lag_lead[block] = make_pair(max_lag, max_lead); + }; + //! Return the type of equation (equation_number) belonging to the block block_number virtual EquationType getBlockEquationType(int block_number, int equation_number) const = 0; //! Return true if the equation has been normalized diff --git a/ParsingDriver.cc b/ParsingDriver.cc index bce54085..32b1b3ac 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -134,7 +134,7 @@ ParsingDriver::create_error_string(const Dynare::parser::location_type &l, const stream << ", cols " << l.begin.column << "-" << l.end.column - 1; else stream << ", col " << l.begin.column << " -" - << " line " << l.end.line << ", col " << l.end.column - 1; + << " line " << l.end.line << ", col " << l.end.column - 1; stream << ": " << m << endl; } @@ -259,8 +259,8 @@ void ParsingDriver::declare_statement_local_variable(string *name) { if (mod_file->symbol_table.exists(*name)) - error("Symbol " + *name + " cannot be assigned within a statement " + - "while being assigned elsewhere in the modfile"); + error("Symbol " + *name + " cannot be assigned within a statement " + +"while being assigned elsewhere in the modfile"); declare_symbol(name, eStatementDeclaredVariable, NULL, NULL); delete name; } @@ -366,7 +366,7 @@ ParsingDriver::add_model_variable(string *name) { // This could be endog or param too. Just declare something to continue parsing, // knowing that processing will end at the end of parsing of the model block - declare_exogenous(new string (*name)); + declare_exogenous(new string(*name)); undeclared_model_vars.insert(*name); symb_id = mod_file->symbol_table.getID(*name); } @@ -752,7 +752,7 @@ ParsingDriver::add_det_shock(string *var, bool conditional_forecast) } det_shocks[symb_id] = v; - + det_shocks_periods.clear(); det_shocks_values.clear(); delete var; @@ -888,7 +888,7 @@ ParsingDriver::end_svar_identification() mod_file->addStatement(new SvarIdentificationStatement(svar_ident_restrictions, svar_upper_cholesky, svar_lower_cholesky, - svar_constants_exclusion, + svar_constants_exclusion, mod_file->symbol_table)); svar_restriction_symbols.clear(); svar_equation_restrictions.clear(); @@ -910,19 +910,19 @@ ParsingDriver::combine_lag_and_restriction(string *lag) for (map >::const_iterator it = svar_equation_restrictions.begin(); it != svar_equation_restrictions.end(); it++) for (vector::const_iterator it1 = it->second.begin(); - it1 != it->second.end(); it1++) + it1 != it->second.end(); it1++) { - SvarIdentificationStatement::svar_identification_restriction new_restriction; - new_restriction.equation = it->first; - if (current_lag > 0) - new_restriction.restriction_nbr = ++svar_Ri_restriction_nbr[it->first]; - else - new_restriction.restriction_nbr = ++svar_Qi_restriction_nbr[it->first]; - new_restriction.lag = current_lag; - new_restriction.variable = *it1; - new_restriction.value = data_tree->One; - svar_ident_restrictions.push_back(new_restriction); - } + SvarIdentificationStatement::svar_identification_restriction new_restriction; + new_restriction.equation = it->first; + if (current_lag > 0) + new_restriction.restriction_nbr = ++svar_Ri_restriction_nbr[it->first]; + else + new_restriction.restriction_nbr = ++svar_Qi_restriction_nbr[it->first]; + new_restriction.lag = current_lag; + new_restriction.variable = *it1; + new_restriction.value = data_tree->One; + svar_ident_restrictions.push_back(new_restriction); + } // svar_ident_exclusion_values[make_pair(current_lag, it->first)] = it->second; svar_upper_cholesky = false; @@ -962,7 +962,7 @@ ParsingDriver::add_in_svar_restriction_symbols(string *tmp_var) delete tmp_var; } -void +void ParsingDriver::add_restriction_equation_nbr(string *eq_nbr) { svar_equation_nbr = atoi(eq_nbr->c_str()); @@ -986,14 +986,14 @@ ParsingDriver::add_positive_restriction_element(expr_t value, string *variable, // if the expression is not on the left handside, change its sign if (!svar_left_handside) value = add_uminus(value); - + add_restriction_element(value, variable, lag); } void ParsingDriver::add_positive_restriction_element(string *variable, string *lag) { - expr_t value(data_tree->One); + expr_t value(data_tree->One); // if the expression is not on the left handside, change its sign if (!svar_left_handside) @@ -1015,7 +1015,7 @@ ParsingDriver::add_negative_restriction_element(expr_t value, string *variable, void ParsingDriver::add_negative_restriction_element(string *variable, string *lag) { - expr_t value(data_tree->One); + expr_t value(data_tree->One); // if the expression is on the left handside, change its sign if (svar_left_handside) @@ -1034,21 +1034,21 @@ ParsingDriver::add_restriction_element(expr_t value, string *variable, string *l if (svar_restriction_type == ParsingDriver::NOT_SET) { if (current_lag == 0) - { - svar_restriction_type = ParsingDriver::Qi_TYPE; - ++svar_Qi_restriction_nbr[svar_equation_nbr]; - } + { + svar_restriction_type = ParsingDriver::Qi_TYPE; + ++svar_Qi_restriction_nbr[svar_equation_nbr]; + } else - { - svar_restriction_type = ParsingDriver::Ri_TYPE; - ++svar_Ri_restriction_nbr[svar_equation_nbr]; - } + { + svar_restriction_type = ParsingDriver::Ri_TYPE; + ++svar_Ri_restriction_nbr[svar_equation_nbr]; + } } else { if ((svar_restriction_type == Qi_TYPE && current_lag > 0) - || (svar_restriction_type == Ri_TYPE && current_lag == 0)) - error("SVAR_IDENTIFICATION: a single restrictions must affect either Qi or Ri, but not both"); + || (svar_restriction_type == Ri_TYPE && current_lag == 0)) + error("SVAR_IDENTIFICATION: a single restrictions must affect either Qi or Ri, but not both"); } SvarIdentificationStatement::svar_identification_restriction new_restriction; new_restriction.equation = svar_equation_nbr; @@ -1213,7 +1213,7 @@ ParsingDriver::option_symbol_list(const string &name_option) != options_list.symbol_list_options.end()) error("option " + name_option + " declared twice"); - if (name_option.compare("irf_shocks")==0) + if (name_option.compare("irf_shocks") == 0) { vector shocks = symbol_list.get_symbols(); for (vector::const_iterator it = shocks.begin(); @@ -1222,7 +1222,7 @@ ParsingDriver::option_symbol_list(const string &name_option) error("Variables passed to irf_shocks must be exogenous. Caused by: " + *it); } - if (name_option.compare("ms.parameters")==0) + if (name_option.compare("ms.parameters") == 0) { vector parameters = symbol_list.get_symbols(); for (vector::const_iterator it = parameters.begin(); @@ -1415,7 +1415,7 @@ ParsingDriver::copy_subsamples(string *to_name1, string *to_name2, string *from_ if (!from_name2->empty()) check_symbol_existence(*from_name2); - if (subsample_declarations.find(make_pair(*from_name1,*from_name2)) == subsample_declarations.end()) + if (subsample_declarations.find(make_pair(*from_name1, *from_name2)) == subsample_declarations.end()) { string err = *from_name1; if (!from_name2->empty()) @@ -1426,8 +1426,8 @@ ParsingDriver::copy_subsamples(string *to_name1, string *to_name2, string *from_ mod_file->addStatement(new SubsamplesEqualStatement(*to_name1, *to_name2, *from_name1, *from_name2, mod_file->symbol_table)); - subsample_declarations[make_pair(*to_name1, *to_name2)] = - subsample_declarations[make_pair(*from_name1, *from_name2)]; + subsample_declarations[make_pair(*to_name1, *to_name2)] + = subsample_declarations[make_pair(*from_name1, *from_name2)]; delete to_name1; delete to_name2; @@ -1461,7 +1461,7 @@ ParsingDriver::check_subsample_declaration_exists(string *name1, string *subsamp if (subsample_name->empty()) return; - string *str_empty = new string (""); + string *str_empty = new string(""); check_subsample_declaration_exists(name1, str_empty, subsample_name); delete str_empty; } @@ -1474,13 +1474,13 @@ ParsingDriver::check_subsample_declaration_exists(string *name1, string *name2, check_symbol_existence(*name1); if (!name2->empty()) - check_symbol_existence(*name2); + check_symbol_existence(*name2); subsample_declarations_t::const_iterator it = subsample_declarations.find(make_pair(*name1, *name2)); if (it == subsample_declarations.end()) { it = subsample_declarations.find(make_pair(*name2, *name1)); - if (it== subsample_declarations.end()) + if (it == subsample_declarations.end()) { string err = *name1; if (!name2->empty()) @@ -1494,7 +1494,6 @@ ParsingDriver::check_subsample_declaration_exists(string *name1, string *name2, error("The subsample name " + *subsample_name + " was not previously declared in a subsample statement."); } - void ParsingDriver::set_prior(string *name, string *subsample_name) { @@ -1509,9 +1508,9 @@ ParsingDriver::set_prior(string *name, string *subsample_name) } void -ParsingDriver::set_joint_prior(vector*symbol_vec) +ParsingDriver::set_joint_prior(vector *symbol_vec) { - for (vector::const_iterator it=symbol_vec->begin(); it != symbol_vec->end(); it++) + for (vector::const_iterator it = symbol_vec->begin(); it != symbol_vec->end(); it++) add_joint_parameter(*it); mod_file->addStatement(new JointPriorStatement(joint_parameters, prior_shape, options_list)); joint_parameters.clear(); @@ -1621,7 +1620,7 @@ ParsingDriver::check_symbol_is_endogenous_or_exogenous(string *name) { check_symbol_existence(*name); int symb_id = mod_file->symbol_table.getID(*name); - switch(mod_file->symbol_table.getType(symb_id)) + switch (mod_file->symbol_table.getType(symb_id)) { case eEndogenous: case eExogenous: @@ -2034,7 +2033,7 @@ ParsingDriver::ms_compute_probabilities() void ParsingDriver::ms_irf() { - mod_file->addStatement(new MSSBVARIrfStatement(symbol_list,options_list)); + mod_file->addStatement(new MSSBVARIrfStatement(symbol_list, options_list)); symbol_list.clear(); options_list.clear(); } @@ -2199,7 +2198,7 @@ ParsingDriver::add_model_equal(expr_t arg1, expr_t arg2) expr_t id = model_tree->AddEqual(arg1, arg2); // Detect if the equation is tagged [static] - bool is_static_only = false; + bool is_static_only = false; for (vector >::const_iterator it = eq_tags.begin(); it != eq_tags.end(); ++it) if (it->first == "static") @@ -2212,7 +2211,7 @@ ParsingDriver::add_model_equal(expr_t arg1, expr_t arg2) { if (!id->isInStaticForm()) error("An equation tagged [static] cannot contain leads, lags, expectations or STEADY_STATE operators"); - + dynamic_model->addStaticOnlyEquation(id, location.begin.line); } else @@ -2705,7 +2704,7 @@ ParsingDriver::add_model_var_or_external_function(string *function_name, bool in if (rv.first) { // assume it's a lead/lagged variable - declare_exogenous(new string (*function_name)); + declare_exogenous(new string(*function_name)); return add_model_variable(mod_file->symbol_table.getID(*function_name), (int) rv.second); } else @@ -2870,18 +2869,19 @@ ParsingDriver::add_moment_calibration_item(string *endo1, string *endo2, string c.lags = *lags; delete lags; - + assert(range->size() == 2); c.lower_bound = *((*range)[0]); c.upper_bound = *((*range)[1]); delete (*range)[0]; delete (*range)[1]; delete range; - + moment_calibration_constraints.push_back(c); } -void ParsingDriver::end_moment_calibration() +void +ParsingDriver::end_moment_calibration() { mod_file->addStatement(new MomentCalibration(moment_calibration_constraints, mod_file->symbol_table)); @@ -2907,18 +2907,19 @@ ParsingDriver::add_irf_calibration_item(string *endo, string *periods, string *e if (mod_file->symbol_table.getType(*exo) != eExogenous) error("Variable " + *endo + " is not an exogenous."); delete exo; - + assert(range->size() == 2); c.lower_bound = *((*range)[0]); c.upper_bound = *((*range)[1]); delete (*range)[0]; delete (*range)[1]; delete range; - + irf_calibration_constraints.push_back(c); } -void ParsingDriver::end_irf_calibration() +void +ParsingDriver::end_irf_calibration() { mod_file->addStatement(new IrfCalibration(irf_calibration_constraints, mod_file->symbol_table, @@ -2940,7 +2941,6 @@ ParsingDriver::histval_file(string *filename) delete filename; } - void ParsingDriver::perfect_foresight_setup() { @@ -2958,7 +2958,7 @@ ParsingDriver::perfect_foresight_solver() void ParsingDriver::prior_posterior_function(bool prior_func) { - mod_file->addStatement(new PriorPosteriorFunctionStatement((bool)prior_func, options_list)); + mod_file->addStatement(new PriorPosteriorFunctionStatement((bool) prior_func, options_list)); options_list.clear(); } @@ -2972,25 +2972,25 @@ ParsingDriver::add_ramsey_constraints_statement() void ParsingDriver::ramsey_constraint_add_less(const string *name, const expr_t rhs) { - add_ramsey_constraint(name,oLess,rhs); + add_ramsey_constraint(name, oLess, rhs); } void ParsingDriver::ramsey_constraint_add_greater(const string *name, const expr_t rhs) { - add_ramsey_constraint(name,oGreater,rhs); + add_ramsey_constraint(name, oGreater, rhs); } void ParsingDriver::ramsey_constraint_add_less_equal(const string *name, const expr_t rhs) { - add_ramsey_constraint(name,oLessEqual,rhs); + add_ramsey_constraint(name, oLessEqual, rhs); } void ParsingDriver::ramsey_constraint_add_greater_equal(const string *name, const expr_t rhs) { - add_ramsey_constraint(name,oGreaterEqual,rhs); + add_ramsey_constraint(name, oGreaterEqual, rhs); } void @@ -3027,7 +3027,6 @@ ParsingDriver::add_shock_group_element(string *name) delete name; } - void ParsingDriver::add_shock_group(string *name) { diff --git a/ParsingDriver.hh b/ParsingDriver.hh index b25105f4..f6f04f8a 100644 --- a/ParsingDriver.hh +++ b/ParsingDriver.hh @@ -171,7 +171,7 @@ private: map > svar_equation_restrictions; //! Temporary storage for restrictions in an equation within an svar_identification block vector svar_restriction_symbols; - //! Temporary storage for constants exculsion within an svar_identification + //! Temporary storage for constants exculsion within an svar_identification bool svar_constants_exclusion; //! Temporary storage for upper cholesky within an svar_identification block bool svar_upper_cholesky; @@ -182,8 +182,8 @@ private: //! Temporary storage for left/right handside of a restriction equation within an svar_identificaton block bool svar_left_handside; //! Temporary storage for current restriction number in svar_identification block - map svar_Qi_restriction_nbr; - map svar_Ri_restriction_nbr; + map svar_Qi_restriction_nbr; + map svar_Ri_restriction_nbr; //! Stores undeclared model variables set undeclared_model_vars; //! Temporary storage for restriction type @@ -239,7 +239,9 @@ private: ostringstream model_errors; public: - ParsingDriver(WarningConsolidation &warnings_arg, bool nostrict_arg) : warnings(warnings_arg), nostrict(nostrict_arg), model_error_encountered(false) { }; + ParsingDriver(WarningConsolidation &warnings_arg, bool nostrict_arg) : warnings(warnings_arg), nostrict(nostrict_arg), model_error_encountered(false) + { + }; //! Starts parsing, and constructs the MOD file representation /*! The returned pointer should be deleted after use */ @@ -449,11 +451,11 @@ public: //! Sets the prior for a parameter void set_prior(string *arg1, string *arg2); //! Sets the joint prior for a set of parameters - void set_joint_prior(vector*symbol_vec); + void set_joint_prior(vector *symbol_vec); //! Adds a parameters to the list of joint parameters void add_joint_parameter(string *name); //! Adds the variance option to its temporary holding place - void set_prior_variance(expr_t variance=NULL); + void set_prior_variance(expr_t variance = NULL); //! Copies the prior from_name to_name void copy_prior(string *to_declaration_type, string *to_name1, string *to_name2, string *to_subsample_name, string *from_declaration_type, string *from_name1, string *from_name2, string *from_subsample_name); @@ -468,7 +470,7 @@ public: void set_std_options(string *arg1, string *arg2); //! Sets the prior for estimated correlation void set_corr_prior(string *arg1, string *arg2, string *arg3); - //! Sets the options for estimated correlation + //! Sets the options for estimated correlation void set_corr_options(string *arg1, string *arg2, string *arg3); //! Runs estimation process void run_estimation(); @@ -501,11 +503,11 @@ public: void add_restriction_equation_nbr(string *eq_nbr); //! Svar_Identification Statement: record presence of equal sign void add_restriction_equal(); - //! Svar_Idenditification Statement: add coefficient of a linear restriction (positive value) + //! Svar_Idenditification Statement: add coefficient of a linear restriction (positive value) void add_positive_restriction_element(expr_t value, string *variable, string *lag); - //! Svar_Idenditification Statement: add unit coefficient of a linear restriction + //! Svar_Idenditification Statement: add unit coefficient of a linear restriction void add_positive_restriction_element(string *variable, string *lag); - //! Svar_Idenditification Statement: add coefficient of a linear restriction (negative value) + //! Svar_Idenditification Statement: add coefficient of a linear restriction (negative value) void add_negative_restriction_element(expr_t value, string *variable, string *lag); //! Svar_Idenditification Statement: add negative unit coefficient of a linear restriction void add_negative_restriction_element(string *variable, string *lag); @@ -534,7 +536,7 @@ public: void run_load_params_and_steady_state(string *filename); void run_save_params_and_steady_state(string *filename); void run_identification(); - void add_mc_filename(string *filename, string *prior = new string("1")); + void add_mc_filename(string *filename, string *prior = new string ("1")); void run_model_comparison(); //! Begin a planner_objective statement void begin_planner_objective(); diff --git a/Shocks.cc b/Shocks.cc index af402624..0aa7fdfa 100644 --- a/Shocks.cc +++ b/Shocks.cc @@ -94,9 +94,9 @@ ShocksStatement::writeOutput(ostream &output, const string &basename, bool minim output << "M_.det_shocks = [];" << endl; output << "M_.Sigma_e = zeros(" << symbol_table.exo_nbr() << ", " - << symbol_table.exo_nbr() << ");" << endl - << "M_.Correlation_matrix = eye(" << symbol_table.exo_nbr() << ", " - << symbol_table.exo_nbr() << ");" << endl; + << symbol_table.exo_nbr() << ");" << endl + << "M_.Correlation_matrix = eye(" << symbol_table.exo_nbr() << ", " + << symbol_table.exo_nbr() << ");" << endl; if (has_calibrated_measurement_errors()) output << "M_.H = zeros(" << symbol_table.observedVariablesNbr() << ", " @@ -254,7 +254,7 @@ ShocksStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidati { int symb_id1 = it->first.first; int symb_id2 = it->first.second; - + if (!((symbol_table.getType(symb_id1) == eExogenous && symbol_table.getType(symb_id2) == eExogenous) || (symbol_table.isObservedVariable(symb_id1) @@ -272,7 +272,7 @@ ShocksStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidati { int symb_id1 = it->first.first; int symb_id2 = it->first.second; - + if (!((symbol_table.getType(symb_id1) == eExogenous && symbol_table.getType(symb_id2) == eExogenous) || (symbol_table.isObservedVariable(symb_id1) @@ -465,7 +465,7 @@ ShockGroupsStatement::writeOutput(ostream &output, const string &basename, bool { int i = 1; bool unique_label = true; - for (vector::const_iterator it = shock_groups.begin(); it != shock_groups.end(); it++, unique_label=true) + for (vector::const_iterator it = shock_groups.begin(); it != shock_groups.end(); it++, unique_label = true) { for (vector::const_iterator it1 = it+1; it1 != shock_groups.end(); it1++) if (it->name == it1->name) @@ -482,7 +482,7 @@ ShockGroupsStatement::writeOutput(ostream &output, const string &basename, bool << ".group" << i << ".label = '" << it->name << "';" << endl << "M_.shock_groups." << name << ".group" << i << ".shocks = {"; - for ( vector::const_iterator it1 = it->list.begin(); it1 != it->list.end(); it1++) + for (vector::const_iterator it1 = it->list.begin(); it1 != it->list.end(); it1++) output << " '" << *it1 << "'"; output << "};" << endl; i++; diff --git a/Shocks.hh b/Shocks.hh index f89e1fba..1c7abb91 100644 --- a/Shocks.hh +++ b/Shocks.hh @@ -160,5 +160,5 @@ public: ShockGroupsStatement(const group_t &shock_groups_arg, const string &name_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; - + #endif diff --git a/Statement.cc b/Statement.cc index d43d1144..d1a34bd2 100644 --- a/Statement.cc +++ b/Statement.cc @@ -77,7 +77,8 @@ Statement::writeCOutput(ostream &output, const string &basename) { } -void Statement::writeJuliaOutput(ostream &output, const string &basename) +void +Statement::writeJuliaOutput(ostream &output, const string &basename) { } @@ -100,7 +101,7 @@ NativeStatement::writeOutput(ostream &output, const string &basename, bool minim sregex regex_dollar = sregex::compile("(\\$)"+date_regex); string ns = regex_replace(native_statement, regex_lookbehind, "dates('$&')"); - ns = regex_replace(ns, regex_dollar, "$2" ); //replace $DATE with DATE + ns = regex_replace(ns, regex_dollar, "$2"); //replace $DATE with DATE output << ns << endl; } @@ -161,9 +162,9 @@ OptionsList::writeOutput(ostream &output, const string &option_group) const { // Initialize option_group as an empty struct iff the field does not exist! unsigned idx = option_group.find_last_of("."); - if (idx(*it) != NULL) (*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)); fnumexpr.write(code_file, instruction_number); (*it)->compile(code_file, instruction_number, false, tt2, map_idx, false, false, tef_terms); - FSTPST_ fstpst((int) (map_idx.find((*it)->idx)->second)); + FSTPST_ fstpst((int)(map_idx.find((*it)->idx)->second)); fstpst.write(code_file, instruction_number); // Insert current node into tt2 tt2.insert(*it); @@ -854,12 +854,12 @@ StaticModel::writeModelEquationsCode_Block(const string file_name, const string if (dynamic_cast(*it) != NULL) (*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)); fnumexpr.write(code_file, instruction_number); (*it)->compile(code_file, instruction_number, false, tt3, map_idx2[block], false, false, tef_terms); - FSTPST_ fstpst((int) (map_idx2[block].find((*it)->idx)->second)); + FSTPST_ fstpst((int)(map_idx2[block].find((*it)->idx)->second)); fstpst.write(code_file, instruction_number); // Insert current node into tt2 tt3.insert(*it); @@ -1058,14 +1058,14 @@ StaticModel::computingPass(const eval_context_t &eval_context, bool no_tmp_terms neweqs.push_back(dynamic_cast(eq_tmp->toStatic(*this))); } - for (unsigned int eq = 0; eq < aux_equations.size(); eq++) + for (unsigned int eq = 0; eq < aux_equations.size(); eq++) { expr_t eq_tmp = aux_equations[eq]->substituteStaticAuxiliaryDefinition(); neweqs.push_back(dynamic_cast(eq_tmp->toStatic(*this))); } - + equations.clear(); - copy(neweqs.begin(),neweqs.end(),back_inserter(equations)); + copy(neweqs.begin(), neweqs.end(), back_inserter(equations)); // Compute derivatives w.r. to all endogenous, and possibly exogenous and exogenous deterministic set vars; @@ -1074,8 +1074,8 @@ StaticModel::computingPass(const eval_context_t &eval_context, bool no_tmp_terms int id = symbol_table.getID(eEndogenous, i); // if (!symbol_table.isAuxiliaryVariableButNotMultiplier(id)) vars.insert(getDerivID(id, 0)); - } - + } + // Launch computations cout << "Computing static model derivatives:" << endl << " - order 1" << endl; @@ -1190,7 +1190,7 @@ StaticModel::writeStaticMFile(const string &func_name) const << "% columns: variables in declaration order" << endl << "% rows: equations in order of declaration" << endl << "%" << endl - << "%" << endl + << "%" << endl << "% Warning : this file is generated automatically by Dynare" << endl << "% from model file (.mod)" << endl << endl; @@ -1338,7 +1338,6 @@ StaticModel::writeStaticModel(ostream &StaticOutput, bool use_dll, bool julia) c int id2 = getSymbIDByDerivID(var2); int id3 = getSymbIDByDerivID(var3); - // Reference column number for the g3 matrix int ref_col = id1 * hessianColsNbr + id2 * JacobianColsNbr + id3; @@ -1440,15 +1439,15 @@ StaticModel::writeStaticModel(ostream &StaticOutput, bool use_dll, bool julia) c // Initialize g3 matrix StaticOutput << "if nargout >= 4," << endl - << " %" << endl - << " % Third order derivatives" << endl - << " %" << endl - << endl; + << " %" << endl + << " % Third order derivatives" << endl + << " %" << endl + << endl; int ncols = hessianColsNbr * JacobianColsNbr; if (third_derivatives.size()) StaticOutput << " v3 = zeros(" << NNZDerivatives[2] << ",3);" << endl - << third_derivatives_output.str() - << " g3 = sparse(v3(:,1),v3(:,2),v3(:,3)," << nrows << "," << ncols << ");" << endl; + << third_derivatives_output.str() + << " g3 = sparse(v3(:,1),v3(:,2),v3(:,3)," << nrows << "," << ncols << ");" << endl; else // Either 3rd derivatives is all zero, or we didn't compute it StaticOutput << " g3 = sparse([],[],[]," << nrows << "," << ncols << ");" << endl; StaticOutput << "end" << endl @@ -1622,7 +1621,6 @@ StaticModel::writeStaticCFile(const string &func_name) const output << "#define max(a, b) (((a) > (b)) ? (a) : (b))" << endl << "#define min(a, b) (((a) > (b)) ? (b) : (a))" << endl; - // Write function definition if oPowerDeriv is used writePowerDerivCHeader(output); writeNormcdfCHeader(output); @@ -1754,7 +1752,7 @@ StaticModel::writeStaticFile(const string &basename, bool block, bool bytecode, chdir(".."); writeStaticBlockMFSFile(basename); } - else if(use_dll) + else if (use_dll) writeStaticCFile(basename); else if (julia) writeStaticJuliaFile(basename); @@ -1859,7 +1857,7 @@ StaticModel::writeOutput(ostream &output, bool block) const for (int i = 0; i < nb_endo; i++) output << " " << equation_reordered[i]+1; output << "];\n"; - + map, int> row_incidence; for (first_derivatives_t::const_iterator it = first_derivatives.begin(); it != first_derivatives.end(); it++) @@ -2129,9 +2127,10 @@ StaticModel::writeAuxVarInitval(ostream &output, ExprNodeOutputType output_type) } } -void StaticModel::writeSetAuxiliaryVariables(const string &basename, const bool julia) const +void +StaticModel::writeSetAuxiliaryVariables(const string &basename, const bool julia) const { - + string func_name = basename + "_set_auxiliary_variables"; string filename = julia ? func_name + ".jl" : func_name + ".m"; string comment = julia ? "#" : "%"; @@ -2311,7 +2310,6 @@ StaticModel::writeParamsDerivativesFile(const string &basename, bool julia) cons third_derivs1_output << ";" << endl; } - ofstream paramsDerivsFile; string filename = julia ? basename + "StaticParamsDerivs.jl" : basename + "_static_params_derivs.m"; paramsDerivsFile.open(filename.c_str(), ios::out | ios::binary); diff --git a/StaticModel.hh b/StaticModel.hh index 8535a714..abf2aa01 100644 --- a/StaticModel.hh +++ b/StaticModel.hh @@ -215,12 +215,14 @@ public: return (block_type_firstequation_size_mfs[block_number].second.first); }; //! Return the number of exogenous variable in the block block_number - virtual unsigned int getBlockExoSize(int block_number) const + virtual unsigned int + getBlockExoSize(int block_number) const { return 0; }; //! Return the number of colums in the jacobian matrix for exogenous variable in the block block_number - virtual unsigned int getBlockExoColSize(int block_number) const + virtual unsigned int + getBlockExoColSize(int block_number) const { return 0; } diff --git a/SteadyStateModel.cc b/SteadyStateModel.cc index 7630823f..5fc9dc1d 100644 --- a/SteadyStateModel.cc +++ b/SteadyStateModel.cc @@ -72,7 +72,7 @@ SteadyStateModel::checkPass(bool ramsey_model, WarningConsolidation &warnings) c if (find(so_far_defined.begin(), so_far_defined.end(), symb_ids[j]) != so_far_defined.end()) 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) { @@ -187,15 +187,15 @@ SteadyStateModel::writeSteadyStateFileC(const string &basename, bool ramsey_mode output << "#include " << endl; output << "void steadystate(" - << "const double *exo_, const double *params, double *ys_, int *info)" << endl + << "const double *exo_, const double *params, double *ys_, int *info)" << endl << "// Steady state file generated by Dynare preprocessor" << endl - << "{" << endl + << "{" << endl << " *info = 0;" << endl; if (def_table.size() == 0) { output << " return;" << endl - << "}" << endl; + << "}" << endl; return; } @@ -204,11 +204,11 @@ SteadyStateModel::writeSteadyStateFileC(const string &basename, bool ramsey_mode const vector &symb_ids = def_table[i].first; output << " "; if (symb_ids.size() > 1) - std::cout << "Error: in C, multiple returns are not permitted in steady_state_model" << std::endl; + std::cout << "Error: in C, multiple returns are not permitted in steady_state_model" << std::endl; variable_node_map_t::const_iterator it = variable_node_map.find(make_pair(symb_ids[0], 0)); assert(it != variable_node_map.end()); if (it->second->get_type() == eModFileLocalVariable) - output << "double "; + output << "double "; dynamic_cast(it->second)->writeOutput(output, oCSteadyStateFile); output << "="; def_table[i].second->writeOutput(output, oCSteadyStateFile); diff --git a/SymbolList.hh b/SymbolList.hh index cbb51cab..950ae0a6 100644 --- a/SymbolList.hh +++ b/SymbolList.hh @@ -42,9 +42,17 @@ public: //! Clears all content void clear(); //! Get a copy of the string vector - vector get_symbols() const { return symbols; }; + vector + get_symbols() const + { + return symbols; + }; //! Is Empty - int empty() const { return symbols.empty(); }; + int + empty() const + { + return symbols.empty(); + }; }; #endif diff --git a/SymbolTable.cc b/SymbolTable.cc index 17b63e95..7af7ffed 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -42,7 +42,7 @@ SymbolTable::SymbolTable() : frozen(false), size(0) } int -SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_name, const vector *> *partition_value) throw (AlreadyDeclaredException, FrozenException) +SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_name, const vector *> *partition_value) throw (AlreadyDeclaredException, FrozenException) { if (frozen) throw FrozenException(); @@ -88,7 +88,7 @@ SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_na { map pmv; for (vector *>::const_iterator it = partition_value->begin(); - it != partition_value->end(); it++) + it != partition_value->end(); it++) pmv[*((*it)->first)] = *((*it)->second); partition_value_map[id] = pmv; } @@ -216,7 +216,6 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException) << "M_.exo_names_tex = char(M_.exo_names_tex, '" << getTeXName(exo_ids[id]) << "');" << endl << "M_.exo_names_long = char(M_.exo_names_long, '" << getLongName(exo_ids[id]) << "');" << endl; - map > partitions = getPartitionsForType(eExogenous); for (map >::const_iterator it = partitions.begin(); it != partitions.end(); it++) @@ -292,7 +291,7 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException) output << it1->second; output << "' "; } - output << "};" << endl; + output << "};" << endl; } } @@ -408,7 +407,7 @@ SymbolTable::writeCOutput(ostream &output) const throw (NotYetFrozenException) { output << "char *exo_names[" << exo_nbr() << "];" << endl; for (int id = 0; id < exo_nbr(); id++) - output << "exo_names[" << id << "] = \"" << getName(exo_ids[id]) << "\";" << endl; + output << "exo_names[" << id << "] = \"" << getName(exo_ids[id]) << "\";" << endl; } output << endl @@ -417,7 +416,7 @@ SymbolTable::writeCOutput(ostream &output) const throw (NotYetFrozenException) { output << "char *exo_det_names[" << exo_det_nbr() << "];" << endl; for (int id = 0; id < exo_det_nbr(); id++) - output << "exo_det_names[" << id << "] = \"" << getName(exo_det_ids[id]) << "\";" << endl; + output << "exo_det_names[" << id << "] = \"" << getName(exo_det_ids[id]) << "\";" << endl; } output << endl @@ -426,7 +425,7 @@ SymbolTable::writeCOutput(ostream &output) const throw (NotYetFrozenException) { output << "char *endo_names[" << endo_nbr() << "];" << endl; for (int id = 0; id < endo_nbr(); id++) - output << "endo_names[" << id << "] = \"" << getName(endo_ids[id]) << "\";" << endl; + output << "endo_names[" << id << "] = \"" << getName(endo_ids[id]) << "\";" << endl; } output << endl @@ -435,7 +434,7 @@ SymbolTable::writeCOutput(ostream &output) const throw (NotYetFrozenException) { output << "char *param_names[" << param_nbr() << "];" << endl; for (int id = 0; id < param_nbr(); id++) - output << "param_names[" << id << "] = \"" << getName(param_ids[id]) << "\";" << endl; + output << "param_names[" << id << "] = \"" << getName(param_ids[id]) << "\";" << endl; } // Write the auxiliary variable table @@ -444,37 +443,37 @@ SymbolTable::writeCOutput(ostream &output) const throw (NotYetFrozenException) { output << "struct aux_vars_t *av[" << aux_vars.size() << "];" << endl; for (int i = 0; i < (int) aux_vars.size(); i++) - { - output << "av[" << i << "].endo_index = " << getTypeSpecificID(aux_vars[i].get_symb_id()) << ";" << endl - << "av[" << i << "].type = " << aux_vars[i].get_type() << ";" << endl; - switch (aux_vars[i].get_type()) - { - case avEndoLead: - case avExoLead: - case avExpectation: - case avMultiplier: - case avDiffForward: - break; - case avEndoLag: - case avExoLag: - output << "av[" << i << "].orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) << ";" << endl - << "av[" << i << "].orig_lead_lag = " << aux_vars[i].get_orig_lead_lag() << ";" << endl; - break; - } - } + { + output << "av[" << i << "].endo_index = " << getTypeSpecificID(aux_vars[i].get_symb_id()) << ";" << endl + << "av[" << i << "].type = " << aux_vars[i].get_type() << ";" << endl; + switch (aux_vars[i].get_type()) + { + case avEndoLead: + case avExoLead: + case avExpectation: + case avMultiplier: + case avDiffForward: + break; + case avEndoLag: + case avExoLag: + output << "av[" << i << "].orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) << ";" << endl + << "av[" << i << "].orig_lead_lag = " << aux_vars[i].get_orig_lead_lag() << ";" << endl; + break; + } + } } output << "int predeterminedNbr = " << predeterminedNbr() << ";" << endl; if (predeterminedNbr() > 0) { - output << "int predetermined_variables[" << predeterminedNbr() << "] = {"; + output << "int predetermined_variables[" << predeterminedNbr() << "] = {"; for (set::const_iterator it = predetermined_variables.begin(); - it != predetermined_variables.end(); it++) - { - if ( it != predetermined_variables.begin() ) - output << ","; - output << getTypeSpecificID(*it); - } + it != predetermined_variables.end(); it++) + { + if (it != predetermined_variables.begin()) + output << ","; + output << getTypeSpecificID(*it); + } output << "};" << endl; } @@ -483,13 +482,13 @@ SymbolTable::writeCOutput(ostream &output) const throw (NotYetFrozenException) { output << "int varobs[" << observedVariablesNbr() << "] = {"; for (vector::const_iterator it = varobs.begin(); - it != varobs.end(); it++) - { - if ( it != varobs.begin() ) - output << ","; - output << getTypeSpecificID(*it); - } - output << "};" << endl; + it != varobs.end(); it++) + { + if (it != varobs.begin()) + output << ","; + output << getTypeSpecificID(*it); + } + output << "};" << endl; } } @@ -928,25 +927,25 @@ SymbolTable::writeJuliaOutput(ostream &output) const throw (NotYetFrozenExceptio output << "]" << endl; } - if (predeterminedNbr() > 0) - { - output << "# Predetermined Variables" << endl - << "model_.pred_vars = [ " << endl; - for (set::const_iterator it = predetermined_variables.begin(); - it != predetermined_variables.end(); it++) - output << " DynareModel.PredVars(" - << getTypeSpecificID(*it)+1 << ")" << endl; - output << " ]" << endl; - } + if (predeterminedNbr() > 0) + { + output << "# Predetermined Variables" << endl + << "model_.pred_vars = [ " << endl; + for (set::const_iterator it = predetermined_variables.begin(); + it != predetermined_variables.end(); it++) + output << " DynareModel.PredVars(" + << getTypeSpecificID(*it)+1 << ")" << endl; + output << " ]" << endl; + } - if (observedVariablesNbr() > 0) - { - output << "# Observed Variables" << endl - << "options_.obs_vars = [" << endl; - for (vector::const_iterator it = varobs.begin(); - it != varobs.end(); it++) - output << " DynareModel.ObsVars(" - << getTypeSpecificID(*it)+1 << ")" << endl; - output << " ]" << endl; - } + if (observedVariablesNbr() > 0) + { + output << "# Observed Variables" << endl + << "options_.obs_vars = [" << endl; + for (vector::const_iterator it = varobs.begin(); + it != varobs.end(); it++) + output << " DynareModel.ObsVars(" + << getTypeSpecificID(*it)+1 << ")" << endl; + output << " ]" << endl; + } } diff --git a/SymbolTable.hh b/SymbolTable.hh index c99dd462..ceb5d535 100644 --- a/SymbolTable.hh +++ b/SymbolTable.hh @@ -58,13 +58,41 @@ private: expr_t expr_node; //! Auxiliary variable definition public: AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id, int orig_lead_lag, int equation_number_for_multiplier_arg, int information_set_arg, expr_t expr_node_arg); - int get_symb_id() const { return symb_id; }; - aux_var_t get_type() const { return type; }; - int get_orig_symb_id() const { return orig_symb_id; }; - int get_orig_lead_lag() const { return orig_lead_lag; }; - int get_equation_number_for_multiplier() const { return equation_number_for_multiplier; }; - int get_information_set() const { return information_set; }; - expr_t get_expr_node() const { return expr_node; } ; + int + get_symb_id() const + { + return symb_id; + }; + aux_var_t + get_type() const + { + return type; + }; + int + get_orig_symb_id() const + { + return orig_symb_id; + }; + int + get_orig_lead_lag() const + { + return orig_lead_lag; + }; + int + get_equation_number_for_multiplier() const + { + return equation_number_for_multiplier; + }; + int + get_information_set() const + { + return information_set; + }; + expr_t + get_expr_node() const + { + return expr_node; + }; }; //! Stores the symbol table @@ -249,7 +277,11 @@ public: */ int searchAuxiliaryVars(int orig_symb_id, int orig_lead_lag) const throw (SearchFailedException); //! Returns the number of auxiliary variables - int AuxVarsSize() const { return aux_vars.size(); }; + int + AuxVarsSize() const + { + return aux_vars.size(); + }; //! Retruns expr_node for an auxiliary variable expr_t getAuxiliaryVarsExprNode(int symb_id) const throw (SearchFailedException); //! Tests if symbol already exists diff --git a/WarningConsolidation.cc b/WarningConsolidation.cc index 653d4730..f026dea8 100644 --- a/WarningConsolidation.cc +++ b/WarningConsolidation.cc @@ -20,8 +20,9 @@ #include "WarningConsolidation.hh" #include -WarningConsolidation& -operator<< (WarningConsolidation& wcc, const string &warning) +WarningConsolidation +& +operator<<(WarningConsolidation &wcc, const string &warning) { if (wcc.no_warn) return wcc; @@ -31,8 +32,8 @@ operator<< (WarningConsolidation& wcc, const string &warning) return wcc; }; -WarningConsolidation& -operator<< (WarningConsolidation& wcc, const Dynare::location& loc) +WarningConsolidation & +operator<<(WarningConsolidation &wcc, const Dynare::location &loc) { if (wcc.no_warn) return wcc; @@ -54,8 +55,8 @@ operator<< (WarningConsolidation& wcc, const Dynare::location& loc) return wcc; }; -WarningConsolidation& -operator<< (WarningConsolidation& wcc, ostream& (*pf) (ostream&)) +WarningConsolidation & +operator<<(WarningConsolidation &wcc, ostream & (*pf)(ostream &)) { if (wcc.no_warn) return wcc; diff --git a/WarningConsolidation.hh b/WarningConsolidation.hh index 135a54a3..582af0f4 100644 --- a/WarningConsolidation.hh +++ b/WarningConsolidation.hh @@ -34,16 +34,28 @@ private: bool no_warn; public: - WarningConsolidation(bool no_warn_arg) : no_warn(no_warn_arg) { }; - ~WarningConsolidation() { }; + WarningConsolidation(bool no_warn_arg) : no_warn(no_warn_arg) + { + }; + ~WarningConsolidation() + { + }; //! Add A Warning to the StringStream - friend WarningConsolidation& operator<< (WarningConsolidation& wcc, const string &warning); - friend WarningConsolidation& operator<< (WarningConsolidation& wcc, const Dynare::location &loc); - friend WarningConsolidation& operator<< (WarningConsolidation& wcc, ostream& (*pf) (ostream&)); + friend WarningConsolidation &operator<<(WarningConsolidation &wcc, const string &warning); + friend WarningConsolidation &operator<<(WarningConsolidation &wcc, const Dynare::location &loc); + friend WarningConsolidation &operator<<(WarningConsolidation &wcc, ostream & (*pf)(ostream &)); - inline void addWarning(const string &w) { warnings << w; }; - inline void addWarning(ostream& (*pf) (ostream&)) { warnings << pf; }; + inline void + addWarning(const string &w) + { + warnings << w; + }; + inline void + addWarning(ostream & (*pf)(ostream &)) + { + warnings << pf; + }; //! Write Warnings to m file void writeOutput(ostream &output) const; diff --git a/macro/MacroDriver.cc b/macro/MacroDriver.cc index 1d13c5ce..c5193cc6 100644 --- a/macro/MacroDriver.cc +++ b/macro/MacroDriver.cc @@ -55,14 +55,14 @@ MacroDriver::parse(const string &f, ostream &out, bool debug, bool no_line_macro an @#endif or an @#endfor - but no newline - no longer trigger an error. */ stringstream file_with_endl; - for (map::iterator it=defines.begin(); - it!=defines.end(); it++) + for (map::iterator it = defines.begin(); + it != defines.end(); it++) try { boost::lexical_cast(it->second); file_with_endl << "@#define " << it->first << " = " << it->second << endl; } - catch(boost::bad_lexical_cast &) + catch (boost::bad_lexical_cast &) { file_with_endl << "@#define " << it->first << " = \"" << it->second << "\"" << endl; } diff --git a/macro/MacroDriver.hh b/macro/MacroDriver.hh index 83828b2e..7b828b02 100644 --- a/macro/MacroDriver.hh +++ b/macro/MacroDriver.hh @@ -177,12 +177,13 @@ public: //! Constructor MacroDriver(); //! Destructor - virtual ~MacroDriver(); + virtual + ~MacroDriver(); //! Starts parsing a file, returns output in out /*! \param no_line_macro should we omit the @#line statements ? */ void parse(const string &f, ostream &out, bool debug, bool no_line_macro, - map defines, vector path); + map defines, vector path); //! Name of main file being parsed string file; diff --git a/macro/MacroValue.hh b/macro/MacroValue.hh index c9da9c3d..64f0cdef 100644 --- a/macro/MacroValue.hh +++ b/macro/MacroValue.hh @@ -49,7 +49,8 @@ public: { }; MacroValue(MacroDriver &driver_arg); - virtual ~MacroValue(); + virtual + ~MacroValue(); //! Applies + operator virtual const MacroValue *operator+(const MacroValue &mv) const throw (TypeError) = 0; //! Applies unary + operator @@ -118,7 +119,8 @@ private: const int value; public: IntMV(MacroDriver &driver, int value_arg); - virtual ~IntMV(); + virtual + ~IntMV(); //! Computes arithmetic addition virtual const MacroValue *operator+(const MacroValue &mv) const throw (TypeError); //! Unary plus @@ -158,7 +160,11 @@ public: If mv2 < mv1, returns an empty range (for consistency with MATLAB). */ static const MacroValue *new_range(MacroDriver &driver, const MacroValue *mv1, const MacroValue *mv2) throw (TypeError); - inline int get_int_value() const { return value; }; + inline int + get_int_value() const + { + return value; + }; }; //! Represents a string value in macro language @@ -170,7 +176,8 @@ private: const string value; public: StringMV(MacroDriver &driver, const string &value_arg); - virtual ~StringMV(); + virtual + ~StringMV(); //! Computes string concatenation virtual const MacroValue *operator+(const MacroValue &mv) const throw (TypeError); virtual const MacroValue *operator==(const MacroValue &mv) const throw (TypeError); @@ -202,7 +209,8 @@ private: const vector values; public: ArrayMV(MacroDriver &driver, const vector &values_arg); - virtual ~ArrayMV(); + virtual + ~ArrayMV(); //! Computes array concatenation /*! Both array must be of same type */ virtual const MacroValue *operator+(const MacroValue &mv) const throw (TypeError); From 5e1cc8d8e53b31ef07d900c4864e2c9d963a7283 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 18 May 2017 17:58:27 +0200 Subject: [PATCH 22/26] preprocessor: clean up initval output --- NumericalInitialization.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index aa7a2502..7d943976 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -213,12 +213,12 @@ InitValStatement::writeOutput(ostream &output, const string &basename, bool mini void InitValStatement::writeOutputPostInit(ostream &output) const { - output << "if M_.exo_nbr > 0;" << endl - << "\too_.exo_simul = [ones(M_.maximum_lag,1)*oo_.exo_steady_state'];" << endl - <<"end;" << endl - << "if M_.exo_det_nbr > 0;" << endl - << "\too_.exo_det_simul = [ones(M_.maximum_lag,1)*oo_.exo_det_steady_state'];" << endl - <<"end;" << endl; + output << "if M_.exo_nbr > 0" << endl + << "\too_.exo_simul = ones(M_.maximum_lag,1)*oo_.exo_steady_state';" << endl + <<"end" << endl + << "if M_.exo_det_nbr > 0" << endl + << "\too_.exo_det_simul = ones(M_.maximum_lag,1)*oo_.exo_det_steady_state';" << endl + <<"end" << endl; } EndValStatement::EndValStatement(const init_values_t &init_values_arg, From 67482f4b7b070f02539ac68a168c61682d3a5828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Thu, 18 May 2017 18:36:38 +0200 Subject: [PATCH 23/26] Fixed copyright notices. --- CodeInterpreter.hh | 2 +- ConfigFile.cc | 2 +- ConfigFile.hh | 2 +- DataTree.hh | 2 +- DynareMain.cc | 2 +- ExtendedPreprocessorTypes.hh | 2 +- MinimumFeedbackSet.cc | 2 +- Shocks.cc | 2 +- Shocks.hh | 2 +- SteadyStateModel.cc | 2 +- SymbolList.hh | 2 +- SymbolTable.cc | 2 +- SymbolTable.hh | 2 +- WarningConsolidation.cc | 2 +- WarningConsolidation.hh | 2 +- macro/MacroDriver.cc | 2 +- macro/MacroDriver.hh | 2 +- macro/MacroValue.hh | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/CodeInterpreter.hh b/CodeInterpreter.hh index 7be9a056..8939950f 100644 --- a/CodeInterpreter.hh +++ b/CodeInterpreter.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2016 Dynare Team + * Copyright (C) 2007-2017 Dynare Team * * This file is part of Dynare. * diff --git a/ConfigFile.cc b/ConfigFile.cc index 36a1faa7..64d899e1 100644 --- a/ConfigFile.cc +++ b/ConfigFile.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2016 Dynare Team + * Copyright (C) 2010-2017 Dynare Team * * This file is part of Dynare. * diff --git a/ConfigFile.hh b/ConfigFile.hh index e054922f..e3d9143e 100644 --- a/ConfigFile.hh +++ b/ConfigFile.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2016 Dynare Team + * Copyright (C) 2010-2017 Dynare Team * * This file is part of Dynare. * diff --git a/DataTree.hh b/DataTree.hh index d7a1de5d..5efb57bd 100644 --- a/DataTree.hh +++ b/DataTree.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2016 Dynare Team + * Copyright (C) 2003-2017 Dynare Team * * This file is part of Dynare. * diff --git a/DynareMain.cc b/DynareMain.cc index 51fa7767..887cf281 100644 --- a/DynareMain.cc +++ b/DynareMain.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2016 Dynare Team + * Copyright (C) 2003-2017 Dynare Team * * This file is part of Dynare. * diff --git a/ExtendedPreprocessorTypes.hh b/ExtendedPreprocessorTypes.hh index 4c6869a3..bf57a19f 100644 --- a/ExtendedPreprocessorTypes.hh +++ b/ExtendedPreprocessorTypes.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014-2015 Dynare Team + * Copyright (C) 2014-2017 Dynare Team * * This file is part of Dynare. * diff --git a/MinimumFeedbackSet.cc b/MinimumFeedbackSet.cc index a84a994a..d91391c5 100644 --- a/MinimumFeedbackSet.cc +++ b/MinimumFeedbackSet.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2012 Dynare Team + * Copyright (C) 2009-2017 Dynare Team * * This file is part of Dynare. * diff --git a/Shocks.cc b/Shocks.cc index 0aa7fdfa..6f95a7a9 100644 --- a/Shocks.cc +++ b/Shocks.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2016 Dynare Team + * Copyright (C) 2003-2017 Dynare Team * * This file is part of Dynare. * diff --git a/Shocks.hh b/Shocks.hh index 1c7abb91..0710e663 100644 --- a/Shocks.hh +++ b/Shocks.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2016 Dynare Team + * Copyright (C) 2003-2017 Dynare Team * * This file is part of Dynare. * diff --git a/SteadyStateModel.cc b/SteadyStateModel.cc index 5fc9dc1d..0a6e1536 100644 --- a/SteadyStateModel.cc +++ b/SteadyStateModel.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2016 Dynare Team + * Copyright (C) 2010-2017 Dynare Team * * This file is part of Dynare. * diff --git a/SymbolList.hh b/SymbolList.hh index 950ae0a6..c0619484 100644 --- a/SymbolList.hh +++ b/SymbolList.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2017 Dynare Team * * This file is part of Dynare. * diff --git a/SymbolTable.cc b/SymbolTable.cc index 7af7ffed..3d43e184 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2016 Dynare Team + * Copyright (C) 2003-2017 Dynare Team * * This file is part of Dynare. * diff --git a/SymbolTable.hh b/SymbolTable.hh index ceb5d535..ff633c63 100644 --- a/SymbolTable.hh +++ b/SymbolTable.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2016 Dynare Team + * Copyright (C) 2003-2017 Dynare Team * * This file is part of Dynare. * diff --git a/WarningConsolidation.cc b/WarningConsolidation.cc index f026dea8..f1c24f4a 100644 --- a/WarningConsolidation.cc +++ b/WarningConsolidation.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2013 Dynare Team + * Copyright (C) 2012-2017 Dynare Team * * This file is part of Dynare. * diff --git a/WarningConsolidation.hh b/WarningConsolidation.hh index 582af0f4..ece47995 100644 --- a/WarningConsolidation.hh +++ b/WarningConsolidation.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2013 Dynare Team + * Copyright (C) 2012-2017 Dynare Team * * This file is part of Dynare. * diff --git a/macro/MacroDriver.cc b/macro/MacroDriver.cc index c5193cc6..71d53b9c 100644 --- a/macro/MacroDriver.cc +++ b/macro/MacroDriver.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2015 Dynare Team + * Copyright (C) 2008-2017 Dynare Team * * This file is part of Dynare. * diff --git a/macro/MacroDriver.hh b/macro/MacroDriver.hh index 7b828b02..773a99dc 100644 --- a/macro/MacroDriver.hh +++ b/macro/MacroDriver.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2015 Dynare Team + * Copyright (C) 2008-2017 Dynare Team * * This file is part of Dynare. * diff --git a/macro/MacroValue.hh b/macro/MacroValue.hh index 64f0cdef..1097841d 100644 --- a/macro/MacroValue.hh +++ b/macro/MacroValue.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2016 Dynare Team + * Copyright (C) 2008-2017 Dynare Team * * This file is part of Dynare. * From 2670ca8db0628443d3b15059cc57bb50d570afc6 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 23 May 2017 13:20:47 +0200 Subject: [PATCH 24/26] Get rid of unused and superseded options_.colormap and make sure options_.plot_shock_decomp.colormap is set --- DynareBison.yy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DynareBison.yy b/DynareBison.yy index 4f9e0371..c82b7025 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -3381,7 +3381,7 @@ o_use_shock_groups : USE_SHOCK_GROUPS { driver.option_str("use_shock_groups","de o_psd_use_shock_groups : USE_SHOCK_GROUPS { driver.option_str("plot_shock_decomp.use_shock_groups","default"); } | USE_SHOCK_GROUPS EQUAL symbol { driver.option_str("plot_shock_decomp.use_shock_groups", $3); } ; -o_colormap : COLORMAP EQUAL symbol { driver.option_num("colormap",$3); }; +o_colormap : COLORMAP EQUAL symbol { driver.option_num("plot_shock_decomp.colormap",$3); }; o_psd_colormap : COLORMAP EQUAL symbol { driver.option_num("plot_shock_decomp.colormap",$3); }; range : symbol ':' symbol From 6255858d210dab443da55718c3b78a3b00f7ad31 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 14 Jun 2017 23:40:30 +0200 Subject: [PATCH 25/26] preprocessor: fix bug: check whether second string in pair is empty. closes #1469 --- ModelTree.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ModelTree.cc b/ModelTree.cc index 9bfb30ea..52de1aa1 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -1588,7 +1588,7 @@ ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output content_output << iteqt->second.first; - if (!empty(iteqt->second.second)) + if (iteqt->second.second.empty()) content_output << "= `" << iteqt->second.second << "'"; wrote_eq_tag = true; From 7153f19aab774c8b6154a3e305e28bf5a87187ad Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 14 Jun 2017 23:49:10 +0200 Subject: [PATCH 26/26] preprocessor: remove comparison warnings from compilation of ModelTree.cc --- ModelTree.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ModelTree.cc b/ModelTree.cc index 52de1aa1..11f9d1e1 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -232,7 +232,7 @@ ModelTree::computeNonSingularNormalization(jacob_map_t &contemporaneous_jacobian void ModelTree::computeNormalizedEquations(multimap &endo2eqs) const { - for (int i = 0; i < equations.size(); i++) + for (size_t i = 0; i < equations.size(); i++) { VariableNode *lhs = dynamic_cast(equations[i]->get_arg1()); if (lhs == NULL) @@ -247,7 +247,7 @@ ModelTree::computeNormalizedEquations(multimap &endo2eqs) const if (endo.find(make_pair(symbol_table.getTypeSpecificID(symb_id), 0)) != endo.end()) continue; - endo2eqs.insert(make_pair(symbol_table.getTypeSpecificID(symb_id), i)); + endo2eqs.insert(make_pair(symbol_table.getTypeSpecificID(symb_id), (int) i)); cout << "Endogenous " << symbol_table.getName(symb_id) << " normalized in equation " << (i+1) << endl; } } @@ -1667,7 +1667,7 @@ ModelTree::addNonstationaryVariables(vector nonstationary_vars, bool log_de void ModelTree::initializeVariablesAndEquations() { - for (int j = 0; j < equations.size(); j++) + for (size_t j = 0; j < equations.size(); j++) { equation_reordered.push_back(j); variable_reordered.push_back(j);