.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/timing/plot01_logit.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_timing_plot01_logit.py: Timing of a logit model ======================= Michel Bierlaire Tue Jul 2 14:48:52 2024 .. GENERATED FROM PYTHON SOURCE LINES 9-12 .. code-block:: Python from tabulate import tabulate .. GENERATED FROM PYTHON SOURCE LINES 13-14 See the data processing script: :ref:`swissmetro_data`. .. GENERATED FROM PYTHON SOURCE LINES 14-31 .. code-block:: Python from biogeme.data.swissmetro 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, read_data, ) from biogeme.expressions import Beta, Expression from biogeme.models import loglogit from timing_expression import timing_expression .. GENERATED FROM PYTHON SOURCE LINES 32-33 Parameters to be estimated. .. GENERATED FROM PYTHON SOURCE LINES 33-39 .. code-block:: Python asc_car = Beta('asc_car', 0, None, None, 0) asc_train = Beta('asc_train', 0, None, None, 0) b_time = Beta('b_time', 0, None, None, 0) b_cost = Beta('b_cost', 0, None, None, 0) .. GENERATED FROM PYTHON SOURCE LINES 40-41 Definition of the utility functions. .. GENERATED FROM PYTHON SOURCE LINES 41-45 .. code-block:: Python v_train = asc_train + b_time * TRAIN_TT_SCALED + b_cost * TRAIN_COST_SCALED v_swissmetro = b_time * SM_TT_SCALED + b_cost * SM_COST_SCALED v_car = asc_car + b_time * CAR_TT_SCALED + b_cost * CAR_CO_SCALED .. GENERATED FROM PYTHON SOURCE LINES 46-47 Associate utility functions with the numbering of alternatives. .. GENERATED FROM PYTHON SOURCE LINES 47-49 .. code-block:: Python v = {1: v_train, 2: v_swissmetro, 3: v_car} .. GENERATED FROM PYTHON SOURCE LINES 50-51 Associate the availability conditions with the alternatives. .. GENERATED FROM PYTHON SOURCE LINES 51-53 .. code-block:: Python av = {1: TRAIN_AV_SP, 2: SM_AV, 3: CAR_AV_SP} .. GENERATED FROM PYTHON SOURCE LINES 54-56 Definition of the model. This is the contribution of each observation to the log likelihood function. .. GENERATED FROM PYTHON SOURCE LINES 56-59 .. code-block:: Python log_probability: Expression = loglogit(v, av, CHOICE) # .. GENERATED FROM PYTHON SOURCE LINES 60-62 .. code-block:: Python database = read_data() .. GENERATED FROM PYTHON SOURCE LINES 63-64 Timing .. GENERATED FROM PYTHON SOURCE LINES 64-69 .. code-block:: Python timing_results = timing_expression( the_expression=log_probability, the_database=database ) results = [[k, f'{v:.3g}'] for k, v in timing_results.items()] print(tabulate(results, headers=['', 'Time (in sec.)'], tablefmt='github')) .. _sphx_glr_download_auto_examples_timing_plot01_logit.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot01_logit.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot01_logit.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot01_logit.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_