biogeme.expressions.log_cross_nested module

Arithmetic expressions accepted by Biogeme: cross-nested logit.

class biogeme.expressions.log_cross_nested.LogCrossNested(util, av, nests, choice, mu=None, _log_recommendation=True)[source]

Bases: Expression

Log probability of the cross-nested logit model.

This expression computes the CNL probability directly, instead of expanding it through generic WeightedLogSumExp and LogLogit nodes.

It implements:

\[H_i = \log \sum_m \alpha_{im}^{\mu_m} \exp(\mu_m V_i) B_m^{(1-\mu_m)/\mu_m}\]

where

\[B_m = \sum_j a_j \alpha_{jm}^{\mu_m} \exp(\mu_m V_j).\]

The log probability is then

\[H_y - \log \sum_j a_j \exp(H_j).\]

If the optional global homogeneity parameter mu is provided, the explicit-mu CNL formulation is used. If mu is None, the standard formulation is used.

Parameters:
  • util (dict[int, ExpressionOrNumeric])

  • av (dict[int, ExpressionOrNumeric] | None)

  • nests (NestsForCrossNestedLogit | OldNestsForCrossNestedLogit)

  • choice (ExpressionOrNumeric)

  • mu (ExpressionOrNumeric | None)

  • _log_recommendation (bool)

deep_flat_copy()[source]

Deep flat copy.

Return type:

LogCrossNested

get_value()[source]

Evaluate the expression using NumPy.

Return type:

float

logit_choice_avail()[source]

Return availability structures appearing in this expression.

Return type:

list[LogitTuple]

recursive_construct_jax_function(numerically_safe)[source]

Generate a compact JAX function for CNL log probability.

Return type:

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

Parameters:

numerically_safe (bool)

recursive_construct_pymc_model_builder()[source]

Return a vectorized, log-domain PyTensor builder for CNL.

Return type:

PymcModelBuilderType

uses_sparse_memberships = False
biogeme.expressions.log_cross_nested.index_of(key, keys)[source]

Return the index of a key in a vector of alternative identifiers.

Return type:

Array

Parameters:
  • key (float)

  • keys (Array)