estimated_params_{bounds,init} now check that a parameter (or correlation) is never declared twice
This check was previously only implemented in estimated_params.pac-components
parent
784dd4122a
commit
62ba9a434a
|
@ -1362,16 +1362,58 @@ DsampleStatement::writeJsonOutput(ostream &output) const
|
||||||
<< R"("value2": )" << val2 << "}";
|
<< R"("value2": )" << val2 << "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
EstimatedParamsStatement::EstimatedParamsStatement(vector<EstimationParams> estim_params_list_arg,
|
AbstractEstimatedParamsStatement::AbstractEstimatedParamsStatement(vector<EstimationParams> estim_params_list_arg,
|
||||||
const SymbolTable &symbol_table_arg) :
|
const SymbolTable &symbol_table_arg) :
|
||||||
estim_params_list{move(estim_params_list_arg)},
|
estim_params_list{move(estim_params_list_arg)},
|
||||||
symbol_table{symbol_table_arg}
|
symbol_table{symbol_table_arg}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
AbstractEstimatedParamsStatement::commonCheckPass() const
|
||||||
|
{
|
||||||
|
// Check that no parameter/endogenous is declared twice in the block
|
||||||
|
set<string> already_declared;
|
||||||
|
set<pair<string, string>> already_declared_corr;
|
||||||
|
for (const auto &it : estim_params_list)
|
||||||
|
{
|
||||||
|
if (it.type == 3) // Correlation
|
||||||
|
{
|
||||||
|
// Use lexical ordering for the pair of symbols
|
||||||
|
auto x = it.name < it.name2 ? make_pair(it.name, it.name2) : make_pair(it.name2, it.name);
|
||||||
|
|
||||||
|
if (already_declared_corr.find(x) == already_declared_corr.end())
|
||||||
|
already_declared_corr.insert(x);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cerr << "ERROR: in `" << blockName() << "' block, the correlation between " << it.name << " and " << it.name2 << " is declared twice." << endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (already_declared.find(it.name) == already_declared.end())
|
||||||
|
already_declared.insert(it.name);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cerr << "ERROR: in `" << blockName() << "' block, the symbol " << it.name << " is declared twice." << endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EstimatedParamsStatement::EstimatedParamsStatement(vector<EstimationParams> estim_params_list_arg,
|
||||||
|
const SymbolTable &symbol_table_arg) :
|
||||||
|
AbstractEstimatedParamsStatement(move(estim_params_list_arg), symbol_table_arg)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
EstimatedParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
|
EstimatedParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
|
||||||
{
|
{
|
||||||
|
commonCheckPass();
|
||||||
|
|
||||||
for (const auto &it : estim_params_list)
|
for (const auto &it : estim_params_list)
|
||||||
{
|
{
|
||||||
if (it.name == "dsge_prior_weight")
|
if (it.name == "dsge_prior_weight")
|
||||||
|
@ -1394,36 +1436,6 @@ EstimatedParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that no parameter/endogenous is declared twice in the block
|
|
||||||
set<string> already_declared;
|
|
||||||
set<pair<string, string>> already_declared_corr;
|
|
||||||
for (const auto &it : estim_params_list)
|
|
||||||
{
|
|
||||||
if (it.type == 3) // Correlation
|
|
||||||
{
|
|
||||||
// Use lexical ordering for the pair of symbols
|
|
||||||
auto x = it.name < it.name2 ? pair(it.name, it.name2) : pair(it.name2, it.name);
|
|
||||||
|
|
||||||
if (already_declared_corr.find(x) == already_declared_corr.end())
|
|
||||||
already_declared_corr.insert(x);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cerr << "ERROR: in `estimated_params' block, the correlation between " << it.name << " and " << it.name2 << " is declared twice." << endl;
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (already_declared.find(it.name) == already_declared.end())
|
|
||||||
already_declared.insert(it.name);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cerr << "ERROR: in `estimated_params' block, the symbol " << it.name << " is declared twice." << endl;
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fill in mod_file_struct.estimated_parameters (related to #469)
|
// Fill in mod_file_struct.estimated_parameters (related to #469)
|
||||||
for (const auto &it : estim_params_list)
|
for (const auto &it : estim_params_list)
|
||||||
if (it.type == 2 && it.name != "dsge_prior_weight")
|
if (it.type == 2 && it.name != "dsge_prior_weight")
|
||||||
|
@ -1537,8 +1549,7 @@ EstimatedParamsStatement::writeJsonOutput(ostream &output) const
|
||||||
EstimatedParamsInitStatement::EstimatedParamsInitStatement(vector<EstimationParams> estim_params_list_arg,
|
EstimatedParamsInitStatement::EstimatedParamsInitStatement(vector<EstimationParams> estim_params_list_arg,
|
||||||
const SymbolTable &symbol_table_arg,
|
const SymbolTable &symbol_table_arg,
|
||||||
const bool use_calibration_arg) :
|
const bool use_calibration_arg) :
|
||||||
estim_params_list{move(estim_params_list_arg)},
|
AbstractEstimatedParamsStatement(move(estim_params_list_arg), symbol_table_arg),
|
||||||
symbol_table{symbol_table_arg},
|
|
||||||
use_calibration{use_calibration_arg}
|
use_calibration{use_calibration_arg}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -1546,6 +1557,8 @@ EstimatedParamsInitStatement::EstimatedParamsInitStatement(vector<EstimationPara
|
||||||
void
|
void
|
||||||
EstimatedParamsInitStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
|
EstimatedParamsInitStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
|
||||||
{
|
{
|
||||||
|
commonCheckPass();
|
||||||
|
|
||||||
if (use_calibration)
|
if (use_calibration)
|
||||||
mod_file_struct.estim_params_use_calib = true;
|
mod_file_struct.estim_params_use_calib = true;
|
||||||
}
|
}
|
||||||
|
@ -1675,11 +1688,16 @@ EstimatedParamsInitStatement::writeJsonOutput(ostream &output) const
|
||||||
|
|
||||||
EstimatedParamsBoundsStatement::EstimatedParamsBoundsStatement(vector<EstimationParams> estim_params_list_arg,
|
EstimatedParamsBoundsStatement::EstimatedParamsBoundsStatement(vector<EstimationParams> estim_params_list_arg,
|
||||||
const SymbolTable &symbol_table_arg) :
|
const SymbolTable &symbol_table_arg) :
|
||||||
estim_params_list{move(estim_params_list_arg)},
|
AbstractEstimatedParamsStatement(move(estim_params_list_arg), symbol_table_arg)
|
||||||
symbol_table{symbol_table_arg}
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
EstimatedParamsBoundsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
|
||||||
|
{
|
||||||
|
commonCheckPass();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
EstimatedParamsBoundsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
|
EstimatedParamsBoundsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -511,42 +511,50 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class EstimatedParamsStatement : public Statement
|
class AbstractEstimatedParamsStatement : public Statement
|
||||||
{
|
{
|
||||||
private:
|
protected:
|
||||||
const vector<EstimationParams> estim_params_list;
|
const vector<EstimationParams> estim_params_list;
|
||||||
const SymbolTable &symbol_table;
|
const SymbolTable &symbol_table;
|
||||||
|
AbstractEstimatedParamsStatement(vector<EstimationParams> estim_params_list_arg,
|
||||||
|
const SymbolTable &symbol_table_arg);
|
||||||
|
virtual string blockName() const = 0;
|
||||||
|
// Part of the check pass that is common to the three estimated_params* blocks
|
||||||
|
void commonCheckPass() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
class EstimatedParamsStatement : public AbstractEstimatedParamsStatement
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
EstimatedParamsStatement(vector<EstimationParams> estim_params_list_arg,
|
EstimatedParamsStatement(vector<EstimationParams> estim_params_list_arg,
|
||||||
const SymbolTable &symbol_table_arg);
|
const SymbolTable &symbol_table_arg);
|
||||||
|
string blockName() const override { return "estimated_params"; };
|
||||||
void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) override;
|
void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) override;
|
||||||
void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const override;
|
void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const override;
|
||||||
void writeJsonOutput(ostream &output) const override;
|
void writeJsonOutput(ostream &output) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class EstimatedParamsInitStatement : public Statement
|
class EstimatedParamsInitStatement : public AbstractEstimatedParamsStatement
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
const vector<EstimationParams> estim_params_list;
|
|
||||||
const SymbolTable &symbol_table;
|
|
||||||
const bool use_calibration;
|
const bool use_calibration;
|
||||||
public:
|
public:
|
||||||
EstimatedParamsInitStatement(vector<EstimationParams> estim_params_list_arg,
|
EstimatedParamsInitStatement(vector<EstimationParams> estim_params_list_arg,
|
||||||
const SymbolTable &symbol_table_arg,
|
const SymbolTable &symbol_table_arg,
|
||||||
const bool use_calibration_arg);
|
const bool use_calibration_arg);
|
||||||
|
string blockName() const override { return "estimated_params_init"; };
|
||||||
void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) override;
|
void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) override;
|
||||||
void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const override;
|
void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const override;
|
||||||
void writeJsonOutput(ostream &output) const override;
|
void writeJsonOutput(ostream &output) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class EstimatedParamsBoundsStatement : public Statement
|
class EstimatedParamsBoundsStatement : public AbstractEstimatedParamsStatement
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
const vector<EstimationParams> estim_params_list;
|
|
||||||
const SymbolTable &symbol_table;
|
|
||||||
public:
|
public:
|
||||||
EstimatedParamsBoundsStatement(vector<EstimationParams> estim_params_list_arg,
|
EstimatedParamsBoundsStatement(vector<EstimationParams> estim_params_list_arg,
|
||||||
const SymbolTable &symbol_table_arg);
|
const SymbolTable &symbol_table_arg);
|
||||||
|
string blockName() const override { return "estimated_params_bounds"; };
|
||||||
|
void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) override;
|
||||||
void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const override;
|
void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const override;
|
||||||
void writeJsonOutput(ostream &output) const override;
|
void writeJsonOutput(ostream &output) const override;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue