New estimated_params_remove statement

pac-components
Sébastien Villemot 2021-12-15 15:59:18 +01:00
parent 06a436fdf0
commit 5ffbc5bad3
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
6 changed files with 128 additions and 2 deletions

View File

@ -1722,6 +1722,99 @@ EstimatedParamsBoundsStatement::writeJsonOutput(ostream &output) const
<< "}";
}
EstimatedParamsRemoveStatement::EstimatedParamsRemoveStatement(vector<EstimationParams> estim_params_list_arg,
const SymbolTable &symbol_table_arg) :
estim_params_list{move(estim_params_list_arg)},
symbol_table{symbol_table_arg}
{
}
void
EstimatedParamsRemoveStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
{
for (const auto &it : estim_params_list)
{
int tsid = symbol_table.getTypeSpecificID(it.name) + 1;
SymbolType symb_type = symbol_table.getType(it.name);
if (it.type < 3)
{
if (symb_type == SymbolType::exogenous)
output << "tmp1 = find(estim_params_.var_exo(:,1)==" << tsid << ");" << endl
<< "if isempty(tmp1)" << endl
<< " error(sprintf('estimated_params_remove: the standard deviation of %s is not estimated.', M_.exo_names{" << tsid << "}))" << endl
<< "else" << endl
<< " estim_params_.var_exo(tmp1,:) = [];"
<< "end" << endl;
else if (symb_type == SymbolType::endogenous)
output << "tmp1 = find(estim_params_.var_endo(:,1)==" << tsid << ");" << endl
<< "if isempty(tmp1)" << endl
<< " error(sprintf('estimated_params_remove: the standard deviation of the measurement error on %s is not estimated.', M_.endo_names{" << tsid << "}))" << endl
<< "else" << endl
<< " estim_params_.var_endo(tmp1,:) = [];"
<< "end" << endl;
else if (symb_type == SymbolType::parameter)
output << "tmp1 = find(estim_params_.param_vals(:,1)==" << tsid << ");" << endl
<< "if isempty(tmp1)" << endl
<< " error(sprintf('estimated_params_remove: parameter %s is not estimated.', M_.param_names{" << tsid << "}))" << endl
<< "else" << endl
<< " estim_params_.param_vals(tmp1,:) = [];"
<< "end" << endl;
}
else
{
int tsid2 = symbol_table.getTypeSpecificID(it.name2) + 1;
if (symb_type == SymbolType::exogenous)
output << "tmp1 = find((estim_params_.corrx(:,1)==" << tsid << " & estim_params_.corrx(:,2)==" << tsid2 << ") | "
<< "(estim_params_.corrx(:,2)==" << tsid << " & estim_params_.corrx(:,1)==" << tsid2 << "));" << endl
<< "if isempty(tmp1)" << endl
<< " error(sprintf('estimated_params_remove: the correlation between %s and %s is not estimated.', M_.exo_names{"
<< tsid << "}, M_.exo_names{" << tsid2 << "}))" << endl
<< "else" << endl
<< " estim_params_.corrx(tmp1,:) = [];"
<< "end" << endl;
else if (symb_type == SymbolType::endogenous)
output << "tmp1 = find((estim_params_.corrn(:,1)==" << tsid << " & estim_params_.corrn(:,2)==" << tsid2 << ") | "
<< "(estim_params_.corrn(:,2)==" << tsid << " & estim_params_.corrn(:,1)==" << tsid2 << "));" << endl
<< "if isempty(tmp1)" << endl
<< " error(sprintf('estimated_params_remove: the correlation between measurement errors on %s and %s is not estimated.', M_.endo_names{"
<< tsid << "}, M_.endo_names{" << tsid2 << "}))" << endl
<< "else" << endl
<< " estim_params_.corrn(tmp1,:) = [];"
<< "end" << endl;
}
}
}
void
EstimatedParamsRemoveStatement::writeJsonOutput(ostream &output) const
{
output << R"({"statementName": "estimated_params_remove", )"
<< R"("params": [)";
for (auto it = estim_params_list.begin(); it != estim_params_list.end(); ++it)
{
if (it != estim_params_list.begin())
output << ", ";
output << "{";
switch (it->type)
{
case 1:
output << R"("var": ")" << it->name << R"(")";
case 2:
output << R"("param": ")" << it->name << R"(")";
break;
case 3:
output << R"("var1": ")" << it->name << R"(",)"
<< R"("var2": ")" << it->name2 << R"(")";
break;
}
output << "}";
}
output << "]"
<< "}";
}
DeterministicTrendsStatement::DeterministicTrendsStatement(trend_elements_t trend_elements_arg,
const SymbolTable &symbol_table_arg) :
trend_elements{move(trend_elements_arg)},

View File

@ -498,7 +498,7 @@ protected:
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
// Part of the check pass that is common to the three estimated_params{,_init,bounds} blocks
void commonCheckPass() const;
};
@ -538,6 +538,18 @@ public:
void writeJsonOutput(ostream &output) const override;
};
class EstimatedParamsRemoveStatement : public Statement
{
public:
// Only the type, name and name2 fields of EstimationParams are used
const vector<EstimationParams> estim_params_list;
const SymbolTable &symbol_table;
EstimatedParamsRemoveStatement(vector<EstimationParams> estim_params_list_arg,
const SymbolTable &symbol_table_arg);
void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const override;
void writeJsonOutput(ostream &output) const override;
};
class OptimWeightsStatement : public Statement
{
public:

View File

@ -184,7 +184,7 @@ class ParsingDriver;
%token NO_IDENTIFICATION_MINIMAL NO_IDENTIFICATION_SPECTRUM NORMALIZE_JACOBIANS GRID_NBR
%token TOL_RANK TOL_DERIV TOL_SV CHECKS_VIA_SUBSETS MAX_DIM_SUBSETS_GROUPS ZERO_MOMENTS_TOLERANCE
%token MAX_NROWS SQUEEZE_SHOCK_DECOMPOSITION WITH_EPILOGUE MODEL_REMOVE MODEL_REPLACE MODEL_OPTIONS
%token VAR_REMOVE
%token VAR_REMOVE ESTIMATED_PARAMS_REMOVE
%token <vector<string>> SYMBOL_VEC
@ -248,6 +248,7 @@ statement : parameters
| estimated_params
| estimated_params_bounds
| estimated_params_init
| estimated_params_remove
| set_time
| data
| epilogue
@ -1895,6 +1896,16 @@ estimated_bounds_elem : STDERR symbol COMMA expression COMMA expression ';'
}
;
estimated_params_remove : ESTIMATED_PARAMS_REMOVE ';' estimated_remove_list END ';'
{ driver.estimated_params_remove(); };
estimated_remove_list : estimated_remove_elem
| estimated_remove_list estimated_remove_elem
;
estimated_remove_elem : estimated_elem1 ';'
{ driver.add_estimated_params_element(); }
osr_params_bounds : OSR_PARAMS_BOUNDS ';' osr_bounds_list END ';'
{ driver.osr_params_bounds(); };

View File

@ -221,6 +221,7 @@ DATE -?[0-9]+([ya]|m([1-9]|1[0-2])|q[1-4])
<INITIAL>priors {BEGIN DYNARE_BLOCK;return token::ESTIMATED_PARAMS;}
<INITIAL>estimated_params_init {BEGIN DYNARE_BLOCK; return token::ESTIMATED_PARAMS_INIT;}
<INITIAL>estimated_params_bounds {BEGIN DYNARE_BLOCK; return token::ESTIMATED_PARAMS_BOUNDS;}
<INITIAL>estimated_params_remove {BEGIN DYNARE_BLOCK; return token::ESTIMATED_PARAMS_REMOVE;}
<INITIAL>osr_params_bounds {BEGIN DYNARE_BLOCK; return token::OSR_PARAMS_BOUNDS;}
<INITIAL>observation_trends {BEGIN DYNARE_BLOCK; return token::OBSERVATION_TRENDS;}
<INITIAL>deterministic_trends {BEGIN DYNARE_BLOCK; return token::DETERMINISTIC_TRENDS;}

View File

@ -1489,6 +1489,13 @@ ParsingDriver::estimated_params_bounds()
estim_params_list.clear();
}
void
ParsingDriver::estimated_params_remove()
{
mod_file->addStatement(make_unique<EstimatedParamsRemoveStatement>(estim_params_list, mod_file->symbol_table));
estim_params_list.clear();
}
void
ParsingDriver::add_osr_params_element()
{

View File

@ -512,6 +512,8 @@ public:
void estimated_params_init(bool use_calibration = false);
//! Writes estimated params bound command
void estimated_params_bounds();
//! Add an estimated_params_remove block
void estimated_params_remove();
//! Adds a declaration for a user-defined external function
void external_function();
//! Sets an external_function option to a string value