estimation: rewrite prior output

issue#70
Houtan Bastani 2012-03-29 15:21:32 +02:00
parent 79b9d6a66e
commit aa21ef6ec5
4 changed files with 46 additions and 121 deletions

View File

@ -1647,7 +1647,8 @@ SubsamplesStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli
void void
SubsamplesStatement::writeOutput(ostream &output, const string &basename) const SubsamplesStatement::writeOutput(ostream &output, const string &basename) const
{ {
output << "subsamples_indx = get_new_or_existing_subsamples_indx('" << name1 << "','" << name2 << "');" << endl output << "subsamples_indx = get_new_or_existing_ei_index('subsamples_index', '"
<< name1 << "','" << name2 << "');" << endl
<< "estimation_info.subsamples_index(subsamples_indx) = {'" << name1; << "estimation_info.subsamples_index(subsamples_indx) = {'" << name1;
if (!name2.empty()) if (!name2.empty())
output << "_" << name2; output << "_" << name2;
@ -1684,7 +1685,8 @@ SubsamplesEqualStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo
void void
SubsamplesEqualStatement::writeOutput(ostream &output, const string &basename) const SubsamplesEqualStatement::writeOutput(ostream &output, const string &basename) const
{ {
output << "subsamples_to_indx = get_new_or_existing_subsamples_indx('" << to_name1 << "','" << to_name2 << "');" << endl output << "subsamples_to_indx = get_new_or_existing_ei_index('subsamples_index', '"
<< to_name1 << "','" << to_name2 << "');" << endl
<< "estimation_info.subsamples_index(subsamples_to_indx) = {'" << to_name1; << "estimation_info.subsamples_index(subsamples_to_indx) = {'" << to_name1;
if (!to_name2.empty()) if (!to_name2.empty())
output << "_" << to_name2; output << "_" << to_name2;
@ -1708,8 +1710,7 @@ BasicPriorStatement::BasicPriorStatement(const string &name_arg,
subsample_name(subsample_name_arg), subsample_name(subsample_name_arg),
prior_shape(prior_shape_arg), prior_shape(prior_shape_arg),
variance(variance_arg), variance(variance_arg),
options_list(options_list_arg), options_list(options_list_arg)
first_statement_encountered(false)
{ {
} }
@ -1760,19 +1761,19 @@ BasicPriorStatement::get_base_name(const SymbolType symb_type, string &lhs_field
lhs_field = "measurement_error"; lhs_field = "measurement_error";
} }
void
BasicPriorStatement::writePriorIndex(ostream &output, const string &lhs_field) const
{
if (first_statement_encountered)
output << "prior_indx = 1;" << endl;
else
output << "prior_indx = size(estimation_info" << lhs_field << "_index, 2) + 1;" << endl;
}
void void
BasicPriorStatement::writeCommonOutput(ostream &output, const string &lhs_field) const BasicPriorStatement::writeCommonOutput(ostream &output, const string &lhs_field) const
{ {
writeShape(output, lhs_field); assert(prior_shape != eNoShape);
output << lhs_field << ".shape = " << prior_shape << ";" << endl;
if (variance)
{
output << lhs_field << ".variance = ";
variance->writeOutput(output);
output << ";" << endl;
}
writeCommonOutputHelper(output, "mean", lhs_field); writeCommonOutputHelper(output, "mean", lhs_field);
writeCommonOutputHelper(output, "mode", lhs_field); writeCommonOutputHelper(output, "mode", lhs_field);
writeCommonOutputHelper(output, "stdev", lhs_field); writeCommonOutputHelper(output, "stdev", lhs_field);
@ -1782,14 +1783,6 @@ BasicPriorStatement::writeCommonOutput(ostream &output, const string &lhs_field)
writeCommonOutputHelper(output, "median", lhs_field); writeCommonOutputHelper(output, "median", lhs_field);
writeCommonOutputHelper(output, "truncate", lhs_field); writeCommonOutputHelper(output, "truncate", lhs_field);
writeCommonOutputHelper(output, "interval", lhs_field); writeCommonOutputHelper(output, "interval", lhs_field);
writeVarianceOption(output, lhs_field);
}
void
BasicPriorStatement::writeShape(ostream &output, const string &lhs_field) const
{
assert(prior_shape != eNoShape);
output << "estimation_info" << lhs_field << "(prior_indx).shape = " << prior_shape << ";" << endl;
} }
void void
@ -1797,43 +1790,22 @@ BasicPriorStatement::writeCommonOutputHelper(ostream &output, const string &fiel
{ {
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 << "(prior_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 << "(prior_indx)." << field
<< " = '" << itd->second << "';" << endl;
} }
void void
BasicPriorStatement::writeVarianceOption(ostream &output, const string &lhs_field) const BasicPriorStatement::writePriorOutput(ostream &output, string &lhs_field) const
{
if (variance)
{
output << "estimation_info" << lhs_field << "(prior_indx).variance = ";
variance->writeOutput(output);
output << ";" << endl;
}
}
void
BasicPriorStatement::writeSubsampleName(ostream &output) const
{
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()) if (subsample_name.empty())
return; lhs_field += ".prior(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 << "','');" << endl
output << "estimation_info" << lhs_field << "(prior_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 << "(prior_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_prior(eisind)";
}
writeCommonOutput(output, lhs_field);
} }
PriorStatement::PriorStatement(const string &name_arg, PriorStatement::PriorStatement(const string &name_arg,
@ -1845,28 +1817,14 @@ PriorStatement::PriorStatement(const string &name_arg,
{ {
} }
void
PriorStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
{
BasicPriorStatement::checkPass(mod_file_struct, warnings);
if (!mod_file_struct.prior_statement_present)
first_statement_encountered = true;
mod_file_struct.prior_statement_present = true;
}
void void
PriorStatement::writeOutput(ostream &output, const string &basename) const PriorStatement::writeOutput(ostream &output, const string &basename) const
{ {
string lhs_field = ".parameters.prior"; string lhs_field = "estimation_info.parameters(eifind)";
output << "eifind = get_new_or_existing_ei_index('parameter_prior_index', '"
writePriorIndex(output, lhs_field); << name << "', '');" << endl
output << "estimation_info" << lhs_field << "_index(prior_indx) = {'" << name; << "estimation_info.parameter_prior_index(eifind) = {'" << name << "'};" << endl;
writeSubsampleName(output); writePriorOutput(output, lhs_field);
output << "'};" << endl
<< "estimation_info" << lhs_field <<"(prior_indx).name = '" << name << "';" << endl;
writeCommonOutput(output, lhs_field);
writeSubsampleInfo(output, lhs_field, name, "");
} }
StdPriorStatement::StdPriorStatement(const string &name_arg, StdPriorStatement::StdPriorStatement(const string &name_arg,
@ -1880,30 +1838,17 @@ StdPriorStatement::StdPriorStatement(const string &name_arg,
{ {
} }
void
StdPriorStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
{
BasicPriorStatement::checkPass(mod_file_struct, warnings);
if (!mod_file_struct.std_prior_statement_present)
first_statement_encountered = true;
mod_file_struct.std_prior_statement_present = true;
}
void void
StdPriorStatement::writeOutput(ostream &output, const string &basename) const StdPriorStatement::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 + ".prior"; output << "eifind = get_new_or_existing_ei_index('" << lhs_field << "_prior_index', '"
<< name << "', '');" << endl
<< "estimation_info." << lhs_field << "_prior_index(eifind) = {'" << name << "'};" << endl;
writePriorIndex(output, lhs_field); lhs_field = "estimation_info." + lhs_field + "(eifind)";
output << "estimation_info" << lhs_field << "_index(prior_indx) = {'" << name; writePriorOutput(output, lhs_field);
writeSubsampleName(output);
output << "'};" << endl
<< "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, CorrPriorStatement::CorrPriorStatement(const string &name_arg1, const string &name_arg2,
@ -1929,9 +1874,6 @@ CorrPriorStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolid
<< "types." << endl; << "types." << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (!mod_file_struct.corr_prior_statement_present)
first_statement_encountered = true;
mod_file_struct.corr_prior_statement_present = true;
} }
void void
@ -1939,17 +1881,17 @@ 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);
lhs_field = "." + lhs_field + "_corr.prior";
writePriorIndex(output, lhs_field); output << "eifind = get_new_or_existing_ei_index('" << lhs_field << "_prior_index', '"
output << "estimation_info" << lhs_field << "_index(prior_indx) = {'" << name << "_" << name1; << name << "', '" << name1 << "');" << endl
writeSubsampleName(output); << "estimation_info." << lhs_field << "_prior_index(eifind) = {'"
output << "'};" << endl << name << "_" << name1 << "'};" << endl;
<< "estimation_info" << lhs_field << "(prior_indx).name1 = '" << name << "';" << endl
<< "estimation_info" << lhs_field << "(prior_indx).name2 = '" << name1 << "';" << endl;
writeCommonOutput(output, lhs_field); lhs_field = "estimation_info." + lhs_field + "_corr(eifind)";
writeSubsampleInfo(output, lhs_field, name, name1); writePriorOutput(output, lhs_field);
output << lhs_field << ".name1 = '" << name << "';" << endl
<< lhs_field << ".name2 = '" << name1 << "';" << endl;
} }
BasicOptionsStatement::~BasicOptionsStatement() BasicOptionsStatement::~BasicOptionsStatement()
@ -2118,7 +2060,6 @@ CorrOptionsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsol
} }
if (!mod_file_struct.corr_options_statement_present) if (!mod_file_struct.corr_options_statement_present)
first_statement_encountered = true; first_statement_encountered = true;
mod_file_struct.corr_prior_statement_present = true;
} }
void void

View File

@ -622,7 +622,6 @@ protected:
const PriorDistributions prior_shape; const PriorDistributions prior_shape;
const expr_t variance; const expr_t variance;
const OptionsList options_list; const OptionsList options_list;
bool first_statement_encountered;
BasicPriorStatement(const string &name_arg, BasicPriorStatement(const string &name_arg,
const string &subsample_name_arg, const string &subsample_name_arg,
const PriorDistributions &prior_shape_arg, const PriorDistributions &prior_shape_arg,
@ -630,13 +629,9 @@ protected:
const OptionsList &options_list_arg); const OptionsList &options_list_arg);
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
void get_base_name(const SymbolType symb_type, string &lhs_field) const; void get_base_name(const SymbolType symb_type, string &lhs_field) const;
void writePriorIndex(ostream &output, const string &lhs_field) const;
void writeVarianceOption(ostream &output, const string &lhs_field) 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 writeShape(ostream &output, const string &lhs_field) const; void writePriorOutput(ostream &output, 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 class PriorStatement : public BasicPriorStatement
@ -647,7 +642,6 @@ public:
const PriorDistributions &prior_shape_arg, const PriorDistributions &prior_shape_arg,
const expr_t &variance_arg, const expr_t &variance_arg,
const OptionsList &options_list_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;
}; };
@ -662,7 +656,6 @@ public:
const expr_t &variance_arg, const expr_t &variance_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),
prior_statement_present(false),
std_prior_statement_present(false),
corr_prior_statement_present(false),
options_statement_present(false), options_statement_present(false),
std_options_statement_present(false), std_options_statement_present(false),
corr_options_statement_present(false), corr_options_statement_present(false),

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 prior statement present
bool prior_statement_present;
//! Whether there is a std prior statement present
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 //! Whether there is a options statement present
bool options_statement_present; bool options_statement_present;
//! Whether there is a std options statement present //! Whether there is a std options statement present