Commit 58d71bb4 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Implement syntaxes for moment_calibration and irf_calibration.

Ref #267
parent 9e962e7a
......@@ -100,13 +100,13 @@ class ParsingDriver;
%token HISTVAL HOMOTOPY_SETUP HOMOTOPY_MODE HOMOTOPY_STEPS HOMOTOPY_FORCE_CONTINUE HP_FILTER HP_NGRID HYBRID
%token IDENTIFICATION INF_CONSTANT INITVAL INITVAL_FILE BOUNDS JSCALE INIT
%token <string_val> INT_NUMBER
%token INV_GAMMA_PDF INV_GAMMA1_PDF INV_GAMMA2_PDF IRF IRF_SHOCKS IRF_PLOT_THRESHOLD
%token INV_GAMMA_PDF INV_GAMMA1_PDF INV_GAMMA2_PDF IRF IRF_SHOCKS IRF_PLOT_THRESHOLD IRF_CALIBRATION
%token KALMAN_ALGO KALMAN_TOL SUBSAMPLES OPTIONS TOLF
%token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_IDENT_FILES LOAD_MH_FILE LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR LOGDATA LYAPUNOV
%token LYAPUNOV_FIXED_POINT_TOL LYAPUNOV_DOUBLING_TOL LYAPUNOV_SQUARE_ROOT_SOLVER_TOL LOG_DEFLATOR LOG_TREND_VAR LOG_GROWTH_FACTOR MARKOWITZ MARGINAL_DENSITY MAX MAXIT
%token MFS MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER POSTERIOR_MAX_SUBSAMPLE_DRAWS MIN MINIMAL_SOLVING_PERIODS
%token MODE_CHECK MODE_CHECK_NEIGHBOURHOOD_SIZE MODE_CHECK_SYMMETRIC_PLOTS MODE_CHECK_NUMBER_OF_POINTS MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MODEL_INFO MSHOCKS ABS SIGN
%token MODEL_DIAGNOSTICS MODIFIEDHARMONICMEAN MOMENTS_VARENDO DIFFUSE_FILTER SUB_DRAWS TAPER_STEPS GEWEKE_INTERVAL MCMC_JUMPING_COVARIANCE
%token MODEL_DIAGNOSTICS MODIFIEDHARMONICMEAN MOMENTS_VARENDO DIFFUSE_FILTER SUB_DRAWS TAPER_STEPS GEWEKE_INTERVAL MCMC_JUMPING_COVARIANCE MOMENT_CALIBRATION
%token <string_val> NAME
%token NAN_CONSTANT NO_STATIC NOBS NOCONSTANT NODISPLAY NOCORR NODIAGNOSTIC NOFUNCTIONS
%token NOGRAPH NOMOMENTS NOPRINT NORMAL_PDF SAVE_DRAWS
......@@ -176,7 +176,7 @@ class ParsingDriver;
%type <string_val> vec_value_1 vec_value signed_inf signed_number_w_inf
%type <string_val> range vec_value_w_inf vec_value_1_w_inf named_var
%type <symbol_type_val> change_type_arg
%type <vector_string_val> change_type_var_list subsamples_eq_opt prior_eq_opt options_eq_opt
%type <vector_string_val> change_type_var_list subsamples_eq_opt prior_eq_opt options_eq_opt calibration_range
%type <vector_int_val> vec_int_elem vec_int_1 vec_int vec_int_number
%type <prior_distributions_val> prior_pdf prior_distribution
%%
......@@ -266,6 +266,8 @@ statement : parameters
| calib_smoother
| extended_path
| model_diagnostics
| moment_calibration
| irf_calibration
;
dsample : DSAMPLE INT_NUMBER ';'
......@@ -2304,6 +2306,60 @@ model_diagnostics : MODEL_DIAGNOSTICS ';'
{ driver.model_diagnostics(); }
;
calibration_range : '[' signed_number_w_inf signed_number_w_inf ']'
{
$$ = new vector<string *>();
$$->push_back($2);
$$->push_back($3);
}
| '[' signed_number_w_inf COMMA signed_number_w_inf ']'
{
$$ = new vector<string *>();
$$->push_back($2);
$$->push_back($4);
}
| PLUS
{
$$ = new vector<string *>();
$$->push_back(new string("0"));
$$->push_back(new string("inf"));
}
| MINUS
{
$$ = new vector<string *>();
$$->push_back(new string("-inf"));
$$->push_back(new string("0"));
}
;
moment_calibration : MOMENT_CALIBRATION ';' moment_calibration_list END ';'
{ driver.end_moment_calibration(); }
;
moment_calibration_list : moment_calibration_item
| moment_calibration_list moment_calibration_item
;
moment_calibration_item : symbol COMMA symbol COMMA calibration_range ';'
{ driver.add_moment_calibration_item($1, $3, new string("0"), $5); }
| symbol COMMA symbol '(' signed_integer ')' COMMA calibration_range ';'
{ driver.add_moment_calibration_item($1, $3, $5, $8); }
;
irf_calibration : IRF_CALIBRATION ';' irf_calibration_list END ';'
{ driver.end_irf_calibration(); }
;
irf_calibration_list : irf_calibration_item
| irf_calibration_list irf_calibration_item
;
irf_calibration_item : symbol COMMA symbol COMMA calibration_range ';'
{ driver.add_irf_calibration_item($1, new string("1"), $3, $5); }
| symbol '(' INT_NUMBER ')' COMMA symbol COMMA calibration_range ';'
{ driver.add_irf_calibration_item($1, $3, $6, $8); }
;
o_dr_algo : DR_ALGO EQUAL INT_NUMBER {
if (*$3 == string("0"))
driver.warning("dr_algo option is now deprecated, and may be removed in a future version of Dynare");
......
......@@ -191,6 +191,8 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2
<INITIAL>homotopy_setup {BEGIN DYNARE_BLOCK; return token::HOMOTOPY_SETUP;}
<INITIAL>conditional_forecast_paths {BEGIN DYNARE_BLOCK; return token::CONDITIONAL_FORECAST_PATHS;}
<INITIAL>svar_identification {BEGIN DYNARE_BLOCK; return token::SVAR_IDENTIFICATION;}
<INITIAL>moment_calibration {BEGIN DYNARE_BLOCK; return token::MOMENT_CALIBRATION;}
<INITIAL>irf_calibration {BEGIN DYNARE_BLOCK; return token::IRF_CALIBRATION;}
/* For the semicolon after an "end" keyword */
<INITIAL>; {return Dynare::parser::token_type (yytext[0]);}
......
......@@ -2571,3 +2571,77 @@ ParsingDriver::add_parallel_local_file(string *filename)
delete filename;
}
void
ParsingDriver::add_moment_calibration_item(string *endo1, string *endo2, string *lag, vector<string *> *range)
{
MomentCalibration::Constraint c;
check_symbol_existence(*endo1);
c.endo1 = mod_file->symbol_table.getID(*endo1);
if (mod_file->symbol_table.getType(*endo1) != eEndogenous)
error("Variable " + *endo1 + " is not an endogenous.");
delete endo1;
check_symbol_existence(*endo2);
c.endo2 = mod_file->symbol_table.getID(*endo2);
if (mod_file->symbol_table.getType(*endo2) != eEndogenous)
error("Variable " + *endo2 + " is not an endogenous.");
delete endo2;
c.lag = abs(atoi(lag->c_str()));
delete lag;
assert(range->size() == 2);
c.lower_bound = *((*range)[0]);
c.upper_bound = *((*range)[1]);
delete (*range)[0];
delete (*range)[1];
delete range;
moment_calibration_constraints.push_back(c);
}
void ParsingDriver::end_moment_calibration()
{
mod_file->addStatement(new MomentCalibration(moment_calibration_constraints,
mod_file->symbol_table));
moment_calibration_constraints.clear();
}
void
ParsingDriver::add_irf_calibration_item(string *endo, string *period, string *exo, vector<string *> *range)
{
IrfCalibration::Constraint c;
check_symbol_existence(*endo);
c.endo = mod_file->symbol_table.getID(*endo);
if (mod_file->symbol_table.getType(*endo) != eEndogenous)
error("Variable " + *endo + " is not an endogenous.");
delete endo;
c.period = atoi(period->c_str());
delete period;
check_symbol_existence(*exo);
c.exo = mod_file->symbol_table.getID(*exo);
if (mod_file->symbol_table.getType(*exo) != eExogenous)
error("Variable " + *endo + " is not an exogenous.");
delete exo;
assert(range->size() == 2);
c.lower_bound = *((*range)[0]);
c.upper_bound = *((*range)[1]);
delete (*range)[0];
delete (*range)[1];
delete range;
irf_calibration_constraints.push_back(c);
}
void ParsingDriver::end_irf_calibration()
{
mod_file->addStatement(new IrfCalibration(irf_calibration_constraints,
mod_file->symbol_table));
irf_calibration_constraints.clear();
}
/*
* Copyright (C) 2003-2013 Dynare Team
* Copyright (C) 2003-2014 Dynare Team
*
* This file is part of Dynare.
*
......@@ -152,6 +152,10 @@ private:
HistValStatement::hist_values_t hist_values;
//! Temporary storage for homotopy_setup blocks
HomotopyStatement::homotopy_values_t homotopy_values;
//! Temporary storage for moment_calibration
MomentCalibration::constraints_t moment_calibration_constraints;
//! Temporary storage for irf_calibration
IrfCalibration::constraints_t irf_calibration_constraints;
//! Temporary storage for svar_identification blocks
SvarIdentificationStatement::svar_identification_restrictions_t svar_ident_restrictions;
//! Temporary storage for mapping the equation number to the restrictions within an svar_identification block
......@@ -651,6 +655,14 @@ public:
void model_diagnostics();
//! 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(string *endo1, string *endo2, string *lag, vector<string *> *range);
//! End a moment_calibration statement
void end_moment_calibration();
//! Add an item of an irf_calibration statement
void add_irf_calibration_item(string *endo, string *period, string *exo, vector<string *> *range);
//! End a moment_calibration statement
void end_irf_calibration();
};
#endif // ! PARSING_DRIVER_HH
/*
* Copyright (C) 2003-2013 Dynare Team
* Copyright (C) 2003-2014 Dynare Team
*
* This file is part of Dynare.
*
......@@ -386,3 +386,47 @@ ConditionalForecastPathsStatement::writeOutput(ostream &output, const string &ba
k++;
}
}
MomentCalibration::MomentCalibration(const constraints_t &constraints_arg,
const SymbolTable &symbol_table_arg)
: constraints(constraints_arg), symbol_table(symbol_table_arg)
{
}
void
MomentCalibration::writeOutput(ostream &output, const string &basename) const
{
output << "options_.moment_calibration = {" << endl;
for (size_t i = 0; i < constraints.size(); i++)
{
const Constraint &c = constraints[i];
output << "'" << symbol_table.getName(c.endo1) << "', "
<< "'" << symbol_table.getName(c.endo2) << "', "
<< c.lag << ", "
<< "[ " << c.lower_bound << ", " << c.upper_bound << " ];"
<< endl;
}
output << "};" << endl;
}
IrfCalibration::IrfCalibration(const constraints_t &constraints_arg,
const SymbolTable &symbol_table_arg)
: constraints(constraints_arg), symbol_table(symbol_table_arg)
{
}
void
IrfCalibration::writeOutput(ostream &output, const string &basename) const
{
output << "options_.irf_calibration = {" << endl;
for (size_t i = 0; i < constraints.size(); i++)
{
const Constraint &c = constraints[i];
output << "'" << symbol_table.getName(c.endo) << "', "
<< "'" << symbol_table.getName(c.exo) << "', "
<< c.period << ", "
<< "[ " << c.lower_bound << ", " << c.upper_bound << " ];"
<< endl;
}
output << "};" << endl;
}
/*
* Copyright (C) 2003-2013 Dynare Team
* Copyright (C) 2003-2014 Dynare Team
*
* This file is part of Dynare.
*
......@@ -97,4 +97,42 @@ public:
virtual void writeOutput(ostream &output, const string &basename) const;
};
class MomentCalibration : public Statement
{
public:
struct Constraint
{
int endo1, endo2;
int lag;
string lower_bound, upper_bound;
};
typedef vector<Constraint> constraints_t;
private:
constraints_t constraints;
const SymbolTable &symbol_table;
public:
MomentCalibration(const constraints_t &constraints_arg,
const SymbolTable &symbol_table_arg);
virtual void writeOutput(ostream &output, const string &basename) const;
};
class IrfCalibration : public Statement
{
public:
struct Constraint
{
int endo, period;
int exo;
string lower_bound, upper_bound;
};
typedef vector<Constraint> constraints_t;
private:
constraints_t constraints;
const SymbolTable &symbol_table;
public:
IrfCalibration(const constraints_t &constraints_arg,
const SymbolTable &symbol_table_arg);
virtual void writeOutput(ostream &output, const string &basename) const;
};
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment