.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/assisted/plot_b08selected_specification.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_assisted_plot_b08selected_specification.py: One model among many ==================== We consider the model with 432 specifications defined in :ref:`everything_spec_section`. We select one specification and estimate it. See `Bierlaire and Ortelli (2023) `_. Michel Bierlaire, EPFL Sun Apr 27 2025, 18:38:30 .. GENERATED FROM PYTHON SOURCE LINES 14-24 .. code-block:: Python from IPython.core.display_functions import display import biogeme.biogeme_logging as blog from biogeme.biogeme import BIOGEME from biogeme.results_processing import get_pandas_estimated_parameters from everything_spec import av, database, model_catalog logger = blog.get_screen_logger(level=blog.INFO) .. GENERATED FROM PYTHON SOURCE LINES 25-28 The code characterizing the specification should be copied from the .pareto file generated by the algorithm, or from one of the glossaries illustrated in earlier examples. .. GENERATED FROM PYTHON SOURCE LINES 28-37 .. code-block:: Python SPEC_ID = ( 'asc:GA-LUGGAGE;' 'b_cost_gen_altspec:generic;' 'b_time:FIRST;' 'b_time_gen_altspec:generic;' 'model_catalog:logit;' 'train_tt_catalog:power' ) .. GENERATED FROM PYTHON SOURCE LINES 38-39 the spec_id, and used as usual. .. GENERATED FROM PYTHON SOURCE LINES 39-46 .. code-block:: Python the_biogeme = BIOGEME.from_configuration( config_id=SPEC_ID, multiple_expression=model_catalog, database=database, ) the_biogeme.model_name = 'my_favorite_model' .. rst-class:: sphx-glr-script-out .. code-block:: none Biogeme parameters read from biogeme.toml. .. GENERATED FROM PYTHON SOURCE LINES 47-48 Calculate of the null log-likelihood for reporting. .. GENERATED FROM PYTHON SOURCE LINES 48-50 .. code-block:: Python the_biogeme.calculate_null_loglikelihood(av) .. rst-class:: sphx-glr-script-out .. code-block:: none -11093.627345287434 .. GENERATED FROM PYTHON SOURCE LINES 51-52 Estimate the parameters. .. GENERATED FROM PYTHON SOURCE LINES 52-54 .. code-block:: Python results = the_biogeme.estimate() .. rst-class:: sphx-glr-script-out .. code-block:: none *** Initial values of the parameters are obtained from the file __my_favorite_model.iter Cannot read file __my_favorite_model.iter. Statement is ignored. Starting values for the algorithm: {} As the model is not too complex, we activate the calculation of second derivatives. To change this behavior, modify the algorithm to "simple_bounds" in the TOML file. Optimization algorithm: hybrid Newton/BFGS with simple bounds [simple_bounds] ** Optimization: Newton with trust region for simple bounds Iter. asc_train_ref asc_train_diff_ asc_train_diff_ asc_train_diff_ b_time_ref b_time_diff_1st square_tt_coef cube_tt_coef b_cost asc_car_ref asc_car_diff_GA asc_car_diff_on asc_car_diff_se Function Relgrad Radius Rho 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.1e+04 0.26 0.5 -0.56 - 1 -0.5 -0.00046 -0.39 -0.015 -0.5 -0.5 0 0 -0.11 0.021 -0.061 -0.017 -0.0049 9e+03 4.7 5 1.1 ++ 2 -0.5 -0.00046 -0.39 -0.015 -0.5 -0.5 0 0 -0.11 0.021 -0.061 -0.017 -0.0049 9e+03 4.7 2.5 -8.3 - 3 -0.5 -0.00046 -0.39 -0.015 -0.5 -0.5 0 0 -0.11 0.021 -0.061 -0.017 -0.0049 9e+03 4.7 1.2 -6.8 - 4 -0.5 -0.00046 -0.39 -0.015 -0.5 -0.5 0 0 -0.11 0.021 -0.061 -0.017 -0.0049 9e+03 4.7 0.62 -5.7 - 5 -0.5 -0.00046 -0.39 -0.015 -0.5 -0.5 0 0 -0.11 0.021 -0.061 -0.017 -0.0049 9e+03 4.7 0.31 -4.9 - 6 -0.5 -0.00046 -0.39 -0.015 -0.5 -0.5 0 0 -0.11 0.021 -0.061 -0.017 -0.0049 9e+03 4.7 0.16 -4.1 - 7 -0.5 -0.00046 -0.39 -0.015 -0.5 -0.5 0 0 -0.11 0.021 -0.061 -0.017 -0.0049 9e+03 4.7 0.078 -3 - 8 -0.5 -0.00046 -0.39 -0.015 -0.5 -0.5 0 0 -0.11 0.021 -0.061 -0.017 -0.0049 9e+03 4.7 0.039 -3.1 - 9 -0.5 -0.00046 -0.39 -0.015 -0.5 -0.5 0 0 -0.11 0.021 -0.061 -0.017 -0.0049 9e+03 4.7 0.02 -3.7 - 10 -0.5 -0.00046 -0.39 -0.015 -0.5 -0.5 0 0 -0.11 0.021 -0.061 -0.017 -0.0049 9e+03 4.7 0.0098 -4.4 - 11 -0.5 -0.00046 -0.39 -0.015 -0.5 -0.5 0 0 -0.11 0.021 -0.061 -0.017 -0.0049 9e+03 4.7 0.0049 -5 - 12 -0.5 -0.00046 -0.39 -0.015 -0.5 -0.5 0 0 -0.11 0.021 -0.061 -0.017 -0.0049 9e+03 4.7 0.0024 -3.9 - 13 -0.5 -0.00046 -0.39 -0.015 -0.5 -0.5 0 0 -0.11 0.021 -0.061 -0.017 -0.0049 9e+03 4.7 0.0012 -2.4 - 14 -0.5 -0.00046 -0.39 -0.015 -0.5 -0.5 0 0 -0.11 0.021 -0.061 -0.017 -0.0049 9e+03 4.7 0.00061 -1.2 - 15 -0.5 -0.00046 -0.39 -0.015 -0.5 -0.5 0 0 -0.11 0.021 -0.061 -0.017 -0.0049 9e+03 4.7 0.00031 -0.13 - 16 -0.5 -0.00016 -0.39 -0.016 -0.5 -0.5 0.00031 -0.00031 -0.11 0.021 -0.061 -0.017 -0.0052 9e+03 2.4 0.00031 0.67 + 17 -0.5 -5.2e-05 -0.39 -0.016 -0.5 -0.5 0.00061 -0.00024 -0.11 0.021 -0.061 -0.017 -0.0053 9e+03 1.1 0.00031 0.81 + 18 -0.5 5.4e-05 -0.39 -0.016 -0.5 -0.5 0.00092 -0.00026 -0.11 0.021 -0.061 -0.017 -0.0053 9e+03 0.089 0.0031 1 ++ 19 -0.5 0.0011 -0.39 -0.016 -0.5 -0.5 0.004 -0.00027 -0.11 0.02 -0.062 -0.018 -0.0053 9e+03 0.39 0.031 1 ++ 20 -0.51 0.012 -0.39 -0.016 -0.52 -0.51 0.034 -0.00041 -0.13 0.018 -0.069 -0.024 -0.0059 8.9e+03 0.17 0.31 1 ++ 21 -0.56 0.19 -0.26 -0.016 -0.65 -0.54 0.13 -0.00083 -0.43 0.042 -0.17 -0.078 -0.014 8.7e+03 0.75 3.1 0.99 ++ 22 -0.56 0.19 -0.26 -0.016 -0.65 -0.54 0.13 -0.00083 -0.43 0.042 -0.17 -0.078 -0.014 8.7e+03 0.75 1.5 -32 - 23 -0.56 0.19 -0.26 -0.016 -0.65 -0.54 0.13 -0.00083 -0.43 0.042 -0.17 -0.078 -0.014 8.7e+03 0.75 0.76 -10 - 24 -0.88 0.95 0.18 -0.01 -1.1 -0.65 -0.11 0.00021 -1.1 0.17 -0.52 -0.22 -0.054 8.5e+03 9.2 0.76 0.51 + 25 -0.97 1.3 0.38 0.23 -1.8 -0.51 -0.066 1.7e-05 -0.76 0.28 -1 -0.094 -0.29 8.2e+03 2.4 0.76 0.8 + 26 -0.97 1.3 0.38 0.23 -1.8 -0.51 -0.066 1.7e-05 -0.76 0.28 -1 -0.094 -0.29 8.2e+03 2.4 0.38 -7.5 - 27 -0.97 1.3 0.38 0.23 -1.8 -0.51 -0.066 1.7e-05 -0.76 0.28 -1 -0.094 -0.29 8.2e+03 2.4 0.19 -2.1 - 28 -0.97 1.3 0.38 0.23 -1.8 -0.51 -0.066 1.7e-05 -0.76 0.28 -1 -0.094 -0.29 8.2e+03 2.4 0.095 -0.75 - 29 -1.1 1.3 0.32 0.23 -1.9 -0.56 -0.13 0.00029 -0.74 0.24 -1 -0.11 -0.29 8.2e+03 23 0.095 0.23 + 30 -1.1 1.4 0.41 0.27 -1.9 -0.62 -0.1 0.0002 -0.79 0.25 -1.1 -0.11 -0.32 8.2e+03 6.5 0.095 0.86 + 31 -1.2 1.4 0.43 0.32 -1.8 -0.62 -0.11 0.0002 -0.75 0.21 -1.1 -0.099 -0.36 8.2e+03 0.61 0.95 1 ++ 32 -1.3 1.4 0.51 0.55 -1.7 -0.67 -0.1 0.00019 -0.77 0.19 -1.2 -0.082 -0.53 8.1e+03 0.12 9.5 1 ++ 33 -1.3 1.4 0.52 0.54 -1.7 -0.67 -0.1 0.00019 -0.77 0.19 -1.2 -0.084 -0.55 8.1e+03 0.014 95 1 ++ 34 -1.3 1.4 0.52 0.54 -1.7 -0.67 -0.1 0.00019 -0.77 0.19 -1.2 -0.083 -0.56 8.1e+03 1.9e-05 9.5e+02 1 ++ 35 -1.3 1.4 0.52 0.54 -1.7 -0.67 -0.1 0.00019 -0.77 0.19 -1.2 -0.084 -0.56 8.1e+03 0.00019 9.5e+03 1 ++ 36 -1.3 1.4 0.52 0.54 -1.7 -0.67 -0.1 0.00019 -0.77 0.19 -1.2 -0.084 -0.56 8.1e+03 1.4e-07 9.5e+03 1 ++ Optimization algorithm has converged. Relative gradient: 1.4271273279837524e-07 Cause of termination: Relative gradient = 1.4e-07 <= 6.1e-06 Number of function evaluations: 72 Number of gradient evaluations: 35 Number of hessian evaluations: 17 Algorithm: Newton with trust region for simple bound constraints Number of iterations: 37 Proportion of Hessian calculation: 17/17 = 100.0% Optimization time: 0:00:00.966750 Calculate second derivatives and BHHH File my_favorite_model.html has been generated. File my_favorite_model.yaml has been generated. .. GENERATED FROM PYTHON SOURCE LINES 55-57 .. code-block:: Python print(results.short_summary()) .. rst-class:: sphx-glr-script-out .. code-block:: none Results for model my_favorite_model Nbr of parameters: 13 Sample size: 10719 Excluded data: 9 Null log likelihood: -11093.63 Final log likelihood: -8148.851 Likelihood ratio test (null): 5889.553 Rho square (null): 0.265 Rho bar square (null): 0.264 Akaike Information Criterion: 16323.7 Bayesian Information Criterion: 16418.34 .. GENERATED FROM PYTHON SOURCE LINES 58-59 Get the results in a pandas table .. GENERATED FROM PYTHON SOURCE LINES 59-63 .. code-block:: Python pandas_results = get_pandas_estimated_parameters( estimation_results=results, ) display(pandas_results) .. rst-class:: sphx-glr-script-out .. code-block:: none Name Value ... Robust t-stat. Robust p-value 0 asc_train_ref -1.305391 ... -16.898724 0.000000e+00 1 asc_train_diff_GA 1.389666 ... 19.323449 0.000000e+00 2 asc_train_diff_one_lugg 0.516161 ... 6.435480 1.230835e-10 3 asc_train_diff_several_lugg 0.538605 ... 3.150186 1.631667e-03 4 b_time_ref -1.693539 ... -18.726679 0.000000e+00 5 b_time_diff_1st_class -0.666079 ... -7.582703 3.375078e-14 6 square_tt_coef -0.103594 ... -20.529517 0.000000e+00 7 cube_tt_coef 0.000193 ... 6.270081 3.608611e-10 8 b_cost -0.773719 ... -13.500577 0.000000e+00 9 asc_car_ref 0.193084 ... 4.369323 1.246323e-05 10 asc_car_diff_GA -1.194871 ... -7.573071 3.641532e-14 11 asc_car_diff_one_lugg -0.083528 ... -1.633950 1.022694e-01 12 asc_car_diff_several_lugg -0.555472 ... -2.550880 1.074514e-02 [13 rows x 5 columns] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.818 seconds) .. _sphx_glr_download_auto_examples_assisted_plot_b08selected_specification.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_b08selected_specification.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_b08selected_specification.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_b08selected_specification.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_