estimation: rewrite subsamples statement as an actual statement
parent
2ac49123d6
commit
d459b0ea7b
|
@ -1630,15 +1630,82 @@ EstimationDataStatement::writeOutput(ostream &output, const string &basename) co
|
|||
output << "options_.dataset.firstobs = options_.initial_period;" << endl;
|
||||
}
|
||||
|
||||
SubsamplesStatement::SubsamplesStatement(const string &name1_arg,
|
||||
const string &name2_arg,
|
||||
const subsample_declaration_map_t subsample_declaration_map_arg) :
|
||||
name1(name1_arg),
|
||||
name2(name2_arg),
|
||||
subsample_declaration_map(subsample_declaration_map_arg)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
SubsamplesStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
SubsamplesStatement::writeOutput(ostream &output, const string &basename) const
|
||||
{
|
||||
output << "subsamples_indx = get_new_or_existing_subsamples_indx('" << name1 << "','" << name2 << "');" << endl
|
||||
<< "estimation_info.subsamples_index(subsamples_indx) = {'" << name1;
|
||||
if (!name2.empty())
|
||||
output << "_" << name2;
|
||||
output << "'};" << endl
|
||||
<< "estimation_info.subsamples(subsamples_indx).range = {};" << endl;
|
||||
|
||||
int map_indx = 1;
|
||||
for (subsample_declaration_map_t::const_iterator it = subsample_declaration_map.begin();
|
||||
it != subsample_declaration_map.end(); it++, map_indx++)
|
||||
output << "estimation_info.subsamples(subsamples_indx).range_index(" << map_indx << ") = {'"
|
||||
<< it->first << "'};" << endl
|
||||
<< "estimation_info.subsamples(subsamples_indx).range(" << map_indx << ").date1 = '"
|
||||
<< it->second.first << "';" << endl
|
||||
<< "estimation_info.subsamples(subsamples_indx).range(" << map_indx << ").date2 = '"
|
||||
<< it->second.second << "';" << endl;
|
||||
}
|
||||
|
||||
SubsamplesEqualStatement::SubsamplesEqualStatement(const string &to_name1_arg,
|
||||
const string &to_name2_arg,
|
||||
const string &from_name1_arg,
|
||||
const string &from_name2_arg) :
|
||||
to_name1(to_name1_arg),
|
||||
to_name2(to_name2_arg),
|
||||
from_name1(from_name1_arg),
|
||||
from_name2(from_name2_arg)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
SubsamplesEqualStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
SubsamplesEqualStatement::writeOutput(ostream &output, const string &basename) const
|
||||
{
|
||||
output << "subsamples_to_indx = get_new_or_existing_subsamples_indx('" << to_name1 << "','" << to_name2 << "');" << endl
|
||||
<< "estimation_info.subsamples_index(subsamples_to_indx) = {'" << to_name1;
|
||||
if (!to_name2.empty())
|
||||
output << "_" << to_name2;
|
||||
output << "'};" << endl
|
||||
<< "subsamples_from_indx = get_existing_subsamples_indx('" << from_name1 << "','" << from_name2 << "');"
|
||||
<< endl
|
||||
<< "estimation_info.subsamples(subsamples_to_indx) = estimation_info.subsamples(subsamples_from_indx);"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
BasicPriorStatement::~BasicPriorStatement()
|
||||
{
|
||||
}
|
||||
|
||||
BasicPriorStatement::BasicPriorStatement(const string &name_arg,
|
||||
const string &subsample_name_arg,
|
||||
const PriorDistributions &prior_shape_arg,
|
||||
const expr_t &variance_arg,
|
||||
const OptionsList &options_list_arg) :
|
||||
name(name_arg),
|
||||
subsample_name(subsample_name_arg),
|
||||
prior_shape(prior_shape_arg),
|
||||
variance(variance_arg),
|
||||
options_list(options_list_arg),
|
||||
|
@ -1655,11 +1722,6 @@ BasicPriorStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
assert((options_list.num_options.find("date1") != options_list.num_options.end() &&
|
||||
options_list.num_options.find("date2") != options_list.num_options.end()) ||
|
||||
(options_list.num_options.find("date1") == options_list.num_options.end() &&
|
||||
options_list.num_options.find("date2") == options_list.num_options.end()));
|
||||
|
||||
OptionsList::num_options_t::const_iterator it_num = options_list.num_options.find("domain");
|
||||
if (it_num != options_list.num_options.end())
|
||||
{
|
||||
|
@ -1701,8 +1763,6 @@ BasicPriorStatement::writeCommonOutput(ostream &output, const string &lhs_field)
|
|||
writeCommonOutputHelper(output, "stdev", lhs_field);
|
||||
writeCommonOutputHelper(output, "shape", lhs_field);
|
||||
writeCommonOutputHelper(output, "shift", lhs_field);
|
||||
writeCommonOutputHelper(output, "date1", lhs_field);
|
||||
writeCommonOutputHelper(output, "date2", lhs_field);
|
||||
writeCommonOutputHelper(output, "domain", lhs_field);
|
||||
writeCommonOutputHelper(output, "median", lhs_field);
|
||||
writeCommonOutputHelper(output, "truncate", lhs_field);
|
||||
|
@ -1745,16 +1805,28 @@ BasicPriorStatement::writeVarianceOption(ostream &output, const string &lhs_fiel
|
|||
void
|
||||
BasicPriorStatement::writeSubsampleName(ostream &output) const
|
||||
{
|
||||
OptionsList::date_options_t::const_iterator itd = options_list.date_options.find("subsample_name");
|
||||
if (itd != options_list.date_options.end())
|
||||
output << ":" << itd->second;
|
||||
if (!subsample_name.empty())
|
||||
output << ":" << subsample_name;
|
||||
}
|
||||
|
||||
void
|
||||
BasicPriorStatement::writeSubsampleInfo(ostream &output, const string &lhs_field, const string name1, const string name2) const
|
||||
{
|
||||
if (subsample_name.empty())
|
||||
return;
|
||||
|
||||
output << "subsamples_indx = get_existing_subsamples_indx('" << name1 << "', '" << name2 << "');" << endl;
|
||||
output << "range_indx = get_subsamples_range_indx(subsamples_indx, '" << subsample_name << "');" << endl;
|
||||
output << "estimation_info" << lhs_field << "(prior_indx).date1 = estimation_info.subsamples(subsamples_indx).range(range_indx).date1;" << endl;
|
||||
output << "estimation_info" << lhs_field << "(prior_indx).date2 = estimation_info.subsamples(subsamples_indx).range(range_indx).date2;" << endl;
|
||||
}
|
||||
|
||||
PriorStatement::PriorStatement(const string &name_arg,
|
||||
const string &subsample_name_arg,
|
||||
const PriorDistributions &prior_shape_arg,
|
||||
const expr_t &variance_arg,
|
||||
const OptionsList &options_list_arg) :
|
||||
BasicPriorStatement(name_arg, prior_shape_arg, variance_arg, options_list_arg)
|
||||
BasicPriorStatement(name_arg, subsample_name_arg, prior_shape_arg, variance_arg, options_list_arg)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1779,14 +1851,16 @@ PriorStatement::writeOutput(ostream &output, const string &basename) const
|
|||
<< "estimation_info" << lhs_field <<"(prior_indx).name = '" << name << "';" << endl;
|
||||
|
||||
writeCommonOutput(output, lhs_field);
|
||||
writeSubsampleInfo(output, lhs_field, name, "");
|
||||
}
|
||||
|
||||
StdPriorStatement::StdPriorStatement(const string &name_arg,
|
||||
const string &subsample_name_arg,
|
||||
const PriorDistributions &prior_shape_arg,
|
||||
const expr_t &variance_arg,
|
||||
const OptionsList &options_list_arg,
|
||||
const SymbolTable &symbol_table_arg ) :
|
||||
BasicPriorStatement(name_arg, prior_shape_arg, variance_arg, options_list_arg),
|
||||
BasicPriorStatement(name_arg, subsample_name_arg, prior_shape_arg, variance_arg, options_list_arg),
|
||||
symbol_table(symbol_table_arg)
|
||||
{
|
||||
}
|
||||
|
@ -1814,14 +1888,16 @@ StdPriorStatement::writeOutput(ostream &output, const string &basename) const
|
|||
<< "estimation_info" << lhs_field << "(prior_indx).name = '" << name << "';" << endl;
|
||||
|
||||
writeCommonOutput(output, lhs_field);
|
||||
writeSubsampleInfo(output, lhs_field, name, "");
|
||||
}
|
||||
|
||||
CorrPriorStatement::CorrPriorStatement(const string &name_arg1, const string &name_arg2,
|
||||
const string &subsample_name_arg,
|
||||
const PriorDistributions &prior_shape_arg,
|
||||
const expr_t &variance_arg,
|
||||
const OptionsList &options_list_arg,
|
||||
const SymbolTable &symbol_table_arg ) :
|
||||
BasicPriorStatement(name_arg1, prior_shape_arg, variance_arg, options_list_arg),
|
||||
BasicPriorStatement(name_arg1, subsample_name_arg, prior_shape_arg, variance_arg, options_list_arg),
|
||||
name1(name_arg2),
|
||||
symbol_table(symbol_table_arg)
|
||||
{
|
||||
|
@ -1858,6 +1934,7 @@ CorrPriorStatement::writeOutput(ostream &output, const string &basename) const
|
|||
<< "estimation_info" << lhs_field << "(prior_indx).name2 = '" << name1 << "';" << endl;
|
||||
|
||||
writeCommonOutput(output, lhs_field);
|
||||
writeSubsampleInfo(output, lhs_field, name, name1);
|
||||
}
|
||||
|
||||
BasicOptionsStatement::~BasicOptionsStatement()
|
||||
|
@ -1865,8 +1942,10 @@ BasicOptionsStatement::~BasicOptionsStatement()
|
|||
}
|
||||
|
||||
BasicOptionsStatement::BasicOptionsStatement(const string &name_arg,
|
||||
const OptionsList &options_list_arg) :
|
||||
const string &subsample_name_arg,
|
||||
const OptionsList &options_list_arg) :
|
||||
name(name_arg),
|
||||
subsample_name(subsample_name_arg),
|
||||
options_list(options_list_arg),
|
||||
first_statement_encountered(false)
|
||||
{
|
||||
|
@ -1875,10 +1954,6 @@ BasicOptionsStatement::BasicOptionsStatement(const string &name_arg,
|
|||
void
|
||||
BasicOptionsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
|
||||
{
|
||||
assert((options_list.num_options.find("date1") != options_list.num_options.end() &&
|
||||
options_list.num_options.find("date2") != options_list.num_options.end()) ||
|
||||
(options_list.num_options.find("date1") == options_list.num_options.end() &&
|
||||
options_list.num_options.find("date2") == options_list.num_options.end()));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1905,8 +1980,6 @@ BasicOptionsStatement::writeCommonOutput(ostream &output, const string &lhs_fiel
|
|||
writeCommonOutputHelper(output, "init", lhs_field);
|
||||
writeCommonOutputHelper(output, "bounds", lhs_field);
|
||||
writeCommonOutputHelper(output, "jscale", lhs_field);
|
||||
writeCommonOutputHelper(output, "date1", lhs_field);
|
||||
writeCommonOutputHelper(output, "date2", lhs_field);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1926,14 +1999,26 @@ BasicOptionsStatement::writeCommonOutputHelper(ostream &output, const string &fi
|
|||
void
|
||||
BasicOptionsStatement::writeSubsampleName(ostream &output) const
|
||||
{
|
||||
OptionsList::date_options_t::const_iterator itd = options_list.date_options.find("subsample_name");
|
||||
if (itd != options_list.date_options.end())
|
||||
output << ":" << itd->second;
|
||||
if (!subsample_name.empty())
|
||||
output << ":" << subsample_name;
|
||||
}
|
||||
|
||||
void
|
||||
BasicOptionsStatement::writeSubsampleInfo(ostream &output, const string &lhs_field, const string name1, const string name2) const
|
||||
{
|
||||
if (subsample_name.empty())
|
||||
return;
|
||||
|
||||
output << "subsamples_indx = get_existing_subsamples_indx('" << name1 << "', '" << name2 << "');" << endl;
|
||||
output << "range_indx = get_subsamples_range_indx(subsamples_indx, '" << subsample_name << "');" << endl;
|
||||
output << "estimation_info" << lhs_field << "(options_indx).date1 = estimation_info.subsamples(subsamples_indx).range(range_indx).date1;" << endl;
|
||||
output << "estimation_info" << lhs_field << "(options_indx).date2 = estimation_info.subsamples(subsamples_indx).range(range_indx).date2;" << endl;
|
||||
}
|
||||
|
||||
OptionsStatement::OptionsStatement(const string &name_arg,
|
||||
const string &subsample_name_arg,
|
||||
const OptionsList &options_list_arg) :
|
||||
BasicOptionsStatement(name_arg, options_list_arg)
|
||||
BasicOptionsStatement(name_arg, subsample_name_arg, options_list_arg)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1958,12 +2043,14 @@ OptionsStatement::writeOutput(ostream &output, const string &basename) const
|
|||
<< "estimation_info" << lhs_field << "(options_indx).name = '" << name << "';" << endl;
|
||||
|
||||
writeCommonOutput(output, lhs_field);
|
||||
writeSubsampleInfo(output, lhs_field, name, "");
|
||||
}
|
||||
|
||||
StdOptionsStatement::StdOptionsStatement(const string &name_arg,
|
||||
const string &subsample_name_arg,
|
||||
const OptionsList &options_list_arg,
|
||||
const SymbolTable &symbol_table_arg ) :
|
||||
BasicOptionsStatement(name_arg, options_list_arg),
|
||||
BasicOptionsStatement(name_arg, subsample_name_arg, options_list_arg),
|
||||
symbol_table(symbol_table_arg)
|
||||
{
|
||||
}
|
||||
|
@ -1991,12 +2078,14 @@ StdOptionsStatement::writeOutput(ostream &output, const string &basename) const
|
|||
<< "estimation_info" << lhs_field << "(options_indx).name = '" << name << "';" << endl;
|
||||
|
||||
writeCommonOutput(output, lhs_field);
|
||||
writeSubsampleInfo(output, lhs_field, name, "");
|
||||
}
|
||||
|
||||
CorrOptionsStatement::CorrOptionsStatement(const string &name_arg1, const string &name_arg2,
|
||||
const string &subsample_name_arg,
|
||||
const OptionsList &options_list_arg,
|
||||
const SymbolTable &symbol_table_arg ) :
|
||||
BasicOptionsStatement(name_arg1, options_list_arg),
|
||||
BasicOptionsStatement(name_arg1, subsample_name_arg, options_list_arg),
|
||||
name1(name_arg2),
|
||||
symbol_table(symbol_table_arg)
|
||||
{
|
||||
|
@ -2032,4 +2121,5 @@ CorrOptionsStatement::writeOutput(ostream &output, const string &basename) const
|
|||
<< "estimation_info" << lhs_field << "(options_indx).name2 = '" << name1 << "';" << endl;
|
||||
|
||||
writeCommonOutput(output, lhs_field);
|
||||
writeSubsampleInfo(output, lhs_field, name, name1);
|
||||
}
|
||||
|
|
|
@ -579,17 +579,52 @@ public:
|
|||
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||
};
|
||||
|
||||
class SubsamplesStatement : public Statement
|
||||
{
|
||||
public:
|
||||
//! Storage for declaring subsamples: map<subsample_name, <date1, date2 >
|
||||
typedef map<string, pair<string, string> > subsample_declaration_map_t;
|
||||
private:
|
||||
const string name1;
|
||||
const string name2;
|
||||
const subsample_declaration_map_t subsample_declaration_map;
|
||||
public:
|
||||
SubsamplesStatement(const string &name1_arg,
|
||||
const string &name2_arg,
|
||||
const subsample_declaration_map_t subsample_declaration_map_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||
};
|
||||
|
||||
class SubsamplesEqualStatement : public Statement
|
||||
{
|
||||
private:
|
||||
const string to_name1;
|
||||
const string to_name2;
|
||||
const string from_name1;
|
||||
const string from_name2;
|
||||
public:
|
||||
SubsamplesEqualStatement(const string &to_name1_arg,
|
||||
const string &to_name2_arg,
|
||||
const string &from_name1_arg,
|
||||
const string &from_name2_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||
};
|
||||
|
||||
class BasicPriorStatement : public Statement
|
||||
{
|
||||
public:
|
||||
virtual ~BasicPriorStatement();
|
||||
protected:
|
||||
const string name;
|
||||
const string subsample_name;
|
||||
const PriorDistributions prior_shape;
|
||||
const expr_t variance;
|
||||
const OptionsList options_list;
|
||||
bool first_statement_encountered;
|
||||
BasicPriorStatement(const string &name_arg,
|
||||
const string &subsample_name_arg,
|
||||
const PriorDistributions &prior_shape_arg,
|
||||
const expr_t &variance_arg,
|
||||
const OptionsList &options_list_arg);
|
||||
|
@ -601,12 +636,14 @@ protected:
|
|||
void writeCommonOutputHelper(ostream &output, const string &field, const string &lhs_field) const;
|
||||
void writeShape(ostream &output, const string &lhs_field) const;
|
||||
void writeSubsampleName(ostream &output) const;
|
||||
void writeSubsampleInfo(ostream &output, const string &lhs_field, const string name1, const string name2) const;
|
||||
};
|
||||
|
||||
class PriorStatement : public BasicPriorStatement
|
||||
{
|
||||
public:
|
||||
PriorStatement(const string &name_arg,
|
||||
const string &subsample_name_arg,
|
||||
const PriorDistributions &prior_shape_arg,
|
||||
const expr_t &variance_arg,
|
||||
const OptionsList &options_list_arg);
|
||||
|
@ -620,6 +657,7 @@ private:
|
|||
const SymbolTable symbol_table;
|
||||
public:
|
||||
StdPriorStatement(const string &name_arg,
|
||||
const string &subsample_name_arg,
|
||||
const PriorDistributions &prior_shape_arg,
|
||||
const expr_t &variance_arg,
|
||||
const OptionsList &options_list_arg,
|
||||
|
@ -636,6 +674,7 @@ private:
|
|||
public:
|
||||
CorrPriorStatement(const string &name_arg1,
|
||||
const string &name_arg2,
|
||||
const string &subsample_name_arg,
|
||||
const PriorDistributions &prior_shape_arg,
|
||||
const expr_t &variance_arg,
|
||||
const OptionsList &options_list_arg,
|
||||
|
@ -650,22 +689,25 @@ public:
|
|||
virtual ~BasicOptionsStatement();
|
||||
protected:
|
||||
const string name;
|
||||
const string subsample_name;
|
||||
const OptionsList options_list;
|
||||
bool first_statement_encountered;
|
||||
BasicOptionsStatement(const string &name_arg,
|
||||
const OptionsList &options_list_arg);
|
||||
const string &subsample_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, WarningConsolidation &warnings);
|
||||
void writeOptionsIndex(ostream &output, const string &lhs_field) const;
|
||||
void writeCommonOutput(ostream &output, const string &lhs_field) const;
|
||||
void writeCommonOutputHelper(ostream &output, const string &field, const string &lhs_field) const;
|
||||
void writeSubsampleName(ostream &output) const;
|
||||
void writeSubsampleInfo(ostream &output, const string &lhs_field, const string name1, const string name2) const;
|
||||
};
|
||||
|
||||
class OptionsStatement : public BasicOptionsStatement
|
||||
{
|
||||
public:
|
||||
OptionsStatement(const string &name_arg, const OptionsList &options_list_arg);
|
||||
OptionsStatement(const string &name_arg, const string &subsample_name_arg, const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||
};
|
||||
|
@ -675,8 +717,10 @@ 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);
|
||||
StdOptionsStatement(const string &name_arg,
|
||||
const string &subsample_name_arg,
|
||||
const OptionsList &options_list_arg,
|
||||
const SymbolTable &symbol_table_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||
};
|
||||
|
@ -688,7 +732,9 @@ private:
|
|||
const SymbolTable symbol_table;
|
||||
public:
|
||||
CorrOptionsStatement(const string &name_arg1, const string &name_arg2,
|
||||
const OptionsList &options_list_arg, const SymbolTable &symbol_table_arg);
|
||||
const string &subsample_name_arg,
|
||||
const OptionsList &options_list_arg,
|
||||
const SymbolTable &symbol_table_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||
};
|
||||
|
|
|
@ -1250,26 +1250,17 @@ subsamples_name_list : subsamples_name_list COMMA o_subsample_name
|
|||
;
|
||||
|
||||
prior : symbol '.' PRIOR { driver.set_prior_variance(); driver.prior_shape = eNoShape; } '(' prior_options_list ')' ';'
|
||||
{ driver.set_prior($1); }
|
||||
{ driver.set_prior($1, new string ("")); }
|
||||
| symbol '.' symbol '.' PRIOR { driver.set_prior_variance(); driver.prior_shape = eNoShape; } '(' prior_options_list ')' ';'
|
||||
{
|
||||
driver.add_subsample_range(new string (*$1), new string (""), $3);
|
||||
driver.set_prior($1);
|
||||
}
|
||||
{ driver.set_prior($1, $3); }
|
||||
| STD '(' symbol ')' '.' PRIOR { driver.set_prior_variance(); driver.prior_shape = eNoShape; } '(' prior_options_list ')' ';'
|
||||
{ driver.set_std_prior($3); }
|
||||
{ driver.set_std_prior($3, new string ("")); }
|
||||
| STD '(' symbol ')' '.' symbol '.' PRIOR { driver.set_prior_variance(); driver.prior_shape = eNoShape; } '(' prior_options_list ')' ';'
|
||||
{
|
||||
driver.add_subsample_range(new string (*$3), new string (""), $6);
|
||||
driver.set_std_prior($3);
|
||||
}
|
||||
{ driver.set_std_prior($3, $6); }
|
||||
| CORR '(' symbol COMMA symbol ')' '.' PRIOR { driver.set_prior_variance(); driver.prior_shape = eNoShape; } '(' prior_options_list ')' ';'
|
||||
{ driver.set_corr_prior($3, $5); }
|
||||
{ driver.set_corr_prior($3, $5, new string ("")); }
|
||||
| CORR '(' symbol COMMA symbol ')' '.' symbol '.' PRIOR { driver.set_prior_variance(); driver.prior_shape = eNoShape; } '(' prior_options_list ')' ';'
|
||||
{
|
||||
driver.add_subsample_range(new string (*$3), new string (*$5), $8);
|
||||
driver.set_corr_prior($3, $5);
|
||||
}
|
||||
{ driver.set_corr_prior($3, $5, $8); }
|
||||
;
|
||||
|
||||
prior_options_list : prior_options_list COMMA prior_options
|
||||
|
@ -1289,26 +1280,17 @@ prior_options : o_shift
|
|||
;
|
||||
|
||||
options : symbol '.' OPTIONS '(' options_options_list ')' ';'
|
||||
{ driver.set_options($1); }
|
||||
{ driver.set_options($1, new string ("")); }
|
||||
| symbol '.' symbol '.' OPTIONS '(' options_options_list ')' ';'
|
||||
{
|
||||
driver.add_subsample_range(new string (*$1), new string (""), $3);
|
||||
driver.set_options($1);
|
||||
}
|
||||
{ driver.set_options($1, $3); }
|
||||
| STD '(' symbol ')' '.' OPTIONS '(' options_options_list ')' ';'
|
||||
{ driver.set_std_options($3); }
|
||||
{ driver.set_std_options($3, new string ("")); }
|
||||
| STD '(' symbol ')' '.' symbol '.' OPTIONS '(' options_options_list ')' ';'
|
||||
{
|
||||
driver.add_subsample_range(new string (*$3), new string (""), $6);
|
||||
driver.set_std_options($3);
|
||||
}
|
||||
{ driver.set_std_options($3, $6); }
|
||||
| CORR '(' symbol COMMA symbol ')' '.' OPTIONS '(' options_options_list ')' ';'
|
||||
{ driver.set_corr_options($3, $5); }
|
||||
{ driver.set_corr_options($3, $5, new string ("")); }
|
||||
| CORR '(' symbol COMMA symbol ')' '.' symbol '.' OPTIONS '(' options_options_list ')' ';'
|
||||
{
|
||||
driver.add_subsample_range(new string (*$3), new string (*$5), $8);
|
||||
driver.set_corr_options($3, $5);
|
||||
}
|
||||
{ driver.set_corr_options($3, $5, $8); }
|
||||
;
|
||||
|
||||
options_options_list : options_options_list COMMA options_options
|
||||
|
@ -2073,10 +2055,7 @@ o_nograph : NOGRAPH
|
|||
{ driver.option_num("nograph", "0"); }
|
||||
;
|
||||
o_subsample_name : symbol EQUAL date_number ':' date_number
|
||||
{
|
||||
driver.declare_statement_local_variable(new string (*$1));
|
||||
driver.set_subsample_name_equal_to_date_range($1, $3, $5);
|
||||
}
|
||||
{ driver.set_subsample_name_equal_to_date_range($1, $3, $5); }
|
||||
;
|
||||
o_conf_sig : CONF_SIG EQUAL non_negative_number { driver.option_num("conf_sig", $3); };
|
||||
o_mh_replic : MH_REPLIC EQUAL INT_NUMBER { driver.option_num("mh_replic", $3); };
|
||||
|
|
|
@ -1242,15 +1242,7 @@ ParsingDriver::set_subsamples(string *name1, string *name2)
|
|||
if (!name2->empty())
|
||||
check_symbol_existence(*name2);
|
||||
|
||||
if (subsample_declarations.find(make_pair(*name1,*name2)) != subsample_declarations.end())
|
||||
{
|
||||
string err = *name1;
|
||||
if (!name2->empty())
|
||||
err.append(",").append(*name2);
|
||||
error(err + " has more than one subsample statement." +
|
||||
"You may only have one subsample statement per variable.");
|
||||
}
|
||||
|
||||
mod_file->addStatement(new SubsamplesStatement(*name1, *name2, subsample_declaration_map));
|
||||
subsample_declarations[make_pair(*name1, *name2)] = subsample_declaration_map;
|
||||
subsample_declaration_map.clear();
|
||||
delete name1;
|
||||
|
@ -1267,14 +1259,6 @@ ParsingDriver::copy_subsamples(string *to_name1, string *to_name2, string *from_
|
|||
if (!from_name2->empty())
|
||||
check_symbol_existence(*from_name2);
|
||||
|
||||
if (subsample_declarations.find(make_pair(*to_name1,*to_name2)) != subsample_declarations.end())
|
||||
{
|
||||
string err = *to_name1;
|
||||
if (!to_name2->empty())
|
||||
err.append(",").append(*to_name2);
|
||||
error(err + " has more than one subsample statement." +
|
||||
"You may only have one subsample statement per symbol (or pair thereof).");
|
||||
}
|
||||
if (subsample_declarations.find(make_pair(*from_name1,*from_name2)) == subsample_declarations.end())
|
||||
{
|
||||
string err = *from_name1;
|
||||
|
@ -1283,6 +1267,8 @@ ParsingDriver::copy_subsamples(string *to_name1, string *to_name2, string *from_
|
|||
error(err + " does not have an associated subsample statement.");
|
||||
}
|
||||
|
||||
mod_file->addStatement(new SubsamplesEqualStatement(*to_name1, *to_name2, *from_name1, *from_name2));
|
||||
|
||||
subsample_declarations[make_pair(*to_name1, *to_name2)] =
|
||||
subsample_declarations[make_pair(*from_name1, *from_name2)];
|
||||
|
||||
|
@ -1304,7 +1290,6 @@ ParsingDriver::check_symbol_is_statement_variable(string *name)
|
|||
void
|
||||
ParsingDriver::set_subsample_name_equal_to_date_range(string *name, string *date1, string *date2)
|
||||
{
|
||||
check_symbol_is_statement_variable(name);
|
||||
if (subsample_declaration_map.find(*name) != subsample_declaration_map.end())
|
||||
error("Symbol " + *name + " may only be assigned once in a SUBSAMPLE statement");
|
||||
subsample_declaration_map[*name] = make_pair(*date1, *date2);
|
||||
|
@ -1314,44 +1299,56 @@ ParsingDriver::set_subsample_name_equal_to_date_range(string *name, string *date
|
|||
}
|
||||
|
||||
void
|
||||
ParsingDriver::add_subsample_range(string *name1, string *name2, string *subsample_name)
|
||||
ParsingDriver::check_subsample_declaration_exists(string *name1, string *subsample_name)
|
||||
{
|
||||
if (subsample_name->empty())
|
||||
return;
|
||||
|
||||
string *str_empty = new string ("");
|
||||
check_subsample_declaration_exists(name1, str_empty, subsample_name);
|
||||
delete str_empty;
|
||||
}
|
||||
|
||||
void
|
||||
ParsingDriver::check_subsample_declaration_exists(string *name1, string *name2, string *subsample_name)
|
||||
{
|
||||
if (subsample_name->empty())
|
||||
return;
|
||||
|
||||
check_symbol_existence(*name1);
|
||||
if (!name2->empty())
|
||||
check_symbol_existence(*name2);
|
||||
check_symbol_is_statement_variable(subsample_name);
|
||||
|
||||
subsample_declarations_t::const_iterator it = subsample_declarations.find(make_pair(*name1, *name2));
|
||||
if (it == subsample_declarations.end())
|
||||
{
|
||||
string err = *name1;
|
||||
if (!name2->empty())
|
||||
err.append(",").append(*name2);
|
||||
error("A subsample statement has not been issued for " + err);
|
||||
it = subsample_declarations.find(make_pair(*name2, *name1));
|
||||
if (it== subsample_declarations.end())
|
||||
{
|
||||
string err = *name1;
|
||||
if (!name2->empty())
|
||||
err.append(",").append(*name2);
|
||||
error("A subsample statement has not been issued for " + err);
|
||||
}
|
||||
}
|
||||
|
||||
subsample_declaration_map_t tmp_map = it->second;
|
||||
SubsamplesStatement::subsample_declaration_map_t tmp_map = it->second;
|
||||
if (tmp_map.find(*subsample_name) == tmp_map.end())
|
||||
error("The subsample name " + *subsample_name + " was not previously declared in a subsample statement.");
|
||||
|
||||
option_date("subsample_name", *subsample_name);
|
||||
option_date("date1", tmp_map[*subsample_name].first);
|
||||
option_date("date2", tmp_map[*subsample_name].second);
|
||||
|
||||
delete name1;
|
||||
delete name2;
|
||||
delete subsample_name;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ParsingDriver::set_prior(string *name)
|
||||
ParsingDriver::set_prior(string *name, string *subsample_name)
|
||||
{
|
||||
check_symbol_is_parameter(name);
|
||||
mod_file->addStatement(new PriorStatement(*name, prior_shape, prior_variance, options_list));
|
||||
check_subsample_declaration_exists(name, subsample_name);
|
||||
mod_file->addStatement(new PriorStatement(*name, *subsample_name, prior_shape, prior_variance, options_list));
|
||||
options_list.clear();
|
||||
set_prior_variance();
|
||||
prior_shape = eNoShape;
|
||||
delete name;
|
||||
delete subsample_name;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1361,12 +1358,14 @@ ParsingDriver::set_prior_variance(expr_t variance)
|
|||
}
|
||||
|
||||
void
|
||||
ParsingDriver::set_options(string *name)
|
||||
ParsingDriver::set_options(string *name, string *subsample_name)
|
||||
{
|
||||
check_symbol_is_parameter(name);
|
||||
mod_file->addStatement(new OptionsStatement(*name, options_list));
|
||||
check_subsample_declaration_exists(name, subsample_name);
|
||||
mod_file->addStatement(new OptionsStatement(*name, *subsample_name, options_list));
|
||||
options_list.clear();
|
||||
delete name;
|
||||
delete subsample_name;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1386,49 +1385,57 @@ ParsingDriver::check_symbol_is_endogenous_or_exogenous(string *name)
|
|||
}
|
||||
|
||||
void
|
||||
ParsingDriver::set_std_prior(string *name)
|
||||
ParsingDriver::set_std_prior(string *name, string *subsample_name)
|
||||
{
|
||||
check_symbol_is_endogenous_or_exogenous(name);
|
||||
mod_file->addStatement(new StdPriorStatement(*name, prior_shape, prior_variance,
|
||||
check_subsample_declaration_exists(name, subsample_name);
|
||||
mod_file->addStatement(new StdPriorStatement(*name, *subsample_name, prior_shape, prior_variance,
|
||||
options_list, mod_file->symbol_table));
|
||||
options_list.clear();
|
||||
set_prior_variance();
|
||||
prior_shape = eNoShape;
|
||||
delete name;
|
||||
delete subsample_name;
|
||||
}
|
||||
|
||||
void
|
||||
ParsingDriver::set_std_options(string *name)
|
||||
ParsingDriver::set_std_options(string *name, string *subsample_name)
|
||||
{
|
||||
check_symbol_is_endogenous_or_exogenous(name);
|
||||
mod_file->addStatement(new StdOptionsStatement(*name, options_list, mod_file->symbol_table));
|
||||
check_subsample_declaration_exists(name, subsample_name);
|
||||
mod_file->addStatement(new StdOptionsStatement(*name, *subsample_name, options_list, mod_file->symbol_table));
|
||||
options_list.clear();
|
||||
delete name;
|
||||
delete subsample_name;
|
||||
}
|
||||
|
||||
void
|
||||
ParsingDriver::set_corr_prior(string *name1, string *name2)
|
||||
ParsingDriver::set_corr_prior(string *name1, string *name2, string *subsample_name)
|
||||
{
|
||||
check_symbol_is_endogenous_or_exogenous(name1);
|
||||
check_symbol_is_endogenous_or_exogenous(name2);
|
||||
mod_file->addStatement(new CorrPriorStatement(*name1, *name2, prior_shape, prior_variance,
|
||||
check_subsample_declaration_exists(name1, name2, subsample_name);
|
||||
mod_file->addStatement(new CorrPriorStatement(*name1, *name2, *subsample_name, prior_shape, prior_variance,
|
||||
options_list, mod_file->symbol_table));
|
||||
options_list.clear();
|
||||
set_prior_variance();
|
||||
prior_shape = eNoShape;
|
||||
delete name1;
|
||||
delete name2;
|
||||
delete subsample_name;
|
||||
}
|
||||
|
||||
void
|
||||
ParsingDriver::set_corr_options(string *name1, string *name2)
|
||||
ParsingDriver::set_corr_options(string *name1, string *name2, string *subsample_name)
|
||||
{
|
||||
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));
|
||||
check_subsample_declaration_exists(name1, name2, subsample_name);
|
||||
mod_file->addStatement(new CorrOptionsStatement(*name1, *name2, *subsample_name, options_list, mod_file->symbol_table));
|
||||
options_list.clear();
|
||||
delete name1;
|
||||
delete name2;
|
||||
delete subsample_name;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -189,11 +189,9 @@ private:
|
|||
vector<int> declared_nonstationary_vars;
|
||||
//! Temporary storage for a variance declared in the prior statement
|
||||
expr_t prior_variance;
|
||||
//! Temporary storage for declaring subsamples: map<statement_local_var, <date1, date2 >
|
||||
typedef map<string, pair<string, string> > subsample_declaration_map_t;
|
||||
subsample_declaration_map_t subsample_declaration_map;
|
||||
SubsamplesStatement::subsample_declaration_map_t subsample_declaration_map;
|
||||
//! Temporary storage for subsample statement: map<pair<var_name1, var_name2>>, subsample_declaration_map >
|
||||
typedef map<pair<string, string >, subsample_declaration_map_t > subsample_declarations_t;
|
||||
typedef map<pair<string, string >, SubsamplesStatement::subsample_declaration_map_t > subsample_declarations_t;
|
||||
subsample_declarations_t subsample_declarations;
|
||||
//! reset the values for temporary storage
|
||||
void reset_current_external_function_options();
|
||||
|
@ -257,8 +255,9 @@ public:
|
|||
void set_subsamples(string *name1, string *name2);
|
||||
//! Declares a subsample, assigning the value to name
|
||||
void set_subsample_name_equal_to_date_range(string *name, string *date1, string *date2);
|
||||
//! Adds a subsample range to the list of options for the prior statement
|
||||
void add_subsample_range(string *name1, string *name2, string *subsample_name);
|
||||
//! Checks that a subsample statement (and given name) were provided for the pair name1 & name2
|
||||
void check_subsample_declaration_exists(string *name1, string *subsample_name);
|
||||
void check_subsample_declaration_exists(string *name1, string *name2, string *subsample_name);
|
||||
//! Copies the set of subsamples from_name to_name
|
||||
void copy_subsamples(string *to_name1, string *to_name2, string *from_name1, string *from_name2);
|
||||
//! Declares declare_optimal_policy_discount_factor as a parameter and initializes it to exprnode
|
||||
|
@ -390,19 +389,19 @@ public:
|
|||
//! Estimation Data
|
||||
void estimation_data();
|
||||
//! Sets the prior for a parameter
|
||||
void set_prior(string *arg);
|
||||
void set_prior(string *arg1, string *arg2);
|
||||
//! Adds the variance option to its temporary holding place
|
||||
void set_prior_variance(expr_t variance=NULL);
|
||||
//! Sets the options for a parameter
|
||||
void set_options(string *arg);
|
||||
void set_options(string *arg1, string *arg2);
|
||||
//! Sets the prior for estimated std dev
|
||||
void set_std_prior(string *arg);
|
||||
void set_std_prior(string *arg1, string *arg2);
|
||||
//! Sets the options for estimated std dev
|
||||
void set_std_options(string *arg);
|
||||
void set_std_options(string *arg1, string *arg2);
|
||||
//! Sets the prior for estimated correlation
|
||||
void set_corr_prior(string *arg1, string *arg2);
|
||||
void set_corr_prior(string *arg1, string *arg2, string *arg3);
|
||||
//! Sets the options for estimated correlation
|
||||
void set_corr_options(string *arg1, string *arg2);
|
||||
void set_corr_options(string *arg1, string *arg2, string *arg3);
|
||||
//! Runs estimation process
|
||||
void run_estimation();
|
||||
//! Runs dynare_sensitivy()
|
||||
|
|
Loading…
Reference in New Issue