biogeme.expressions.unary_expressions module

Arithmetic expressions accepted by Biogeme: unary operators

author:

Michel Bierlaire

date:

Sat Sep 9 15:51:53 2023

class biogeme.expressions.unary_expressions.BelongsTo(child, the_set)[source]

Bases: UnaryOperator

Check if a value belongs to a set

Parameters:
  • child (ExpressionOrNumeric)

  • the_set (set[float])

audit(database=None)[source]

Performs various checks on the expressions.

Parameters:

database (Database) – database object

Returns:

tuple list_of_errors, list_of_warnings

Return type:

list(string), list(string)

get_signature()[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:

  1. the signatures of the child expression,

  2. the name of the expression between < >

  3. the id of the expression between { }, preceded by a comma

  4. the id of the children, preceded by a comma

  5. the index of the randon variable, preceded 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)

class biogeme.expressions.unary_expressions.Derive(child, name)[source]

Bases: UnaryOperator

Derivative with respect to an elementary expression

Parameters:
  • child (ExpressionOrNumeric)

  • name (str)

get_signature()[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:

  1. the signatures of the child expression,

  2. the name of the expression between < >

  3. the id of the expression between { }

  4. the id of the child, preceded 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)

class biogeme.expressions.unary_expressions.Integrate(child, name)[source]

Bases: UnaryOperator

Numerical integration

Parameters:
  • child (ExpressionOrNumeric)

  • name (str)

audit(database=None)[source]

Performs various checks on the expressions.

Parameters:

database (Database) – database object

Returns:

tuple list_of_errors, list_of_warnings

Return type:

list(string), list(string)

check_rv()[source]

List of random variables defined outside of ‘Integrate’

Returns:

List of names of variables

Return type:

list(str)

get_signature()[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:

  1. the signatures of the child expression,

  2. the name of the expression between < >

  3. the id of the expression between { }, preceeded by a comma

  4. the id of the children, preceeded by a comma

  5. 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)

class biogeme.expressions.unary_expressions.MonteCarlo(child)[source]

Bases: UnaryOperator

Monte Carlo integration

Parameters:

child (ExpressionOrNumeric)

audit(database=None)[source]

Performs various checks on the expressions.

Parameters:

database (Database) – database object

Returns:

tuple list_of_errors, list_of_warnings

Return type:

list(string), list(string)

check_draws()[source]

List of draws defined outside of ‘MonteCarlo’

Returns:

List of names of variables

Return type:

list(str)

class biogeme.expressions.unary_expressions.PanelLikelihoodTrajectory(child)[source]

Bases: UnaryOperator

Likelihood of a sequences of observations for the same individual

Parameters:

child (ExpressionOrNumeric)

audit(database=None)[source]

Performs various checks on the expressions.

Parameters:

database (Database) – database object

Returns:

tuple list_of_errors, list_of_warnings

Return type:

list(string), list(string)

check_panel_trajectory()[source]

List of variables defined outside of ‘PanelLikelihoodTrajectory’

Returns:

List of names of variables

Return type:

list(str)

count_panel_trajectory_expressions()[source]

Count the number of times the PanelLikelihoodTrajectory is used in the formula.

Return type:

int

class biogeme.expressions.unary_expressions.PowerConstant(child, exponent)[source]

Bases: UnaryOperator

Raise the argument to a constant power.

Parameters:
  • child (ExpressionOrNumeric)

  • exponent (float)

get_signature()[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:

  1. the signatures of the child expression,

  2. the name of the expression between < >

  3. the id of the expression between { }, preceded by a comma

  4. the id of the children, preceded by a comma

  5. the index of the randon variable, preceded 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)

get_value()[source]

Evaluates the value of the expression

Returns:

value of the expression

Return type:

float

class biogeme.expressions.unary_expressions.UnaryMinus(child)[source]

Bases: UnaryOperator

Unary minus expression

Parameters:

child (ExpressionOrNumeric)

getValue()[source]

Warning

This function is deprecated. Use get_value() instead.

Kept for backward compatibility

Return type:

float

get_value()[source]

Evaluates the value of the expression

Returns:

value of the expression

Return type:

float

class biogeme.expressions.unary_expressions.UnaryOperator(child)[source]

Bases: 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.

Parameters:

child (ExpressionOrNumeric)

class biogeme.expressions.unary_expressions.bioNormalCdf(child)[source]

Bases: UnaryOperator

Cumulative Distribution Function of a normal random variable

Parameters:

child (ExpressionOrNumeric)

class biogeme.expressions.unary_expressions.cos(child)[source]

Bases: UnaryOperator

cosine expression

Parameters:

child (ExpressionOrNumeric)

getValue()[source]

Warning

This function is deprecated. Use get_value() instead.

Kept for backward compatibility

Return type:

float

get_value()[source]

Evaluates the value of the expression

Returns:

value of the expression

Return type:

float

class biogeme.expressions.unary_expressions.exp(child)[source]

Bases: UnaryOperator

exponential expression

Parameters:

child (ExpressionOrNumeric)

getValue()[source]

Warning

This function is deprecated. Use get_value() instead.

Kept for backward compatibility

Return type:

float

get_value()[source]

Evaluates the value of the expression

Returns:

value of the expression

Return type:

float

class biogeme.expressions.unary_expressions.log(child)[source]

Bases: UnaryOperator

logarithm expression

Parameters:

child (ExpressionOrNumeric)

getValue()[source]

Warning

This function is deprecated. Use get_value() instead.

Kept for backward compatibility

Return type:

float

get_value()[source]

Evaluates the value of the expression

Returns:

value of the expression

Return type:

float

class biogeme.expressions.unary_expressions.logzero(child)[source]

Bases: UnaryOperator

logarithm expression. Returns zero if the argument is zero.

Parameters:

child (ExpressionOrNumeric)

getValue()[source]

Warning

This function is deprecated. Use get_value() instead.

Kept for backward compatibility

Return type:

float

get_value()[source]

Evaluates the value of the expression

Returns:

value of the expression

Return type:

float

class biogeme.expressions.unary_expressions.sin(child)[source]

Bases: UnaryOperator

sine expression

Parameters:

child (ExpressionOrNumeric)

getValue()[source]

Warning

This function is deprecated. Use get_value() instead.

Kept for backward compatibility

Return type:

float

get_value()[source]

Evaluates the value of the expression

Returns:

value of the expression

Return type:

float