estimation: introduce options = options syntax
parent
87fba231fd
commit
36a56199c4
|
@ -2131,3 +2131,107 @@ CorrOptionsStatement::writeOutput(ostream &output, const string &basename) const
|
|||
lhs_field = "estimation_info." + lhs_field + "_corr(eifind)";
|
||||
writeOptionsOutput(output, lhs_field, name1);
|
||||
}
|
||||
|
||||
OptionsEqualStatement::OptionsEqualStatement(const string &to_declaration_type_arg,
|
||||
const string &to_name1_arg,
|
||||
const string &to_name2_arg,
|
||||
const string &to_subsample_name_arg,
|
||||
const string &from_declaration_type_arg,
|
||||
const string &from_name1_arg,
|
||||
const string &from_name2_arg,
|
||||
const string &from_subsample_name_arg,
|
||||
const SymbolTable &symbol_table_arg) :
|
||||
to_declaration_type(to_declaration_type_arg),
|
||||
to_name1(to_name1_arg),
|
||||
to_name2(to_name2_arg),
|
||||
to_subsample_name(to_subsample_name_arg),
|
||||
from_declaration_type(from_declaration_type_arg),
|
||||
from_name1(from_name1_arg),
|
||||
from_name2(from_name2_arg),
|
||||
from_subsample_name(from_subsample_name_arg),
|
||||
symbol_table(symbol_table_arg)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
OptionsEqualStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
|
||||
{
|
||||
if ((to_declaration_type != "par" && to_declaration_type != "std" && to_declaration_type != "corr") ||
|
||||
(from_declaration_type != "par" && from_declaration_type != "std" && from_declaration_type != "corr"))
|
||||
{
|
||||
cerr << "Internal Dynare Error" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
OptionsEqualStatement::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
|
||||
OptionsEqualStatement::writeOutput(ostream &output, const string &basename) const
|
||||
{
|
||||
string lhs_field, rhs_field;
|
||||
|
||||
if (to_declaration_type == "par")
|
||||
lhs_field = "parameter";
|
||||
else
|
||||
get_base_name(symbol_table.getType(to_name1), lhs_field);
|
||||
|
||||
if (from_declaration_type == "par")
|
||||
rhs_field = "parameter";
|
||||
else
|
||||
get_base_name(symbol_table.getType(from_name1), rhs_field);
|
||||
|
||||
|
||||
if (to_declaration_type == "corr")
|
||||
lhs_field += "_corr";
|
||||
|
||||
if (from_declaration_type == "corr")
|
||||
rhs_field += "_corr";
|
||||
|
||||
output << "ei_to_ind = get_new_or_existing_ei_index('" << lhs_field << "_options_index', '"
|
||||
<< to_name1 << "', '" << to_name2<< "');" << endl
|
||||
<< "ei_from_ind = get_new_or_existing_ei_index('" << rhs_field << "_options_index', '"
|
||||
<< from_name1 << "', '" << from_name2<< "');" << endl
|
||||
<< "estimation_info." << lhs_field << "_options_index(ei_to_ind) = {'" << to_name1;
|
||||
|
||||
if (to_declaration_type == "corr")
|
||||
output << ":" << to_name2;
|
||||
output << "'};" << endl;
|
||||
|
||||
if (to_declaration_type == "par")
|
||||
lhs_field = "parameters";
|
||||
|
||||
if (from_declaration_type == "par")
|
||||
rhs_field = "parameters";
|
||||
|
||||
lhs_field = "estimation_info." + lhs_field + "(ei_to_ind)";
|
||||
rhs_field = "estimation_info." + rhs_field + "(ei_from_ind)";
|
||||
|
||||
if (to_subsample_name.empty())
|
||||
lhs_field += ".options";
|
||||
else
|
||||
{
|
||||
output << "subsamples_to_indx = get_existing_subsamples_indx('" << to_name1 << "','" << to_name2 << "');" << endl
|
||||
<< lhs_field << ".range_index = estimation_info.subsamples(subsamples_to_indx).range_index;" << endl
|
||||
<< "ei_to_ss_ind = get_subsamples_range_indx(subsamples_to_indx, '" << to_subsample_name << "');" << endl;
|
||||
lhs_field += ".subsample_options(ei_to_ss_ind)";
|
||||
}
|
||||
|
||||
if (from_subsample_name.empty())
|
||||
rhs_field += ".options";
|
||||
else
|
||||
{
|
||||
output << "subsamples_from_indx = get_existing_subsamples_indx('" << from_name1 << "','" << from_name2 << "');" << endl
|
||||
<< "ei_from_ss_ind = get_subsamples_range_indx(subsamples_from_indx, '" << from_subsample_name << "');" << endl;
|
||||
rhs_field += ".subsample_options(ei_from_ss_ind)";
|
||||
}
|
||||
|
||||
output << lhs_field << " = " << rhs_field << ";" << endl;
|
||||
}
|
||||
|
|
|
@ -753,4 +753,31 @@ public:
|
|||
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||
};
|
||||
|
||||
class OptionsEqualStatement : public Statement
|
||||
{
|
||||
private:
|
||||
const string to_declaration_type;
|
||||
const string to_name1;
|
||||
const string to_name2;
|
||||
const string to_subsample_name;
|
||||
const string from_declaration_type;
|
||||
const string from_name1;
|
||||
const string from_name2;
|
||||
const string from_subsample_name;
|
||||
const SymbolTable symbol_table;
|
||||
public:
|
||||
OptionsEqualStatement(const string &to_declaration_type_arg,
|
||||
const string &to_name1_arg,
|
||||
const string &to_name2_arg,
|
||||
const string &to_subsample_name_arg,
|
||||
const string &from_declaration_type_arg,
|
||||
const string &from_name1_arg,
|
||||
const string &from_name2_arg,
|
||||
const string &from_subsample_name_arg,
|
||||
const SymbolTable &symbol_table_arg);
|
||||
void get_base_name(const SymbolType symb_type, string &lhs_field) const;
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -182,7 +182,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
|
||||
%type <symbol_type_val> change_type_arg
|
||||
%type <vector_string_val> change_type_var_list subsamples_eq_opt prior_eq_opt
|
||||
%type <vector_string_val> change_type_var_list subsamples_eq_opt prior_eq_opt options_eq_opt
|
||||
%type <vector_int_val> vec_int_elem vec_int_1 vec_int vec_int_number
|
||||
%type <prior_distributions_val> prior_pdf prior_distribution
|
||||
%%
|
||||
|
@ -224,6 +224,7 @@ statement : parameters
|
|||
| subsamples
|
||||
| subsamples_eq
|
||||
| options
|
||||
| options_eq
|
||||
| varobs
|
||||
| observation_trends
|
||||
| unit_root_vars
|
||||
|
@ -1362,6 +1363,65 @@ options_options : o_jscale
|
|||
| o_bounds
|
||||
;
|
||||
|
||||
options_eq : options_eq_opt EQUAL options_eq_opt ';'
|
||||
{
|
||||
driver.copy_options($1->at(0), $1->at(1), $1->at(2), $1->at(3),
|
||||
$3->at(0), $3->at(1), $3->at(2), $3->at(3));
|
||||
delete $1;
|
||||
delete $3;
|
||||
}
|
||||
;
|
||||
|
||||
options_eq_opt : symbol '.' OPTIONS
|
||||
{
|
||||
$$ = new vector<string *>();
|
||||
$$->push_back(new string ("par"));
|
||||
$$->push_back($1);
|
||||
$$->push_back(new string (""));
|
||||
$$->push_back(new string (""));
|
||||
}
|
||||
| symbol '.' symbol '.' OPTIONS
|
||||
{
|
||||
$$ = new vector<string *>();
|
||||
$$->push_back(new string ("par"));
|
||||
$$->push_back($1);
|
||||
$$->push_back(new string (""));
|
||||
$$->push_back($3);
|
||||
}
|
||||
| STD '(' symbol ')' '.' OPTIONS
|
||||
{
|
||||
$$ = new vector<string *>();
|
||||
$$->push_back(new string ("std"));
|
||||
$$->push_back($3);
|
||||
$$->push_back(new string (""));
|
||||
$$->push_back(new string (""));
|
||||
}
|
||||
| STD '(' symbol ')' '.' symbol '.' OPTIONS
|
||||
{
|
||||
$$ = new vector<string *>();
|
||||
$$->push_back(new string ("std"));
|
||||
$$->push_back($3);
|
||||
$$->push_back(new string (""));
|
||||
$$->push_back($6);
|
||||
}
|
||||
| CORR '(' symbol COMMA symbol ')' '.' OPTIONS
|
||||
{
|
||||
$$ = new vector<string *>();
|
||||
$$->push_back(new string ("corr"));
|
||||
$$->push_back($3);
|
||||
$$->push_back($5);
|
||||
$$->push_back(new string (""));
|
||||
}
|
||||
| CORR '(' symbol COMMA symbol ')' '.' symbol '.' OPTIONS
|
||||
{
|
||||
$$ = new vector<string *>();
|
||||
$$->push_back(new string ("corr"));
|
||||
$$->push_back($3);
|
||||
$$->push_back($5);
|
||||
$$->push_back($8);
|
||||
}
|
||||
;
|
||||
|
||||
estimation : ESTIMATION ';'
|
||||
{ driver.run_estimation(); }
|
||||
| ESTIMATION '(' estimation_options_list ')' ';'
|
||||
|
|
|
@ -1394,6 +1394,32 @@ ParsingDriver::set_options(string *name, string *subsample_name)
|
|||
delete subsample_name;
|
||||
}
|
||||
|
||||
void
|
||||
ParsingDriver::copy_options(string *to_declaration_type, string *to_name1, string *to_name2, string *to_subsample_name,
|
||||
string *from_declaration_type, string *from_name1, string *from_name2, string *from_subsample_name)
|
||||
{
|
||||
check_symbol_existence(*to_name1);
|
||||
check_symbol_existence(*from_name1);
|
||||
|
||||
if (!to_name2->empty())
|
||||
check_symbol_existence(*to_name2);
|
||||
|
||||
if (!from_name2->empty())
|
||||
check_symbol_existence(*from_name2);
|
||||
|
||||
mod_file->addStatement(new OptionsEqualStatement(*to_declaration_type, *to_name1, *to_name2, *to_subsample_name,
|
||||
*from_declaration_type, *from_name1, *from_name2, *from_subsample_name,
|
||||
mod_file->symbol_table));
|
||||
delete to_declaration_type;
|
||||
delete to_name1;
|
||||
delete to_name2;
|
||||
delete to_subsample_name;
|
||||
delete from_declaration_type;
|
||||
delete from_name1;
|
||||
delete from_name2;
|
||||
delete from_subsample_name;
|
||||
}
|
||||
|
||||
void
|
||||
ParsingDriver::check_symbol_is_endogenous_or_exogenous(string *name)
|
||||
{
|
||||
|
|
|
@ -397,6 +397,9 @@ public:
|
|||
string *from_declaration_type, string *from_name1, string *from_name2, string *from_subsample_name);
|
||||
//! Sets the options for a parameter
|
||||
void set_options(string *arg1, string *arg2);
|
||||
//! Copies the options from_name to_name
|
||||
void copy_options(string *to_declaration_type, string *to_name1, string *to_name2, string *to_subsample_name,
|
||||
string *from_declaration_type, string *from_name1, string *from_name2, string *from_subsample_name);
|
||||
//! Sets the prior for estimated std dev
|
||||
void set_std_prior(string *arg1, string *arg2);
|
||||
//! Sets the options for estimated std dev
|
||||
|
|
Loading…
Reference in New Issue