New option “overwrite” to “estimated_params” block

This option provides the same behaviour as before the change in
60ef6bbdbd.

It is typically useful when doing several estimations in the same .mod file.
pac-components
Sébastien Villemot 2021-12-16 14:22:31 +01:00
parent 5ffbc5bad3
commit ea44aa19d6
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
5 changed files with 29 additions and 16 deletions

View File

@ -1320,8 +1320,10 @@ AbstractEstimatedParamsStatement::commonCheckPass() const
}
EstimatedParamsStatement::EstimatedParamsStatement(vector<EstimationParams> estim_params_list_arg,
const SymbolTable &symbol_table_arg) :
AbstractEstimatedParamsStatement(move(estim_params_list_arg), symbol_table_arg)
const SymbolTable &symbol_table_arg,
bool overwrite_arg) :
AbstractEstimatedParamsStatement(move(estim_params_list_arg), symbol_table_arg),
overwrite{overwrite_arg}
{
}
@ -1361,15 +1363,19 @@ EstimatedParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo
void
EstimatedParamsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
{
/* Multiple estimated_params statements are allowed, so make sure we dont
overwrite previous ones. */
output << "if isempty(estim_params_)" << endl
<< " estim_params_.var_exo = zeros(0, 10);" << endl
<< " estim_params_.var_endo = zeros(0, 10);" << endl
<< " estim_params_.corrx = zeros(0, 11);" << endl
<< " estim_params_.corrn = zeros(0, 11);" << endl
<< " estim_params_.param_vals = zeros(0, 10);" << endl
<< "end" << endl;
string indent;
if (!overwrite)
{
output << "if isempty(estim_params_)" << endl;
indent = " ";
}
output << indent << "estim_params_.var_exo = zeros(0, 10);" << endl
<< indent << "estim_params_.var_endo = zeros(0, 10);" << endl
<< indent << "estim_params_.corrx = zeros(0, 11);" << endl
<< indent << "estim_params_.corrn = zeros(0, 11);" << endl
<< indent << "estim_params_.param_vals = zeros(0, 10);" << endl;
if (!overwrite)
output << "end" << endl;
for (const auto &it : estim_params_list)
{

View File

@ -504,9 +504,12 @@ protected:
class EstimatedParamsStatement : public AbstractEstimatedParamsStatement
{
private:
const bool overwrite;
public:
EstimatedParamsStatement(vector<EstimationParams> estim_params_list_arg,
const SymbolTable &symbol_table_arg);
const SymbolTable &symbol_table_arg,
bool overwrite_arg);
string blockName() const override { return "estimated_params"; };
void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) override;
void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const override;

View File

@ -1738,7 +1738,11 @@ boolean : TRUE
| FALSE
;
estimated_params : ESTIMATED_PARAMS ';' estimated_list END ';' { driver.estimated_params(); };
estimated_params : ESTIMATED_PARAMS ';' estimated_list END ';'
{ driver.estimated_params(false); }
| ESTIMATED_PARAMS '(' OVERWRITE ')' ';' estimated_list END ';'
{ driver.estimated_params(true); }
;
estimated_list : estimated_list estimated_elem
{ driver.add_estimated_params_element(); }

View File

@ -1469,9 +1469,9 @@ ParsingDriver::add_estimated_params_element()
}
void
ParsingDriver::estimated_params()
ParsingDriver::estimated_params(bool overwrite)
{
mod_file->addStatement(make_unique<EstimatedParamsStatement>(estim_params_list, mod_file->symbol_table));
mod_file->addStatement(make_unique<EstimatedParamsStatement>(estim_params_list, mod_file->symbol_table, overwrite));
estim_params_list.clear();
}

View File

@ -507,7 +507,7 @@ public:
//! Writes model_info command
void model_info();
//! Writes estimated params command
void estimated_params();
void estimated_params(bool overwrite);
//! Writes estimated params init command
void estimated_params_init(bool use_calibration = false);
//! Writes estimated params bound command