biogeme.expressions.base_expressions module

Arithmetic expressions accepted by Biogeme: generic class

Michel Bierlaire Tue Mar 25 17:00:02 2025

class biogeme.expressions.base_expressions.Expression[source]

Bases: object

This is the general arithmetic expression in biogeme. It serves as a base class for concrete expressions.

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 parameters, and the values are the new value for the parameters.

children

List of children expressions

deep_flat_copy()[source]

Provides a copy of the expression. It is deep in the sense that it generates copies of the children. It is flat in the sense that any MultipleExpression is transformed into the currently selected expression.

Return type:

Expression

embed_expression(name)[source]

Check if an expression embeds a specific operator

Return type:

bool

Parameters:

name (type)

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.

fixed_beta_values

values of the Beta that are not estimated

get_children()[source]

Retrieve the list of children

Returns:

list of children

Return type:

list(Expression)

get_class_name()[source]

Obtain the name of the top class of the expression structure

Returns:

the name of the class

Return type:

string

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_value()[source]

Calculates the value of the expression if it is simple

Return type:

float

is_complex()[source]

Determine if the expression is complex.

An expression is considered complex if its own _is_complex flag is set or if any of its children are complex.

Return type:

bool

Returns:

True if the expression or any of its children is complex.

logit_choice_avail()[source]

Extract a dict with all elementary expressions of a specific type

Returns:

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

Return type:

dict(string:biogeme.expressions.Expression)

recursive_construct_jax_function(numerically_safe)[source]

Generates recursively a function to be used by biogeme_jax. Must be overloaded by each expression :rtype: Callable[[Array, Array, Array, Array], array] :return: the function takes two parameters: the parameters, and one row of the database.

Parameters:

numerically_safe (bool)

Return type:

Callable[[Array, Array, Array, Array], array]

requires_draws()[source]
set_maximum_number_of_observations_per_individual(max_number)[source]
Return type:

None

Parameters:

max_number (int)

set_specific_id(the_name, specific_id, the_type)[source]

The elementary IDs identify the position of each element in the corresponding datab

Parameters:

the_type (TypeOfElementaryExpression)

class biogeme.expressions.base_expressions.LogitTuple(choice, availabilities)[source]

Bases: NamedTuple

Parameters:
availabilities: dict[int, Expression]

Alias for field number 1

choice: Expression

Alias for field number 0