14 userexpr =
'UserExpression' 15 userdraws =
'UserDraws' 19 mcunifdraws =
'MCUnifDraw' 22 uniformSym =
'U[-1,1]' 23 absOp, negOp =
'abs',
'minus' 24 exp, log =
'exp',
'log' 25 bioNormalCdf =
'bioNormalCdf' 26 add, sub, mul, div, power =
'+',
'-',
'*',
'/',
'**' 27 andOp, orOp, equal, notEqual =
'and',
'or',
'==',
'<>' 28 greater, greaterEq, less, lessEq =
'>',
'>=',
'<',
'<=' 29 minOp, maxOp, mod =
'min',
'max',
'mod' 30 sumOp, prodOp, integralOp, derivativeOp =
'sum',
'prod',
'integral',
'derivative' 31 monteCarloOp =
'MonteCarlo' 32 monteCarloCVOp =
'MonteCarloControlVariate' 33 elemOp, enumOp, logitOp, loglogitOp, multSumOp, multProdOp, bioNormalPdf =
'elem',
'enumerate',
'logit',
'loglogit',
'multSum',
'multProd',
'bioNormalPdf' 35 bayesMeanOp =
'bioBayesNormalDraw' 45 MIN_ITERATOROP_INDEX = 70
46 MAX_ITERATOROP_INDEX = 89
52 operatorIndexDic = {num:0, \
64 exp:30, log:31, bioNormalCdf: 33, monteCarloOp: 34,\
65 add:40, sub:41, mul:42, div:43, power:44, \
66 andOp:45, orOp:46, equal:47, notEqual:48, \
67 greater:49, greaterEq:50, less:51, lessEq:52, \
68 minOp:53, maxOp:54, mod:55, \
69 sumOp:70, prodOp:71, \
70 elemOp:90, enumOp:91, integralOp:92, derivativeOp:93, \
71 defineOp:94, logitOp:95, bioNormalPdf:96, multSumOp:97, multProdOp:98, mhOp:99, bayesMeanOp:100,monteCarloCVOp: 101,loglogitOp:102 }
74 def getOpIndex(self,op):
75 return Operator.operatorIndexDic[op];
83 def buildExpressionObj(exp):
87 return isinstance(obj,int)
or isinstance(obj,float)
103 raise NotImplementedError(
"getExpression must be implemented! ")
117 return UnOp(Operator.negOp, self)
123 return BinOp(Operator.add, self, buildExpressionObj(expression))
129 return BinOp(Operator.add, buildExpressionObj(expression), self)
135 return BinOp(Operator.sub, self, buildExpressionObj(expression))
141 return BinOp(Operator.sub, buildExpressionObj(expression), self)
147 return BinOp(Operator.mul, self, buildExpressionObj(expression))
153 return BinOp(Operator.mul, buildExpressionObj(expression), self)
159 return BinOp(Operator.div, self, buildExpressionObj(expression))
165 return BinOp(Operator.div, buildExpressionObj(expression), self)
172 return BinOp(Operator.div, self, buildExpressionObj(expression))
179 return BinOp(Operator.div, buildExpressionObj(expression), self)
185 return BinOp(Operator.modOp, self, buildExpressionObj(expression))
191 return BinOp(Operator.power, self, buildExpressionObj(expression))
197 return BinOp(Operator.power, buildExpressionObj(expression), self)
203 return BinOp(Operator.andOp, self, buildExpressionObj(expression))
209 return BinOp(Operator.orOp, self, buildExpressionObj(expression))
215 return BinOp(Operator.equal, self, buildExpressionObj(expression))
221 return BinOp(Operator.notEqual, self, buildExpressionObj(expression))
227 return BinOp(Operator.lessEq, self, buildExpressionObj(expression))
233 return BinOp(Operator.greaterEq, self, buildExpressionObj(expression))
239 return BinOp(Operator.less, self, buildExpressionObj(expression))
245 return BinOp(Operator.greater, self, buildExpressionObj(expression))
256 def getExpression(self):
257 return "(" + str(self.
number) +
")" 277 def getExpression(self):
278 return str(self.
name)
299 def getExpression(self):
300 return str(self.
name)
322 self.
expression = buildExpressionObj(expression)
323 self.
operatorIndex = Operator.operatorIndexDic[Operator.userexpr]
325 def getExpression(self):
326 return self.
name + self.expression.getExpression()
338 self.
expression = buildExpressionObj(expression)
340 self.
operatorIndex = Operator.operatorIndexDic[Operator.userdraws]
342 def getExpression(self):
343 return self.
name + self.expression.getExpression()
366 def __init__(self,name,value,lowerbound,upperbound,status,desc=''):
373 self.
operatorIndex = Operator.operatorIndexDic[Operator.param]
375 def getExpression(self):
377 return self.
name +
" " + str(self.
val) +
" " + str(self.
lb) + \
378 " " + str(self.
ub) +
" " + str(self.
st) +
" " + self.
desc 393 print(
"**** DRAWS", name,
" ",Operator.mcdraws)
395 self.
operatorIndex = Operator.operatorIndexDic[Operator.mcdraws]
397 def getExpression(self):
398 return str(self.
name)
412 print(
"**** RECYCLED DRAWS", name,
" ",Operator.mcunifdraws)
414 self.
operatorIndex = Operator.operatorIndexDic[Operator.mcunifdraws]
415 print(
"Id: ", self.
getID())
417 def getExpression(self):
418 return "Unif("+str(self.
name)+
")" 444 msg =
'Deprecated syntax: bioNormalDraws(\''+name+
'\'). Use bioDraws(\''+name+
'\') and BIOGEME_OBJECT.DRAWS = { \''+name+
'\': \'NORMAL\' }' 446 raise SyntaxError(msg)
469 msg =
'Deprecated syntax: bioUniformSymmetricDraws(\''+name+
'\'). Use bioDraws(\''+name+
'\') and BIOGEME_OBJECT.DRAWS = { \''+name+
'\': \'UNIFORMSYM\' }' 471 raise SyntaxError(msg)
494 msg =
'Deprecated syntax: bioUniformDraws(\''+name+
'\'). Use bioDraws(\''+name+
'\') and BIOGEME_OBJECT.DRAWS = { \''+name+
'\': \'UNIFORM\' }' 496 raise SyntaxError(msg)
503 self.
expression = buildExpressionObj(expression)
506 def getExpression(self):
507 return self.
op +
"(" + self.expression.getExpression() +
")" 522 self.
expression = buildExpressionObj(expression)
523 self.
operatorIndex = Operator.operatorIndexDic[Operator.absOp]
525 def getExpression(self):
526 return Operator.absOp +
"(" + self.expression.getExpression() +
")" 539 self.
expression = buildExpressionObj(expression)
542 def getExpression(self):
543 return Operator.exp +
"(" + self.expression.getExpression() +
")" 555 self.
expression = buildExpressionObj(expression)
558 def getExpression(self):
559 return Operator.log +
"(" + self.expression.getExpression() +
")" 578 self.
expression = buildExpressionObj(expression)
579 self.
operatorIndex = Operator.operatorIndexDic[Operator.bioNormalCdf]
581 def getExpression(self):
582 return Operator.normalCdf +
"(" + self.expression.getExpression() +
")" 593 self.
left = buildExpressionObj(left)
594 self.
right = buildExpressionObj(right)
595 self.
operatorIndex = Operator.operatorIndexDic[Operator.maxOp]
597 def getExpression(self):
598 return "max(" + self.left.getExpression() +
"," + self.right.getExpression() +
")" 607 def __init__(self,left,right):
608 self.
left = buildExpressionObj(left)
609 self.
right = buildExpressionObj(right)
610 self.
operatorIndex = Operator.operatorIndexDic[Operator.minOp]
612 def getExpression(self):
613 return "min(" + self.left.getExpression() +
"," + self.right.getExpression() +
")" 622 self.
left = buildExpressionObj(left)
623 self.
right = buildExpressionObj(right)
626 def getExpression(self):
627 return "(" + self.left.getExpression() + self.
op + self.right.getExpression() +
")" 637 self.
expression = buildExpressionObj(expression)
638 self.
operatorIndex = Operator.operatorIndexDic[Operator.monteCarloOp]
640 def getExpression(self) :
641 strexpr =
"MonteCarlo" 642 strexpr +=
"(" + self.expression.getExpression() +
")" 652 def __init__(self, expression, integrand,integral) :
653 self.
expression = buildExpressionObj(expression)
654 self.
integrand = buildExpressionObj(integrand)
655 self.
integral = buildExpressionObj(integral)
656 self.
operatorIndex = Operator.operatorIndexDic[Operator.monteCarloCVOp]
658 def getExpression(self) :
659 strexpr =
"MonteCarloControlVariate" 660 strexpr +=
"(" + self.function.getExpression() +
")" 680 self.
function = buildExpressionObj(term)
682 self.
operatorIndex = Operator.operatorIndexDic[Operator.sumOp]
684 def getExpression(self) :
687 strexpr +=
"(" + self.function.getExpression() +
")" 739 def __init__(self, term, iteratorName,positive=False) :
740 self.
function = buildExpressionObj(term)
743 self.
operatorIndex = Operator.operatorIndexDic[Operator.prodOp]
745 def getExpression(self) :
748 strexpr +=
"(" + self.function.getExpression() +
")" 787 self.
function = buildExpressionObj(term)
789 self.
operatorIndex = Operator.operatorIndexDic[Operator.integralOp]
791 def getExpression(self) :
793 strexpr +=
"(" + self.function.getExpression() +
"," + variable +
")" 818 self.
function = buildExpressionObj(term)
820 self.
operatorIndex = Operator.operatorIndexDic[Operator.derivativeOp]
822 def getExpression(self) :
824 strexpr +=
"(" + self.function.getExpression() +
"," + variable +
")" 843 self.
function = buildExpressionObj(term)
844 self.
operatorIndex = Operator.operatorIndexDic[Operator.bioNormalPdf]
846 def getExpression(self) :
847 strexpr =
"normalPdf" 848 strexpr +=
"(" + self.function.getExpression() +
")" 880 def __init__(self, dictionary, key, default = Numeric(0)) :
882 for k,v
in dictionary.items() :
883 self.
prob[k] = buildExpressionObj(v)
885 self.
choice = buildExpressionObj(key)
886 self.
default = buildExpressionObj(default)
887 self.
operatorIndex = Operator.operatorIndexDic[Operator.elemOp]
889 def getExpression(self) :
891 res +=
"[" + str(self.
choice) +
"]" 893 for i,v
in self.prob.items():
894 res +=
"(" + str(i) +
": " + str(v) +
")" 930 for k,v
in util.items() :
931 self.
prob[k] = buildExpressionObj(v)
933 for k,v
in av.items() :
934 self.
av[k] = buildExpressionObj(v)
935 self.
choice = buildExpressionObj(choice)
936 self.
operatorIndex = Operator.operatorIndexDic[Operator.logitOp]
938 def getExpression(self) :
940 res +=
"[" + str(self.
choice) +
"]" 942 for i,v
in self.prob.items():
943 res +=
"(" + str(i) +
": " + str(v) +
")" 946 for i,v
in self.av.items():
947 res +=
"(" + str(i) +
": " + str(v) +
")" 979 for k,v
in util.items() :
980 self.
prob[k] = buildExpressionObj(v)
982 for k,v
in av.items() :
983 self.
av[k] = buildExpressionObj(v)
985 self.
choice = buildExpressionObj(choice)
986 self.
operatorIndex = Operator.operatorIndexDic[Operator.loglogitOp]
988 def getExpression(self) :
990 res +=
"[" + str(self.
choice) +
"]" 992 for i,v
in self.prob.items():
993 res +=
"(" + str(i) +
": " + str(v) +
")" 996 for i,v
in self.av.items():
997 res +=
"(" + str(i) +
": " + str(v) +
")" 1013 def __init__(self, terms) :
1014 if type(terms).__name__ ==
'list':
1018 self.terms.append(buildExpressionObj(k))
1019 elif type(terms).__name__ ==
'dict':
1022 for k,v
in terms.items() :
1023 self.
terms[k] = buildExpressionObj(v)
1026 self.
operatorIndex = Operator.operatorIndexDic[Operator.multSumOp]
1028 def getExpression(self) :
1032 for i,v
in self.terms.items():
1033 res += v.getExpression() +
"," 1036 for k
in self.
terms:
1037 res += k.getExpression() +
"," 1040 res = res[:-1] +
")" 1075 for k,v
in term.items():
1076 self.
theDict[k] = buildExpressionObj(v)
1078 self.
operatorIndex = Operator.operatorIndexDic[Operator.enumOp]
1080 def getExpression(self) :
1081 strexpr =
"Enumerate" 1084 for i,v
in self.term.items():
1085 strexpr +=
"(" + str(i) +
": " + str(v) +
")" 1096 def __init__(self, mean, realizations, varcovar):
1098 if type(mean).__name__ ==
'list':
1101 self.mean.append(buildExpressionObj(k))
1103 self.
error =
"Syntax error: the first argument of bioBayesNormalDraw must be a list of expressions. Syntax: [B_TIME, B_COST]. " ;
1105 if type(realizations).__name__ ==
'list':
1107 for k
in realizations :
1108 self.realizations.append(buildExpressionObj(k))
1110 self.
error =
"Syntax error: the second argument of bioBayesNormalDraw must be a list of expressions. Syntax: [B_TIME_RND, B_COST_RND]" 1111 if type(varcovar).__name__ ==
'list':
1115 if type(k).__name__ ==
'list':
1117 row.append(buildExpressionObj(k))
1118 self.varcovar.append(row)
1120 self.
error =
"Syntax error: the third argument of bioBayesNormalDraw must be a list of list of expressions. Syntax: [[ B_TIME_S , B_COVAR ] , [B_COVAR , B_COST_S]]." ;
1124 self.
error =
"Syntax error: the third argument of bioBayesNormalDraw must be a list of list of expressions. Syntax: [[ B_TIME_S , B_COVAR ] , [B_COVAR , B_COST_S]]." 1126 self.
operatorIndex = Operator.operatorIndexDic[Operator.bayesMeanOp]
1151 if type(beta).__name__ ==
'list':
1155 self.beta.append(buildExpressionObj(k))
1156 elif type(beta).__name__ ==
'dict':
1159 for k,v
in beta.items() :
1160 self.
beta[k] = buildExpressionObj(v)
1166 self.
operatorIndex = Operator.operatorIndexDic[Operator.mhOp]
Class representing the expression for natural logarithm.
Class representing the product of the same expression applied to a list of data.
def __init__(self, beta, density, warmup, steps)
def __init__(self, op, left, right)
def __eq__(self, expression)
Class representing the definition of a new variable.
Class calculating a logit choice probability.
Class performing numerical integration relying on the Gauss-Hermite quadrature to compute ...
def __truediv__(self, expression)
Support for Python version 3.x.
Class representing the variables defined in the data file.
def __radd__(self, expression)
Class representing a normally distributed random variable for simulated integration.
def __pow__(self, expression)
Class representing the definition of a new type of draws.
def __init__(self, term, iteratorName, positive=False)
Generic class for binary operators.
def __rpow__(self, expression)
def __init__(self, expression)
def __init__(self, name, index='__rowId__')
Class generating the analytical derivative of an expression.
Interface for mathematical expressions.
def __gt__(self, expression)
def __ge__(self, expression)
def __lt__(self, expression)
def __init__(self, expression)
Class computing the sum of multiple expressions.
def __rsub__(self, expression)
Class performing draws from densities for Bayesian estimation using Metropolis-Hastings algorithm...
def __init__(self, expression)
Class representing a random variable for integration using Monte Carlo simulation.
def __init__(self, term, v)
Class performing draws from the posterior of the mean of a normal variable knowing realizations and v...
Class representing the expression for the minimum of two expressions.
def __init__(self, left, right)
def __rdiv__(self, expression)
def __init__(self, expression, integrand, integral)
Class representing a parameter to be estimated.
Class wrapping an integer or a float value.
Generic class for an operator.
def __rmul__(self, expression)
Class representing the expression for the maximum of two expressions.
Class representing the cumulative distribution function of the normal distribution.
def __init__(self, term, iteratorName)
def __init__(self, term, v)
Class calculating the log of a logit choice probability.
Class representing the expression for exponential.
Class representing the expression for absolute value.
Class representing the uniform draw of a random variable used for integration using Monte Carlo simul...
def __init__(self, util, av, choice)
def __mod__(self, expression)
Class representing the probability density function of a standardized normally distributed random var...
def __init__(self, expression)
def __and__(self, expression)
def __init__(self, op, expression)
def __div__(self, expression)
def __rtruediv__(self, expression)
Support for Python version 3.x.
Class representing the sum of the same expression applied to a list of data.
def __init__(self, util, av, choice)
def __sub__(self, expression)
def __init__(self, name, value, lowerbound, upperbound, status, desc='')
Generic class for unary operators.
def __init__(self, dictionary, key, default=Numeric(0))
def __init__(self, expression)
def __init__(self, term, iteratorName)
def __init__(self, name, expression, iteratorName)
Class representing a random variable for numerical integration.
def __init__(self)
Constructor.
def __mul__(self, expression)
Class representing the Monte Carlo integration of an expression, using a control variate method to de...
Class performing a sample enumeration.
Class extracting an expression from a dictionary.
Class representing the Monte Carlo integration of an expression.
def __or__(self, expression)
def __init__(self, name, expression)
def __le__(self, expression)
def __init__(self, number)
def __add__(self, expression)
def __ne__(self, expression)