Add min(,) max(,) and dummy() functions to dynare... Buggy until tomorrow ;-)

git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1417 ac1d8469-bf42-47a9-8791-bf33cf982152
time-shift
adjemian 2007-10-05 19:47:27 +00:00
parent aa9b217788
commit 163c5b4146
12 changed files with 2271 additions and 2049 deletions

View File

@ -319,6 +319,24 @@ DataTree::AddSqRt(NodeID iArg1)
return Zero; return Zero;
} }
NodeID
DataTree::AddMaX(NodeID iArg1, NodeID iArg2)
{
return AddBinaryOp(iArg1, oMax, iArg2);
}
NodeID
DataTree::AddMin(NodeID iArg1, NodeID iArg2)
{
return AddBinaryOp(iArg1, oMin, iArg2);
}
NodeID
DataTree::AddDuMmY(NodeID iArg1)
{
return AddUnaryOp(oDummy,iArg1);
}
NodeID NodeID
DataTree::AddEqual(NodeID iArg1, NodeID iArg2) DataTree::AddEqual(NodeID iArg1, NodeID iArg2)
{ {

File diff suppressed because it is too large Load Diff

View File

@ -40,7 +40,7 @@ class ParsingDriver;
%token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN %token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN
%token BVAR_REPLIC %token BVAR_REPLIC
%token CALIB CALIB_VAR CHECK CONF_SIG CONSTANT CORR COVAR CUTOFF %token CALIB CALIB_VAR CHECK CONF_SIG CONSTANT CORR COVAR CUTOFF
%token DATAFILE DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE %token DATAFILE DR_ALGO DROP DSAMPLE DUMMY DYNASAVE DYNATYPE
%token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT %token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT
%token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS %token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS
%token <string_val> FLOAT_NUMBER %token <string_val> FLOAT_NUMBER
@ -51,8 +51,8 @@ class ParsingDriver;
%token <string_val> INT_NUMBER %token <string_val> INT_NUMBER
%token INV_GAMMA_PDF IRF %token INV_GAMMA_PDF IRF
%token KALMAN_ALGO KALMAN_TOL %token KALMAN_ALGO KALMAN_TOL
%token LAPLACE LCC_COMPILER LIK_ALGO LIK_INIT LINEAR LOAD_MH_FILE LOGLINEAR MARKOWITZ %token LAPLACE LCC_COMPILER LIK_ALGO LIK_INIT LINEAR LOAD_MH_FILE LOGLINEAR MARKOWITZ MAX
%token MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER %token MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER MIN
%token MODE_CHECK MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MSHOCKS %token MODE_CHECK MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MSHOCKS
%token MODEL_COMPARISON_APPROXIMATION MODIFIEDHARMONICMEAN MOMENTS_VARENDO %token MODEL_COMPARISON_APPROXIMATION MODIFIEDHARMONICMEAN MOMENTS_VARENDO
%token <string_val> NAME %token <string_val> NAME
@ -281,14 +281,20 @@ expression : '(' expression ')'
{ $$ = driver.add_atan($3); } { $$ = driver.add_atan($3); }
| SQRT '(' expression ')' | SQRT '(' expression ')'
{ $$ = driver.add_sqrt($3); } { $$ = driver.add_sqrt($3); }
| DUMMY '(' expression ')'
{ $$ = driver.add_dummy($3); }
| MAX '(' expression COMMA expression ')'
{ $$ = driver.add_max($3 , $5); }
| MIN '(' expression COMMA expression ')'
{ $$ = driver.add_min($3 , $5); }
| NAME '(' comma_expression ')' | NAME '(' comma_expression ')'
{ $$ = driver.add_unknown_function($1); } { $$ = driver.add_unknown_function($1); }
; ;
comma_expression : expression comma_expression : expression
{ driver.add_unknown_function_arg($1); } { driver.add_unknown_function_arg($1); }
| comma_expression COMMA expression /* | comma_expression COMMA expression
{ driver.add_unknown_function_arg($3); } { driver.add_unknown_function_arg($3); }*/
; ;
initval : INITVAL ';' initval_list END initval : INITVAL ';' initval_list END
@ -395,6 +401,12 @@ hand_side : '(' hand_side ')'
{ $$ = driver.add_atan($3); } { $$ = driver.add_atan($3); }
| SQRT '(' hand_side ')' | SQRT '(' hand_side ')'
{ $$ = driver.add_sqrt($3); } { $$ = driver.add_sqrt($3); }
| DUMMY '(' expression ')'
{ $$ = driver.add_dummy($3); }
| MAX '(' expression COMMA expression ')'
{ $$ = driver.add_max($3 , $5); }
| MIN '(' expression COMMA expression ')'
{ $$ = driver.add_min($3 , $5); }
; ;
pound_expression: '#' NAME EQUAL hand_side ';' pound_expression: '#' NAME EQUAL hand_side ';'

View File

@ -260,7 +260,10 @@ int sigma_e = 0;
<DYNARE_STATEMENT,DYNARE_BLOCK>asinh {return token::ASINH;} <DYNARE_STATEMENT,DYNARE_BLOCK>asinh {return token::ASINH;}
<DYNARE_STATEMENT,DYNARE_BLOCK>acosh {return token::ACOSH;} <DYNARE_STATEMENT,DYNARE_BLOCK>acosh {return token::ACOSH;}
<DYNARE_STATEMENT,DYNARE_BLOCK>atanh {return token::ATANH;} <DYNARE_STATEMENT,DYNARE_BLOCK>atanh {return token::ATANH;}
<DYNARE_STATEMENT,DYNARE_BLOCK>sqrt {return token::SQRT;} <DYNARE_STATEMENT,DYNARE_BLOCK>sqrt {return token::SQRT;}
<DYNARE_STATEMENT,DYNARE_BLOCK>max {return token::MAX;}
<DYNARE_STATEMENT,DYNARE_BLOCK>min {return token::MIN;}
<DYNARE_STATEMENT,DYNARE_BLOCK>dummy {return token::DUMMY;}
/* options for GSA module by Marco Ratto */ /* options for GSA module by Marco Ratto */
<DYNARE_STATEMENT>identification {return token::IDENTIFICATION;} <DYNARE_STATEMENT>identification {return token::IDENTIFICATION;}

View File

@ -521,6 +521,8 @@ UnaryOpNode::computeDerivative(int varID)
case oSqrt: case oSqrt:
t11 = datatree.AddPlus(this, this); t11 = datatree.AddPlus(this, this);
return datatree.AddDivide(darg, t11); return datatree.AddDivide(darg, t11);
case oDummy:
return datatree.Zero;
} }
cerr << "Impossible case!" << endl; cerr << "Impossible case!" << endl;
exit(-1); exit(-1);
@ -572,6 +574,8 @@ UnaryOpNode::cost(const temporary_terms_type &temporary_terms, bool is_matlab) c
return cost + 350; return cost + 350;
case oSqrt: case oSqrt:
return cost + 570; return cost + 570;
case oDummy:
return cost + 200;
} }
else else
// Cost for C files // Cost for C files
@ -606,6 +610,8 @@ UnaryOpNode::cost(const temporary_terms_type &temporary_terms, bool is_matlab) c
return cost + 150; return cost + 150;
case oSqrt: case oSqrt:
return cost + 90; return cost + 90;
case oDummy:
return cost + 50;
} }
cerr << "Impossible case!" << endl; cerr << "Impossible case!" << endl;
exit(-1); exit(-1);
@ -674,10 +680,23 @@ UnaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
return; return;
} }
if (op_code == oDummy)
{
if (OFFSET(output_type))
output << "double";
output << "(";
arg->writeOutput(output, output_type, temporary_terms);
output << ">0)";
return;
}
// Always put parenthesis around uminus nodes // Always put parenthesis around uminus nodes
if (op_code == oUminus) if (op_code == oUminus)
output << "("; output << "(";
switch(op_code) switch(op_code)
{ {
case oUminus: case oUminus:
@ -797,6 +816,8 @@ UnaryOpNode::eval_opcode(UnaryOpcode op_code, double v) throw (EvalException)
return(atanh(v)); return(atanh(v));
case oSqrt: case oSqrt:
return(sqrt(v)); return(sqrt(v));
case oDummy:
return(double (v>0));
} }
// Impossible // Impossible
throw EvalException(); throw EvalException();
@ -899,8 +920,22 @@ BinaryOpNode::computeDerivative(int varID)
t15 = datatree.AddPlus(t12, t14); t15 = datatree.AddPlus(t12, t14);
return datatree.AddTimes(t15, this); return datatree.AddTimes(t15, this);
} }
case oMax:
t11 = datatree.AddMinus(arg1,arg2);
t12 = datatree.AddDuMmY(t11);
t13 = datatree.AddTimes(t12,darg1);
t14 = datatree.AddMinus(datatree.One,t12);
t15 = datatree.AddTimes(t14,darg2);
return datatree.AddPlus(t15,t13);
case oMin:
t11 = datatree.AddMinus(arg2,arg1);
t12 = datatree.AddDuMmY(t11);
t13 = datatree.AddTimes(t12,darg1);
t14 = datatree.AddMinus(datatree.One,t12);
t15 = datatree.AddTimes(t14,darg2);
return datatree.AddPlus(t15,t13);
case oEqual: case oEqual:
return datatree.AddMinus(darg1, darg2); return datatree.AddMinus(darg1, darg2);
} }
cerr << "Impossible case!" << endl; cerr << "Impossible case!" << endl;
exit(-1); exit(-1);
@ -919,6 +954,8 @@ BinaryOpNode::precedence(ExprNodeOutputType output_type, const temporary_terms_t
case oEqual: case oEqual:
case oPlus: case oPlus:
case oMinus: case oMinus:
case oMax:
case oMin:
return 0; return 0;
case oTimes: case oTimes:
case oDivide: case oDivide:
@ -928,7 +965,7 @@ BinaryOpNode::precedence(ExprNodeOutputType output_type, const temporary_terms_t
// In C, power operator is of the form pow(a, b) // In C, power operator is of the form pow(a, b)
return 100; return 100;
else else
return 3; return 3;
} }
cerr << "Impossible case!" << endl; cerr << "Impossible case!" << endl;
exit(-1); exit(-1);
@ -953,6 +990,9 @@ BinaryOpNode::cost(const temporary_terms_type &temporary_terms, bool is_matlab)
case oMinus: case oMinus:
case oTimes: case oTimes:
return cost + 90; return cost + 90;
case oMax:
case oMin:
return cost + 110;
case oDivide: case oDivide:
return cost + 990; return cost + 990;
case oPower: case oPower:
@ -968,6 +1008,9 @@ BinaryOpNode::cost(const temporary_terms_type &temporary_terms, bool is_matlab)
case oMinus: case oMinus:
case oTimes: case oTimes:
return cost + 4; return cost + 4;
case oMax:
case oMin:
return cost + 5;
case oDivide: case oDivide:
return cost + 15; return cost + 15;
case oPower: case oPower:
@ -1047,6 +1090,16 @@ BinaryOpNode::eval_opcode(double v1, BinaryOpcode op_code, double v2) throw (Eva
return(v1 / v2); return(v1 / v2);
case oPower: case oPower:
return(pow(v1, v2)); return(pow(v1, v2));
case oMax:
if(v1<v2)
return( v2);
else
return( v1);
case oMin:
if(v1>v2)
return( v2);
else
return( v1);
case oEqual: case oEqual:
default: default:
throw EvalException(); throw EvalException();
@ -1099,9 +1152,20 @@ BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
} }
// Treat special case of power operator in C // Treat special case of power operator in C
if (op_code == oPower && (!OFFSET(output_type))) if ((op_code == oPower && !OFFSET(output_type)) || op_code == oMax || op_code == oMin )
{ {
output << "pow("; switch (op_code)
{
case oPower:
output << "pow(";
break;
case oMax:
output << "max(";
break;
case oMin:
output << "min(";
break;
}
arg1->writeOutput(output, output_type, temporary_terms); arg1->writeOutput(output, output_type, temporary_terms);
output << ","; output << ",";
arg2->writeOutput(output, output_type, temporary_terms); arg2->writeOutput(output, output_type, temporary_terms);

View File

@ -1149,6 +1149,24 @@ ParsingDriver::add_sqrt(NodeID arg1)
return data_tree->AddSqRt(arg1); return data_tree->AddSqRt(arg1);
} }
NodeID
ParsingDriver::add_max(NodeID arg1, NodeID arg2)
{
return data_tree->AddMaX(arg1,arg2);
}
NodeID
ParsingDriver::add_min(NodeID arg1, NodeID arg2)
{
return data_tree->AddMin(arg1,arg2);
}
NodeID
ParsingDriver::add_dummy(NodeID arg1)
{
return data_tree->AddDuMmY(arg1);
}
void void
ParsingDriver::add_unknown_function_arg(NodeID arg) ParsingDriver::add_unknown_function_arg(NodeID arg)
{ {

View File

@ -109,6 +109,12 @@ public:
NodeID AddATanH(NodeID iArg1); NodeID AddATanH(NodeID iArg1);
//! Adds "sqrt(arg)" to model tree //! Adds "sqrt(arg)" to model tree
NodeID AddSqRt(NodeID iArg1); NodeID AddSqRt(NodeID iArg1);
//! Adds "max(arg1,arg2)" to model tree
NodeID AddMaX(NodeID iArg1, NodeID iArg2);
//! Adds "min(arg1,arg2)" to model tree
NodeID AddMin(NodeID iArg1, NodeID iArg2);
//! Adds "dummy(arg1)" to model tree
NodeID AddDuMmY(NodeID iArg1);
//! Adds "arg1=arg2" to model tree //! Adds "arg1=arg2" to model tree
NodeID AddEqual(NodeID iArg1, NodeID iArg2); NodeID AddEqual(NodeID iArg1, NodeID iArg2);
void AddLocalParameter(const string &name, NodeID value) throw (LocalParameterException); void AddLocalParameter(const string &name, NodeID value) throw (LocalParameterException);

View File

@ -153,167 +153,170 @@ namespace yy
DR_ALGO = 281, DR_ALGO = 281,
DROP = 282, DROP = 282,
DSAMPLE = 283, DSAMPLE = 283,
DYNASAVE = 284, DUMMY = 284,
DYNATYPE = 285, DYNASAVE = 285,
END = 286, DYNATYPE = 286,
ENDVAL = 287, END = 287,
EQUAL = 288, ENDVAL = 288,
ESTIMATION = 289, EQUAL = 289,
ESTIMATED_PARAMS = 290, ESTIMATION = 290,
ESTIMATED_PARAMS_BOUNDS = 291, ESTIMATED_PARAMS = 291,
ESTIMATED_PARAMS_INIT = 292, ESTIMATED_PARAMS_BOUNDS = 292,
FILENAME = 293, ESTIMATED_PARAMS_INIT = 293,
FILTER_STEP_AHEAD = 294, FILENAME = 294,
FILTERED_VARS = 295, FILTER_STEP_AHEAD = 295,
FIRST_OBS = 296, FILTERED_VARS = 296,
FLOAT_NUMBER = 297, FIRST_OBS = 297,
FORECAST = 298, FLOAT_NUMBER = 298,
GAMMA_PDF = 299, FORECAST = 299,
GCC_COMPILER = 300, GAMMA_PDF = 300,
GRAPH = 301, GCC_COMPILER = 301,
HISTVAL = 302, GRAPH = 302,
HP_FILTER = 303, HISTVAL = 303,
HP_NGRID = 304, HP_FILTER = 304,
INITVAL = 305, HP_NGRID = 305,
INT_NUMBER = 306, INITVAL = 306,
INV_GAMMA_PDF = 307, INT_NUMBER = 307,
IRF = 308, INV_GAMMA_PDF = 308,
KALMAN_ALGO = 309, IRF = 309,
KALMAN_TOL = 310, KALMAN_ALGO = 310,
LAPLACE = 311, KALMAN_TOL = 311,
LCC_COMPILER = 312, LAPLACE = 312,
LIK_ALGO = 313, LCC_COMPILER = 313,
LIK_INIT = 314, LIK_ALGO = 314,
LINEAR = 315, LIK_INIT = 315,
LOAD_MH_FILE = 316, LINEAR = 316,
LOGLINEAR = 317, LOAD_MH_FILE = 317,
MARKOWITZ = 318, LOGLINEAR = 318,
MH_DROP = 319, MARKOWITZ = 319,
MH_INIT_SCALE = 320, MAX = 320,
MH_JSCALE = 321, MH_DROP = 321,
MH_MODE = 322, MH_INIT_SCALE = 322,
MH_NBLOCKS = 323, MH_JSCALE = 323,
MH_REPLIC = 324, MH_MODE = 324,
MH_RECOVER = 325, MH_NBLOCKS = 325,
MODE_CHECK = 326, MH_REPLIC = 326,
MODE_COMPUTE = 327, MH_RECOVER = 327,
MODE_FILE = 328, MIN = 328,
MODEL = 329, MODE_CHECK = 329,
MODEL_COMPARISON = 330, MODE_COMPUTE = 330,
MSHOCKS = 331, MODE_FILE = 331,
MODEL_COMPARISON_APPROXIMATION = 332, MODEL = 332,
MODIFIEDHARMONICMEAN = 333, MODEL_COMPARISON = 333,
MOMENTS_VARENDO = 334, MSHOCKS = 334,
NAME = 335, MODEL_COMPARISON_APPROXIMATION = 335,
NO_COMPILER = 336, MODIFIEDHARMONICMEAN = 336,
NOBS = 337, MOMENTS_VARENDO = 337,
NOCONSTANT = 338, NAME = 338,
NOCORR = 339, NO_COMPILER = 339,
NODIAGNOSTIC = 340, NOBS = 340,
NOFUNCTIONS = 341, NOCONSTANT = 341,
NOGRAPH = 342, NOCORR = 342,
NOMOMENTS = 343, NODIAGNOSTIC = 343,
NOPRINT = 344, NOFUNCTIONS = 344,
NORMAL_PDF = 345, NOGRAPH = 345,
OBSERVATION_TRENDS = 346, NOMOMENTS = 346,
OPTIM = 347, NOPRINT = 347,
OPTIM_WEIGHTS = 348, NORMAL_PDF = 348,
ORDER = 349, OBSERVATION_TRENDS = 349,
OSR = 350, OPTIM = 350,
OSR_PARAMS = 351, OPTIM_WEIGHTS = 351,
PARAMETERS = 352, ORDER = 352,
PERIODS = 353, OSR = 353,
PLANNER_OBJECTIVE = 354, OSR_PARAMS = 354,
PREFILTER = 355, PARAMETERS = 355,
PRESAMPLE = 356, PERIODS = 356,
PRINT = 357, PLANNER_OBJECTIVE = 357,
PRIOR_TRUNC = 358, PREFILTER = 358,
PRIOR_ANALYSIS = 359, PRESAMPLE = 359,
POSTERIOR_ANALYSIS = 360, PRINT = 360,
QZ_CRITERIUM = 361, PRIOR_TRUNC = 361,
RELATIVE_IRF = 362, PRIOR_ANALYSIS = 362,
REPLIC = 363, POSTERIOR_ANALYSIS = 363,
RPLOT = 364, QZ_CRITERIUM = 364,
SHOCKS = 365, RELATIVE_IRF = 365,
SIGMA_E = 366, REPLIC = 366,
SIMUL = 367, RPLOT = 367,
SIMUL_ALGO = 368, SHOCKS = 368,
SIMUL_SEED = 369, SIGMA_E = 369,
SMOOTHER = 370, SIMUL = 370,
SOLVE_ALGO = 371, SIMUL_ALGO = 371,
SPARSE_DLL = 372, SIMUL_SEED = 372,
STDERR = 373, SMOOTHER = 373,
STEADY = 374, SOLVE_ALGO = 374,
STOCH_SIMUL = 375, SPARSE_DLL = 375,
TEX = 376, STDERR = 376,
RAMSEY_POLICY = 377, STEADY = 377,
PLANNER_DISCOUNT = 378, STOCH_SIMUL = 378,
TEX_NAME = 379, TEX = 379,
UNIFORM_PDF = 380, RAMSEY_POLICY = 380,
UNIT_ROOT_VARS = 381, PLANNER_DISCOUNT = 381,
USE_DLL = 382, TEX_NAME = 382,
VALUES = 383, UNIFORM_PDF = 383,
VAR = 384, UNIT_ROOT_VARS = 384,
VAREXO = 385, USE_DLL = 385,
VAREXO_DET = 386, VALUES = 386,
VAROBS = 387, VAR = 387,
XLS_SHEET = 388, VAREXO = 388,
XLS_RANGE = 389, VAREXO_DET = 389,
COMMA = 390, VAROBS = 390,
MINUS = 391, XLS_SHEET = 391,
PLUS = 392, XLS_RANGE = 392,
DIVIDE = 393, COMMA = 393,
TIMES = 394, MINUS = 394,
UMINUS = 395, PLUS = 395,
POWER = 396, DIVIDE = 396,
EXP = 397, TIMES = 397,
LOG = 398, UMINUS = 398,
LOG10 = 399, POWER = 399,
SIN = 400, EXP = 400,
COS = 401, LOG = 401,
TAN = 402, LOG10 = 402,
ASIN = 403, SIN = 403,
ACOS = 404, COS = 404,
ATAN = 405, TAN = 405,
SINH = 406, ASIN = 406,
COSH = 407, ACOS = 407,
TANH = 408, ATAN = 408,
ASINH = 409, SINH = 409,
ACOSH = 410, COSH = 410,
ATANH = 411, TANH = 411,
SQRT = 412, ASINH = 412,
DYNARE_SENSITIVITY = 413, ACOSH = 413,
IDENTIFICATION = 414, ATANH = 414,
MORRIS = 415, SQRT = 415,
STAB = 416, DYNARE_SENSITIVITY = 416,
REDFORM = 417, IDENTIFICATION = 417,
PPRIOR = 418, MORRIS = 418,
PRIOR_RANGE = 419, STAB = 419,
PPOST = 420, REDFORM = 420,
ILPTAU = 421, PPRIOR = 421,
GLUE = 422, PRIOR_RANGE = 422,
MORRIS_NLIV = 423, PPOST = 423,
MORRIS_NTRA = 424, ILPTAU = 424,
NSAM = 425, GLUE = 425,
LOAD_REDFORM = 426, MORRIS_NLIV = 426,
LOAD_RMSE = 427, MORRIS_NTRA = 427,
LOAD_STAB = 428, NSAM = 428,
ALPHA2_STAB = 429, LOAD_REDFORM = 429,
KSSTAT = 430, LOAD_RMSE = 430,
LOGTRANS_REDFORM = 431, LOAD_STAB = 431,
THRESHOLD_REDFORM = 432, ALPHA2_STAB = 432,
KSSTAT_REDFORM = 433, KSSTAT = 433,
ALPHA2_REDFORM = 434, LOGTRANS_REDFORM = 434,
NAMENDO = 435, THRESHOLD_REDFORM = 435,
NAMLAGENDO = 436, KSSTAT_REDFORM = 436,
NAMEXO = 437, ALPHA2_REDFORM = 437,
RMSE = 438, NAMENDO = 438,
LIK_ONLY = 439, NAMLAGENDO = 439,
VAR_RMSE = 440, NAMEXO = 440,
PFILT_RMSE = 441, RMSE = 441,
ISTART_RMSE = 442, LIK_ONLY = 442,
ALPHA_RMSE = 443, VAR_RMSE = 443,
ALPHA2_RMSE = 444 PFILT_RMSE = 444,
ISTART_RMSE = 445,
ALPHA_RMSE = 446,
ALPHA2_RMSE = 447
}; };
}; };

View File

@ -207,7 +207,8 @@ enum UnaryOpcode
oAcosh, oAcosh,
oAsinh, oAsinh,
oAtanh, oAtanh,
oSqrt oSqrt,
oDummy
}; };
//! Unary operator node //! Unary operator node
@ -245,7 +246,9 @@ enum BinaryOpcode
oTimes, oTimes,
oDivide, oDivide,
oPower, oPower,
oEqual oEqual,
oMax,
oMin
}; };
//! Binary operator node //! Binary operator node

View File

@ -354,6 +354,12 @@ public:
NodeID add_atanh(NodeID arg1); NodeID add_atanh(NodeID arg1);
//! Writes token "sqrt(arg1)" to model tree //! Writes token "sqrt(arg1)" to model tree
NodeID add_sqrt(NodeID arg1); NodeID add_sqrt(NodeID arg1);
//! Writes token "max(arg1,arg2)" to model tree
NodeID add_max(NodeID arg1, NodeID arg2);
//! Writes token "min(arg1,arg2)" to model tree
NodeID add_min(NodeID arg1, NodeID arg2);
//! Writes token "dummy(arg1)" to model tree
NodeID add_dummy(NodeID arg1);
//! Adds an unknwon function argument //! Adds an unknwon function argument
void add_unknown_function_arg(NodeID arg); void add_unknown_function_arg(NodeID arg);
//! Adds an unknown function call node //! Adds an unknown function call node

View File

@ -1,11 +1,30 @@
#ifndef SIMULATE_HH_INCLUDED #ifndef SIMULATE_HH_INCLUDED
#define SIMULATE_HH_INCLUDED #define SIMULATE_HH_INCLUDED
typedef struct IM_compact #include <math>
{ #include <stack>
int size, u_init, u_finish, nb_endo; #include <set>
int *u, *Var, *Equ, *Var_Index, *Equ_Index, *Var_dyn_Index; #include <vector>
}; #include <math.h>
#include <iostream>
#include <fstream>
//#include "pctimer_h.hh"
#include <time.h>
#include <string>
#include <map>
#include <algorithm>
#include "CodeInterpreter.hh"
#include "SymbolTableTypes.hh"
#include "mex.h"
#include "ExprNode.hh"
#define pow_ pow
//#define pow pow1
// typedef struct IM_compact
// {
// int size, u_init, u_finish, nb_endo;
// int *u, *Var, *Equ, *Var_Index, *Equ_Index, *Var_dyn_Index;
// };
typedef struct Variable_l typedef struct Variable_l
{ {
int* Index; int* Index;
@ -47,22 +66,7 @@ typedef long double longd;
#else #else
typedef double longd; typedef double longd;
#endif #endif
#include <stack>
#include <set>
#include <vector>
#include <math.h>
#include <iostream>
#include <fstream>
//#include "pctimer_h.hh"
#include <time.h>
#include <string>
#include <map>
#include <algorithm>
#include "CodeInterpreter.hh"
#include "SymbolTableTypes.hh"
#include "mex.h"
#define pow_ pow
//#define pow pow1
using namespace std; using namespace std;
@ -217,11 +221,11 @@ class Interpreter
longd *g1, *r; longd *g1, *r;
bool GaussSeidel; bool GaussSeidel;
public : public :
Interpreter::Interpreter(); Interpreter();
void compute_blocks(string file_name, string bin_basename); void compute_blocks(string file_name, string bin_basename);
}; };
std::fstream SaveCode, SaveCode_swp; std::fstream SaveCode, SaveCode_swp;
#endif // SIMULATE_HH_INCLUDED #endif // SIMULATE_HH_INCLUDED

View File

@ -3997,6 +3997,18 @@ Interpreter::compute_block_time() /*throw(EvalException)*/
Stack.push(pow1(v1, v2)); Stack.push(pow1(v1, v2));
#ifdef DEBUGC #ifdef DEBUGC
mexPrintf("pow(%f, %f)\n",v1,v2); mexPrintf("pow(%f, %f)\n",v1,v2);
#endif
break;
case oMax:
Stack.push(max(v1, v2));
#ifdef DEBUGC
mexPrintf("max(%f, %f)\n",v1,v2);
#endif
break;
case oMin:
Stack.push(min(v1, v2));
#ifdef DEBUGC
mexPrintf("min(%f, %f)\n",v1,v2);
#endif #endif
break; break;
case oEqual: case oEqual:
@ -4114,6 +4126,12 @@ Interpreter::compute_block_time() /*throw(EvalException)*/
Stack.push(sqrt(v1)); Stack.push(sqrt(v1));
#ifdef DEBUGC #ifdef DEBUGC
mexPrintf("sqrt\n"); mexPrintf("sqrt\n");
#endif
break;
case oDummy:
Stack.push(double (v1>0));
#ifdef DEBUGC
mexPrintf("dummy\n");
#endif #endif
break; break;
default: default:
@ -4179,6 +4197,7 @@ Interpreter::simulate_a_block(int size,int type, string file_name, string bin_ba
int Block_List_Max_Lag; int Block_List_Max_Lag;
int Block_List_Max_Lead; int Block_List_Max_Lead;
int giter; int giter;
int u_count_int;
double *y_save; double *y_save;
GaussSeidel=false; GaussSeidel=false;
@ -4483,7 +4502,7 @@ Interpreter::simulate_a_block(int size,int type, string file_name, string bin_ba
mxFree(r); mxFree(r);
mxFree(u); mxFree(u);
break; break;
case SOLVE_TWO_BOUNDARIES_COMPLETE : case SOLVE_TWO_BOUNDARIES_COMPLETE:
#ifdef DEBUGC #ifdef DEBUGC
mexPrintf("SOLVE_TWO_BOUNDARIES_COMPLETE\n"); mexPrintf("SOLVE_TWO_BOUNDARIES_COMPLETE\n");
#endif #endif
@ -4507,7 +4526,7 @@ Interpreter::simulate_a_block(int size,int type, string file_name, string bin_ba
#ifdef DEBUGC #ifdef DEBUGC
mexPrintf("Block_List_Max_Lead=%d\n",Block_List_Max_Lead); mexPrintf("Block_List_Max_Lead=%d\n",Block_List_Max_Lead);
#endif #endif
int u_count_int=get_code_int u_count_int=get_code_int
#ifdef DEBUGC #ifdef DEBUGC
mexPrintf("u_count_int=%d\n",u_count_int); mexPrintf("u_count_int=%d\n",u_count_int);
mexPrintf("periods=%d\n",periods); mexPrintf("periods=%d\n",periods);