.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/tutorials/plot_b05_simulation.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_tutorials_plot_b05_simulation.py: Using the estimated model ========================= Once the model has been estimated, it can be applied to calculate the choice probability under several Michel Bierlaire, EPFL Sun Jun 15 2025, 08:30:48 .. GENERATED FROM PYTHON SOURCE LINES 10-20 .. code-block:: Python import pandas as pd from IPython.core.display_functions import display from biogeme.biogeme import BIOGEME from biogeme.database import Database from biogeme.models import logit from biogeme.results_processing import EstimationResults from tutorial_model import utilities .. GENERATED FROM PYTHON SOURCE LINES 21-22 Read the estimation results from a file .. GENERATED FROM PYTHON SOURCE LINES 22-43 .. code-block:: Python filename = 'saved_results/first_model.yaml' estimation_results = EstimationResults.from_yaml_file(filename=filename) scenarios = { 'ID': pd.Series([1, 2]), 'auto_time': pd.Series( [ 10.0, 12.0, ] ), 'transit_time': pd.Series( [ 4.4, 13.0, ] ), } pandas_dataframe = pd.DataFrame(scenarios) display(pandas_dataframe) .. rst-class:: sphx-glr-script-out .. code-block:: none ID auto_time transit_time 0 1 10.0 4.4 1 2 12.0 13.0 .. GENERATED FROM PYTHON SOURCE LINES 44-56 .. code-block:: Python car_id = 0 transit_id = 1 proba_car = logit(utilities, None, car_id) proba_transit = logit(utilities, None, transit_id) simulate = { 'Utility car': utilities[car_id], 'Utility transit': utilities[transit_id], 'Proba. car': proba_car, 'Proba. transit': proba_transit, } .. GENERATED FROM PYTHON SOURCE LINES 57-58 The data frame is used to initialize the Biogeme database. .. GENERATED FROM PYTHON SOURCE LINES 58-60 .. code-block:: Python scenarios_database = Database('ben_akiva_lerman_scenarios', pandas_dataframe) .. GENERATED FROM PYTHON SOURCE LINES 61-62 Now we can perform simulation .. GENERATED FROM PYTHON SOURCE LINES 62-65 .. code-block:: Python biogeme_object = BIOGEME(scenarios_database, simulate) results = biogeme_object.simulate(the_beta_values=estimation_results.get_beta_values()) .. GENERATED FROM PYTHON SOURCE LINES 66-67 The results are stored in a Pamdas dataframe, one row for each scenario in the original database. .. GENERATED FROM PYTHON SOURCE LINES 67-68 .. code-block:: Python display(results) .. rst-class:: sphx-glr-script-out .. code-block:: none Utility car Utility transit Proba. car Proba. transit 0 -0.768671 -0.233683 0.369354 0.630646 1 -0.874891 -0.690428 0.454015 0.545985 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.373 seconds) .. _sphx_glr_download_auto_examples_tutorials_plot_b05_simulation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_b05_simulation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_b05_simulation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_b05_simulation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_