v4 parser: corrected bug for normcdf in DynareBison.yy
begin implementation of homotopy (not finished) git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1461 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
d90393f9df
commit
f60bb42588
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
@ -71,6 +71,7 @@ class ParsingDriver;
|
||||||
%token VALUES VAR VAREXO VAREXO_DET VAROBS
|
%token VALUES VAR VAREXO VAREXO_DET VAROBS
|
||||||
%token XLS_SHEET XLS_RANGE
|
%token XLS_SHEET XLS_RANGE
|
||||||
%token NORMCDF
|
%token NORMCDF
|
||||||
|
%token HOMOTOPY_SETUP HOMOTOPY_MODE HOMOTOPY_STEPS
|
||||||
%left LESS GREATER LESS_EQUAL GREATER_EQUAL EQUAL_EQUAL EXCLAMATION EXCLAMATION_EQUAL
|
%left LESS GREATER LESS_EQUAL GREATER_EQUAL EQUAL_EQUAL EXCLAMATION EXCLAMATION_EQUAL
|
||||||
%left COMMA
|
%left COMMA
|
||||||
%left PLUS MINUS
|
%left PLUS MINUS
|
||||||
|
@ -139,6 +140,7 @@ statement : declaration
|
||||||
| bvar_density
|
| bvar_density
|
||||||
| bvar_forecast
|
| bvar_forecast
|
||||||
| dynare_sensitivity
|
| dynare_sensitivity
|
||||||
|
| homotopy_setup
|
||||||
;
|
;
|
||||||
|
|
||||||
declaration : parameters
|
declaration : parameters
|
||||||
|
@ -446,7 +448,7 @@ hand_side : '(' hand_side ')'
|
||||||
{ $$ = driver.add_max($3 , $5); }
|
{ $$ = driver.add_max($3 , $5); }
|
||||||
| MIN '(' hand_side COMMA hand_side ')'
|
| MIN '(' hand_side COMMA hand_side ')'
|
||||||
{ $$ = driver.add_min($3 , $5); }
|
{ $$ = driver.add_min($3 , $5); }
|
||||||
| NORMCDF '(' expression COMMA expression COMMA expression ')'
|
| NORMCDF '(' hand_side COMMA hand_side COMMA hand_side ')'
|
||||||
{ $$ = driver.add_normcdf($3,$5,$7);}
|
{ $$ = driver.add_normcdf($3,$5,$7);}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -541,7 +543,10 @@ steady_options_list : steady_options_list COMMA steady_options
|
||||||
| steady_options
|
| steady_options
|
||||||
;
|
;
|
||||||
|
|
||||||
steady_options : o_solve_algo;
|
steady_options : o_solve_algo
|
||||||
|
| o_homotopy_mode
|
||||||
|
| o_homotopy_steps
|
||||||
|
;
|
||||||
|
|
||||||
check : CHECK ';'
|
check : CHECK ';'
|
||||||
{ driver.check(); }
|
{ driver.check(); }
|
||||||
|
@ -1187,6 +1192,16 @@ dynare_sensitivity_option : o_gsa_identification
|
||||||
| o_gsa_threshold_redform
|
| o_gsa_threshold_redform
|
||||||
;
|
;
|
||||||
|
|
||||||
|
homotopy_setup: HOMOTOPY_SETUP ';' homotopy_list END
|
||||||
|
{ driver.end_homotopy();};
|
||||||
|
|
||||||
|
homotopy_list : homotopy_item
|
||||||
|
| homotopy_list homotopy_item
|
||||||
|
;
|
||||||
|
|
||||||
|
homotopy_item : NAME COMMA expression COMMA expression ';'
|
||||||
|
{ driver.homotopy_val($1,$3,$5);};
|
||||||
|
|
||||||
number : INT_NUMBER
|
number : INT_NUMBER
|
||||||
| FLOAT_NUMBER
|
| FLOAT_NUMBER
|
||||||
;
|
;
|
||||||
|
@ -1318,6 +1333,8 @@ o_gsa_istart_rmse : ISTART_RMSE EQUAL INT_NUMBER { driver.option_num("istart_rms
|
||||||
o_gsa_alpha_rmse : ALPHA_RMSE EQUAL number { driver.option_num("alpha_rmse", $3); };
|
o_gsa_alpha_rmse : ALPHA_RMSE EQUAL number { driver.option_num("alpha_rmse", $3); };
|
||||||
o_gsa_alpha2_rmse : ALPHA2_RMSE EQUAL number { driver.option_num("alpha2_rmse", $3); };
|
o_gsa_alpha2_rmse : ALPHA2_RMSE EQUAL number { driver.option_num("alpha2_rmse", $3); };
|
||||||
|
|
||||||
|
o_homotopy_mode : HOMOTOPY_MODE EQUAL INT_NUMBER {driver.option_num("homotopy_mode",$3); };
|
||||||
|
o_homotopy_steps : HOMOTOPY_STEPS EQUAL INT_NUMBER {driver.option_num("homotopy_steps",$3); };
|
||||||
|
|
||||||
range : NAME ':' NAME
|
range : NAME ':' NAME
|
||||||
{
|
{
|
||||||
|
|
|
@ -107,6 +107,7 @@ int sigma_e = 0;
|
||||||
<INITIAL>observation_trends {BEGIN DYNARE_BLOCK; return token::OBSERVATION_TRENDS;}
|
<INITIAL>observation_trends {BEGIN DYNARE_BLOCK; return token::OBSERVATION_TRENDS;}
|
||||||
<INITIAL>optim_weights {BEGIN DYNARE_BLOCK; return token::OPTIM_WEIGHTS;}
|
<INITIAL>optim_weights {BEGIN DYNARE_BLOCK; return token::OPTIM_WEIGHTS;}
|
||||||
<INITIAL>calib_var {BEGIN DYNARE_BLOCK; return token::CALIB_VAR;}
|
<INITIAL>calib_var {BEGIN DYNARE_BLOCK; return token::CALIB_VAR;}
|
||||||
|
<INITIAL>homotopy_setup {BEGIN DYNARE_BLOCK; return token::HOMOTOPY_SETUP;}
|
||||||
|
|
||||||
/* End of a Dynare block */
|
/* End of a Dynare block */
|
||||||
<DYNARE_BLOCK>end[ \t\n]*; {BEGIN INITIAL; return token::END;}
|
<DYNARE_BLOCK>end[ \t\n]*; {BEGIN INITIAL; return token::END;}
|
||||||
|
@ -171,6 +172,9 @@ int sigma_e = 0;
|
||||||
<DYNARE_STATEMENT>bvar_prior_train { return token::BVAR_PRIOR_TRAIN; }
|
<DYNARE_STATEMENT>bvar_prior_train { return token::BVAR_PRIOR_TRAIN; }
|
||||||
<DYNARE_STATEMENT>bvar_replic { return token::BVAR_REPLIC; }
|
<DYNARE_STATEMENT>bvar_replic { return token::BVAR_REPLIC; }
|
||||||
|
|
||||||
|
<DYNARE_STATEMENT>homotopy_mode {return token::HOMOTOPY_MODE; }
|
||||||
|
<DYNARE_STATEMENT>homotopy_steps {return token::HOMOTOPY_STEPS; }
|
||||||
|
|
||||||
<DYNARE_STATEMENT>[\$][^$]*[\$] {
|
<DYNARE_STATEMENT>[\$][^$]*[\$] {
|
||||||
strtok(yytext+1, "$");
|
strtok(yytext+1, "$");
|
||||||
yylval->string_val = new string(yytext + 1);
|
yylval->string_val = new string(yytext + 1);
|
||||||
|
|
|
@ -133,3 +133,48 @@ HistValStatement::writeOutput(ostream &output, const string &basename) const
|
||||||
output << ";" << endl;
|
output << ";" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HomotopyStatement::HomotopyStatement(const homotopy_values_type &homotopy_values_arg,
|
||||||
|
const SymbolTable &symbol_table_arg) :
|
||||||
|
homotopy_values(homotopy_values_arg),
|
||||||
|
symbol_table(symbol_table_arg)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
HomotopyStatement::writeOutput(ostream &output, const string &basename) const
|
||||||
|
{
|
||||||
|
output << interfaces::comment() << "\n" << interfaces::comment() << "HOMOTOPY_SETUP instructions\n"
|
||||||
|
<< interfaces::comment() << "\n";
|
||||||
|
output << "homotopy_param = {};" << endl;
|
||||||
|
output << "homotopy_exo = {};" << endl;
|
||||||
|
output << "homotopy_exodet = {};" << endl;
|
||||||
|
|
||||||
|
for(homotopy_values_type::const_iterator it = homotopy_values.begin();
|
||||||
|
it != homotopy_values.end(); it++)
|
||||||
|
{
|
||||||
|
const string &name = it->first;
|
||||||
|
const NodeID expression1 = it->second.first;
|
||||||
|
const NodeID expression2 = it->second.second;
|
||||||
|
|
||||||
|
Type type = symbol_table.getType(name);
|
||||||
|
|
||||||
|
if (type == eParameter)
|
||||||
|
output << "homotopy_param = vertcat(homotopy_param,{ '" << name << "', ";
|
||||||
|
else if (type == eExogenous)
|
||||||
|
output << "homotopy_exo = vertcat(homotopy_exo,{ '" << name << "', ";
|
||||||
|
else if (type != eExogenousDet)
|
||||||
|
output << "homotopy_exodet = vertcat(homotopy_exodet,{ '" << name << "', ";
|
||||||
|
|
||||||
|
|
||||||
|
expression1->writeOutput(output);
|
||||||
|
output << ", ";
|
||||||
|
expression2->writeOutput(output);
|
||||||
|
output << "});" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
output << "options_.homotopy_param = homotopy_param;" << endl;
|
||||||
|
output << "options_.homotopy_exo = homotopy_exo;" << endl;
|
||||||
|
output << "options_.homotopy_exodet = homotopy_exodet;" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -308,6 +308,26 @@ ParsingDriver::hist_val(string *name, string *lag, NodeID rhs)
|
||||||
delete lag;
|
delete lag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ParsingDriver::homotopy_val(string *name, NodeID val1, NodeID val2)
|
||||||
|
{
|
||||||
|
check_symbol_existence(*name);
|
||||||
|
Type type = mod_file->symbol_table.getType(*name);
|
||||||
|
|
||||||
|
if (type != eParameter
|
||||||
|
&& type != eExogenous
|
||||||
|
&& type != eExogenousDet)
|
||||||
|
error("homotopy_val: " + *name + " should be a parameter or exogenous variable");
|
||||||
|
|
||||||
|
if (homotopy_values.find(*name) != homotopy_values.end())
|
||||||
|
error("homotopy_val: " + *name +" declared twice");
|
||||||
|
|
||||||
|
pair<NodeID, NodeID> expressions(val1, val2);
|
||||||
|
homotopy_values[*name] = expressions;
|
||||||
|
|
||||||
|
delete name;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::use_dll()
|
ParsingDriver::use_dll()
|
||||||
{
|
{
|
||||||
|
@ -349,6 +369,13 @@ ParsingDriver::end_histval()
|
||||||
hist_values.clear();
|
hist_values.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ParsingDriver::end_homotopy()
|
||||||
|
{
|
||||||
|
mod_file->addStatement(new HomotopyStatement(homotopy_values, mod_file->symbol_table));
|
||||||
|
homotopy_values.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::begin_model()
|
ParsingDriver::begin_model()
|
||||||
{
|
{
|
||||||
|
|
|
@ -262,68 +262,71 @@ namespace yy
|
||||||
XLS_SHEET = 390,
|
XLS_SHEET = 390,
|
||||||
XLS_RANGE = 391,
|
XLS_RANGE = 391,
|
||||||
NORMCDF = 392,
|
NORMCDF = 392,
|
||||||
EXCLAMATION_EQUAL = 393,
|
HOMOTOPY_SETUP = 393,
|
||||||
EXCLAMATION = 394,
|
HOMOTOPY_MODE = 394,
|
||||||
EQUAL_EQUAL = 395,
|
HOMOTOPY_STEPS = 395,
|
||||||
GREATER_EQUAL = 396,
|
EXCLAMATION_EQUAL = 396,
|
||||||
LESS_EQUAL = 397,
|
EXCLAMATION = 397,
|
||||||
GREATER = 398,
|
EQUAL_EQUAL = 398,
|
||||||
LESS = 399,
|
GREATER_EQUAL = 399,
|
||||||
COMMA = 400,
|
LESS_EQUAL = 400,
|
||||||
MINUS = 401,
|
GREATER = 401,
|
||||||
PLUS = 402,
|
LESS = 402,
|
||||||
DIVIDE = 403,
|
COMMA = 403,
|
||||||
TIMES = 404,
|
MINUS = 404,
|
||||||
UMINUS = 405,
|
PLUS = 405,
|
||||||
POWER = 406,
|
DIVIDE = 406,
|
||||||
EXP = 407,
|
TIMES = 407,
|
||||||
LOG = 408,
|
UMINUS = 408,
|
||||||
LOG10 = 409,
|
POWER = 409,
|
||||||
SIN = 410,
|
EXP = 410,
|
||||||
COS = 411,
|
LOG = 411,
|
||||||
TAN = 412,
|
LOG10 = 412,
|
||||||
ASIN = 413,
|
SIN = 413,
|
||||||
ACOS = 414,
|
COS = 414,
|
||||||
ATAN = 415,
|
TAN = 415,
|
||||||
SINH = 416,
|
ASIN = 416,
|
||||||
COSH = 417,
|
ACOS = 417,
|
||||||
TANH = 418,
|
ATAN = 418,
|
||||||
ASINH = 419,
|
SINH = 419,
|
||||||
ACOSH = 420,
|
COSH = 420,
|
||||||
ATANH = 421,
|
TANH = 421,
|
||||||
SQRT = 422,
|
ASINH = 422,
|
||||||
DYNARE_SENSITIVITY = 423,
|
ACOSH = 423,
|
||||||
IDENTIFICATION = 424,
|
ATANH = 424,
|
||||||
MORRIS = 425,
|
SQRT = 425,
|
||||||
STAB = 426,
|
DYNARE_SENSITIVITY = 426,
|
||||||
REDFORM = 427,
|
IDENTIFICATION = 427,
|
||||||
PPRIOR = 428,
|
MORRIS = 428,
|
||||||
PRIOR_RANGE = 429,
|
STAB = 429,
|
||||||
PPOST = 430,
|
REDFORM = 430,
|
||||||
ILPTAU = 431,
|
PPRIOR = 431,
|
||||||
GLUE = 432,
|
PRIOR_RANGE = 432,
|
||||||
MORRIS_NLIV = 433,
|
PPOST = 433,
|
||||||
MORRIS_NTRA = 434,
|
ILPTAU = 434,
|
||||||
NSAM = 435,
|
GLUE = 435,
|
||||||
LOAD_REDFORM = 436,
|
MORRIS_NLIV = 436,
|
||||||
LOAD_RMSE = 437,
|
MORRIS_NTRA = 437,
|
||||||
LOAD_STAB = 438,
|
NSAM = 438,
|
||||||
ALPHA2_STAB = 439,
|
LOAD_REDFORM = 439,
|
||||||
KSSTAT = 440,
|
LOAD_RMSE = 440,
|
||||||
LOGTRANS_REDFORM = 441,
|
LOAD_STAB = 441,
|
||||||
THRESHOLD_REDFORM = 442,
|
ALPHA2_STAB = 442,
|
||||||
KSSTAT_REDFORM = 443,
|
KSSTAT = 443,
|
||||||
ALPHA2_REDFORM = 444,
|
LOGTRANS_REDFORM = 444,
|
||||||
NAMENDO = 445,
|
THRESHOLD_REDFORM = 445,
|
||||||
NAMLAGENDO = 446,
|
KSSTAT_REDFORM = 446,
|
||||||
NAMEXO = 447,
|
ALPHA2_REDFORM = 447,
|
||||||
RMSE = 448,
|
NAMENDO = 448,
|
||||||
LIK_ONLY = 449,
|
NAMLAGENDO = 449,
|
||||||
VAR_RMSE = 450,
|
NAMEXO = 450,
|
||||||
PFILT_RMSE = 451,
|
RMSE = 451,
|
||||||
ISTART_RMSE = 452,
|
LIK_ONLY = 452,
|
||||||
ALPHA_RMSE = 453,
|
VAR_RMSE = 453,
|
||||||
ALPHA2_RMSE = 454
|
PFILT_RMSE = 454,
|
||||||
|
ISTART_RMSE = 455,
|
||||||
|
ALPHA_RMSE = 456,
|
||||||
|
ALPHA2_RMSE = 457
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -73,4 +73,20 @@ public:
|
||||||
virtual void writeOutput(ostream &output, const string &basename) const;
|
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class HomotopyStatement : public Statement
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*!
|
||||||
|
Contrary to Initval and Endval, we use a map, since it is impossible to reuse
|
||||||
|
a given initialization value in a second initialization inside the block.
|
||||||
|
*/
|
||||||
|
typedef map<string,pair<NodeID,NodeID> > homotopy_values_type;
|
||||||
|
private:
|
||||||
|
const homotopy_values_type homotopy_values;
|
||||||
|
const SymbolTable &symbol_table;
|
||||||
|
public:
|
||||||
|
HomotopyStatement(const homotopy_values_type &homotopy_values_arg,
|
||||||
|
const SymbolTable &symbol_table_arg);
|
||||||
|
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -98,6 +98,8 @@ private:
|
||||||
InitOrEndValStatement::init_values_type init_values;
|
InitOrEndValStatement::init_values_type init_values;
|
||||||
//! Temporary storage for histval blocks
|
//! Temporary storage for histval blocks
|
||||||
HistValStatement::hist_values_type hist_values;
|
HistValStatement::hist_values_type hist_values;
|
||||||
|
//! Temporary storage for homotopy_setup blocks
|
||||||
|
HomotopyStatement::homotopy_values_type homotopy_values;
|
||||||
|
|
||||||
//! Temporary storage for argument list of unknown function
|
//! Temporary storage for argument list of unknown function
|
||||||
vector<NodeID> unknown_function_args;
|
vector<NodeID> unknown_function_args;
|
||||||
|
@ -195,12 +197,16 @@ public:
|
||||||
void init_val(string *name, NodeID rhs);
|
void init_val(string *name, NodeID rhs);
|
||||||
//! Writes an histval block
|
//! Writes an histval block
|
||||||
void hist_val(string *name, string *lag, NodeID rhs);
|
void hist_val(string *name, string *lag, NodeID rhs);
|
||||||
|
//! Writes an homotopy_setup block
|
||||||
|
void homotopy_val(string *name, NodeID val1, NodeID val2);
|
||||||
//! Writes end of an initval block
|
//! Writes end of an initval block
|
||||||
void end_initval();
|
void end_initval();
|
||||||
//! Writes end of an endval block
|
//! Writes end of an endval block
|
||||||
void end_endval();
|
void end_endval();
|
||||||
//! Writes end of an histval block
|
//! Writes end of an histval block
|
||||||
void end_histval();
|
void end_histval();
|
||||||
|
//! Writes end of an homotopy_setup block
|
||||||
|
void end_homotopy();
|
||||||
//! Begin a model block
|
//! Begin a model block
|
||||||
void begin_model();
|
void begin_model();
|
||||||
//! Writes a shocks statement
|
//! Writes a shocks statement
|
||||||
|
|
Loading…
Reference in New Issue