Source code for biogeme.expressions.panel_likelihood_trajectory
"""Arithmetic expressions accepted by Biogeme: PanelLikelihoodTrajectoryMichel Bierlaire11.04.2025 09:29"""from__future__importannotationsimportcopyimportloggingfrombiogeme.exceptionsimportBiogemeErrorfrom.importadd_prefix_suffix_to_all_variablesfrom.base_expressionsimportExpression,ExpressionOrNumericfrom.conditional_sumimportConditionalSum,ConditionalTermTuplefrom.expimportexpfrom.jax_utilsimportJaxFunctionTypefrom.logimportlogfrom.variableimportVariablelogger=logging.getLogger(__name__)
[docs]classPanelLikelihoodTrajectory(Expression):""" Likelihood of a sequences of observations for the same individual """def__init__(self,child:ExpressionOrNumeric):"""Constructor :param child: first arithmetic expression :type child: biogeme.expressions.Expression """# In this case, the formula itself is not a child. It will have to be manipulated by the function# `set_maximum_number_of_observations_per_individual`. Therefore, the super().__init__() has no argument.super().__init__()self.child:Expression|None=Noneself.initial_formula:Expression=childself.maximum_number_of_observations_per_individual:int|None=None
[docs]defdeep_flat_copy(self)->PanelLikelihoodTrajectory:"""Provides a copy of the expression. It is deep in the sense that it generates copies of the children. It is flat in the sense that any `MultipleExpression` is transformed into the currently selected expression. The flat part is irrelevant for this expression. """copy_child=self.initial_formula.deep_flat_copy()the_copy=PanelLikelihoodTrajectory(child=copy_child)ifself.maximum_number_of_observations_per_individualisnotNone:the_copy.set_maximum_number_of_observations_per_individual(self.maximum_number_of_observations_per_individual)returnthe_copy
[docs]defrecursive_construct_jax_function(self,numerically_safe:bool)->JaxFunctionType:""" Generates recursively a function to be used by biogeme_jax. Must be overloaded by each expression :return: the function takes two parameters: the parameters, and one row of the database. """ifself.childisNone:error_msg='The PanelLikelihoodTrajectory has not been prepared before being evaluated.'raiseBiogemeError(error_msg)ifself.maximum_number_of_observations_per_individualisNone:error_msg=('Maximum number of observations per individual has not been defined.')raiseBiogemeError(error_msg)returnself.child.recursive_construct_jax_function(numerically_safe=numerically_safe)