biogeme.expressions.parameter_overrides module

Explicit replacement of parameters in Biogeme expressions.

The objects in this module are deliberately independent of BIOGEME. They are intended to be used as a preprocessing step, before formulas are passed to an estimation or simulation object.

class biogeme.expressions.parameter_overrides.ParameterOverrides[source]

Bases: object

Collection of explicit replacements keyed by the original Beta name.

Replacements are stored in insertion order. They are applied simultaneously and exactly once: if a replacement contains a Beta whose name is also overridden, that inserted Beta is not rewritten again during the same call.

items()[source]

Return the registered overrides in insertion order.

Return type:

ItemsView[str, Expression]

set(name, replacement)[source]

Register a replacement for a Beta name.

Parameters:
  • name (str) – Name of the original Beta to replace.

  • replacement (Expression | float | int | bool) – Any valid Biogeme expression, including a numeric value which is converted to Numeric.

Raises:
  • BiogemeError – if name is not a non-empty string.

  • DuplicateError – if the name was already registered.

  • TypeError – if replacement is not a valid expression.

Return type:

None

biogeme.expressions.parameter_overrides.apply_parameter_overrides(formulas, overrides)[source]

Apply explicit Beta replacements to formulas without mutating them.

The complete expression graph is copied before replacement. Every Beta with a matching name is replaced, including Betas in non-selected catalog alternatives. The function performs one simultaneous pass: an expression inserted as a replacement is never inspected for further replacements.

Parameters:
  • formulas (Expression | dict[str, Expression | float | int | bool]) – One Biogeme expression or a dictionary of formulas.

  • overrides (ParameterOverrides) – Explicit replacements keyed by Beta name.

Return type:

Expression | dict[str, Expression | float | int | bool]

Returns:

A new expression or formula dictionary with the replacements applied. With no overrides, the original object is returned.

Raises:

BiogemeError – for invalid formulas, an invalid override object, or an override name absent from all formula branches.