preprocessor: add symbol.options statement
parent
6ea0dd59e4
commit
744b5abf1e
|
@ -1700,3 +1700,171 @@ CorrPriorStatement::writeOutput(ostream &output, const string &basename) const
|
|||
writeOutputHelper(output, "interval", lhs_field);
|
||||
BasicPriorStatement::writeVarianceOption(output, lhs_field);
|
||||
}
|
||||
|
||||
BasicOptionsStatement::~BasicOptionsStatement()
|
||||
{
|
||||
}
|
||||
|
||||
BasicOptionsStatement::BasicOptionsStatement(const string &name_arg,
|
||||
const OptionsList &options_list_arg) :
|
||||
name(name_arg),
|
||||
options_list(options_list_arg),
|
||||
first_statement_encountered(false)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
BasicOptionsStatement::checkPass(ModFileStructure &mod_file_struct)
|
||||
{
|
||||
if (options_list.num_options.find("date1") != options_list.num_options.end() ||
|
||||
options_list.num_options.find("date2") != options_list.num_options.end())
|
||||
if (options_list.num_options.find("date1") == options_list.num_options.end() ||
|
||||
options_list.num_options.find("date2") == options_list.num_options.end())
|
||||
{
|
||||
cerr << "ERROR: OptionsStatement::checkPass(1). Should not arrive here. "
|
||||
<< "Please inform Dynare Team." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BasicOptionsStatement::writeOptionsIndex(ostream &output, const string &lhs_field) const
|
||||
{
|
||||
if (first_statement_encountered)
|
||||
output << "options_indx = 1;" << endl;
|
||||
else
|
||||
output << "options_indx = size(estimation_info" << lhs_field << "_index, 2) + 1;" << endl;
|
||||
}
|
||||
|
||||
void
|
||||
BasicOptionsStatement::get_base_name(const SymbolType symb_type, string &lhs_field) const
|
||||
{
|
||||
if (symb_type == eExogenous || symb_type == eExogenousDet)
|
||||
lhs_field = "structural_innovation";
|
||||
else
|
||||
lhs_field = "measurement_error";
|
||||
}
|
||||
|
||||
void
|
||||
BasicOptionsStatement::writeOutputHelper(ostream &output, const string &field, const string &lhs_field) const
|
||||
{
|
||||
OptionsList::num_options_t::const_iterator itn = options_list.num_options.find(field);
|
||||
if (itn != options_list.num_options.end())
|
||||
output << "estimation_info" << lhs_field << "(options_indx)." << field
|
||||
<< " = " << itn->second << ";" << endl;
|
||||
|
||||
OptionsList::date_options_t::const_iterator itd = options_list.date_options.find(field);
|
||||
if (itd != options_list.date_options.end())
|
||||
output << "estimation_info" << lhs_field << "(options_indx)." << field
|
||||
<< " = '" << itd->second << "';" << endl;
|
||||
}
|
||||
|
||||
OptionsStatement::OptionsStatement(const string &name_arg,
|
||||
const OptionsList &options_list_arg) :
|
||||
BasicOptionsStatement(name_arg, options_list_arg)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
OptionsStatement::checkPass(ModFileStructure &mod_file_struct)
|
||||
{
|
||||
BasicOptionsStatement::checkPass(mod_file_struct);
|
||||
if (!mod_file_struct.options_statement_present)
|
||||
first_statement_encountered = true;
|
||||
mod_file_struct.options_statement_present = true;
|
||||
}
|
||||
|
||||
void
|
||||
OptionsStatement::writeOutput(ostream &output, const string &basename) const
|
||||
{
|
||||
string lhs_field = ".options";
|
||||
|
||||
BasicOptionsStatement::writeOptionsIndex(output, lhs_field);
|
||||
output << "estimation_info" << lhs_field <<"_index(options_indx) = {'" << name << "'};" << endl
|
||||
<< "estimation_info" << lhs_field << "(options_indx).name = '" << name << "';" << endl;
|
||||
|
||||
writeOutputHelper(output, "init", lhs_field);
|
||||
writeOutputHelper(output, "bounds", lhs_field);
|
||||
writeOutputHelper(output, "jscale", lhs_field);
|
||||
writeOutputHelper(output, "date1", lhs_field);
|
||||
writeOutputHelper(output, "date2", lhs_field);
|
||||
}
|
||||
|
||||
StdOptionsStatement::StdOptionsStatement(const string &name_arg,
|
||||
const OptionsList &options_list_arg,
|
||||
const SymbolTable &symbol_table_arg ) :
|
||||
BasicOptionsStatement(name_arg, options_list_arg),
|
||||
symbol_table(symbol_table_arg)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
StdOptionsStatement::checkPass(ModFileStructure &mod_file_struct)
|
||||
{
|
||||
BasicOptionsStatement::checkPass(mod_file_struct);
|
||||
if (!mod_file_struct.std_options_statement_present)
|
||||
first_statement_encountered = true;
|
||||
mod_file_struct.std_options_statement_present = true;
|
||||
}
|
||||
|
||||
void
|
||||
StdOptionsStatement::writeOutput(ostream &output, const string &basename) const
|
||||
{
|
||||
string lhs_field;
|
||||
get_base_name(symbol_table.getType(name), lhs_field);
|
||||
lhs_field = "." + lhs_field + ".options";
|
||||
|
||||
BasicOptionsStatement::writeOptionsIndex(output, lhs_field);
|
||||
output << "estimation_info" << lhs_field << "_index(options_indx) = {'" << name << "'};" << endl;
|
||||
output << "estimation_info" << lhs_field << "(options_indx).name = '" << name << "';" << endl;
|
||||
|
||||
writeOutputHelper(output, "init", lhs_field);
|
||||
writeOutputHelper(output, "bounds", lhs_field);
|
||||
writeOutputHelper(output, "jscale", lhs_field);
|
||||
writeOutputHelper(output, "date1", lhs_field);
|
||||
writeOutputHelper(output, "date2", lhs_field);
|
||||
}
|
||||
|
||||
CorrOptionsStatement::CorrOptionsStatement(const string &name_arg1, const string &name_arg2,
|
||||
const OptionsList &options_list_arg,
|
||||
const SymbolTable &symbol_table_arg ) :
|
||||
BasicOptionsStatement(name_arg1, options_list_arg),
|
||||
name1(name_arg2),
|
||||
symbol_table(symbol_table_arg)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
CorrOptionsStatement::checkPass(ModFileStructure &mod_file_struct)
|
||||
{
|
||||
if (symbol_table.getType(name) != symbol_table.getType(name1))
|
||||
{
|
||||
cerr << "ERROR: In the corr(A,B).options statement, A and B must be of the same type. "
|
||||
<< "In your case, " << name << " and " << name1 << " are of different "
|
||||
<< "types." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (!mod_file_struct.corr_options_statement_present)
|
||||
first_statement_encountered = true;
|
||||
mod_file_struct.corr_prior_statement_present = true;
|
||||
}
|
||||
|
||||
void
|
||||
CorrOptionsStatement::writeOutput(ostream &output, const string &basename) const
|
||||
{
|
||||
string lhs_field;
|
||||
get_base_name(symbol_table.getType(name), lhs_field);
|
||||
lhs_field = "." + lhs_field + "_corr.options";
|
||||
|
||||
BasicOptionsStatement::writeOptionsIndex(output, lhs_field);
|
||||
output << "estimation_info" << lhs_field << "_index(options_indx) = {'" << name << "_" << name1 << "'};" << endl;
|
||||
lhs_field += ".";
|
||||
output << "estimation_info" << lhs_field << "(options_indx).name1 = '" << name << "';" << endl;
|
||||
output << "estimation_info" << lhs_field << "(options_indx).name2 = '" << name1 << "';" << endl;
|
||||
|
||||
writeOutputHelper(output, "init", lhs_field);
|
||||
writeOutputHelper(output, "bounds", lhs_field);
|
||||
writeOutputHelper(output, "jscale", lhs_field);
|
||||
writeOutputHelper(output, "date1", lhs_field);
|
||||
writeOutputHelper(output, "date2", lhs_field);
|
||||
}
|
||||
|
|
|
@ -632,4 +632,51 @@ public:
|
|||
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||
};
|
||||
|
||||
class BasicOptionsStatement : public Statement
|
||||
{
|
||||
public:
|
||||
virtual ~BasicOptionsStatement();
|
||||
protected:
|
||||
const string name;
|
||||
const OptionsList options_list;
|
||||
bool first_statement_encountered;
|
||||
BasicOptionsStatement(const string &name_arg,
|
||||
const OptionsList &options_list_arg);
|
||||
void get_base_name(const SymbolType symb_type, string &lhs_field) const;
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct);
|
||||
void writeOptionsIndex(ostream &output, const string &lhs_field) const;
|
||||
void writeOutputHelper(ostream &output, const string &field, const string &lhs_field) const;
|
||||
};
|
||||
|
||||
class OptionsStatement : public BasicOptionsStatement
|
||||
{
|
||||
public:
|
||||
OptionsStatement(const string &name_arg, const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct);
|
||||
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||
};
|
||||
|
||||
class StdOptionsStatement : public BasicOptionsStatement
|
||||
{
|
||||
private:
|
||||
const SymbolTable symbol_table;
|
||||
public:
|
||||
StdOptionsStatement(const string &name_arg, const OptionsList &options_list_arg,
|
||||
const SymbolTable &symbol_table_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct);
|
||||
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||
};
|
||||
|
||||
class CorrOptionsStatement : public BasicOptionsStatement
|
||||
{
|
||||
private:
|
||||
const string name1;
|
||||
const SymbolTable symbol_table;
|
||||
public:
|
||||
CorrOptionsStatement(const string &name_arg1, const string &name_arg2,
|
||||
const OptionsList &options_list_arg, const SymbolTable &symbol_table_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct);
|
||||
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -101,11 +101,11 @@ class ParsingDriver;
|
|||
%token FORECAST K_ORDER_SOLVER INSTRUMENTS PRIOR SHIFT MEAN STDEV VARIANCE MODE INTERVAL SHAPE DOMAINN
|
||||
%token GAMMA_PDF GRAPH CONDITIONAL_VARIANCE_DECOMPOSITION NOCHECK STD
|
||||
%token HISTVAL HOMOTOPY_SETUP HOMOTOPY_MODE HOMOTOPY_STEPS HP_FILTER HP_NGRID
|
||||
%token IDENTIFICATION INF_CONSTANT INITVAL INITVAL_FILE
|
||||
%token IDENTIFICATION INF_CONSTANT INITVAL INITVAL_FILE BOUNDS JSCALE INIT
|
||||
%token <string_val> INT_NUMBER
|
||||
%token <string_val> DATE_NUMBER
|
||||
%token INV_GAMMA_PDF INV_GAMMA1_PDF INV_GAMMA2_PDF IRF IRF_SHOCKS
|
||||
%token KALMAN_ALGO KALMAN_TOL SUBSAMPLES
|
||||
%token KALMAN_ALGO KALMAN_TOL SUBSAMPLES OPTIONS
|
||||
%token LABELS LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_IDENT_FILES LOAD_MH_FILE LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR
|
||||
%token MARKOWITZ MARGINAL_DENSITY MAX MAXIT
|
||||
%token MFS MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER MIN MINIMAL_SOLVING_PERIODS
|
||||
|
@ -176,8 +176,8 @@ class ParsingDriver;
|
|||
%type <node_val> equation hand_side
|
||||
%type <string_val> non_negative_number signed_number signed_integer date_number
|
||||
%type <string_val> filename symbol prior_distribution
|
||||
%type <string_val> vec_value_1 vec_value
|
||||
%type <string_val> range prior_pdf_string
|
||||
%type <string_val> vec_value_1 vec_value signed_inf signed_number_w_inf
|
||||
%type <string_val> range prior_pdf_string vec_value_w_inf vec_value_1_w_inf
|
||||
%type <symbol_type_val> change_type_arg
|
||||
%type <vector_string_val> change_type_var_list
|
||||
%type <vector_int_val> vec_int_elem vec_int_1 vec_int vec_int_number
|
||||
|
@ -219,6 +219,7 @@ statement : parameters
|
|||
| prior
|
||||
| subsamples
|
||||
| subsamples_eq
|
||||
| options
|
||||
| varobs
|
||||
| observation_trends
|
||||
| unit_root_vars
|
||||
|
@ -980,6 +981,18 @@ signed_number : PLUS non_negative_number
|
|||
| non_negative_number
|
||||
;
|
||||
|
||||
signed_inf : PLUS INF_CONSTANT
|
||||
{ $$ = new string ("Inf"); }
|
||||
| MINUS INF_CONSTANT
|
||||
{ $$ = new string ("-Inf"); }
|
||||
| INF_CONSTANT
|
||||
{ $$ = new string ("Inf"); }
|
||||
;
|
||||
|
||||
signed_number_w_inf : signed_inf
|
||||
| signed_number
|
||||
;
|
||||
|
||||
estimated_params : ESTIMATED_PARAMS ';' estimated_list END ';' { driver.estimated_params(); };
|
||||
|
||||
estimated_list : estimated_list estimated_elem
|
||||
|
@ -1238,6 +1251,28 @@ prior_options : o_shift
|
|||
| o_domain
|
||||
;
|
||||
|
||||
options : symbol '.' OPTIONS '(' options_options_list ')' ';'
|
||||
{ driver.set_options($1); }
|
||||
| symbol '.' symbol '.' OPTIONS '(' options_options_list ')' ';'
|
||||
{
|
||||
driver.add_subsample_range(new string (*$1), $3);
|
||||
driver.set_options($1);
|
||||
}
|
||||
| STD '(' symbol ')' '.' OPTIONS '(' options_options_list ')' ';'
|
||||
{ driver.set_std_options($3); }
|
||||
| CORR '(' symbol COMMA symbol')' '.' OPTIONS '(' options_options_list ')' ';'
|
||||
{ driver.set_corr_options($3, $5); }
|
||||
;
|
||||
|
||||
options_options_list : options_options_list COMMA options_options
|
||||
| options_options
|
||||
;
|
||||
|
||||
options_options : o_jscale
|
||||
| o_init
|
||||
| o_bounds
|
||||
;
|
||||
|
||||
estimation : ESTIMATION ';'
|
||||
{ driver.run_estimation(); }
|
||||
| ESTIMATION '(' estimation_options_list ')' ';'
|
||||
|
@ -1961,6 +1996,9 @@ o_shape : SHAPE EQUAL prior_distribution { driver.option_num("shape", $3); };
|
|||
o_mode : MODE EQUAL signed_number { driver.option_num("mode", $3); };
|
||||
o_mean : MEAN EQUAL signed_number { driver.option_num("mean", $3); };
|
||||
o_stdev : STDEV EQUAL non_negative_number { driver.option_num("stdev", $3); };
|
||||
o_jscale : JSCALE EQUAL non_negative_number { driver.option_num("jscale", $3); };
|
||||
o_init : INIT EQUAL signed_number { driver.option_num("init", $3); };
|
||||
o_bounds : BOUNDS EQUAL vec_value_w_inf { driver.option_num("bounds", $3); };
|
||||
o_domain : DOMAINN EQUAL vec_value { driver.option_num("domain", $3); };
|
||||
o_interval : INTERVAL EQUAL vec_value { driver.option_num("interval", $3); };
|
||||
o_variance : VARIANCE EQUAL expression { driver.add_expression_to_prior_statement($3); }
|
||||
|
@ -2339,6 +2377,19 @@ vec_value_1 : '[' signed_number
|
|||
|
||||
vec_value : vec_value_1 ']' { $1->append("]"); $$ = $1; };
|
||||
|
||||
vec_value_1_w_inf : '[' signed_number_w_inf
|
||||
{ $2->insert(0, "["); $$ = $2;}
|
||||
| vec_value_1_w_inf signed_number_w_inf
|
||||
{
|
||||
$1->append(" ");
|
||||
$1->append(*$2);
|
||||
delete $2;
|
||||
$$ = $1;
|
||||
}
|
||||
;
|
||||
|
||||
vec_value_w_inf : vec_value_1_w_inf ']' { $1->append("]"); $$ = $1; };
|
||||
|
||||
symbol : NAME
|
||||
| ALPHA
|
||||
| BETA
|
||||
|
|
|
@ -190,6 +190,7 @@ string eofbuff;
|
|||
<DYNARE_BLOCK>end {BEGIN INITIAL; return token::END;}
|
||||
|
||||
<DYNARE_STATEMENT>subsamples {return token::SUBSAMPLES;}
|
||||
<DYNARE_STATEMENT>options {return token::OPTIONS;}
|
||||
<DYNARE_STATEMENT>prior {return token::PRIOR;}
|
||||
<INITIAL>std {BEGIN DYNARE_STATEMENT; return token::STD;}
|
||||
<INITIAL>corr {BEGIN DYNARE_STATEMENT; return token::CORR;}
|
||||
|
@ -208,6 +209,9 @@ string eofbuff;
|
|||
<DYNARE_STATEMENT>interval {return token::INTERVAL;}
|
||||
<DYNARE_STATEMENT>shape {return token::SHAPE;}
|
||||
<DYNARE_STATEMENT>shift {return token::SHIFT;}
|
||||
<DYNARE_STATEMENT>bounds {return token::BOUNDS;}
|
||||
<DYNARE_STATEMENT>init {return token::INIT;}
|
||||
<DYNARE_STATEMENT>jscale {return token::JSCALE;}
|
||||
<DYNARE_STATEMENT>prefilter {return token::PREFILTER;}
|
||||
<DYNARE_STATEMENT>presample {return token::PRESAMPLE;}
|
||||
<DYNARE_STATEMENT>lik_algo {return token::LIK_ALGO;}
|
||||
|
|
|
@ -1315,6 +1315,15 @@ ParsingDriver::add_expression_to_prior_statement(expr_t variance)
|
|||
prior_variance = variance;
|
||||
}
|
||||
|
||||
void
|
||||
ParsingDriver::set_options(string *name)
|
||||
{
|
||||
check_symbol_is_parameter(name);
|
||||
mod_file->addStatement(new OptionsStatement(*name, options_list));
|
||||
options_list.clear();
|
||||
delete name;
|
||||
}
|
||||
|
||||
void
|
||||
ParsingDriver::check_symbol_is_endogenous_or_exogenous(string *name)
|
||||
{
|
||||
|
@ -1341,6 +1350,15 @@ ParsingDriver::set_std_prior(string *name)
|
|||
delete name;
|
||||
}
|
||||
|
||||
void
|
||||
ParsingDriver::set_std_options(string *name)
|
||||
{
|
||||
check_symbol_is_endogenous_or_exogenous(name);
|
||||
// mod_file->addStatement(new StdOptionsStatement(*name, options_list, mod_file->symbol_table));
|
||||
options_list.clear();
|
||||
delete name;
|
||||
}
|
||||
|
||||
void
|
||||
ParsingDriver::set_corr_prior(string *name1, string *name2)
|
||||
{
|
||||
|
@ -1353,6 +1371,17 @@ ParsingDriver::set_corr_prior(string *name1, string *name2)
|
|||
delete name2;
|
||||
}
|
||||
|
||||
void
|
||||
ParsingDriver::set_corr_options(string *name1, string *name2)
|
||||
{
|
||||
check_symbol_is_endogenous_or_exogenous(name1);
|
||||
check_symbol_is_endogenous_or_exogenous(name2);
|
||||
// mod_file->addStatement(new CorrOptionsStatement(*name1, *name2, options_list, mod_file->symbol_table));
|
||||
options_list.clear();
|
||||
delete name1;
|
||||
delete name2;
|
||||
}
|
||||
|
||||
void
|
||||
ParsingDriver::run_estimation()
|
||||
{
|
||||
|
|
|
@ -390,10 +390,16 @@ public:
|
|||
void set_prior(string *arg);
|
||||
//! Adds the variance option to its temporary holding place
|
||||
void add_expression_to_prior_statement(expr_t variance);
|
||||
//! Sets the options for a parameter
|
||||
void set_options(string *arg);
|
||||
//! Sets the prior for estimated std dev
|
||||
void set_std_prior(string *arg);
|
||||
//! Sets the options for estimated std dev
|
||||
void set_std_options(string *arg);
|
||||
//! Sets the prior for estimated correlation
|
||||
void set_corr_prior(string *arg1, string *arg2);
|
||||
//! Sets the options for estimated correlation
|
||||
void set_corr_options(string *arg1, string *arg2);
|
||||
//! Runs estimation process
|
||||
void run_estimation();
|
||||
//! Runs dynare_sensitivy()
|
||||
|
|
|
@ -94,6 +94,12 @@ public:
|
|||
bool std_prior_statement_present;
|
||||
//! Whether there is a corr prior statement present
|
||||
bool corr_prior_statement_present;
|
||||
//! Whether there is a options statement present
|
||||
bool options_statement_present;
|
||||
//! Whether there is a std options statement present
|
||||
bool std_options_statement_present;
|
||||
//! Whether there is a corr options statement present
|
||||
bool corr_options_statement_present;
|
||||
};
|
||||
|
||||
class Statement
|
||||
|
|
Loading…
Reference in New Issue