NestedLogit.make_P_nest#
- NestedLogit.make_P_nest(U, W, betas_fixed, lambdas_nests, level)[source]#
Calculate the probability of choosing a nest.
This function collates the exponentiated inclusive value (
exp_W_nest
) for each alternative group (nest), sums them, and then normalizes across nests to obtain the probability of selecting a nest. The within-nest conditional probabilities (P_y_given
) are computed in themake_exp_nest
method.This is used within the PyMC model to construct the tree-based aggregation of utilities, where lower-level nodes (alternative-specific utilities) are passed upward in the tree structure to compute nest-level and top-level choice probabilities.
- Parameters:
- U
TensorVariable
Tensor of systematic utilities with shape
(n_obs, n_alternatives)
.- W
TensorVariable
|None
Fixed covariates design matrix (if used), else
None
.- betas_fixed
TensorVariable
Alternative-specific coefficients for the fixed covariates.
- lambdas_nests
TensorVariable
A Beta random variable for each of the nests
- level
str
Which nesting level to compute (“top” or “mid”), indicating whether to compute probabilities for top-level or mid-level nests.
- U
- Returns:
- conditional_probs
dict
[str
,dict
[str
,TensorVariable
]] Dictionary for each nest containing: - “exp”: the exponentiated inclusive value of the nest. - “P_y_given”: conditional choice probabilities within the nest.
- nest_probs
dict
[str
,TensorVariable
] Dictionary mapping each nest to its overall selection probability.
- conditional_probs
- Raises:
ValueError
If the nesting structure is invalid or the nest name is not found.