biogeme.expressions.panel_log_likelihood module

class biogeme.expressions.panel_log_likelihood.PanelLogLikelihood(child)[source]

Bases: Expression

Aggregate per-observation log-probabilities into per-individual log-likelihoods.

This expression assumes its child evaluates, for a given dataframe, to a 1-D tensor of shape (obs,) containing the log-probability of each observation. It then sums these log-probabilities within each individual (panel) and returns a 1-D tensor of shape (indiv,).

Notes

  • Intended for Bayesian estimation with PyMC, which operates in log-space.

  • The panel/individual id column name is taken from self.panel_index_name if available, otherwise it defaults to 'ID'.

  • A coord named Dimension.INDIVIDUALS is created on the active PyMC model if it does not yet exist, to label the individuals’ axis.

type child:

Expression | float | int | bool

param child:

Expression that returns per-observation log-probabilities when evaluated by the PyMC builder.

deep_flat_copy()[source]

Return a deep/flat copy of the expression.

Return type:

PanelLogLikelihood

Returns:

A structurally independent copy whose child is a deep/flat copy.

recursive_construct_pymc_model_builder()[source]

Build a PyMC evaluation closure that returns per-individual log-likelihoods, using a precomputed ContiguousPanelMap to aggregate rows belonging to the same individual via cumulative-sum + index differences.

Return type:

PymcModelBuilderType

Parameters:

child (ExpressionOrNumeric)