estimation: rewrite options output

issue#70
Houtan Bastani 2012-03-29 16:45:46 +02:00
parent aa21ef6ec5
commit 0b0d4d0455
4 changed files with 34 additions and 97 deletions

View File

@ -1882,9 +1882,9 @@ CorrPriorStatement::writeOutput(ostream &output, const string &basename) const
string lhs_field; string lhs_field;
get_base_name(symbol_table.getType(name), lhs_field); get_base_name(symbol_table.getType(name), lhs_field);
output << "eifind = get_new_or_existing_ei_index('" << lhs_field << "_prior_index', '" output << "eifind = get_new_or_existing_ei_index('" << lhs_field << "_corr_prior_index', '"
<< name << "', '" << name1 << "');" << endl << name << "', '" << name1 << "');" << endl
<< "estimation_info." << lhs_field << "_prior_index(eifind) = {'" << "estimation_info." << lhs_field << "_corr_prior_index(eifind) = {'"
<< name << "_" << name1 << "'};" << endl; << name << "_" << name1 << "'};" << endl;
lhs_field = "estimation_info." + lhs_field + "_corr(eifind)"; lhs_field = "estimation_info." + lhs_field + "_corr(eifind)";
@ -1903,8 +1903,7 @@ BasicOptionsStatement::BasicOptionsStatement(const string &name_arg,
const OptionsList &options_list_arg) : const OptionsList &options_list_arg) :
name(name_arg), name(name_arg),
subsample_name(subsample_name_arg), subsample_name(subsample_name_arg),
options_list(options_list_arg), options_list(options_list_arg)
first_statement_encountered(false)
{ {
} }
@ -1913,15 +1912,6 @@ BasicOptionsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso
{ {
} }
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 void
BasicOptionsStatement::get_base_name(const SymbolType symb_type, string &lhs_field) const BasicOptionsStatement::get_base_name(const SymbolType symb_type, string &lhs_field) const
{ {
@ -1944,32 +1934,22 @@ BasicOptionsStatement::writeCommonOutputHelper(ostream &output, const string &fi
{ {
OptionsList::num_options_t::const_iterator itn = options_list.num_options.find(field); OptionsList::num_options_t::const_iterator itn = options_list.num_options.find(field);
if (itn != options_list.num_options.end()) if (itn != options_list.num_options.end())
output << "estimation_info" << lhs_field << "(options_indx)." << field output << lhs_field << "." << field << " = " << itn->second << ";" << endl;
<< " = " << 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;
} }
void void
BasicOptionsStatement::writeSubsampleName(ostream &output) const BasicOptionsStatement::writeOptionsOutput(ostream &output, string &lhs_field, const string &name2) const
{
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()) if (subsample_name.empty())
return; lhs_field += ".options(1)";
else
output << "subsamples_indx = get_existing_subsamples_indx('" << name1 << "', '" << name2 << "');" << endl; {
output << "range_indx = get_subsamples_range_indx(subsamples_indx, '" << subsample_name << "');" << endl; output << "subsamples_indx = get_existing_subsamples_indx('" << name << "','" << name2 << "');" << endl
output << "estimation_info" << lhs_field << "(options_indx).date1 = estimation_info.subsamples(subsamples_indx).range(range_indx).date1;" << endl; << lhs_field << ".range_index = estimation_info.subsamples(subsamples_indx).range_index;" << endl
output << "estimation_info" << lhs_field << "(options_indx).date2 = estimation_info.subsamples(subsamples_indx).range(range_indx).date2;" << endl; << "eisind = get_subsamples_range_indx(subsamples_indx, '" << subsample_name << "');" << endl;
lhs_field += ".subsample_options(eisind)";
}
writeCommonOutput(output, lhs_field);
} }
OptionsStatement::OptionsStatement(const string &name_arg, OptionsStatement::OptionsStatement(const string &name_arg,
@ -1979,28 +1959,14 @@ OptionsStatement::OptionsStatement(const string &name_arg,
{ {
} }
void
OptionsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
{
BasicOptionsStatement::checkPass(mod_file_struct, warnings);
if (!mod_file_struct.options_statement_present)
first_statement_encountered = true;
mod_file_struct.options_statement_present = true;
}
void void
OptionsStatement::writeOutput(ostream &output, const string &basename) const OptionsStatement::writeOutput(ostream &output, const string &basename) const
{ {
string lhs_field = ".parameters.options"; string lhs_field = "estimation_info.parameters(eifind)";
output << "eifind = get_new_or_existing_ei_index('parameter_options_index', '"
writeOptionsIndex(output, lhs_field); << name << "', '');" << endl
output << "estimation_info" << lhs_field <<"_index(options_indx) = {'" << name; << "estimation_info.parameter_options_index(eifind) = {'" << name << "'};" << endl;
writeSubsampleName(output); writeOptionsOutput(output, lhs_field, "");
output << "'};" << endl
<< "estimation_info" << lhs_field << "(options_indx).name = '" << name << "';" << endl;
writeCommonOutput(output, lhs_field);
writeSubsampleInfo(output, lhs_field, name, "");
} }
StdOptionsStatement::StdOptionsStatement(const string &name_arg, StdOptionsStatement::StdOptionsStatement(const string &name_arg,
@ -2012,30 +1978,17 @@ StdOptionsStatement::StdOptionsStatement(const string &name_arg,
{ {
} }
void
StdOptionsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
{
BasicOptionsStatement::checkPass(mod_file_struct, warnings);
if (!mod_file_struct.std_options_statement_present)
first_statement_encountered = true;
mod_file_struct.std_options_statement_present = true;
}
void void
StdOptionsStatement::writeOutput(ostream &output, const string &basename) const StdOptionsStatement::writeOutput(ostream &output, const string &basename) const
{ {
string lhs_field; string lhs_field;
get_base_name(symbol_table.getType(name), lhs_field); get_base_name(symbol_table.getType(name), lhs_field);
lhs_field = "." + lhs_field + ".options"; output << "eifind = get_new_or_existing_ei_index('" << lhs_field << "_options_index', '"
<< name << "', '');" << endl
<< "estimation_info." << lhs_field << "_options_index(eifind) = {'" << name << "'};" << endl;
writeOptionsIndex(output, lhs_field); lhs_field = "estimation_info." + lhs_field + "(eifind)";
output << "estimation_info" << lhs_field << "_index(options_indx) = {'" << name; writeOptionsOutput(output, lhs_field, "");
writeSubsampleName(output);
output << "'};" << endl
<< "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, CorrOptionsStatement::CorrOptionsStatement(const string &name_arg1, const string &name_arg2,
@ -2058,8 +2011,6 @@ CorrOptionsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsol
<< "types." << endl; << "types." << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (!mod_file_struct.corr_options_statement_present)
first_statement_encountered = true;
} }
void void
@ -2067,15 +2018,15 @@ CorrOptionsStatement::writeOutput(ostream &output, const string &basename) const
{ {
string lhs_field; string lhs_field;
get_base_name(symbol_table.getType(name), lhs_field); get_base_name(symbol_table.getType(name), lhs_field);
lhs_field = "." + lhs_field + "_corr.options";
writeOptionsIndex(output, lhs_field); output << "eifind = get_new_or_existing_ei_index('" << lhs_field << "_corr_options_index', '"
output << "estimation_info" << lhs_field << "_index(options_indx) = {'" << name << "_" << name1; << name << "', '" << name1 << "');" << endl
writeSubsampleName(output); << "estimation_info." << lhs_field << "_corr_options_index(eifind) = {'"
output << "'};" << endl << name << "_" << name1 << "'};" << endl;
<< "estimation_info" << lhs_field << "(options_indx).name1 = '" << name << "';" << endl
<< "estimation_info" << lhs_field << "(options_indx).name2 = '" << name1 << "';" << endl;
writeCommonOutput(output, lhs_field); lhs_field = "estimation_info." + lhs_field + "_corr(eifind)";
writeSubsampleInfo(output, lhs_field, name, name1); writeOptionsOutput(output, lhs_field, name1);
output << lhs_field << ".name1 = '" << name << "';" << endl
<< lhs_field << ".name2 = '" << name1 << "';" << endl;
} }

View File

@ -684,24 +684,20 @@ protected:
const string name; const string name;
const string subsample_name; const string subsample_name;
const OptionsList options_list; const OptionsList options_list;
bool first_statement_encountered;
BasicOptionsStatement(const string &name_arg, BasicOptionsStatement(const string &name_arg,
const string &subsample_name_arg, const string &subsample_name_arg,
const OptionsList &options_list_arg); const OptionsList &options_list_arg);
void get_base_name(const SymbolType symb_type, string &lhs_field) const; void get_base_name(const SymbolType symb_type, string &lhs_field) const;
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
void writeOptionsIndex(ostream &output, const string &lhs_field) const; void writeOptionsOutput(ostream &output, string &lhs_field, const string &name2) const;
void writeCommonOutput(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 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 class OptionsStatement : public BasicOptionsStatement
{ {
public: public:
OptionsStatement(const string &name_arg, const string &subsample_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; virtual void writeOutput(ostream &output, const string &basename) const;
}; };
@ -714,7 +710,6 @@ public:
const string &subsample_name_arg, const string &subsample_name_arg,
const OptionsList &options_list_arg, const OptionsList &options_list_arg,
const SymbolTable &symbol_table_arg); const SymbolTable &symbol_table_arg);
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
virtual void writeOutput(ostream &output, const string &basename) const; virtual void writeOutput(ostream &output, const string &basename) const;
}; };

View File

@ -45,9 +45,6 @@ ModFileStructure::ModFileStructure() :
dsge_var_estimated(false), dsge_var_estimated(false),
bayesian_irf_present(false), bayesian_irf_present(false),
estimation_data_statement_present(false), estimation_data_statement_present(false),
options_statement_present(false),
std_options_statement_present(false),
corr_options_statement_present(false),
last_markov_switching_chain(0) last_markov_switching_chain(0)
{ {
} }

View File

@ -89,12 +89,6 @@ public:
bool bayesian_irf_present; bool bayesian_irf_present;
//! Whether there is a data statement present //! Whether there is a data statement present
bool estimation_data_statement_present; bool estimation_data_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;
//! Last chain number for Markov Switching statement //! Last chain number for Markov Switching statement
int last_markov_switching_chain; int last_markov_switching_chain;
}; };