biogeme.expressions.convert module¶
Convert expressions to float and vice versa
Michel Bierlaire Tue Mar 25 18:43:36 2025
- biogeme.expressions.convert.expression_to_value(expression, betas=None)[source]¶
Convert an expression to a float value, if possible.
- Parameters:
expression (
Expression
|float
|int
|bool
) – The expression to convert. Can be a boolean, a numeric value, or an instance of Expression.betas (
dict
[str
,float
] |None
) – Optional dictionary of beta values used to initialize the expression, if applicable.
- Return type:
float
- Returns:
The numerical value of the expression as a float.
- Raises:
TypeError – If the input is not a valid expression type.
BiogemeError – If the expression cannot be evaluated to a numeric value.
- biogeme.expressions.convert.get_dict_expressions(the_dict)[source]¶
If the dictionary contains float, they are transformed into a numerical expression.
- Return type:
dict
[int
,Expression
]- Parameters:
the_dict (dict[int, Expression | float | int | bool])
- biogeme.expressions.convert.get_dict_values(the_dict, betas=None)[source]¶
If the dictionary contains Expressions, they are transformed into a numerical expression.
- Return type:
dict
[int
,float
]- Parameters:
the_dict (dict[int, Expression | float | int | bool])
betas (dict[str, float] | None)
- biogeme.expressions.convert.validate_and_convert(expression)[source]¶
Validates the expression and returns the converted expression if necessary.
- Return type:
- Parameters:
expression (Expression | float | int | bool)