estimation: introduce prior = prior syntax
parent
a54214b7e8
commit
c9aa2d7b23
|
@ -1890,6 +1890,108 @@ CorrPriorStatement::writeOutput(ostream &output, const string &basename) const
|
|||
writePriorOutput(output, lhs_field);
|
||||
}
|
||||
|
||||
PriorEqualStatement::PriorEqualStatement(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
|
||||
PriorEqualStatement::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
|
||||
PriorEqualStatement::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
|
||||
PriorEqualStatement::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 << "_prior_index', '"
|
||||
<< to_name1 << "', '" << to_name2<< "');" << endl
|
||||
<< "ei_from_ind = get_new_or_existing_ei_index('" << rhs_field << "_prior_index', '"
|
||||
<< from_name1 << "', '" << from_name2<< "');" << endl
|
||||
<< "estimation_info." << lhs_field << "_prior_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 += ".prior";
|
||||
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_prior(ei_to_ss_ind)";
|
||||
}
|
||||
|
||||
if (from_subsample_name.empty())
|
||||
rhs_field += ".prior";
|
||||
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_prior(ei_from_ss_ind)";
|
||||
}
|
||||
|
||||
output << lhs_field << " = " << rhs_field << ";" << endl;
|
||||
}
|
||||
|
||||
BasicOptionsStatement::~BasicOptionsStatement()
|
||||
|
|
|
@ -675,6 +675,33 @@ public:
|
|||
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||
};
|
||||
|
||||
class PriorEqualStatement : 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:
|
||||
PriorEqualStatement(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;
|
||||
};
|
||||
|
||||
class BasicOptionsStatement : public Statement
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -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
|
||||
%type <vector_string_val> change_type_var_list subsamples_eq_opt prior_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
|
||||
%%
|
||||
|
@ -220,6 +220,7 @@ statement : parameters
|
|||
| set_time
|
||||
| data
|
||||
| prior
|
||||
| prior_eq
|
||||
| subsamples
|
||||
| subsamples_eq
|
||||
| options
|
||||
|
@ -1279,6 +1280,65 @@ prior_options : o_shift
|
|||
| o_domain
|
||||
;
|
||||
|
||||
prior_eq : prior_eq_opt EQUAL prior_eq_opt ';'
|
||||
{
|
||||
driver.copy_prior($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;
|
||||
}
|
||||
;
|
||||
|
||||
prior_eq_opt : symbol '.' PRIOR
|
||||
{
|
||||
$$ = new vector<string *>();
|
||||
$$->push_back(new string ("par"));
|
||||
$$->push_back($1);
|
||||
$$->push_back(new string (""));
|
||||
$$->push_back(new string (""));
|
||||
}
|
||||
| symbol '.' symbol '.' PRIOR
|
||||
{
|
||||
$$ = new vector<string *>();
|
||||
$$->push_back(new string ("par"));
|
||||
$$->push_back($1);
|
||||
$$->push_back(new string (""));
|
||||
$$->push_back($3);
|
||||
}
|
||||
| STD '(' symbol ')' '.' PRIOR
|
||||
{
|
||||
$$ = new vector<string *>();
|
||||
$$->push_back(new string ("std"));
|
||||
$$->push_back($3);
|
||||
$$->push_back(new string (""));
|
||||
$$->push_back(new string (""));
|
||||
}
|
||||
| STD '(' symbol ')' '.' symbol '.' PRIOR
|
||||
{
|
||||
$$ = new vector<string *>();
|
||||
$$->push_back(new string ("std"));
|
||||
$$->push_back($3);
|
||||
$$->push_back(new string (""));
|
||||
$$->push_back($6);
|
||||
}
|
||||
| CORR '(' symbol COMMA symbol ')' '.' PRIOR
|
||||
{
|
||||
$$ = new vector<string *>();
|
||||
$$->push_back(new string ("corr"));
|
||||
$$->push_back($3);
|
||||
$$->push_back($5);
|
||||
$$->push_back(new string (""));
|
||||
}
|
||||
| CORR '(' symbol COMMA symbol ')' '.' symbol '.' PRIOR
|
||||
{
|
||||
$$ = new vector<string *>();
|
||||
$$->push_back(new string ("corr"));
|
||||
$$->push_back($3);
|
||||
$$->push_back($5);
|
||||
$$->push_back($8);
|
||||
}
|
||||
;
|
||||
|
||||
options : symbol '.' OPTIONS '(' options_options_list ')' ';'
|
||||
{ driver.set_options($1, new string ("")); }
|
||||
| symbol '.' symbol '.' OPTIONS '(' options_options_list ')' ';'
|
||||
|
|
|
@ -1357,6 +1357,32 @@ ParsingDriver::set_prior_variance(expr_t variance)
|
|||
prior_variance = variance;
|
||||
}
|
||||
|
||||
void
|
||||
ParsingDriver::copy_prior(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 PriorEqualStatement(*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::set_options(string *name, string *subsample_name)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2003-2011 Dynare Team
|
||||
* Copyright (C) 2003-2012 Dynare Team
|
||||
*
|
||||
* This file is part of Dynare.
|
||||
*
|
||||
|
@ -392,6 +392,9 @@ public:
|
|||
void set_prior(string *arg1, string *arg2);
|
||||
//! Adds the variance option to its temporary holding place
|
||||
void set_prior_variance(expr_t variance=NULL);
|
||||
//! Copies the prior from_name to_name
|
||||
void copy_prior(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 options for a parameter
|
||||
void set_options(string *arg1, string *arg2);
|
||||
//! Sets the prior for estimated std dev
|
||||
|
|
Loading…
Reference in New Issue