.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/montecarlo/plot_b04normal_mixture_numerical.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_montecarlo_plot_b04normal_mixture_numerical.py: Numerical integration ===================== Calculation of a mixtures of logit models where the integral is calculated using numerical integration. Michel Bierlaire, EPFL Sat Jun 28 2025, 21:09:58 .. GENERATED FROM PYTHON SOURCE LINES 12-32 .. code-block:: Python from IPython.core.display_functions import display from biogeme.biogeme import BIOGEME from biogeme.expressions import IntegrateNormal, RandomVariable from biogeme.models import logit from swissmetro_one import ( CAR_AV_SP, CAR_CO_SCALED, CAR_TT_SCALED, CHOICE, SM_AV, SM_COST_SCALED, SM_TT_SCALED, TRAIN_AV_SP, TRAIN_COST_SCALED, TRAIN_TT_SCALED, database, ) .. GENERATED FROM PYTHON SOURCE LINES 33-34 Parameters .. GENERATED FROM PYTHON SOURCE LINES 34-41 .. code-block:: Python asc_car = 0.137 asc_train = -0.402 asc_sm = 0 b_time = -2.26 b_time_s = 1.66 b_cost = -1.29 .. GENERATED FROM PYTHON SOURCE LINES 42-44 Define a random parameter, normally distributed, designed to be used for integration .. GENERATED FROM PYTHON SOURCE LINES 44-47 .. code-block:: Python omega = RandomVariable('omega') b_time_rnd = b_time + b_time_s * omega .. GENERATED FROM PYTHON SOURCE LINES 48-49 Definition of the utility functions .. GENERATED FROM PYTHON SOURCE LINES 49-53 .. code-block:: Python v_train = asc_train + b_time_rnd * TRAIN_TT_SCALED + b_cost * TRAIN_COST_SCALED v_swissmetro = asc_sm + b_time_rnd * SM_TT_SCALED + b_cost * SM_COST_SCALED v_car = asc_car + b_time_rnd * CAR_TT_SCALED + b_cost * CAR_CO_SCALED .. GENERATED FROM PYTHON SOURCE LINES 54-55 Associate utility functions with the numbering of alternatives .. GENERATED FROM PYTHON SOURCE LINES 55-57 .. code-block:: Python util = {1: v_train, 2: v_swissmetro, 3: v_car} .. GENERATED FROM PYTHON SOURCE LINES 58-59 Associate the availability conditions with the alternatives .. GENERATED FROM PYTHON SOURCE LINES 59-61 .. code-block:: Python av = {1: TRAIN_AV_SP, 2: SM_AV, 3: CAR_AV_SP} .. GENERATED FROM PYTHON SOURCE LINES 62-63 The choice model is a logit, with availability conditions .. GENERATED FROM PYTHON SOURCE LINES 63-66 .. code-block:: Python integrand = logit(util, av, CHOICE) numerical_integral = IntegrateNormal(integrand, 'omega') .. GENERATED FROM PYTHON SOURCE LINES 67-69 .. code-block:: Python simulate = {'Numerical': numerical_integral} .. GENERATED FROM PYTHON SOURCE LINES 70-72 .. code-block:: Python biosim = BIOGEME(database, simulate) .. GENERATED FROM PYTHON SOURCE LINES 73-76 .. code-block:: Python results = biosim.simulate(the_beta_values={}) display(results) .. rst-class:: sphx-glr-script-out .. code-block:: none Numerical 0 0.63785 .. GENERATED FROM PYTHON SOURCE LINES 77-78 .. code-block:: Python print('Mixture of logit - numerical integration: ', results.iloc[0]['Numerical']) .. rst-class:: sphx-glr-script-out .. code-block:: none Mixture of logit - numerical integration: 0.6378498356723438 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.178 seconds) .. _sphx_glr_download_auto_examples_montecarlo_plot_b04normal_mixture_numerical.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_b04normal_mixture_numerical.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_b04normal_mixture_numerical.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_b04normal_mixture_numerical.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_