biogeme.expressions.multiple_expressions module

Defines the interface for a catalog of expressions that may be considered in a specification

author:

Michel Bierlaire

date:

Sun Feb 5 15:34:56 2023

class biogeme.expressions.multiple_expressions.CatalogItem(catalog_name, item_index, item_name)[source]

Bases: NamedTuple

Parameters:
  • catalog_name (str)

  • item_index (int)

  • item_name (str)

catalog_name: str

Alias for field number 0

item_index: int

Alias for field number 1

item_name: str

Alias for field number 2

class biogeme.expressions.multiple_expressions.MultipleExpression(name)[source]

Bases: Expression

Interface for catalog of expressions that are interchangeable. Only one of them defines the specification. They are designed to be modified algorithmically.

Parameters:

name (str)

catalog_size()[source]

Provide the size of the catalog

Returns:

number of expressions in the catalog

Return type:

int

change_init_values(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.

check_draws()[source]

Set of draws defined outside of ‘MonteCarlo’

Returns:

List of names of variables

Return type:

set(str)

check_panel_trajectory()[source]

Set of variables defined outside of ‘PanelLikelihoodTrajectory’

Returns:

List of names of variables

Return type:

set(str)

check_rv()[source]

Set of random variables defined outside of ‘Integrate’

Returns:

List of names of variables

Return type:

set(str)

count_panel_trajectory_expressions()[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

dict_of_elementary_expression(the_type)[source]

Extract a dict with all elementary expressions of a specific type

Parameters:

the_type (TypeOfElementaryExpression) – the type of expression

Returns:

returns a dict with the variables appearing in the expression the keys being their names.

Return type:

dict(string:biogeme.expressions.Expression)

embed_expression(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

Parameters:

t (str)

fix_betas(beta_values, prefix=None, suffix=None)[source]

Fix all the values of the Beta parameters appearing in the dictionary

Parameters:
  • beta_values (dict(str: float)) – dictionary containing the betas to be fixed (as key) and their value.

  • prefix (str) – if not None, the parameter is renamed, with a prefix defined by this argument.

  • suffix (str) – if not None, the parameter is renamed, with a suffix defined by this argument.

getValue()[source]

Warning

This function is deprecated. Use get_value() instead.

Kept for backward compatibility

Return type:

float

get_children()[source]

Retrieve the list of children

Returns:

list of children

Return type:

list(Expression)

get_elementary_expression(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:

biogeme.expressions.Expression

get_id()[source]

Retrieve the id of the expression used in the signature

Returns:

id of the object

Return type:

int

abstract get_iterator()[source]

Returns an iterator on NamedExpression

Return type:

Iterator[NamedExpression]

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 all the children expressions,

  2. the name of the expression between < >

  3. the id of the expression between { }

  4. the number of children between ( )

  5. the ids of each 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)

get_status_id_manager()[source]

Check the elementary expressions that are associated with an ID manager.

Returns:

two sets of elementary expressions, those with and without an ID manager.

Return type:

tuple(set(str), set(str))

get_value()[source]

Evaluates the value of the expression

Returns:

value of the expression

Return type:

float

rename_elementary(names, prefix=None, suffix=None)[source]

Rename elementary expressions by adding a prefix and/or a suffix

Parameters:
  • names (list(str)) – names of expressions to rename

  • prefix (str) – if not None, the expression is renamed, with a prefix defined by this argument.

  • suffix (str) – if not None, the expression is renamed, with a suffix defined by this argument.

abstract selected()[source]

Return the selected expression and its name

Returns:

the name and the selected expression

Return type:

tuple(str, biogeme.expressions.Expression)

selected_expression()[source]

Obtain the selected expression

Returns:

the selected expression

Return type:

biogeme.expressions.Expression

selected_name()[source]

Obtain the name of the selection

Returns:

the name of the selected expression

Return type:

str

set_id_manager(id_manager)[source]

The ID manager contains the IDs of the elementary expressions.

It is externally created, as it may nee to coordinate the numbering of several expressions. It is stored only in the expressions of type Elementary.

Parameters:

id_manager (class IdManager) – ID manager to be propagated to the elementary expressions. If None, all the IDs are set to None.

set_of_elementary_expression(the_type)[source]

Extract a dict with all elementary expressions of a specific type

Parameters:

the_type (TypeOfElementaryExpression) – the type of expression

Returns:

returns a set with the names of the elementary expressions

Return type:

set(string.Expression)

class biogeme.expressions.multiple_expressions.NamedExpression(name, expression)[source]

Bases: NamedTuple

Parameters:
expression: Expression

Alias for field number 1

name: str

Alias for field number 0