biogeme.expressions.log_nested module¶
Arithmetic expressions accepted by Biogeme: nested logit.
- class biogeme.expressions.log_nested.LogNested(util, av, nests, choice, mu=None)[source]¶
Bases:
ExpressionLog probability of the nested logit model.
This expression computes the nested logit probability directly, instead of expanding it through generic MEV and LogLogit nodes.
For each nest \(m\), define
\[B_m = \sum_{j \in C_m} a_j \exp(\mu_m V_j).\]For an alternative \(i \in C_m\), the standard formulation uses
\[H_i = \mu_m V_i + \left(\frac{1}{\mu_m} - 1\right) \log B_m.\]If the optional global homogeneity parameter
muis provided, the explicit-mu formulation uses\[H_i = \log \mu + \mu_m V_i + \left(\frac{\mu}{\mu_m} - 1\right) \log B_m.\]The log probability is
\[H_y - \log \sum_j a_j \exp(H_j).\]Alternatives that do not belong to any explicit nest are treated as singleton alternatives, consistently with
NestsForNestedLogit.alone.- Parameters:
util (dict[int, ExpressionOrNumeric])
av (dict[int, ExpressionOrNumeric] | None)
nests (NestsForNestedLogit | OldNestsForNestedLogit)
choice (ExpressionOrNumeric)
mu (ExpressionOrNumeric | None)
- 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 nested logit log probability.
- Return type:
Callable[[Array,Array,Array,Array],Array]- Parameters:
numerically_safe (bool)
- recursive_construct_pymc_model_builder()[source]¶
Return a vectorized PyTensor builder for nested-logit log probabilities.
The builder mirrors the compact NumPy and JAX implementations above. In particular, scalar PyMC random variables (nest parameters and the optional global homogeneity parameter) are broadcast to all observations, while utility, availability, and choice expressions are evaluated row by row.
- Return type: