biogeme.expressions.elem module¶
Arithmetic expressions accepted by Biogeme: Elem
Michel Bierlaire Fri Apr 25 2025, 10:33:58
- class biogeme.expressions.elem.Elem(dict_of_expressions, key_expression)[source]¶
Bases:
ExpressionThis returns the element of a dictionary. The key is evaluated from an expression and must return an integer, possibly negative.
- Parameters:
dict_of_expressions (dict[int, ExpressionOrNumeric])
key_expression (ExpressionOrNumeric)
- 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. The flat part is irrelevant for this expression.
- Return type:
- dict_of_expressions¶
dict of expressions
- get_value()[source]¶
Evaluates the value of the expression
- Returns:
value of the expression
- Return type:
float
- Raises:
BiogemeError – if the calculated key is not present in the dictionary.
- recursive_construct_jax_function(numerically_safe)[source]¶
Generates recursively a function to be used by PyMc. Must be overloaded by each expression :rtype:
Callable[[Array,Array,Array,Array],array] :return: the expression in TensorVariable format, suitable for PyMc- Parameters:
numerically_safe (bool)
- Return type:
Callable[[Array, Array, Array, Array], array]
- recursive_construct_pymc_model_builder()[source]¶
Return a PyTensor builder that selects the expression associated with the evaluated integer key.
Implementation detail: build a stack of branch tensors (one per key) and use an index derived from argmax(key_vec == key) to pick the correct slice. If the key does not match any provided key, the result is zero-like (same shape/dtype as a branch).