biogeme.expressions.log_sampled_logit module

Arithmetic expressions accepted by Biogeme: sampled logit.

class biogeme.expressions.log_sampled_logit.LogSampledLogit(utilities, log_probabilities, choice=0)[source]

Bases: Expression

Log probability for a sampled multinomial logit model.

This expression is designed for sampling of alternatives. It represents

\[V_0 - \omega_0 - \log \sum_{j \in S} \exp(V_j - \omega_j),\]

where alternative 0 is the chosen alternative by construction, and \(\omega_j\) is the log of the sampling probability correction stored in the generated database.

This replaces a large expanded expression of the form

loglogit(
    {
        i: utility_i - log_sampling_probability_i
        for i in sample
    },
    None,
    0,
)

by a single expression node with a compact JAX implementation.

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

  • log_probabilities (dict[int, ExpressionOrNumeric])

  • choice (ExpressionOrNumeric)

deep_flat_copy()[source]

Deep flat copy.

Return type:

LogSampledLogit

get_value()[source]

Evaluate the sampled logit log probability 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 sampled logit.

Return type:

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

Parameters:

numerically_safe (bool)