diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 9af570b7..e037f2d4 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -517,6 +517,12 @@ EstimatedParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo } } } + + // Fill in mod_file_struct.estimated_parameters (related to #469) + for (vector::const_iterator it = estim_params_list.begin(); + it != estim_params_list.end(); it++) + if (it->type == 2) + mod_file_struct.estimated_parameters.insert(symbol_table.getID(it->name)); } void diff --git a/ModFile.cc b/ModFile.cc index 1a1b7e3e..3e5f0a86 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -264,6 +264,28 @@ ModFile::checkPass() || 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; + + // Test if some estimated parameters are used within the values of shocks + // statements (see issue #469) + set parameters_intersect; + set_intersection(mod_file_struct.parameters_within_shocks_values.begin(), + mod_file_struct.parameters_within_shocks_values.end(), + mod_file_struct.estimated_parameters.begin(), + mod_file_struct.estimated_parameters.end(), + inserter(parameters_intersect, parameters_intersect.begin())); + if (parameters_intersect.size() > 0) + { + cerr << "ERROR: some estimated parameters ("; + for (set::const_iterator it = parameters_intersect.begin(); + it != parameters_intersect.end(); ) + { + cerr << symbol_table.getName(*it); + if (++it != parameters_intersect.end()) + cerr << ", "; + } + cerr << ") also appear in the expressions defining the variance/covariance matrix of shocks; this is not allowed." << endl; + exit(EXIT_FAILURE); + } } void diff --git a/Shocks.cc b/Shocks.cc index cc0b7700..2e93a3ac 100644 --- a/Shocks.cc +++ b/Shocks.cc @@ -284,6 +284,25 @@ ShocksStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidati || symbol_table.isObservedVariable(it->first.second)) mod_file_struct.calibrated_measurement_errors = true; } + + // Fill in mod_file_struct.parameters_with_shocks_values (related to #469) + set > params_lags; + for (var_and_std_shocks_t::const_iterator it = var_shocks.begin(); + it != var_shocks.end(); ++it) + it->second->collectVariables(eParameter, params_lags); + for (var_and_std_shocks_t::const_iterator it = std_shocks.begin(); + it != std_shocks.end(); ++it) + it->second->collectVariables(eParameter, params_lags); + for (covar_and_corr_shocks_t::const_iterator it = covar_shocks.begin(); + it != covar_shocks.end(); ++it) + it->second->collectVariables(eParameter, params_lags); + for (covar_and_corr_shocks_t::const_iterator it = corr_shocks.begin(); + it != corr_shocks.end(); ++it) + it->second->collectVariables(eParameter, params_lags); + + for (set >::const_iterator it = params_lags.begin(); + it != params_lags.end(); ++it) + mod_file_struct.parameters_within_shocks_values.insert(it->first); } MShocksStatement::MShocksStatement(const det_shocks_t &det_shocks_arg, diff --git a/Statement.hh b/Statement.hh index 0563ced9..d4dad9b8 100644 --- a/Statement.hh +++ b/Statement.hh @@ -23,6 +23,7 @@ #include #include #include +#include #include "SymbolList.hh" #include "WarningConsolidation.hh" @@ -97,6 +98,11 @@ public: int last_markov_switching_chain; //! Whether a calib_smoother statement is present bool calib_smoother_present; + //! Set of parameters used within shocks blocks, inside the expressions + //! defining the values of covariances (stored as symbol ids) + set parameters_within_shocks_values; + //! Set of estimated parameters (stored as symbol ids) + set estimated_parameters; }; class Statement