.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/latent/choice_model.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_latent_choice_model.py: Specification of the choice model ================================= Implementation of the utility functions Michel Bierlaire, EPFL Wed Sept 03 2025, 08:13:34 .. GENERATED FROM PYTHON SOURCE LINES 12-25 .. code-block:: Python from optima import ( CostCarCHF, MarginalCostPT, TimeCar_hour, TimePT_hour, WaitingTimePT, distance_category, distance_km, ) from biogeme.expressions import Beta, exp .. GENERATED FROM PYTHON SOURCE LINES 26-27 Choice model: parameters .. GENERATED FROM PYTHON SOURCE LINES 27-74 .. code-block:: Python choice_asc_car_short_dist = Beta('choice_asc_car_short_dist', 0.0, None, None, 0) choice_asc_car_long_dist = Beta('choice_asc_car_long_dist', 0.0, None, None, 0) choice_asc_pt_short_dist = Beta('choice_asc_pt_short_dist', 0, None, None, 0) choice_asc_pt_long_dist = Beta('choice_asc_pt_long_dist', 0, None, None, 0) choice_beta_cost = Beta('choice_beta_cost', -1, None, None, 1) choice_beta_dist = Beta('choice_beta_dist', 0, None, None, 0) choice_beta_time_car_short_dist = Beta( 'choice_beta_time_car_short_dist', 0, None, None, 0 ) choice_beta_time_car_long_dist = Beta( 'choice_beta_time_car_long_dist', 0, None, None, 0 ) choice_beta_time_pt_short_dist = Beta( 'choice_beta_time_pt_short_dist', 0, None, None, 0 ) choice_beta_time_pt_long_dist = Beta('choice_beta_time_pt_long_dist', 0, None, None, 0) choice_beta_waiting_time = Beta('choice_beta_waiting_time', 0, None, None, 0) log_scale_choice_model_long_dist = Beta( 'log_scale_choice_model_long_dist', 0, None, None, 0 ) log_scale_choice_model_medium_dist = Beta( 'log_scale_choice_model_medium_dist', 0, None, None, 0 ) log_scale_choice_model_short_dist = Beta( 'log_scale_choice_model_short_dist', 0, None, None, 0 ) log_scale_choice_model = log_scale_choice_model_short_dist * ( distance_category == 1 ) + log_scale_choice_model_long_dist * (distance_category == 2) scale_choice_model = exp(log_scale_choice_model) choice_asc_car = choice_asc_car_short_dist * ( distance_category == 1 ) + choice_asc_car_long_dist * (distance_category == 2) choice_asc_pt = choice_asc_pt_short_dist * ( distance_category == 1 ) + choice_asc_pt_long_dist * (distance_category == 2) choice_beta_time_pt = choice_beta_time_pt_short_dist * ( distance_category == 1 ) + choice_beta_time_pt_long_dist * (distance_category == 2) choice_beta_time_car = choice_beta_time_car_short_dist * ( distance_category == 1 ) + choice_beta_time_car_long_dist * (distance_category == 2) .. GENERATED FROM PYTHON SOURCE LINES 75-76 Definition of utility functions: .. GENERATED FROM PYTHON SOURCE LINES 76-89 .. code-block:: Python v_public_transport = scale_choice_model * ( choice_asc_pt + choice_beta_time_pt * TimePT_hour + choice_beta_waiting_time * WaitingTimePT / 60 + choice_beta_cost * MarginalCostPT ) v_car = scale_choice_model * ( choice_asc_car + choice_beta_time_car * TimeCar_hour + choice_beta_cost * CostCarCHF ) v_slow_modes = scale_choice_model * (choice_beta_dist * distance_km) .. GENERATED FROM PYTHON SOURCE LINES 90-91 Associate utility functions with the numbering of alternatives .. GENERATED FROM PYTHON SOURCE LINES 91-92 .. code-block:: Python v = {0: v_public_transport, 1: v_car, 2: v_slow_modes} .. _sphx_glr_download_auto_examples_latent_choice_model.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: choice_model.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: choice_model.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: choice_model.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_