allow for expressions as upper bound for irf_calibration and moment_calibration. Closes #12

issue#70
Houtan Bastani 2019-09-25 12:02:44 +02:00
parent f66e6a7f35
commit 1fcd305015
No known key found for this signature in database
GPG Key ID: 000094FB955BE169
5 changed files with 34 additions and 18 deletions

View File

@ -184,7 +184,8 @@ class ParsingDriver;
%type <vector<string>> change_type_var_list
%type <vector<int>> vec_int_elem vec_int_1 vec_int vec_int_number
%type <PriorDistributions> prior_pdf prior_distribution
%type <pair<string,string>> named_var_elem subsamples_eq_opt calibration_range integer_range_w_inf
%type <pair<expr_t,expr_t>> calibration_range
%type <pair<string,string>> named_var_elem subsamples_eq_opt integer_range_w_inf
%type <vector<pair<string,string>>> named_var named_var_1
%type <tuple<string,string,string,string>> prior_eq_opt options_eq_opt
%%
@ -2998,14 +2999,12 @@ model_diagnostics : MODEL_DIAGNOSTICS ';'
{ driver.model_diagnostics(); }
;
calibration_range : '[' signed_number_w_inf signed_number_w_inf ']'
{ $$ = make_pair($2, $3); }
| '[' signed_number_w_inf COMMA signed_number_w_inf ']'
calibration_range : '[' expression COMMA expression ']'
{ $$ = make_pair($2, $4); }
| PLUS
{ $$ = make_pair("0", "inf"); }
{ $$ = make_pair(driver.add_non_negative_constant("0"), driver.add_inf_constant()); }
| MINUS
{ $$ = make_pair("-inf", "0"); }
{ $$ = make_pair(driver.add_uminus(driver.add_inf_constant()), driver.add_non_negative_constant("0")); }
;
moment_calibration : MOMENT_CALIBRATION ';' moment_calibration_list END ';'

View File

@ -3205,7 +3205,7 @@ ParsingDriver::add_parallel_local_file(string filename)
}
void
ParsingDriver::add_moment_calibration_item(const string &endo1, const string &endo2, string lags, const pair<string, string> &range)
ParsingDriver::add_moment_calibration_item(const string &endo1, const string &endo2, string lags, const pair<expr_t, expr_t> &range)
{
MomentCalibration::Constraint c;
@ -3232,7 +3232,7 @@ ParsingDriver::end_moment_calibration()
}
void
ParsingDriver::add_irf_calibration_item(const string &endo, string periods, const string &exo, const pair<string, string> &range)
ParsingDriver::add_irf_calibration_item(const string &endo, string periods, const string &exo, const pair<expr_t, expr_t> &range)
{
IrfCalibration::Constraint c;

View File

@ -845,11 +845,11 @@ public:
//! Processing the parallel_local_files option
void add_parallel_local_file(string filename);
//! Add an item of a moment_calibration statement
void add_moment_calibration_item(const string &endo1, const string &endo2, string lags, const pair<string, string> &range);
void add_moment_calibration_item(const string &endo1, const string &endo2, string lags, const pair<expr_t, expr_t> &range);
//! End a moment_calibration statement
void end_moment_calibration();
//! Add an item of an irf_calibration statement
void add_irf_calibration_item(const string &endo, string periods, const string &exo, const pair<string, string> &range);
void add_irf_calibration_item(const string &endo, string periods, const string &exo, const pair<expr_t, expr_t> &range);
//! End a moment_calibration statement
void end_irf_calibration();
//! Add a shock to a group

View File

@ -525,7 +525,11 @@ MomentCalibration::writeOutput(ostream &output, const string &basename, bool min
output << "'" << symbol_table.getName(c.endo1) << "', "
<< "'" << symbol_table.getName(c.endo2) << "', "
<< c.lags << ", "
<< "[ " << c.lower_bound << ", " << c.upper_bound << " ];"
<< "[ ";
c.lower_bound->writeOutput(output);
output << ", ";
c.upper_bound->writeOutput(output);
output << " ];"
<< endl;
}
output << "};" << endl;
@ -543,8 +547,12 @@ MomentCalibration::writeJsonOutput(ostream &output) const
output << R"({"endogenous1": ")" << symbol_table.getName(it->endo1) << R"(")"
<< R"(, "endogenous2": ")" << symbol_table.getName(it->endo2) << R"(")"
<< R"(, "lags": ")" << it->lags << R"(")"
<< R"(, "lower_bound": ")" << it->lower_bound << R"(")"
<< R"(, "upper_bound": ")" << it->upper_bound << R"(")"
<< R"(, "lower_bound": ")";
it->lower_bound->writeJsonOutput(output, {}, {});
output << R"(")"
<< R"(, "upper_bound": ")";
it->upper_bound->writeJsonOutput(output, {}, {});
output << R"(")"
<< "}";
}
output << "]"
@ -569,7 +577,11 @@ IrfCalibration::writeOutput(ostream &output, const string &basename, bool minima
output << "'" << symbol_table.getName(c.endo) << "', "
<< "'" << symbol_table.getName(c.exo) << "', "
<< c.periods << ", "
<< "[ " << c.lower_bound << ", " << c.upper_bound << " ];"
<< "[ ";
c.lower_bound->writeOutput(output);
output << ", ";
c.upper_bound->writeOutput(output);
output << " ];"
<< endl;
}
output << "};" << endl;
@ -593,8 +605,12 @@ IrfCalibration::writeJsonOutput(ostream &output) const
output << R"({"endogenous": ")" << symbol_table.getName(it->endo) << R"(")"
<< R"(, "exogenous": ")" << symbol_table.getName(it->exo) << R"(")"
<< R"(, "periods": ")" << it->periods << R"(")"
<< R"(, "lower_bound": ")" << it->lower_bound << R"(")"
<< R"(, "upper_bound": ")" << it->upper_bound << R"(")"
<< R"(, "lower_bound": ")";
it->lower_bound->writeJsonOutput(output, {}, {});
output << R"(")";
output << R"(, "upper_bound": ")";
it->upper_bound->writeJsonOutput(output, {}, {});
output << R"(")"
<< "}";
}
output << "]"

View File

@ -113,7 +113,7 @@ public:
{
int endo1, endo2;
string lags;
string lower_bound, upper_bound;
expr_t lower_bound, upper_bound;
};
using constraints_t = vector<Constraint>;
private:
@ -133,7 +133,8 @@ public:
{
int endo;
int exo;
string periods, lower_bound, upper_bound;
string periods;
expr_t lower_bound, upper_bound;
};
using constraints_t = vector<Constraint>;
private: