biogeme.expressions.weighted_logsum_exp module¶
Arithmetic expressions accepted by Biogeme: weighted log-sum-exp.
Michel Bierlaire
- class biogeme.expressions.weighted_logsum_exp.WeightedLogSumExp(terms, weights)[source]¶
Bases:
ExpressionWeighted log-sum-exp expression.
It represents
\[\log\left(\sum_i w_i \exp(x_i)\right).\]By convention, if the weighted sum is exactly zero, the expression returns zero, consistently with
logzero(MultipleSum(...)).- Parameters:
terms (list[ExpressionOrNumeric])
weights (list[ExpressionOrNumeric])
- recursive_construct_jax_function(numerically_safe)[source]¶
Generate a JAX function for weighted log-sum-exp.
Terms and weights are each compiled into one stacked JAX function. This keeps the weighted log-sum-exp node closer to a vector primitive and avoids maintaining one runtime list for all children together.
- Return type:
Callable[[Array,Array,Array,Array],Array]- Parameters:
numerically_safe (bool)
- property terms¶
Terms \(x_i\).
- property weights¶
Weights \(w_i\).
- biogeme.expressions.weighted_logsum_exp.weighted_logsumexp(terms, weights)[source]¶
Factory function for weighted log-sum-exp.
- Return type:
- Parameters:
terms (list[Expression | float | int | bool])
weights (list[Expression | float | int | bool])