.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/swissmetro/plot_b21c_process_pareto.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_swissmetro_plot_b21c_process_pareto.py: .. _plot_b21c_process_pareto: 21c. Re-estimate the Pareto optimal models ========================================== The assisted specification algorithm generates a file containing the pareto optimal specification. This script is designed to re-estimate the Pareto optimal models. The catalog of specifications is defined in :ref:`plot_b21b_multiple_models_spec` . Michel Bierlaire, EPFL Sat Jun 28 2025, 20:58:22 .. GENERATED FROM PYTHON SOURCE LINES 15-37 .. code-block:: Python import biogeme.biogeme_logging as blog from biogeme.results_processing import compile_estimation_results try: import matplotlib.pyplot as plt can_plot = True except ModuleNotFoundError: can_plot = False from biogeme_optimization.exceptions import OptimizationError from biogeme.assisted import ParetoPostProcessing from plot_b21b_multiple_models_spec import the_biogeme, PARETO_FILE_NAME PATH_PARETO_FILE_NAME = f'saved_results/{PARETO_FILE_NAME}' logger = blog.get_screen_logger(blog.INFO) logger.info('Example b21c_process_pareto.py') CSV_FILE = 'b21_process_pareto.csv' SEP_CSV = ',' .. rst-class:: sphx-glr-script-out .. code-block:: none income_segmentation=INCOME: [{0: 'inc-zero', 1: 'inc-under50', 2: 'inc-50-100', 3: 'inc-100+', 4: 'inc-unknown'}] ref: inc-zero Example b21c_process_pareto.py .. GENERATED FROM PYTHON SOURCE LINES 38-43 The constructor of the Pareto post processing object takes two arguments: - the biogeme object, - the name of the file where the algorithm has stored the estimated models. .. GENERATED FROM PYTHON SOURCE LINES 43-48 .. code-block:: Python the_pareto_post = ParetoPostProcessing( biogeme_object=the_biogeme, pareto_file_name=PATH_PARETO_FILE_NAME, ) .. rst-class:: sphx-glr-script-out .. code-block:: none Unable to read file saved_results/b21_multiple_models.pareto. Pareto set empty. .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: Python the_pareto_post.log_statistics() .. rst-class:: sphx-glr-script-out .. code-block:: none Pareto: 0 Considered: 0 Removed: 0 .. GENERATED FROM PYTHON SOURCE LINES 52-54 Complete re-estimation of the best models, including the calculation of the statistics. .. GENERATED FROM PYTHON SOURCE LINES 54-56 .. code-block:: Python all_results = the_pareto_post.reestimate(recycle=False) .. GENERATED FROM PYTHON SOURCE LINES 57-60 .. code-block:: Python summary, description = compile_estimation_results(all_results, use_short_names=True) print(summary) .. rst-class:: sphx-glr-script-out .. code-block:: none Empty DataFrame Columns: [] Index: [] .. GENERATED FROM PYTHON SOURCE LINES 61-64 .. code-block:: Python print(f'Summary table available in {CSV_FILE}') summary.to_csv(CSV_FILE, sep=SEP_CSV) .. rst-class:: sphx-glr-script-out .. code-block:: none Summary table available in b21_process_pareto.csv .. GENERATED FROM PYTHON SOURCE LINES 65-66 Explanation of the short names of the models. .. GENERATED FROM PYTHON SOURCE LINES 66-73 .. code-block:: Python with open(CSV_FILE, 'a', encoding='utf-8') as f: print('\n\n', file=f) for k, v in description.items(): if k != v: print(f'{k}: {v}') print(f'{k}{SEP_CSV}{v}', file=f) .. GENERATED FROM PYTHON SOURCE LINES 74-82 The following plot illustrates all models that have been estimated. Each dot corresponds to a model. The x-coordinate corresponds to the negative log-likelihood. The y-coordinate corresponds to the number of parameters. If the shape of the dot is a circle, it means that it corresponds to a Pareto optimal model. If the shape is a cross, it means that the model has been Pareto optimal at some point during the algorithm and later removed as a new model dominating it has been found. .. GENERATED FROM PYTHON SOURCE LINES 82-90 .. code-block:: Python if can_plot: try: _ = the_pareto_post.plot( label_x='Negative loglikelihood', label_y='Number of parameters' ) plt.show() except OptimizationError as e: print(f'No plot available: {e}') .. image-sg:: /auto_examples/swissmetro/images/sphx_glr_plot_b21c_process_pareto_001.png :alt: plot b21c process pareto :srcset: /auto_examples/swissmetro/images/sphx_glr_plot_b21c_process_pareto_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none No plot available: Cannot plot an empty Pareto set .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.081 seconds) .. _sphx_glr_download_auto_examples_swissmetro_plot_b21c_process_pareto.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_b21c_process_pareto.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_b21c_process_pareto.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_b21c_process_pareto.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_