Expressions¶
Mathematical expressions
biogeme.expressions module¶
Defines the various arithmetic expressions accepted by Biogeme.
- author
Michel Bierlaire
- date
Tue Mar 26 16:47:49 2019
-
class
biogeme.expressions.
And
(left, right)[source]¶ Bases:
biogeme.expressions.BinaryOperator
Logical and
-
__init__
(left, right)[source]¶ Constructor
- Parameters
left (biogeme.expressions.Expression) – first arithmetic expression
right (biogeme.expressions.Expression) – second arithmetic expression
-
-
class
biogeme.expressions.
Beta
(name, value, lowerbound, upperbound, status)[source]¶ Bases:
biogeme.expressions.Elementary
Unknown parameters to be estimated from data.
-
__init__
(name, value, lowerbound, upperbound, status)[source]¶ Constructor
- Parameters
name (string) – name of the parameter.
value (float) – default value.
lowerbound (float) – if different from None, imposes a lower bound on the value of the parameter during the optimization.
upperbound (float) – if different from None, imposes an upper bound on the value of the parameter during the optimization.
status (int) – if different from 0, the parameter is fixed to its default value, and not modified by the optimization algorithm.
- Raises
biogemeError – if the first parameter is not a str.
biogemeError – if the second parameter is not a int or a float.
-
changeInitValues
(betas)[source]¶ Modifies the initial values of the Beta parameters.
The fact that the parameters are fixed or free is irrelevant here.
- Parameters
betas (dict(string:float)) – dictionary where the keys are the names of the parameters, and the values are the new value for the parameters.
-
dictOfBetas
(free=True, fixed=False)[source]¶ Extract the set of parameters from the expression. Overload the generic function.
- Parameters
free (bool) – if True, the free parameters are included. Default: True.
fixed (bool) – if True, the fixed parameters are included. Default: False.
- Returns
a dict with the beta parameters appearing in the expression, the keys being the names of the parameters.
- Return type
dict(string:biogeme.expressions.Expression)
-
getSignature
()[source]¶ The signature of a string characterizing an expression.
This is designed to be communicated to C++, so that the expression can be reconstructed in this environment.
The list contains the following elements:
the name of the expression between < >
the id of the expression between { }
the name of the parameter,
the status between [ ]
the unique ID, preceeded by a comma
the beta ID, preceeded by a comma
Consider the following expression:
\[2 \beta_1 V_1 - \frac{\exp(-\beta_2 V_2) }{ \beta_3 (\beta_2 \geq \beta_1)}.\]It is defined as:
2 * beta1 * Variable1 - expressions.exp(-beta2*Variable2) / (beta3 * (beta2 >= beta1))
And its signature is:
[b'<Numeric>{4780527008},2', b'<Beta>{4780277152}"beta1"[0],0,0', b'<Times>{4780526952}(2),4780527008,4780277152', b'<Variable>{4511837152}"Variable1",5,2', b'<Times>{4780527064}(2),4780526952,4511837152', b'<Beta>{4780277656}"beta2"[0],1,1', b'<UnaryMinus>{4780527120}(1),4780277656', b'<Variable>{4511837712}"Variable2",6,3', b'<Times>{4780527176}(2),4780527120,4511837712', b'<exp>{4780527232}(1),4780527176', b'<Beta>{4780277264}"beta3"[1],2,0', b'<Beta>{4780277656}"beta2"[0],1,1', b'<Beta>{4780277152}"beta1"[0],0,0', b'<GreaterOrEqual>{4780527288}(2),4780277656,4780277152', b'<Times>{4780527344}(2),4780277264,4780527288', b'<Divide>{4780527400}(2),4780527232,4780527344', b'<Minus>{4780527456}(2),4780527064,4780527400']
- Returns
list of the signatures of an expression and its children.
- Return type
list(string)
- Raises
biogeme.exceptions.biogemeError – if no id has been defined for elementary expression
biogeme.exceptions.biogemeError – if no id has been defined for parameter
-
getValue
()[source]¶ Evaluates the value of the expression
- Returns
value of the expression
- Return type
float
-
setOfBetas
(free=True, fixed=False)[source]¶ Extract the set of parameters from the expression. Overload the generic function.
- Parameters
free (bool) – if True, the free parameters are included. Default: True.
fixed (bool) – if True, the fixed parameters are included. Default: False.
- Returns
returns a set with the beta parameters appearing in the expression.
- Return type
-
setSpecificIndices
(indicesOfFreeBetas, indicesOfFixedBetas, indicesOfRandomVariables, indicesOfDraws)[source]¶ Provide an index to all elementary expressions, specific to their type
- Parameters
indicesOfFreeBetas (dict(string:int)) – dictionary mapping the name of the free betas with their index
indicesOfFixedBetas (dict(string:int)) – dictionary mapping the name of the fixed betas with their index
indicesOfRandomVariables (dict(string:int)) – dictionary mapping the name of the random variables with their index
indicesOfDraws (dict(string:int)) – dictionary mapping the name of the draws with their index
- Raises
biogemeError – if no index is available for one of the parameters
-
-
class
biogeme.expressions.
BinaryOperator
(left, right)[source]¶ Bases:
biogeme.expressions.Expression
Base class for arithmetic expressions that are binary operators. This expression is the result of the combination of two expressions, typically addition, substraction, multiplication or division.
-
__init__
(left, right)[source]¶ Constructor
- Parameters
left (biogeme.expressions.Expression) – first arithmetic expression
right (biogeme.expressions.Expression) – second arithmetic expression
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
left
¶ left parent
-
right
¶ right parent
-
-
class
biogeme.expressions.
DefineVariable
(name, expression, database)[source]¶ Bases:
biogeme.expressions.Variable
Expression that defines a new variable and add a column in the database.
This expression allows the use to define a new variable that will be added to the database. It avoids that it is recalculated each time it is needed.
-
__init__
(name, expression, database)[source]¶ Constructor
- Parameters
name (string) – name of the variable.
expression – formula that defines the variable
type – biogeme.expressions.Expression
database (biogeme.database.Database) – object identifying the database.
- Raises
biogemeError – if the expression is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
-
class
biogeme.expressions.
Derive
(child, name)[source]¶ Bases:
biogeme.expressions.UnaryOperator
Derivative with respect to an elementary expression
-
__init__
(child, name)[source]¶ Constructor
- Parameters
child (biogeme.expressions.Expression) – first arithmetic expression
-
getSignature
()[source]¶ The signature of a string characterizing an expression.
This is designed to be communicated to C++, so that the expression can be reconstructed in this environment.
The list contains the following elements:
the signatures of the child expression,
the name of the expression between < >
the id of the expression between { }
the id of the child, preceeded by a comma.
Consider the following expression:
\[2 \beta_1 V_1 - \frac{\exp(-\beta_2 V_2) }{ \beta_3 (\beta_2 \geq \beta_1)}.\]It is defined as:
2 * beta1 * Variable1 - expressions.exp(-beta2*Variable2) / (beta3 * (beta2 >= beta1))
And its signature is:
[b'<Numeric>{4780527008},2', b'<Beta>{4780277152}"beta1"[0],0,0', b'<Times>{4780526952}(2),4780527008,4780277152', b'<Variable>{4511837152}"Variable1",5,2', b'<Times>{4780527064}(2),4780526952,4511837152', b'<Beta>{4780277656}"beta2"[0],1,1', b'<UnaryMinus>{4780527120}(1),4780277656', b'<Variable>{4511837712}"Variable2",6,3', b'<Times>{4780527176}(2),4780527120,4511837712', b'<exp>{4780527232}(1),4780527176', b'<Beta>{4780277264}"beta3"[1],2,0', b'<Beta>{4780277656}"beta2"[0],1,1', b'<Beta>{4780277152}"beta1"[0],0,0', b'<GreaterOrEqual>{4780527288}(2),4780277656,4780277152', b'<Times>{4780527344}(2),4780277264,4780527288', b'<Divide>{4780527400}(2),4780527232,4780527344', b'<Minus>{4780527456}(2),4780527064,4780527400']
- Returns
list of the signatures of an expression and its children.
- Return type
list(string)
-
setUniqueId
(idsOfElementaryExpressions)[source]¶ Provides a unique id to the elementary expressions.
- Parameters
idsOfElementaryExpressions (dict(string:int)) – dictionary mapping the name of the elementary expression with their id.
- Raises
biogemeError – if no index is available for an expression.
-
-
class
biogeme.expressions.
Divide
(left, right)[source]¶ Bases:
biogeme.expressions.BinaryOperator
Division expression
-
__init__
(left, right)[source]¶ Constructor
- Parameters
left (biogeme.expressions.Expression) – first arithmetic expression
right (biogeme.expressions.Expression) – second arithmetic expression
-
-
class
biogeme.expressions.
Elem
(dictOfExpressions, keyExpression)[source]¶ Bases:
biogeme.expressions.Expression
This returns the element of a dictionary. The key is evaluated from an expression.
-
__init__
(dictOfExpressions, keyExpression)[source]¶ Constructor
- Parameters
dictOfExpressions (dict(int: biogeme.expressions.Expression)) – dict of objects with numerical keys.
keyExpression (biogeme.expressions.Expression) – object providing the key of the element to be evaluated.
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
dictOfExpressions
¶ dict of expressions
-
getSignature
()[source]¶ The signature of a string characterizing an expression.
This is designed to be communicated to C++, so that the expression can be reconstructed in this environment.
The list contains the following elements:
the signature of the expression defining the key
the signatures of all the children expressions,
the name of the expression between < >
the id of the expression between { }
the number of elements between ( )
the id of the expression defining the key
for each element: the value of the key and the id of the expression, separated by commas.
Consider the following expression:
\[2 \beta_1 V_1 - \frac{\exp(-\beta_2 V_2) }{ \beta_3 (\beta_2 \geq \beta_1)}.\]It is defined as:
2 * beta1 * Variable1 - expressions.exp(-beta2*Variable2) / (beta3 * (beta2 >= beta1))
And its signature is:
[b'<Numeric>{4780527008},2', b'<Beta>{4780277152}"beta1"[0],0,0', b'<Times>{4780526952}(2),4780527008,4780277152', b'<Variable>{4511837152}"Variable1",5,2', b'<Times>{4780527064}(2),4780526952,4511837152', b'<Beta>{4780277656}"beta2"[0],1,1', b'<UnaryMinus>{4780527120}(1),4780277656', b'<Variable>{4511837712}"Variable2",6,3', b'<Times>{4780527176}(2),4780527120,4511837712', b'<exp>{4780527232}(1),4780527176', b'<Beta>{4780277264}"beta3"[1],2,0', b'<Beta>{4780277656}"beta2"[0],1,1', b'<Beta>{4780277152}"beta1"[0],0,0', b'<GreaterOrEqual>{4780527288}(2),4780277656,4780277152', b'<Times>{4780527344}(2),4780277264,4780527288', b'<Divide>{4780527400}(2),4780527232,4780527344', b'<Minus>{4780527456}(2),4780527064,4780527400']
- Returns
list of the signatures of an expression and its children.
- Return type
list(string)
-
getValue
()[source]¶ Evaluates the value of the expression
- Returns
value of the expression
- Return type
float
-
keyExpression
¶ expression for the key
-
-
class
biogeme.expressions.
Elementary
(name)[source]¶ Bases:
biogeme.expressions.Expression
Elementary expression.
It is typically defined by a name appearing in an expression. It can be a variable (from the database), or a parameter (fixed or to be estimated using maximum likelihood), a random variable for numrerical integration, or Monte-Carlo integration.
-
getElementaryExpression
(name)[source]¶ - Returns
an elementary expression from its name if it appears in the expression. None otherwise.
- Return type
biogeme.Expression
-
name
¶ name of the elementary expressiom
-
setUniqueId
(idsOfElementaryExpressions)[source]¶ Provides a unique id to the elementary expressions. Overloads the generic function
- Parameters
idsOfElementaryExpressions (dict(string:int)) – dictionary mapping the name of the elementary expression with their id.
- Raises
biogemeError – if no index is available for an expression.
-
uniqueId
¶ The id should be unique for all elementary expressions appearing in a given set of formulas.
-
-
class
biogeme.expressions.
Equal
(left, right)[source]¶ Bases:
biogeme.expressions.BinaryOperator
Logical equal
-
__init__
(left, right)[source]¶ Constructor
- Parameters
left (biogeme.expressions.Expression) – first arithmetic expression
right (biogeme.expressions.Expression) – second arithmetic expression
-
-
class
biogeme.expressions.
Expression
[source]¶ Bases:
object
This is the general arithmetic expression in biogeme. It serves as a base class for concrete expressions.
-
__add__
(other)[source]¶ Operator overloading. Generate an expression for addition.
- Parameters
other (biogeme.expressions.Expression) – expression to be added
- Returns
self + other
- Return type
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
__and__
(other)[source]¶ Operator overloading. Generate an expression for logical and.
- Parameters
other (biogeme.expressions.Expression) – expression for logical and
- Returns
self and other
- Return type
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
__div__
(other)[source]¶ Operator overloading. Generate an expression for division.
- Parameters
other (biogeme.expressions.Expression) – expression for division
- Returns
self / other
- Return type
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
__eq__
(other)[source]¶ Operator overloading. Generate an expression for comparison.
- Parameters
other (biogeme.expressions.Expression) – expression for equality
- Returns
self == other
- Return type
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
__ge__
(other)[source]¶ Operator overloading. Generate an expression for comparison.
- Parameters
other (biogeme.expressions.Expression) – expression for greater or equal
- Returns
self >= other
- Return type
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
__gt__
(other)[source]¶ Operator overloading. Generate an expression for comparison.
- Parameters
other (biogeme.expressions.Expression) – expression for greater than
- Returns
self > other
- Return type
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
__le__
(other)[source]¶ Operator overloading. Generate an expression for comparison.
- Parameters
other (biogeme.expressions.Expression) – expression for less or equal
- Returns
self <= other
- Return type
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
__lt__
(other)[source]¶ Operator overloading. Generate an expression for comparison.
- Parameters
other (biogeme.expressions.Expression) – expression for less than
- Returns
self < other
- Return type
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
__mul__
(other)[source]¶ Operator overloading. Generate an expression for multiplication.
- Parameters
other (biogeme.expressions.Expression) – expression to be multiplied
- Returns
self * other
- Return type
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
__ne__
(other)[source]¶ Operator overloading. Generate an expression for comparison.
- Parameters
other (biogeme.expressions.Expression) – expression for difference
- Returns
self != other
- Return type
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
__neg__
()[source]¶ Operator overloading. Generate an expression for unary minus.
- Returns
-self
- Return type
-
__or__
(other)[source]¶ Operator overloading. Generate an expression for logical or.
- Parameters
other (biogeme.expressions.Expression) – expression for logical or
- Returns
self or other
- Return type
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
__pow__
(other)[source]¶ Operator overloading. Generate an expression for power.
- Parameters
other (biogeme.expressions.Expression) – expression for power
- Returns
self ^ other
- Return type
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
__radd__
(other)[source]¶ Operator overloading. Generate an expression for addition.
- Parameters
other (biogeme.expressions.Expression) – expression to be added
- Returns
other + self
- Return type
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
__rdiv__
(other)[source]¶ Operator overloading. Generate an expression for division.
- Parameters
other (biogeme.expressions.Expression) – expression for division
- Returns
other / self
- Return type
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
__rmul__
(other)[source]¶ Operator overloading. Generate an expression for multiplication.
- Parameters
other (biogeme.expressions.Expression) – expression to be multiplied
- Returns
other * self
- Return type
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
__rpow__
(other)[source]¶ Operator overloading. Generate an expression for power.
- Parameters
other (biogeme.expressions.Expression) – expression for power
- Returns
other ^ self
- Return type
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
__rsub__
(other)[source]¶ Operator overloading. Generate an expression for substraction.
- Parameters
other (biogeme.expressions.Expression) – expression to be substracted
- Returns
other - self
- Return type
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
__rtruediv__
(other)[source]¶ Operator overloading. Generate an expression for division.
- Parameters
other (biogeme.expressions.Expression) – expression for division
- Returns
other / self
- Return type
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
__sub__
(other)[source]¶ Operator overloading. Generate an expression for substraction.
- Parameters
other (biogeme.expressions.Expression) – expression to substract
- Returns
self - other
- Return type
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
__truediv__
(other)[source]¶ Operator overloading. Generate an expression for division.
- Parameters
other (biogeme.expressions.Expression) – expression for division
- Returns
self / other
- Return type
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
allDraws
¶ dict of draws
-
allFixedBetas
¶ dict of fixed parameters
-
allFreeBetas
¶ dict of free parameters
-
allRandomVariables
¶ dict of random variables
-
audit
(database=None)[source]¶ Performs various checks on the expressions.
- Parameters
database (biogeme.database.Database) – database object
- Returns
tuple listOfErrors, listOfWarnings
- Return type
list(string), list(string)
-
betaIds
¶ List of ids of the free beta parameters (those to be estimated)
-
changeInitValues
(betas)[source]¶ Modifies the initial values of the Beta parameters.
The fact that the parameters are fixed or free is irrelevant here.
- Parameters
betas (dict(string:float)) – dictionary where the keys are the names of the parameters, and the values are the new value for the parameters.
-
children
¶ List of children expressions
-
countPanelTrajectoryExpressions
()[source]¶ Count the number of times the PanelLikelihoodTrajectory is used in the formula. It should trigger an error if it is used more than once.
- Returns
number of times the PanelLikelihoodTrajectory is used in the formula
- Return type
int
-
dictOfBetas
(free=True, fixed=False)[source]¶ Extract the set of parameters from the expression.
- Parameters
free (bool) – if True, the free parameters are included. Default: True.
fixed (bool) – if True, the fixed parameters are included. Default: False.
- Returns
a dict with the beta parameters appearing in the expression, the keys being the names of the parameters.
- Return type
dict(string:biogeme.expressions.Expression)
-
dictOfDraws
()[source]¶ Recursively extract the random variables (draws for Monte-Carlo) appearing in the expression, and store them in a dictionary.
- Returns
dict where the keys are the random variables and the elements the type of draws
- Return type
dict(string:string)
-
dictOfRandomVariables
()[source]¶ Recursively extract the random variables appearing in the expression, and store them in a dictionary.
- Returns
returns a dict with the random variables appearing in the expression the keys being their names.
- Return type
dict(string:biogeme.expressions.Expression)
-
dictOfVariables
()[source]¶ Recursively extract the variables appearing in the expression, and store them in a dictionary.
- Returns
returns a dict with the variables appearing in the expression the keys being their names.
- Return type
dict(string:biogeme.expressions.Expression)
-
drawNames
¶ list of draw types
-
elementaryExpressionIndex
¶ Indices of the elementary expressions (dict)
-
embedExpression
(t)[source]¶ Check if the expression contains an expression of type t.
Typically, this would be used to check that a MonteCarlo expression contains a bioDraws expression.
- Returns
True if the expression contains an expression of type t.
- Return type
bool
See: Expression.isContainedIn
-
fixedBetaNames
¶ list of names of fixed parameters
-
fixedBetaValues
¶ List of values of the fixed beta parameters (those to be estimated)
-
freeBetaNames
¶ list of names of free parameters
-
freeBetaValues
¶ List of values of the free beta parameters (those to be estimated)
-
getClassName
()[source]¶ Obtain the name of the top class of the expression structure
- Returns
the name of the class
- Return type
string
-
getElementaryExpression
(name)[source]¶ Return: an elementary expression from its name if it appears in the expression.
- Parameters
name (string) – name of the elementary expression.
- Returns
the expression if it exists. None otherwise.
- Return type
-
getSignature
()[source]¶ The signature of a string characterizing an expression.
This is designed to be communicated to C++, so that the expression can be reconstructed in this environment.
The list contains the following elements:
the signatures of all the children expressions,
the name of the expression between < >
the id of the expression between { }
the number of children between ( )
the ids of each children, preceeded by a comma.
Consider the following expression:
\[2 \beta_1 V_1 - \frac{\exp(-\beta_2 V_2) } { \beta_3 (\beta_2 \geq \beta_1)}.\]It is defined as:
2 * beta1 * Variable1 - expressions.exp(-beta2*Variable2) / (beta3 * (beta2 >= beta1))
And its signature is:
[b'<Numeric>{4780527008},2', b'<Beta>{4780277152}"beta1"[0],0,0', b'<Times>{4780526952}(2),4780527008,4780277152', b'<Variable>{4511837152}"Variable1",5,2', b'<Times>{4780527064}(2),4780526952,4511837152', b'<Beta>{4780277656}"beta2"[0],1,1', b'<UnaryMinus>{4780527120}(1),4780277656', b'<Variable>{4511837712}"Variable2",6,3', b'<Times>{4780527176}(2),4780527120,4511837712', b'<exp>{4780527232}(1),4780527176', b'<Beta>{4780277264}"beta3"[1],2,0', b'<Beta>{4780277656}"beta2"[0],1,1', b'<Beta>{4780277152}"beta1"[0],0,0', b'<GreaterOrEqual>{4780527288}(2),4780277656,4780277152', b'<Times>{4780527344}(2),4780277264,4780527288', b'<Divide>{4780527400}(2),4780527232,4780527344', b'<Minus>{4780527456}(2),4780527064,4780527400']
- Returns
list of the signatures of an expression and its children.
- Return type
list(string)
-
getValue_c
(database, numberOfDraws=1000)[source]¶ Evaluation of the expression
In Biogeme the complexity of some expressions requires a specific implementation, in C++. This function invokes the C++ code to evaluate the value of the expression for a series of entries in a database. Note that this function will generate draws if needed.
- Parameters
database (biogeme.database.Database) – database
numberOfDraws (int) – number of draws if needed by Monte-Carlo integration.
- Returns
a list where each entry is the result of applying the expression on one entry of the dsatabase.
- Return type
numpy.array
-
isContainedIn
(t)[source]¶ Check if the expression is contained in an expression of type t.
Typically, this would be used to check that a bioDraws expression is contained in a MonteCarlo expression. If not, it cannot be evaluated.
- Returns
True if the expression is contained in an expression of type t.
- Return type
bool.
-
logger
¶ Logger that controls the output of messages to the screen and log file. Type: class
biogeme.messaging.bioMessage
.
-
parent
¶ Parent expression
-
randomVariableNames
¶ list of random variables names
-
setOfBetas
(free=True, fixed=False)[source]¶ Extract the set of parameters from the expression.
- Parameters
free (bool) – if True, the free parameters are included. Default: True.
fixed (bool) – if True, the fixed parameters are included. Default: False.
- Returns
returns a set with the beta parameters appearing in the expression.
- Return type
-
setOfVariables
()[source]¶ Extract the set of variables used in the expression.
- Returns
returns a set with the variables appearing in the expression.
- Return type
-
setRow
(row)[source]¶ This function identifies the row of the database from which the values of the variables must be obtained.
- Parameters
row (int) – id of the row.
-
setSpecificIndices
(indicesOfFreeBetas, indicesOfFixedBetas, indicesOfRandomVariables, indicesOfDraws)[source]¶ Provides an index to all elementary expressions, specific to their type
- Parameters
indicesOfFreeBetas (dict(string:int)) – dictionary mapping the name of the free betas with their index
indicesOfFixedBetas (dict(string:int)) – dictionary mapping the name of the fixed betas with their index
indicesOfRandomVariables (dict(string:int)) – dictionary mapping the name of the random variables with their index
indicesOfDraws (dict(string:int)) – dictionary mapping the name of the draws with their index
-
setUniqueId
(idsOfElementaryExpressions)[source]¶ Provides a unique id to the elementary expressions.
- Parameters
idsOfElementaryExpressions (dict(string:int)) – dictionary mapping the name of the elementary expression with their id.
-
setVariableIndices
(indicesOfVariables)[source]¶ Provide an index to all variables
- Parameters
indicesOfVariables (dict(string:int)) – dictionary mapping the name of the variables with their index
-
variableNames
¶ list of variables names
-
-
class
biogeme.expressions.
Greater
(left, right)[source]¶ Bases:
biogeme.expressions.BinaryOperator
Logical greater
-
__init__
(left, right)[source]¶ Constructor
- Parameters
left (biogeme.expressions.Expression) – first arithmetic expression
right (biogeme.expressions.Expression) – second arithmetic expression
-
-
class
biogeme.expressions.
GreaterOrEqual
(left, right)[source]¶ Bases:
biogeme.expressions.BinaryOperator
Logical greater or equal
-
__init__
(left, right)[source]¶ Constructor
- Parameters
left (biogeme.expressions.Expression) – first arithmetic expression
right (biogeme.expressions.Expression) – second arithmetic expression
-
-
class
biogeme.expressions.
Integrate
(child, name)[source]¶ Bases:
biogeme.expressions.UnaryOperator
Numerical integration
-
__init__
(child, name)[source]¶ Constructor
- Parameters
child (biogeme.expressions.Expression) – first arithmetic expression
name (string) – name of the random variable for the integration.
-
audit
(database=None)[source]¶ Performs various checks on the expressions.
- Parameters
database (biogeme.database.Database) – database object
- Returns
tuple listOfErrors, listOfWarnings
- Return type
list(string), list(string)
-
getSignature
()[source]¶ The signature of a string characterizing an expression.
This is designed to be communicated to C++, so that the expression can be reconstructed in this environment.
The list contains the following elements:
the signatures of the child expression,
the name of the expression between < >
the id of the expression between { }, preceeded by a comma
the id of the children, preceeded by a comma
the index of the randon variable, preceeded by a comma
Consider the following expression:
\[2 \beta_1 V_1 - \frac{\exp(-\beta_2 V_2) } { \beta_3 (\beta_2 \geq \beta_1)}.\]It is defined as:
2 * beta1 * Variable1 - expressions.exp(-beta2*Variable2) / (beta3 * (beta2 >= beta1))
And its signature is:
[b'<Numeric>{4780527008},2', b'<Beta>{4780277152}"beta1"[0],0,0', b'<Times>{4780526952}(2),4780527008,4780277152', b'<Variable>{4511837152}"Variable1",5,2', b'<Times>{4780527064}(2),4780526952,4511837152', b'<Beta>{4780277656}"beta2"[0],1,1', b'<UnaryMinus>{4780527120}(1),4780277656', b'<Variable>{4511837712}"Variable2",6,3', b'<Times>{4780527176}(2),4780527120,4511837712', b'<exp>{4780527232}(1),4780527176', b'<Beta>{4780277264}"beta3"[1],2,0', b'<Beta>{4780277656}"beta2"[0],1,1', b'<Beta>{4780277152}"beta1"[0],0,0', b'<GreaterOrEqual>{4780527288}(2),4780277656,4780277152', b'<Times>{4780527344}(2),4780277264,4780527288', b'<Divide>{4780527400}(2),4780527232,4780527344', b'<Minus>{4780527456}(2),4780527064,4780527400']
- Returns
list of the signatures of an expression and its children.
- Return type
list(string)
-
setSpecificIndices
(indicesOfFreeBetas, indicesOfFixedBetas, indicesOfRandomVariables, indicesOfDraws)[source]¶ Provide an index to all elementary expressions, specific to their type Overloads the generic function.
- Parameters
indicesOfFreeBetas (dict(string:int)) – dictionary mapping the name of the free betas with their index
indicesOfFixedBetas (dict(string:int)) – dictionary mapping the name of the fixed betas with their index
indicesOfRandomVariables (dict(string:int)) – dictionary mapping the name of the random variables with their index
indicesOfDraws (dict(string:int)) – dictionary mapping the name of the draws with their index
- Raises
biogemeError – if no index is available for a random variable.
-
setUniqueId
(idsOfElementaryExpressions)[source]¶ Provides a unique id to the elementary expressions. Overloads the generic function
- Parameters
idsOfElementaryExpressions (dict(string:int)) – dictionary mapping the name of the elementary expression with their id.
- Raises
biogemeError – if no index is available for a random variable.
-
-
class
biogeme.expressions.
Less
(left, right)[source]¶ Bases:
biogeme.expressions.BinaryOperator
Logical less
-
__init__
(left, right)[source]¶ Constructor
- Parameters
left (biogeme.expressions.Expression) – first arithmetic expression
right (biogeme.expressions.Expression) – second arithmetic expression
-
-
class
biogeme.expressions.
LessOrEqual
(left, right)[source]¶ Bases:
biogeme.expressions.BinaryOperator
Logical less or equal
-
__init__
(left, right)[source]¶ Constructor
- Parameters
left (biogeme.expressions.Expression) – first arithmetic expression
right (biogeme.expressions.Expression) – second arithmetic expression
-
-
class
biogeme.expressions.
LogLogit
(util, av, choice)[source]¶ Bases:
biogeme.expressions.Expression
Expression capturing the logit formula.
It contains one formula for the target alternative, a dict of formula for the availabilities and a dict of formulas for the utilities
-
__init__
(util, av, choice)[source]¶ Constructor
- Parameters
util (dict(int:biogeme.expressions.Expression)) – dictionary where the keys are the identifiers of the alternatives, and the elements are objects defining the utility functions.
av (dict(int:biogeme.expressions.Expression)) – dictionary where the keys are the identifiers of the alternatives, and the elements are object of type biogeme.expressions.Expression defining the availability conditions. If av is None, all the alternatives are assumed to be always available
choice (biogeme.expressions.Expression) – formula to obtain the alternative for which the logit probability must be calculated.
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
audit
(database=None)[source]¶ Performs various checks on the expressions.
- Parameters
database (biogeme.database.Database) – database object
- Returns
tuple listOfErrors, listOfWarnings
- Return type
list(string), list(string)
-
av
¶ dict of availability formulas
-
choice
¶ expression for the chosen alternative
-
getSignature
()[source]¶ The signature of a string characterizing an expression.
This is designed to be communicated to C++, so that the expression can be reconstructed in this environment.
The list contains the following elements:
the signatures of all the children expressions,
the name of the expression between < >
the id of the expression between { }
the number of alternatives between ( )
the id of the expression for the chosen alternative, preceeded by a comma.
for each alternative, separated by commas:
the number of the alternative, as defined by the user,
the id of the expression for the utility,
the id of the expression for the availability condition.
Consider the following expression:
\[2 \beta_1 V_1 - \frac{\exp(-\beta_2 V_2) }{ \beta_3 (\beta_2 \geq \beta_1)}.\]It is defined as:
2 * beta1 * Variable1 - expressions.exp(-beta2*Variable2) / (beta3 * (beta2 >= beta1))
And its signature is:
[b'<Numeric>{4780527008},2', b'<Beta>{4780277152}"beta1"[0],0,0', b'<Times>{4780526952}(2),4780527008,4780277152', b'<Variable>{4511837152}"Variable1",5,2', b'<Times>{4780527064}(2),4780526952,4511837152', b'<Beta>{4780277656}"beta2"[0],1,1', b'<UnaryMinus>{4780527120}(1),4780277656', b'<Variable>{4511837712}"Variable2",6,3', b'<Times>{4780527176}(2),4780527120,4511837712', b'<exp>{4780527232}(1),4780527176', b'<Beta>{4780277264}"beta3"[1],2,0', b'<Beta>{4780277656}"beta2"[0],1,1', b'<Beta>{4780277152}"beta1"[0],0,0', b'<GreaterOrEqual>{4780527288}(2),4780277656,4780277152', b'<Times>{4780527344}(2),4780277264,4780527288', b'<Divide>{4780527400}(2),4780527232,4780527344', b'<Minus>{4780527456}(2),4780527064,4780527400']
- Returns
list of the signatures of an expression and its children.
- Return type
list(string)
-
getValue
()[source]¶ Evaluates the value of the expression
- Returns
value of the expression
- Return type
float
-
util
¶ dict of utility functions
-
-
class
biogeme.expressions.
Minus
(left, right)[source]¶ Bases:
biogeme.expressions.BinaryOperator
Substraction expression
-
__init__
(left, right)[source]¶ Constructor
- Parameters
left (biogeme.expressions.Expression) – first arithmetic expression
right (biogeme.expressions.Expression) – second arithmetic expression
-
-
class
biogeme.expressions.
MonteCarlo
(child)[source]¶ Bases:
biogeme.expressions.UnaryOperator
Monte Carlo integration
-
__init__
(child)[source]¶ Constructor
- Parameters
child (biogeme.expressions.Expression) – arithmetic expression
-
audit
(database=None)[source]¶ Performs various checks on the expressions.
- Parameters
database (biogeme.database.Database) – database object
- Returns
tuple listOfErrors, listOfWarnings
- Return type
list(string), list(string)
-
-
class
biogeme.expressions.
NotEqual
(left, right)[source]¶ Bases:
biogeme.expressions.BinaryOperator
Logical not equal
-
__init__
(left, right)[source]¶ Constructor
- Parameters
left (biogeme.expressions.Expression) – first arithmetic expression
right (biogeme.expressions.Expression) – second arithmetic expression
-
-
class
biogeme.expressions.
Numeric
(value)[source]¶ Bases:
biogeme.expressions.Expression
Numerical expression for a simple number
-
getSignature
()[source]¶ The signature of a string characterizing an expression.
This is designed to be communicated to C++, so that the expression can be reconstructed in this environment.
The list contains the following elements:
the name of the expression between < >
the id of the expression between { }
the value, preceeded by a comma.
Consider the following expression:
\[2 \beta_1 V_1 - \frac{\exp(-\beta_2 V_2) }{ \beta_3 (\beta_2 \geq \beta_1)}.\]It is defined as:
2 * beta1 * Variable1 - expressions.exp(-beta2*Variable2) / (beta3 * (beta2 >= beta1))
And its signature is:
[b'<Numeric>{4780527008},2', b'<Beta>{4780277152}"beta1"[0],0,0', b'<Times>{4780526952}(2),4780527008,4780277152', b'<Variable>{4511837152}"Variable1",5,2', b'<Times>{4780527064}(2),4780526952,4511837152', b'<Beta>{4780277656}"beta2"[0],1,1', b'<UnaryMinus>{4780527120}(1),4780277656', b'<Variable>{4511837712}"Variable2",6,3', b'<Times>{4780527176}(2),4780527120,4511837712', b'<exp>{4780527232}(1),4780527176', b'<Beta>{4780277264}"beta3"[1],2,0', b'<Beta>{4780277656}"beta2"[0],1,1', b'<Beta>{4780277152}"beta1"[0],0,0', b'<GreaterOrEqual>{4780527288}(2),4780277656,4780277152', b'<Times>{4780527344}(2),4780277264,4780527288', b'<Divide>{4780527400}(2),4780527232,4780527344', b'<Minus>{4780527456}(2),4780527064,4780527400']
- Returns
list of the signatures of an expression and its children.
- Return type
list(string)
-
getValue
()[source]¶ Evaluates the value of the expression
- Returns
value of the expression
- Return type
float
-
value
¶ numeric value
-
-
class
biogeme.expressions.
Or
(left, right)[source]¶ Bases:
biogeme.expressions.BinaryOperator
Logical or
-
__init__
(left, right)[source]¶ Constructor
- Parameters
left (biogeme.expressions.Expression) – first arithmetic expression
right (biogeme.expressions.Expression) – second arithmetic expression
-
-
class
biogeme.expressions.
PanelLikelihoodTrajectory
(child)[source]¶ Bases:
biogeme.expressions.UnaryOperator
Likelihood of a sequences of observations for the same individual
-
__init__
(child)[source]¶ Constructor
- Parameters
child (biogeme.expressions.Expression) – first arithmetic expression
-
audit
(database=None)[source]¶ Performs various checks on the expressions.
- Parameters
database (biogeme.database.Database) – database object
- Returns
tuple listOfErrors, listOfWarnings
- Return type
list(string), list(string)
-
-
class
biogeme.expressions.
Plus
(left, right)[source]¶ Bases:
biogeme.expressions.BinaryOperator
Addition expression
-
__init__
(left, right)[source]¶ Constructor
- Parameters
left (biogeme.expressions.Expression) – first arithmetic expression
right (biogeme.expressions.Expression) – second arithmetic expression
-
-
class
biogeme.expressions.
Power
(left, right)[source]¶ Bases:
biogeme.expressions.BinaryOperator
Power expression
-
__init__
(left, right)[source]¶ Constructor
- Parameters
left (biogeme.expressions.Expression) – first arithmetic expression
right (biogeme.expressions.Expression) – second arithmetic expression
-
-
class
biogeme.expressions.
RandomVariable
(name)[source]¶ Bases:
biogeme.expressions.Elementary
Random variable for numerical integration
-
__init__
(name)[source]¶ Constructor
- Parameters
name (string.) – name of the random variable involved in the integration.
-
audit
(database=None)[source]¶ Performs various checks on the expressions.
- Parameters
database (biogeme.database.Database) – database object
- Returns
tuple listOfErrors, listOfWarnings
- Return type
list(string), list(string)
-
dictOfRandomVariables
()[source]¶ Recursively extract the random variables appearing in the expression, and store them in a dictionary.
Overloads the generic function.
- Returns
returns a dict with the random variables appearing in the expression the keys being their names.
- Return type
dict(string:biogeme.expressions.Expression)
-
getSignature
()[source]¶ The signature of a string characterizing an expression.
This is designed to be communicated to C++, so that the expression can be reconstructed in this environment.
The list contains the following elements:
the name of the expression between < >
the id of the expression between { }
the name of the random variable,
the unique ID, preceeded by a comma,
the ID of the random variable.
Consider the following expression:
\[2 \beta_1 V_1 - \frac{\exp(-\beta_2 V_2) }{ \beta_3 (\beta_2 \geq \beta_1)}.\]It is defined as:
2 * beta1 * Variable1 - expressions.exp(-beta2*Variable2) / (beta3 * (beta2 >= beta1))
And its signature is:
[b'<Numeric>{4780527008},2', b'<Beta>{4780277152}"beta1"[0],0,0', b'<Times>{4780526952}(2),4780527008,4780277152', b'<Variable>{4511837152}"Variable1",5,2', b'<Times>{4780527064}(2),4780526952,4511837152', b'<Beta>{4780277656}"beta2"[0],1,1', b'<UnaryMinus>{4780527120}(1),4780277656', b'<Variable>{4511837712}"Variable2",6,3', b'<Times>{4780527176}(2),4780527120,4511837712', b'<exp>{4780527232}(1),4780527176', b'<Beta>{4780277264}"beta3"[1],2,0', b'<Beta>{4780277656}"beta2"[0],1,1', b'<Beta>{4780277152}"beta1"[0],0,0', b'<GreaterOrEqual>{4780527288}(2),4780277656,4780277152', b'<Times>{4780527344}(2),4780277264,4780527288', b'<Divide>{4780527400}(2),4780527232,4780527344', b'<Minus>{4780527456}(2),4780527064,4780527400']
- Returns
list of the signatures of an expression and its children.
- Return type
list(string)
- Raises
biogeme.exceptions.biogemeError – if no id has been defined for elementary expression
biogeme.exceptions.biogemeError – if no id has been defined for random variable
-
setSpecificIndices
(indicesOfFreeBetas, indicesOfFixedBetas, indicesOfRandomVariables, indicesOfDraws)[source]¶ Provide an index to all elementary expressions, specific to their type Overloads the generic function.
- Parameters
indicesOfFreeBetas (dict(string:int)) – dictionary mapping the name of the free betas with their index
indicesOfFixedBetas (dict(string:int)) – dictionary mapping the name of the fixed betas with their index
indicesOfRandomVariables (dict(string:int)) – dictionary mapping the name of the random variables with their index
indicesOfDraws (dict(string:int)) – dictionary mapping the name of the draws with their index
- Raises
biogemeError – if no index is available for a random variable.
-
-
class
biogeme.expressions.
Times
(left, right)[source]¶ Bases:
biogeme.expressions.BinaryOperator
Multiplication expression
-
__init__
(left, right)[source]¶ Constructor
- Parameters
left (biogeme.expressions.Expression) – first arithmetic expression
right (biogeme.expressions.Expression) – second arithmetic expression
-
-
class
biogeme.expressions.
UnaryMinus
(child)[source]¶ Bases:
biogeme.expressions.UnaryOperator
Unary minus expression
-
__init__
(child)[source]¶ Constructor
- Parameters
child (biogeme.expressions.Expression) – first arithmetic expression
-
-
class
biogeme.expressions.
UnaryOperator
(child)[source]¶ Bases:
biogeme.expressions.Expression
Base class for arithmetic expressions that are unary operators.
Such an expression is the result of the modification of another expressions, typically changing its sign.
-
__init__
(child)[source]¶ Constructor
- Parameters
child (biogeme.expressions.Expression) – first arithmetic expression
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
child
¶ child
-
-
class
biogeme.expressions.
Variable
(name)[source]¶ Bases:
biogeme.expressions.Elementary
Explanatory variable
This represents the explanatory variables of the choice model. Typically, they come from the data set.
-
audit
(database=None)[source]¶ Performs various checks on the expressions.
- Parameters
database (biogeme.database.Database) – database object
- Returns
tuple listOfErrors, listOfWarnings
- Return type
list(string), list(string)
- Raises
biogemeError – if no database is provided.
biogemeError – if the name of the variable does not appear in the database.
-
dictOfVariables
()[source]¶ Recursively extract the variables appearing in the expression, and store them in a dictionary.
Overload the generic function.
- Returns
returns a dict with the variables appearing in the expression the keys being their names. Here, it contains only one element.
- Return type
dict(string:biogeme.expressions.Expression)
-
getSignature
()[source]¶ The signature of a string characterizing an expression.
This is designed to be communicated to C++, so that the expression can be reconstructed in this environment.
The list contains the following elements:
the name of the expression between < >
the id of the expression between { }
the name of the variable,
the unique ID, preceeded by a comma.
the variabvle ID, preceeded by a comma.
Consider the following expression:
\[2 \beta_1 V_1 - \frac{\exp(-\beta_2 V_2) }{ \beta_3 (\beta_2 \geq \beta_1)}.\]It is defined as:
2 * beta1 * Variable1 - expressions.exp(-beta2*Variable2) / (beta3 * (beta2 >= beta1))
And its signature is:
[b'<Numeric>{4780527008},2', b'<Beta>{4780277152}"beta1"[0],0,0', b'<Times>{4780526952}(2),4780527008,4780277152', b'<Variable>{4511837152}"Variable1",5,2', b'<Times>{4780527064}(2),4780526952,4511837152', b'<Beta>{4780277656}"beta2"[0],1,1', b'<UnaryMinus>{4780527120}(1),4780277656', b'<Variable>{4511837712}"Variable2",6,3', b'<Times>{4780527176}(2),4780527120,4511837712', b'<exp>{4780527232}(1),4780527176', b'<Beta>{4780277264}"beta3"[1],2,0', b'<Beta>{4780277656}"beta2"[0],1,1', b'<Beta>{4780277152}"beta1"[0],0,0', b'<GreaterOrEqual>{4780527288}(2),4780277656,4780277152', b'<Times>{4780527344}(2),4780277264,4780527288', b'<Divide>{4780527400}(2),4780527232,4780527344', b'<Minus>{4780527456}(2),4780527064,4780527400']
- Returns
list of the signatures of an expression and its children.
- Return type
list(string)
- Raises
biogeme.exceptions.biogemeError – if no id has been defined for elementary expression
biogeme.exceptions.biogemeError – if no id has been defined for variable
-
-
class
biogeme.expressions.
bioDraws
(name, drawType)[source]¶ Bases:
biogeme.expressions.Elementary
Draws for Monte-Carlo integration
-
__init__
(name, drawType)[source]¶ Constructor
- Parameters
name (string) – name of the random variable with a series of draws.
drawType (string) – type of draws.
-
audit
(database=None)[source]¶ Performs various checks on the expressions.
- Parameters
database (biogeme.database.Database) – database object
- Returns
tuple listOfErrors, listOfWarnings
- Return type
list(string), list(string)
-
dictOfDraws
()[source]¶ Recursively extract the random variables (draws for Monte-Carlo). Overloads the generic function. appearing in the expression, and store them in a dictionary.
- Returns
dict where the keys are the random variables and the elements the type of draws. Here, contains only one element.
- Return type
dict(string:string)
-
getSignature
()[source]¶ The signature of a string characterizing an expression.
This is designed to be communicated to C++, so that the expression can be reconstructed in this environment.
The list contains the following elements:
the name of the expression between < >
the id of the expression between { }, preceeded by a comma
the name of the draws
the unique ID (preceeded by a comma),
the draw ID (preceeded by a comma).
Consider the following expression:
\[2 \beta_1 V_1 - \frac{\exp(-\beta_2 V_2) }{ \beta_3 (\beta_2 \geq \beta_1)}.\]It is defined as:
2 * beta1 * Variable1 - expressions.exp(-beta2*Variable2) / (beta3 * (beta2 >= beta1))
And its signature is:
[b'<Numeric>{4780527008},2', b'<Beta>{4780277152}"beta1"[0],0,0', b'<Times>{4780526952}(2),4780527008,4780277152', b'<Variable>{4511837152}"Variable1",5,2', b'<Times>{4780527064}(2),4780526952,4511837152', b'<Beta>{4780277656}"beta2"[0],1,1', b'<UnaryMinus>{4780527120}(1),4780277656', b'<Variable>{4511837712}"Variable2",6,3', b'<Times>{4780527176}(2),4780527120,4511837712', b'<exp>{4780527232}(1),4780527176', b'<Beta>{4780277264}"beta3"[1],2,0', b'<Beta>{4780277656}"beta2"[0],1,1', b'<Beta>{4780277152}"beta1"[0],0,0', b'<GreaterOrEqual>{4780527288}(2),4780277656,4780277152', b'<Times>{4780527344}(2),4780277264,4780527288', b'<Divide>{4780527400}(2),4780527232,4780527344', b'<Minus>{4780527456}(2),4780527064,4780527400']
- Returns
list of the signatures of an expression and its children.
- Return type
list(string)
- Raises
biogeme.exceptions.biogemeError – if no id has been defined for elementary expression
biogeme.exceptions.biogemeError – if no id has been defined for draw
-
setDrawIndex
(idsOfDraws)[source]¶ Provide an index to a series of draw for a random variable. Overload the generic function.
- Parameters
idsOfDraws (dict(string:int)) – dictionary mapping the name of the draws with their id.
- Raises
biogemeError – if no id is available for a draw.
-
setSpecificIndices
(indicesOfFreeBetas, indicesOfFixedBetas, indicesOfRandomVariables, indicesOfDraws)[source]¶ Provide an index to all elementary expressions, specific to their type Overloads the generic function.
- Parameters
indicesOfFreeBetas (dict(string:int)) – dictionary mapping the name of the free betas with their index
indicesOfFixedBetas (dict(string:int)) – dictionary mapping the name of the fixed betas with their index
indicesOfRandomVariables (dict(string:int)) – dictionary mapping the name of the random variables with their index
indicesOfDraws (dict(string:int)) – dictionary mapping the name of the draws with their index
- Raises
biogemeError – if no index is available for one draw type.
-
-
class
biogeme.expressions.
bioLinearUtility
(listOfTerms)[source]¶ Bases:
biogeme.expressions.Expression
When the utility function is linear, it is expressed as a list of terms, where a parameter multiplies a variable.
-
__init__
(listOfTerms)[source]¶ Constructor
- Parameters
listOfTerms (list(biogeme.expressions.Expression, biogeme.expressions.Expression)) – a list of tuple. Each tuple contains first a beta parameter, second the name of a variable.
- Raises
biogeme.exceptions.biogemeError – if the object is not a list of tuples (parameter, variable)
-
betas
¶ list of parameters
-
dictOfBetas
(free=True, fixed=False)[source]¶ Extract the set of parameters from the expression.
- Parameters
free (bool) – if True, the free parameters are included. Default: True.
fixed (bool) – if True, the fixed parameters are included. Default: False.
- Returns
a dict with the beta parameters appearing in the expression, the keys being the names of the parameters.
- Return type
dict(string:biogeme.expressions.Expression)
-
dictOfDraws
()[source]¶ Recursively extract the random variables (draws for Monte-Carlo). Overloads the generic function. appearing in the expression, and store them in a dictionary.
- Returns
dict where the keys are the random variables and the elements the type of draws. Here, returns an empty dict.
- Return type
dict(string:string)
-
dictOfRandomVariables
()[source]¶ Recursively extract the random variables appearing in the expression, and store them in a dictionary.
- Returns
returns a dict with the random variables appearing in the expression the keys being their names.
- Return type
dict(string:biogeme.expressions.Expression)
-
dictOfVariables
()[source]¶ Recursively extract the variables appearing in the expression, and store them in a dictionary.
Overloads the generic function.
- Returns
returns a dict with the variables appearing in the expression the keys being their names.
- Return type
dict(string:biogeme.expressions.Expression)
-
getSignature
()[source]¶ The signature of a string characterizing an expression.
This is designed to be communicated to C++, so that the expression can be reconstructed in this environment.
The list contains the following elements:
the signatures of all the children expressions,
the name of the expression between < >
the id of the expression between { }
the number of terms in the utility ( )
for each term:
the id of the beta parameter
the unique id of the beta parameter
the name of the parameter
the id of the variable
the unique id of the variable
the name of the variable
Consider the following expression:
\[2 \beta_1 V_1 - \frac{\exp(-\beta_2 V_2) }{ \beta_3 (\beta_2 \geq \beta_1)}.\]It is defined as:
2 * beta1 * Variable1 - expressions.exp(-beta2*Variable2) / (beta3 * (beta2 >= beta1))
And its signature is:
[b'<Numeric>{4780527008},2', b'<Beta>{4780277152}"beta1"[0],0,0', b'<Times>{4780526952}(2),4780527008,4780277152', b'<Variable>{4511837152}"Variable1",5,2', b'<Times>{4780527064}(2),4780526952,4511837152', b'<Beta>{4780277656}"beta2"[0],1,1', b'<UnaryMinus>{4780527120}(1),4780277656', b'<Variable>{4511837712}"Variable2",6,3', b'<Times>{4780527176}(2),4780527120,4511837712', b'<exp>{4780527232}(1),4780527176', b'<Beta>{4780277264}"beta3"[1],2,0', b'<Beta>{4780277656}"beta2"[0],1,1', b'<Beta>{4780277152}"beta1"[0],0,0', b'<GreaterOrEqual>{4780527288}(2),4780277656,4780277152', b'<Times>{4780527344}(2),4780277264,4780527288', b'<Divide>{4780527400}(2),4780527232,4780527344', b'<Minus>{4780527456}(2),4780527064,4780527400']
- Returns
list of the signatures of an expression and its children.
- Return type
list(string)
-
listOfTerms
¶ List of terms
-
setOfBetas
(free=True, fixed=False)[source]¶ Extract the set of parameters from the expression.
- Parameters
free (bool) – if True, the free parameters are included. Default: True.
fixed (bool) – if True, the fixed parameters are included. Default: False.
- Returns
returns a set with the beta parameters appearing in the expression.
- Return type
-
variables
¶ list of variables
-
-
class
biogeme.expressions.
bioMax
(left, right)[source]¶ Bases:
biogeme.expressions.BinaryOperator
Maximum of two expressions
-
__init__
(left, right)[source]¶ Constructor
- Parameters
left (biogeme.expressions.Expression) – first arithmetic expression
right (biogeme.expressions.Expression) – second arithmetic expression
-
-
class
biogeme.expressions.
bioMin
(left, right)[source]¶ Bases:
biogeme.expressions.BinaryOperator
Minimum of two expressions
-
__init__
(left, right)[source]¶ Constructor
- Parameters
left (biogeme.expressions.Expression) – first arithmetic expression
right (biogeme.expressions.Expression) – second arithmetic expression
-
-
class
biogeme.expressions.
bioMultSum
(listOfExpressions)[source]¶ Bases:
biogeme.expressions.Expression
This expression returns the sum of several other expressions.
It is a generalization of ‘Plus’ for more than two terms
-
__init__
(listOfExpressions)[source]¶ Constructor
- Parameters
listOfExpressions (list(biogeme.expressions.Expression)) – list of objects representing the terms of the sum.
- Raises
biogemeError – if one of the expressions is invalid, that is neither a numeric value or a biogeme.expressions.Expression object.
-
-
class
biogeme.expressions.
bioNormalCdf
(child)[source]¶ Bases:
biogeme.expressions.UnaryOperator
Cumulative Distribution Function of a normal random variable
-
__init__
(child)[source]¶ Constructor
- Parameters
child (biogeme.expressions.Expression) – first arithmetic expression
-
-
biogeme.expressions.
defineNumberingOfElementaryExpressions
(collectionOfFormulas, variableNames)[source]¶ Provides indices for elementary expressions
The numbering is done in the following order:
free betas,
fixed betas,
random variables for numrerical integration,
random variables for Monte-Carlo integration,
variables
The numbering convention will be performed for all expressions together, so that the same elementary expressions in several expressions will have the same index.
- Parameters
collectionOfFormulas (list(biogeme.expressions.Expression)) – collection of Biogeme expressions.
variableNames (list(string)) – list of the names of the variables
- Returns
dict, free, freeNames, fixed, fixedNames, rv, rvNames, draws, drawsNames where
dict is a dictionary mapping the names of the elementary expressions with their index,
free is a dict with the free betas,
freeNames is a list of the names of the free betas,
fixed is a dict with the fixed betas,
fixedNames is the list of the names of the fixed betas,
rv is a dict with the random variables for numerical integration,
rvNames is a list with their names,
draws is a dict of the draws, and
drawsNames is a list with their names.
- Return type
tuple(dict(str: class Expression), dict(str: class Beta), list(str), dict(str: class Beta), list(str), dict(str: class RandomVariable), list(str), dict(str: class bioDraws), list(str))
- Raises
biogemeError – if some elementary expressions are defined more than once.
-
class
biogeme.expressions.
exp
(child)[source]¶ Bases:
biogeme.expressions.UnaryOperator
exponential expression
-
__init__
(child)[source]¶ Constructor
- Parameters
child (biogeme.expressions.Expression) – first arithmetic expression
-
-
biogeme.expressions.
isNumeric
(obj)[source]¶ Identifies if an object is numeric, that is int, float or bool.
- Parameters
obj (object) – any object
- Returns
True if the object is int, float or bool.
- Return type
bool
-
class
biogeme.expressions.
log
(child)[source]¶ Bases:
biogeme.expressions.UnaryOperator
logarithm expression
-
__init__
(child)[source]¶ Constructor
- Parameters
child (biogeme.expressions.Expression) – first arithmetic expression
-