Remove unused expectation syntax

issue#70
Houtan Bastani 2011-10-25 16:46:12 +02:00
parent b8c22d128f
commit b75d0e733f
9 changed files with 51 additions and 120 deletions

View File

@ -465,13 +465,13 @@ DataTree::AddSteadyState(expr_t iArg1)
expr_t
DataTree::AddSteadyStateParamDeriv(expr_t iArg1, int param_symb_id)
{
return AddUnaryOp(oSteadyStateParamDeriv, iArg1, 0, "", param_symb_id);
return AddUnaryOp(oSteadyStateParamDeriv, iArg1, 0, param_symb_id);
}
expr_t
DataTree::AddSteadyStateParam2ndDeriv(expr_t iArg1, int param1_symb_id, int param2_symb_id)
{
return AddUnaryOp(oSteadyStateParam2ndDeriv, iArg1, 0, "", param1_symb_id, param2_symb_id);
return AddUnaryOp(oSteadyStateParam2ndDeriv, iArg1, 0, param1_symb_id, param2_symb_id);
}
expr_t
@ -480,12 +480,6 @@ DataTree::AddExpectation(int iArg1, expr_t iArg2)
return AddUnaryOp(oExpectation, iArg2, iArg1);
}
expr_t
DataTree::AddExpectation(string *iArg1, expr_t iArg2)
{
return AddUnaryOp(oExpectation, iArg2, 0, *iArg1);
}
expr_t
DataTree::AddEqual(expr_t iArg1, expr_t iArg2)
{

View File

@ -59,8 +59,8 @@ protected:
//! Pair (symbol_id, lag) used as key
typedef map<pair<int, int>, VariableNode *> variable_node_map_t;
variable_node_map_t variable_node_map;
//! Pair( Pair (arg1, UnaryOpCode), Pair(Pair(Expectation Info Set, Expectation Info Set Name), (param1_symb_id, param2_symb_id)) )
typedef map<pair<pair<expr_t, UnaryOpcode>, pair<pair<int, string>, pair<int, int> > >, UnaryOpNode *> unary_op_node_map_t;
//! Pair( Pair(arg1, UnaryOpCode), Pair( Expectation Info Set, Pair(param1_symb_id, param2_symb_id)) ))
typedef map<pair<pair<expr_t, UnaryOpcode>, pair<int, pair<int, int> > >, UnaryOpNode *> unary_op_node_map_t;
unary_op_node_map_t unary_op_node_map;
//! Pair( Pair( Pair(arg1, arg2), order of Power Derivative), opCode)
typedef map<pair<pair<pair<expr_t, expr_t>, int>, BinaryOpcode>, BinaryOpNode *> binary_op_node_map_t;
@ -88,7 +88,7 @@ private:
int node_counter;
inline expr_t AddPossiblyNegativeConstant(double val);
inline expr_t AddUnaryOp(UnaryOpcode op_code, expr_t arg, int arg_exp_info_set = 0, const string &arg_exp_info_set_name = "", int param1_symb_id = 0, int param2_symb_id = 0);
inline expr_t AddUnaryOp(UnaryOpcode op_code, expr_t arg, int arg_exp_info_set = 0, int param1_symb_id = 0, int param2_symb_id = 0);
inline expr_t AddBinaryOp(expr_t arg1, BinaryOpcode op_code, expr_t arg2, int powerDerivOrder = 0);
inline expr_t AddTrinaryOp(expr_t arg1, TrinaryOpcode op_code, expr_t arg2, expr_t arg3);
@ -142,8 +142,6 @@ public:
expr_t AddPowerDeriv(expr_t iArg1, expr_t iArg2, int powerDerivOrder);
//! Adds "E(arg1)(arg2)" to model tree
expr_t AddExpectation(int iArg1, expr_t iArg2);
//! Adds "E(arg1)(arg2)" to model tree
expr_t AddExpectation(string *iArg1, expr_t iArg2);
//! Adds "exp(arg)" to model tree
expr_t AddExp(expr_t iArg1);
//! Adds "log(arg)" to model tree
@ -281,10 +279,10 @@ DataTree::AddPossiblyNegativeConstant(double v)
}
inline expr_t
DataTree::AddUnaryOp(UnaryOpcode op_code, expr_t arg, int arg_exp_info_set, const string &arg_exp_info_set_name, int param1_symb_id, int param2_symb_id)
DataTree::AddUnaryOp(UnaryOpcode op_code, expr_t arg, int arg_exp_info_set, int param1_symb_id, int param2_symb_id)
{
// If the node already exists in tree, share it
unary_op_node_map_t::iterator it = unary_op_node_map.find(make_pair(make_pair(arg, op_code), make_pair(make_pair(arg_exp_info_set, arg_exp_info_set_name), make_pair(param1_symb_id, param2_symb_id))));
unary_op_node_map_t::iterator it = unary_op_node_map.find(make_pair(make_pair(arg, op_code), make_pair(arg_exp_info_set, make_pair(param1_symb_id, param2_symb_id))));
if (it != unary_op_node_map.end())
return it->second;
@ -303,7 +301,7 @@ DataTree::AddUnaryOp(UnaryOpcode op_code, expr_t arg, int arg_exp_info_set, cons
{
}
}
return new UnaryOpNode(*this, op_code, arg, arg_exp_info_set, arg_exp_info_set_name, param1_symb_id, param2_symb_id);
return new UnaryOpNode(*this, op_code, arg, arg_exp_info_set, param1_symb_id, param2_symb_id);
}
inline expr_t

View File

@ -4041,9 +4041,6 @@ DynamicModel::substituteLeadLagInternal(aux_var_t type, bool deterministic_model
case avExpectation:
cout << "expectation";
break;
case avExpectationRIS:
cout << "expectation conditional on a restricted information set";
break;
case avMultiplier:
cerr << "avMultiplier encountered: impossible case" << endl;
exit(EXIT_FAILURE);

View File

@ -174,7 +174,7 @@ class ParsingDriver;
%type <node_val> expression expression_or_empty
%type <node_val> equation hand_side
%type <string_val> non_negative_number signed_number signed_integer
%type <string_val> filename symbol expectation_input
%type <string_val> filename symbol
%type <string_val> vec_value_1 vec_value
%type <string_val> range prior
%type <symbol_type_val> change_type_arg
@ -589,7 +589,7 @@ hand_side : '(' hand_side ')'
{ $$ = driver.add_different($1, $3); }
| hand_side POWER hand_side
{ $$ = driver.add_power($1, $3); }
| EXPECTATION '(' expectation_input ')''(' hand_side ')'
| EXPECTATION '(' signed_integer ')''(' hand_side ')'
{ $$ = driver.add_expectation($3, $6); }
| MINUS hand_side %prec UMINUS
{ $$ = driver.add_uminus($2); }
@ -647,11 +647,6 @@ comma_hand_side : hand_side
{ driver.add_external_function_arg($3); }
;
expectation_input : signed_integer
| VAROBS { string *varobs = new string("varobs"); $$ = varobs; }
| FULL { string *full = new string("full"); $$ = full; }
;
pound_expression: '#' symbol EQUAL hand_side ';'
{ driver.declare_and_init_model_local_variable($2, $4); };

View File

@ -1231,18 +1231,17 @@ VariableNode::removeTrendLeadLag(map<int, expr_t> trend_symbols_map) const
}
}
UnaryOpNode::UnaryOpNode(DataTree &datatree_arg, UnaryOpcode op_code_arg, const expr_t arg_arg, int expectation_information_set_arg, const string &expectation_information_set_name_arg, int param1_symb_id_arg, int param2_symb_id_arg) :
UnaryOpNode::UnaryOpNode(DataTree &datatree_arg, UnaryOpcode op_code_arg, const expr_t arg_arg, int expectation_information_set_arg, int param1_symb_id_arg, int param2_symb_id_arg) :
ExprNode(datatree_arg),
arg(arg_arg),
expectation_information_set(expectation_information_set_arg),
expectation_information_set_name(expectation_information_set_name_arg),
param1_symb_id(param1_symb_id_arg),
param2_symb_id(param2_symb_id_arg),
op_code(op_code_arg)
{
// Add myself to the unary op map
datatree.unary_op_node_map[make_pair(make_pair(arg, op_code),
make_pair(make_pair(expectation_information_set, expectation_information_set_name),
make_pair(expectation_information_set,
make_pair(param1_symb_id, param2_symb_id)))] = this;
}
@ -2155,69 +2154,39 @@ UnaryOpNode::substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *>
expr_t
UnaryOpNode::substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const
{
switch (op_code)
if (op_code==oExpectation)
{
case oExpectation:
{
subst_table_t::iterator it = subst_table.find(const_cast<UnaryOpNode *>(this));
if (it != subst_table.end())
return const_cast<VariableNode *>(it->second);
subst_table_t::iterator it = subst_table.find(const_cast<UnaryOpNode *>(this));
if (it != subst_table.end())
return const_cast<VariableNode *>(it->second);
//Arriving here, we need to create an auxiliary variable for this Expectation Operator:
//AUX_EXPECT_(LEAD/LAG)_(period)_(arg.idx) OR
//AUX_EXPECT_(info_set_name)_(arg.idx)
int symb_id = datatree.symbol_table.addExpectationAuxiliaryVar(expectation_information_set, arg->idx, expectation_information_set_name);
expr_t newAuxE = datatree.AddVariable(symb_id, 0);
//Arriving here, we need to create an auxiliary variable for this Expectation Operator:
//AUX_EXPECT_(LEAD/LAG)_(period)_(arg.idx) OR
//AUX_EXPECT_(info_set_name)_(arg.idx)
int symb_id = datatree.symbol_table.addExpectationAuxiliaryVar(expectation_information_set, arg->idx);
expr_t newAuxE = datatree.AddVariable(symb_id, 0);
if (partial_information_model && expectation_information_set == 0)
if (partial_information_model && expectation_information_set == 0)
if (dynamic_cast<VariableNode *>(arg) == NULL)
{
if (dynamic_cast<VariableNode *>(arg) == NULL)
{
cerr << "ERROR: In Partial Information models, EXPECTATION(";
if (expectation_information_set_name.empty())
cerr << 0;
else
cerr << expectation_information_set_name;
cerr << ")(X) can only be used when X is a single variable." << endl;
exit(EXIT_FAILURE);
}
cerr << "ERROR: In Partial Information models, EXPECTATION(0)(X) "
<< "can only be used when X is a single variable." << endl;
exit(EXIT_FAILURE);
}
if (!expectation_information_set_name.empty())
{
if (!partial_information_model)
{
cerr << "ERROR: EXPECTATION(" << expectation_information_set_name << ")(X) is only valid in models with partial information." << endl;
exit(EXIT_FAILURE);
}
//take care of any nested expectation operators by calling arg->substituteExpectation(.), then decreaseLeadsLags for this oExpectation operator
//arg(lag-period) (holds entire subtree of arg(lag-period)
expr_t substexpr = (arg->substituteExpectation(subst_table, neweqs, partial_information_model))->decreaseLeadsLags(expectation_information_set);
assert(substexpr != NULL);
neweqs.push_back(dynamic_cast<BinaryOpNode *>(datatree.AddEqual(newAuxE, substexpr))); //AUXE_period_arg.idx = arg(lag-period)
newAuxE = datatree.AddVariable(symb_id, expectation_information_set);
if (expectation_information_set != 0)
{
cerr << "ERROR: UnaryOpNode::substituteExpectation() should not arrive here. Please inform Dynare Team." << endl;
exit(EXIT_FAILURE);
}
else if (dynamic_cast<VariableNode *>(arg)->get_lag() != 0)
{
cerr << "ERROR: EXPECTATION(" << expectation_information_set_name << ")(X) requres that X be from the current period." << endl;
exit(EXIT_FAILURE);
}
//Will not have nested Expectation operators of this type since we require that X be a single endogenous variable.
//Hence, the newAuxE with lag = 0 is all we need here.
}
else
{
//take care of any nested expectation operators by calling arg->substituteExpectation(.), then decreaseLeadsLags for this oExpectation operator
//arg(lag-period) (holds entire subtree of arg(lag-period)
expr_t substexpr = (arg->substituteExpectation(subst_table, neweqs, partial_information_model))->decreaseLeadsLags(expectation_information_set);
assert(substexpr != NULL);
neweqs.push_back(dynamic_cast<BinaryOpNode *>(datatree.AddEqual(newAuxE, substexpr))); //AUXE_period_arg.idx = arg(lag-period)
newAuxE = datatree.AddVariable(symb_id, expectation_information_set);
}
assert(dynamic_cast<VariableNode *>(newAuxE) != NULL);
subst_table[this] = dynamic_cast<VariableNode *>(newAuxE);
return newAuxE;
}
default:
assert(dynamic_cast<VariableNode *>(newAuxE) != NULL);
subst_table[this] = dynamic_cast<VariableNode *>(newAuxE);
return newAuxE;
}
else
{
expr_t argsubst = arg->substituteExpectation(subst_table, neweqs, partial_information_model);
return buildSimilarUnaryOpNode(argsubst, datatree);
}

View File

@ -504,8 +504,6 @@ private:
const expr_t arg;
//! Stores the information set. Only used for expectation operator
const int expectation_information_set;
//! Stores the information set name. Only used for expectation operator
const string expectation_information_set_name;
//! Only used for oSteadyStateParamDeriv and oSteadyStateParam2ndDeriv
const int param1_symb_id, param2_symb_id;
const UnaryOpcode op_code;
@ -514,7 +512,7 @@ private:
//! Returns the derivative of this node if darg is the derivative of the argument
expr_t composeDerivatives(expr_t darg, int deriv_id);
public:
UnaryOpNode(DataTree &datatree_arg, UnaryOpcode op_code_arg, const expr_t arg_arg, int expectation_information_set_arg, const string &expectation_information_set_name_arg, int param1_symb_id_arg, int param2_symb_id_arg);
UnaryOpNode(DataTree &datatree_arg, UnaryOpcode op_code_arg, const expr_t arg_arg, int expectation_information_set_arg, int param1_symb_id_arg, int param2_symb_id_arg);
virtual void prepareForDerivation();
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;

View File

@ -1743,17 +1743,7 @@ expr_t
ParsingDriver::add_expectation(string *arg1, expr_t arg2)
{
expr_t expectationNode;
if ("varobs" == *arg1 || "full" == *arg1)
if (dynamic_cast<VariableNode *>(arg2) == NULL)
error("EXPECTATION(" + *arg1 + ")(X) can only be used when X is a single variable.");
else
if (mod_file->symbol_table.getType(dynamic_cast<VariableNode *>(arg2)->get_symb_id()) != eEndogenous)
error(mod_file->symbol_table.getName(dynamic_cast<VariableNode *>(arg2)->get_symb_id()) + " is not endogenous.");
else
expectationNode = data_tree->AddExpectation(arg1, arg2);
else
expectationNode = data_tree->AddExpectation(atoi(arg1->c_str()), arg2);
expectationNode = data_tree->AddExpectation(atoi(arg1->c_str()), arg2);
delete arg1;
return expectationNode;
}

View File

@ -25,12 +25,11 @@
#include "SymbolTable.hh"
AuxVarInfo::AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id_arg, int orig_lead_lag_arg,
string expectation_information_set_name_arg, int equation_number_for_multiplier_arg) :
int equation_number_for_multiplier_arg) :
symb_id(symb_id_arg),
type(type_arg),
orig_symb_id(orig_symb_id_arg),
orig_lead_lag(orig_lead_lag_arg),
expectation_information_set_name(expectation_information_set_name_arg),
equation_number_for_multiplier(equation_number_for_multiplier_arg)
{
}
@ -229,9 +228,6 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
case avExoLead:
case avExpectation:
break;
case avExpectationRIS:
output << "M_.aux_vars(" << i+1 << ").expectation_information_set_name = '" << aux_vars[i].get_expectation_information_set_name() << "';" << endl;
break;
case avEndoLag:
case avExoLag:
output << "M_.aux_vars(" << i+1 << ").orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id())+1 << ";" << endl
@ -290,7 +286,7 @@ SymbolTable::addLeadAuxiliaryVarInternal(bool endo, int index) throw (FrozenExce
exit(EXIT_FAILURE);
}
aux_vars.push_back(AuxVarInfo(symb_id, (endo ? avEndoLead : avExoLead), 0, 0, "", 0));
aux_vars.push_back(AuxVarInfo(symb_id, (endo ? avEndoLead : avExoLead), 0, 0, 0));
return symb_id;
}
@ -316,7 +312,7 @@ SymbolTable::addLagAuxiliaryVarInternal(bool endo, int orig_symb_id, int orig_le
exit(EXIT_FAILURE);
}
aux_vars.push_back(AuxVarInfo(symb_id, (endo ? avEndoLag : avExoLag), orig_symb_id, orig_lead_lag, "", 0));
aux_vars.push_back(AuxVarInfo(symb_id, (endo ? avEndoLag : avExoLag), orig_symb_id, orig_lead_lag, 0));
return symb_id;
}
@ -346,16 +342,13 @@ SymbolTable::addExoLagAuxiliaryVar(int orig_symb_id, int orig_lead_lag) throw (F
}
int
SymbolTable::addExpectationAuxiliaryVar(int information_set, int index, const string &information_set_name) throw (FrozenException)
SymbolTable::addExpectationAuxiliaryVar(int information_set, int index) throw (FrozenException)
{
ostringstream varname;
int symb_id;
if (information_set_name.empty())
varname << "AUX_EXPECT_" << (information_set < 0 ? "LAG" : "LEAD") << "_"
<< abs(information_set) << "_" << index;
else
varname << "AUX_EXPECT_" << information_set_name << "_" << index;
varname << "AUX_EXPECT_" << (information_set < 0 ? "LAG" : "LEAD") << "_"
<< abs(information_set) << "_" << index;
try
{
@ -367,7 +360,7 @@ SymbolTable::addExpectationAuxiliaryVar(int information_set, int index, const st
exit(EXIT_FAILURE);
}
aux_vars.push_back(AuxVarInfo(symb_id, (information_set_name.empty() ? avExpectation : avExpectationRIS), 0, 0, information_set_name, 0));
aux_vars.push_back(AuxVarInfo(symb_id, avExpectation, 0, 0, 0));
return symb_id;
}
@ -389,7 +382,7 @@ SymbolTable::addMultiplierAuxiliaryVar(int index) throw (FrozenException)
exit(EXIT_FAILURE);
}
aux_vars.push_back(AuxVarInfo(symb_id, avMultiplier, 0, 0, "", index));
aux_vars.push_back(AuxVarInfo(symb_id, avMultiplier, 0, 0, index));
return symb_id;
}

View File

@ -38,8 +38,7 @@ enum aux_var_t
avExoLead = 2, //!< Substitute for exo leads >= 2
avExoLag = 3, //!< Substitute for exo lags >= 2
avExpectation = 4, //!< Substitute for Expectation Operator
avExpectationRIS = 5, //!< Substitute for Expectation Operator Conditional on Restricted Information Set
avMultiplier = 6 //!< Multipliers for FOC of Ramsey Probelem
avMultiplier = 5 //!< Multipliers for FOC of Ramsey Probelem
};
//! Information on some auxiliary variables
@ -50,15 +49,13 @@ private:
aux_var_t type; //!< Its type
int orig_symb_id; //!< Symbol ID of the endo of the original model represented by this aux var. Only used for avEndoLag and avExoLag.
int orig_lead_lag; //!< Lead/lag of the endo of the original model represented by this aux var. Only used for avEndoLag and avExoLag.
string expectation_information_set_name; //!< Stores 'full' or 'varobs' for avExpectationRIS. Not used otherwise.
int equation_number_for_multiplier; //!< Stores the original constraint equation number associated with this aux var. Only used for avMultiplier.
public:
AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id, int orig_lead_lag, string expectation_information_set_name_arg, int equation_number_for_multiplier_arg);
AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id, int orig_lead_lag, int equation_number_for_multiplier_arg);
int get_symb_id() const { return symb_id; };
aux_var_t get_type() const { return type; };
int get_orig_symb_id() const { return orig_symb_id; };
int get_orig_lead_lag() const { return orig_lead_lag; };
string get_expectation_information_set_name() const { return expectation_information_set_name; };
int get_equation_number_for_multiplier() const { return equation_number_for_multiplier; };
};
@ -216,7 +213,7 @@ public:
\param[in] index Used to construct the variable name
\return the symbol ID of the new symbol
*/
int addExpectationAuxiliaryVar(int information_set, int index, const string &information_set_name) throw (FrozenException);
int addExpectationAuxiliaryVar(int information_set, int index) throw (FrozenException);
//! Adds an auxiliary variable for the multiplier for the FOCs of the Ramsey Problem
/*!
\param[in] index Used to construct the variable name