preprocessor: interface for prior_posterior_function command. closes #1076
parent
4d06a6623e
commit
863e13db55
|
@ -138,6 +138,50 @@ PerfectForesightSolverStatement::writeOutput(ostream &output, const string &base
|
|||
output << "perfect_foresight_solver;" << endl;
|
||||
}
|
||||
|
||||
PriorPosteriorFunctionStatement::PriorPosteriorFunctionStatement(const OptionsList &options_list_arg) :
|
||||
options_list(options_list_arg)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
PriorPosteriorFunctionStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
|
||||
{
|
||||
// Fill in option_occbin of mod_file_struct
|
||||
OptionsList::num_options_t::const_iterator it = options_list.num_options.find("prior");
|
||||
OptionsList::num_options_t::const_iterator it1 = options_list.num_options.find("posterior");
|
||||
if ((it == options_list.num_options.end() && it1 == options_list.num_options.end())
|
||||
|| (it != options_list.num_options.end() && it1 != options_list.num_options.end()))
|
||||
{
|
||||
cerr << "ERROR: prior_posterior_function requires one of 'prior' or 'posterior'" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
OptionsList::string_options_t::const_iterator it2 = options_list.string_options.find("function");
|
||||
if (it2 == options_list.string_options.end() || it2->second.empty())
|
||||
{
|
||||
cerr << "ERROR: prior_posterior_function requires the function argument" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PriorPosteriorFunctionStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
|
||||
{
|
||||
OptionsList::num_options_t::const_iterator it =
|
||||
options_list.num_options.find("prior_posterior_sampling_draws");
|
||||
if (it != options_list.num_options.end())
|
||||
cout << it->first << " = " << it->second << ";" << endl;
|
||||
|
||||
string type = "posterior";
|
||||
if (options_list.num_options.find("prior") != options_list.num_options.end())
|
||||
type = "prior";
|
||||
|
||||
output << "oo_ = execute_prior_posterior_function("
|
||||
<< "'" << options_list.string_options.find("function")->second << "',"
|
||||
<< "M_, options_, oo_, estim_params_, bayestopt_, dataset_, dataset_info, "
|
||||
<< "'" << type << "');" << endl;
|
||||
}
|
||||
|
||||
StochSimulStatement::StochSimulStatement(const SymbolList &symbol_list_arg,
|
||||
const OptionsList &options_list_arg) :
|
||||
symbol_list(symbol_list_arg),
|
||||
|
|
|
@ -77,6 +77,16 @@ public:
|
|||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
};
|
||||
|
||||
class PriorPosteriorFunctionStatement : public Statement
|
||||
{
|
||||
private:
|
||||
const OptionsList options_list;
|
||||
public:
|
||||
PriorPosteriorFunctionStatement(const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
};
|
||||
|
||||
class ModelInfoStatement : public Statement
|
||||
{
|
||||
private:
|
||||
|
|
|
@ -114,7 +114,7 @@ class ParsingDriver;
|
|||
%token NOGRAPH NOMOMENTS NOPRINT NORMAL_PDF SAVE_DRAWS
|
||||
%token OBSERVATION_TRENDS OPTIM OPTIM_WEIGHTS ORDER OSR OSR_PARAMS MAX_DIM_COVA_GROUP ADVANCED OUTFILE OUTVARS OVERWRITE
|
||||
%token PARALLEL_LOCAL_FILES PARAMETERS PARAMETER_SET PARTIAL_INFORMATION PERFECT_FORESIGHT PERIODS PERIOD PLANNER_OBJECTIVE PLOT_CONDITIONAL_FORECAST PLOT_PRIORS PREFILTER PRESAMPLE
|
||||
%token PERFECT_FORESIGHT_SETUP PERFECT_FORESIGHT_SOLVER NO_POSTERIOR_KERNEL_DENSITY
|
||||
%token PERFECT_FORESIGHT_SETUP PERFECT_FORESIGHT_SOLVER NO_POSTERIOR_KERNEL_DENSITY FUNCTION
|
||||
%token PRINT PRIOR_MC PRIOR_TRUNC PRIOR_MODE PRIOR_MEAN POSTERIOR_MODE POSTERIOR_MEAN POSTERIOR_MEDIAN PRUNING
|
||||
%token <string_val> QUOTED_STRING
|
||||
%token QZ_CRITERIUM QZ_ZERO_THRESHOLD FULL DSGE_VAR DSGE_VARLAG DSGE_PRIOR_WEIGHT TRUNCATE
|
||||
|
@ -147,7 +147,7 @@ class ParsingDriver;
|
|||
%token VLISTLOG VLISTPER SPECTRAL_DENSITY
|
||||
%token RESTRICTION RESTRICTION_FNAME CROSS_RESTRICTIONS NLAGS CONTEMP_REDUCED_FORM REAL_PSEUDO_FORECAST
|
||||
%token DUMMY_OBS NSTATES INDXSCALESSTATES NO_BAYESIAN_PRIOR SPECIFICATION SIMS_ZHA
|
||||
%token <string_val> ALPHA BETA ABAND NINV CMS NCMS CNUM GAMMA INV_GAMMA INV_GAMMA1 INV_GAMMA2 NORMAL UNIFORM EPS PDF FIG DR NONE PRIOR PRIOR_VARIANCE HESSIAN IDENTITY_MATRIX DIRICHLET
|
||||
%token <string_val> ALPHA BETA ABAND NINV CMS NCMS CNUM GAMMA INV_GAMMA INV_GAMMA1 INV_GAMMA2 NORMAL UNIFORM EPS PDF FIG DR NONE PRIOR POSTERIOR PRIOR_VARIANCE HESSIAN IDENTITY_MATRIX DIRICHLET
|
||||
%token GSIG2_LMDM Q_DIAG FLAT_PRIOR NCSK NSTD WEIBULL WEIBULL_PDF
|
||||
%token INDXPARR INDXOVR INDXAP APBAND INDXIMF IMFBAND INDXFORE FOREBAND INDXGFOREHAT INDXGIMFHAT
|
||||
%token INDXESTIMA INDXGDLS EQ_MS FILTER_COVARIANCE FILTER_DECOMPOSITION
|
||||
|
@ -162,7 +162,7 @@ class ParsingDriver;
|
|||
%token SELECTED_VARIABLES_ONLY COVA_COMPUTE SIMULATION_FILE_TAG FILE_TAG
|
||||
%token NO_ERROR_BANDS ERROR_BAND_PERCENTILES SHOCKS_PER_PARAMETER NO_CREATE_INIT
|
||||
%token SHOCK_DRAWS FREE_PARAMETERS MEDIAN DATA_OBS_NBR NEIGHBORHOOD_WIDTH PVALUE_KS PVALUE_CORR
|
||||
%token FILTERED_PROBABILITIES REAL_TIME_SMOOTHED
|
||||
%token FILTERED_PROBABILITIES REAL_TIME_SMOOTHED PRIOR_POSTERIOR_FUNCTION PRIOR_POSTERIOR_SAMPLING_DRAWS
|
||||
%token PROPOSAL_TYPE PROPOSAL_UPPER_BOUND PROPOSAL_LOWER_BOUND PROPOSAL_DRAWS USE_MEAN_CENTER
|
||||
%token ADAPTIVE_MH_DRAWS THINNING_FACTOR COEFFICIENTS_PRIOR_HYPERPARAMETERS
|
||||
%token CONVERGENCE_STARTING_VALUE CONVERGENCE_ENDING_VALUE CONVERGENCE_INCREMENT_VALUE
|
||||
|
@ -281,6 +281,7 @@ statement : parameters
|
|||
| histval_file
|
||||
| perfect_foresight_setup
|
||||
| perfect_foresight_solver
|
||||
| prior_posterior_function
|
||||
;
|
||||
|
||||
dsample : DSAMPLE INT_NUMBER ';'
|
||||
|
@ -1022,6 +1023,20 @@ perfect_foresight_solver_options : o_stack_solve_algo
|
|||
| o_occbin
|
||||
;
|
||||
|
||||
prior_posterior_function : PRIOR_POSTERIOR_FUNCTION '(' prior_posterior_function_options_list ')' ';'
|
||||
{ driver.prior_posterior_function(); }
|
||||
;
|
||||
|
||||
prior_posterior_function_options_list : prior_posterior_function_options_list COMMA prior_posterior_function_options
|
||||
| prior_posterior_function_options
|
||||
;
|
||||
|
||||
prior_posterior_function_options : o_function
|
||||
| o_prior
|
||||
| o_posterior
|
||||
| o_prior_posterior_sampling_draws
|
||||
;
|
||||
|
||||
simul : SIMUL ';'
|
||||
{ driver.simul(); }
|
||||
| SIMUL '(' simul_options_list ')' ';'
|
||||
|
@ -3065,7 +3080,11 @@ o_period : PERIOD EQUAL INT_NUMBER { driver.option_num("period", $3); };
|
|||
o_outfile : OUTFILE EQUAL filename { driver.option_str("outfile", $3); };
|
||||
o_outvars : OUTVARS EQUAL '(' symbol_list ')' { driver.option_symbol_list("outvars"); };
|
||||
o_lmmcp : LMMCP {driver.option_num("lmmcp", "1"); };
|
||||
o_occbin : OCCBIN {driver.option_num("occbin", "1"); };
|
||||
o_occbin : OCCBIN {driver.option_num("occbin", "1"); };
|
||||
o_function : FUNCTION EQUAL filename { driver.option_str("function", $3); };
|
||||
o_prior : PRIOR { driver.option_num("prior", "1"); };
|
||||
o_posterior : POSTERIOR { driver.option_num("posterior", "1"); };
|
||||
o_prior_posterior_sampling_draws : PRIOR_POSTERIOR_SAMPLING_DRAWS EQUAL INT_NUMBER { driver.option_num("prior_posterior_sampling_draws",$3); };
|
||||
|
||||
range : symbol ':' symbol
|
||||
{
|
||||
|
@ -3210,6 +3229,7 @@ symbol : NAME
|
|||
| NONE
|
||||
| DR
|
||||
| PRIOR
|
||||
| POSTERIOR
|
||||
;
|
||||
%%
|
||||
|
||||
|
|
|
@ -214,8 +214,15 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2
|
|||
yylval->string_val = new string(yytext);
|
||||
return token::PRIOR;
|
||||
}
|
||||
<DYNARE_STATEMENT>posterior {
|
||||
yylval->string_val = new string(yytext);
|
||||
return token::POSTERIOR;
|
||||
}
|
||||
<INITIAL>std {BEGIN DYNARE_STATEMENT; return token::STD;}
|
||||
<INITIAL>corr {BEGIN DYNARE_STATEMENT; return token::CORR;}
|
||||
<DYNARE_STATEMENT>function {return token::FUNCTION;}
|
||||
<DYNARE_STATEMENT>prior_posterior_sampling_draws {return token::PRIOR_POSTERIOR_SAMPLING_DRAWS;}
|
||||
<INITIAL>prior_posterior_function {BEGIN DYNARE_STATEMENT; return token::PRIOR_POSTERIOR_FUNCTION;}
|
||||
|
||||
/* Inside of a Dynare statement */
|
||||
<DYNARE_STATEMENT>{DATE} {
|
||||
|
|
|
@ -2797,6 +2797,13 @@ ParsingDriver::perfect_foresight_solver()
|
|||
options_list.clear();
|
||||
}
|
||||
|
||||
void
|
||||
ParsingDriver::prior_posterior_function()
|
||||
{
|
||||
mod_file->addStatement(new PriorPosteriorFunctionStatement(options_list));
|
||||
options_list.clear();
|
||||
}
|
||||
|
||||
void
|
||||
ParsingDriver::add_ramsey_constraints_statement()
|
||||
{
|
||||
|
|
|
@ -702,7 +702,8 @@ public:
|
|||
void smoother2histval();
|
||||
void histval_file(string *filename);
|
||||
void perfect_foresight_setup();
|
||||
void perfect_foresight_solver();
|
||||
void perfect_foresight_solver();
|
||||
void prior_posterior_function();
|
||||
};
|
||||
|
||||
#endif // ! PARSING_DRIVER_HH
|
||||
|
|
Loading…
Reference in New Issue