.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/indicators/plot_b02estimation.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_indicators_plot_b02estimation.py: Estimation and simulation of a nested logit model ================================================= We estimate a nested logit model, and we perform simulation using the estimated model. Michel Bierlaire, EPFL Sat Jun 28 2025, 16:08:07 .. GENERATED FROM PYTHON SOURCE LINES 12-26 .. code-block:: Python from IPython.core.display_functions import display import biogeme.biogeme_logging as blog from biogeme.biogeme import BIOGEME from biogeme.data.optima import read_data from biogeme.jax_calculator import get_value_c from biogeme.models import lognested from biogeme.results_processing import get_pandas_estimated_parameters from scenarios import scenario logger = blog.get_screen_logger(level=blog.INFO) logger.info('Example plot_b02estimation') .. rst-class:: sphx-glr-script-out .. code-block:: none Example plot_b02estimation .. GENERATED FROM PYTHON SOURCE LINES 27-29 Obtain the specification for the default scenario. The definition of the scenarios is available in ``scenarios.py``. .. GENERATED FROM PYTHON SOURCE LINES 29-31 .. code-block:: Python V, nests, choice, _ = scenario() .. GENERATED FROM PYTHON SOURCE LINES 32-34 The choice model is a nested logit, with availability conditions For estimation, we need the log of the probability. .. GENERATED FROM PYTHON SOURCE LINES 34-36 .. code-block:: Python log_probability = lognested(util=V, availability=None, nests=nests, choice=choice) .. GENERATED FROM PYTHON SOURCE LINES 37-38 Get the database .. GENERATED FROM PYTHON SOURCE LINES 38-39 .. code-block:: Python database = read_data() .. GENERATED FROM PYTHON SOURCE LINES 40-41 Create the Biogeme object for estimation. .. GENERATED FROM PYTHON SOURCE LINES 41-44 .. code-block:: Python the_biogeme = BIOGEME(database, log_probability) the_biogeme.model_name = 'b02estimation' .. rst-class:: sphx-glr-script-out .. code-block:: none Default values of the Biogeme parameters are used. File biogeme.toml has been created .. GENERATED FROM PYTHON SOURCE LINES 45-46 Estimate the parameters. Perform bootstrapping. .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: Python results = the_biogeme.estimate(run_bootstrap=True) .. rst-class:: sphx-glr-script-out .. code-block:: none *** Initial values of the parameters are obtained from the file __b02estimation.iter Cannot read file __b02estimation.iter. Statement is ignored. Starting values for the algorithm: {} Analytical Hessian method: full As the model is rather complex, we cancel the calculation of second derivatives. If you want to control the parameters, change the algorithm from "automatic" to "simple_bounds" in the TOML file. Optimization algorithm: hybrid Newton/BFGS with simple bounds [simple_bounds] ** Optimization: BFGS with trust region for simple bounds Iter. beta_time_fullt beta_time_other beta_cost asc_car asc_sm beta_dist_male beta_dist_femal beta_dist_unrep mu_no_car Function Relgrad Radius Rho 0 0 0 0 0 0 0 0 0 1 2.1e+03 1.3 0.5 0.067 - 1 0.5 0.5 -0.5 0.5 -0.5 -0.5 -0.5 -0.5 1.5 1.4e+03 0.067 0.5 0.21 + 2 0.32 0.39 -1 0.78 -0.22 -0.38 -0.5 -0.49 1.3 1.3e+03 0.031 0.5 0.39 + 3 0.32 0.39 -1 0.78 -0.22 -0.38 -0.5 -0.49 1.3 1.3e+03 0.031 0.25 0.072 - 4 0.23 0.42 -0.85 0.53 -0.14 -0.54 -0.63 -0.5 1.3 1.3e+03 0.013 0.25 0.8 + 5 -0.021 0.34 -0.86 0.72 0.018 -0.54 -0.75 -0.53 1.4 1.3e+03 0.029 0.25 0.44 + 6 -0.27 0.31 -0.75 0.49 0.26 -0.53 -0.78 -0.58 1.3 1.3e+03 0.027 0.25 0.3 + 7 -0.36 0.28 -0.72 0.51 0.16 -0.78 -0.82 -0.61 1.5 1.3e+03 0.019 0.25 0.21 + 8 -0.36 0.28 -0.72 0.51 0.16 -0.78 -0.82 -0.61 1.5 1.3e+03 0.019 0.12 -0.5 - 9 -0.46 0.21 -0.84 0.57 0.24 -0.66 -0.8 -0.62 1.4 1.3e+03 0.011 0.12 0.57 + 10 -0.51 0.21 -0.74 0.45 0.21 -0.67 -0.84 -0.64 1.4 1.3e+03 0.012 0.12 0.39 + 11 -0.63 0.13 -0.76 0.53 0.17 -0.67 -0.86 -0.67 1.5 1.3e+03 0.01 0.12 0.56 + 12 -0.63 0.13 -0.76 0.53 0.17 -0.67 -0.86 -0.67 1.5 1.3e+03 0.01 0.062 -0.036 - 13 -0.63 0.13 -0.76 0.53 0.17 -0.67 -0.86 -0.67 1.5 1.3e+03 0.01 0.031 -0.32 - 14 -0.67 0.1 -0.8 0.49 0.21 -0.64 -0.83 -0.7 1.4 1.3e+03 0.0046 0.031 0.58 + 15 -0.7 0.085 -0.76 0.46 0.17 -0.67 -0.84 -0.7 1.5 1.3e+03 0.0042 0.031 0.77 + 16 -0.73 0.054 -0.77 0.45 0.19 -0.66 -0.82 -0.7 1.4 1.3e+03 0.0038 0.31 0.92 ++ 17 -1 -0.14 -0.72 0.41 0.14 -0.71 -0.82 -0.7 1.5 1.3e+03 0.0077 0.31 0.7 + 18 -1.4 -0.34 -0.76 0.29 0.11 -0.61 -0.87 -0.69 1.5 1.3e+03 0.013 0.31 0.27 + 19 -1.4 -0.34 -0.76 0.29 0.11 -0.61 -0.87 -0.69 1.5 1.3e+03 0.013 0.16 -4.8 - 20 -1.4 -0.34 -0.76 0.29 0.11 -0.61 -0.87 -0.69 1.5 1.3e+03 0.013 0.078 -0.8 - 21 -1.4 -0.35 -0.74 0.31 0.088 -0.69 -0.84 -0.69 1.5 1.3e+03 0.0029 0.078 0.76 + 22 -1.4 -0.35 -0.74 0.31 0.088 -0.69 -0.84 -0.69 1.5 1.3e+03 0.0029 0.039 -0.79 - 23 -1.4 -0.35 -0.74 0.31 0.088 -0.69 -0.84 -0.69 1.5 1.3e+03 0.0029 0.02 0.0073 - 24 -1.4 -0.37 -0.74 0.3 0.11 -0.67 -0.82 -0.67 1.5 1.3e+03 0.0026 0.02 0.41 + 25 -1.4 -0.38 -0.72 0.31 0.094 -0.68 -0.82 -0.68 1.5 1.3e+03 0.0011 0.02 0.69 + 26 -1.4 -0.4 -0.73 0.3 0.092 -0.67 -0.82 -0.69 1.5 1.3e+03 0.00097 0.02 0.89 + 27 -1.4 -0.42 -0.73 0.3 0.083 -0.68 -0.82 -0.69 1.5 1.3e+03 0.0012 0.02 0.75 + 28 -1.4 -0.44 -0.73 0.29 0.086 -0.68 -0.82 -0.69 1.5 1.3e+03 0.00073 0.2 0.92 ++ 29 -1.4 -0.44 -0.73 0.29 0.086 -0.68 -0.82 -0.69 1.5 1.3e+03 0.00073 0.098 -4.8 - 30 -1.4 -0.44 -0.73 0.29 0.086 -0.68 -0.82 -0.69 1.5 1.3e+03 0.00073 0.049 -2 - 31 -1.4 -0.44 -0.73 0.29 0.086 -0.68 -0.82 -0.69 1.5 1.3e+03 0.00073 0.024 -0.38 - 32 -1.5 -0.46 -0.71 0.28 0.077 -0.67 -0.83 -0.7 1.5 1.3e+03 0.0014 0.024 0.37 + 33 -1.5 -0.48 -0.73 0.28 0.074 -0.69 -0.82 -0.7 1.5 1.3e+03 0.0019 0.024 0.57 + 34 -1.5 -0.48 -0.73 0.28 0.074 -0.69 -0.82 -0.7 1.5 1.3e+03 0.0019 0.012 -1.1 - 35 -1.5 -0.49 -0.72 0.28 0.087 -0.68 -0.83 -0.7 1.5 1.3e+03 0.0014 0.012 0.54 + 36 -1.5 -0.49 -0.72 0.28 0.087 -0.68 -0.83 -0.7 1.5 1.3e+03 0.0014 0.0061 0.066 - 37 -1.5 -0.49 -0.72 0.28 0.081 -0.69 -0.83 -0.7 1.5 1.3e+03 0.00051 0.0061 0.88 + 38 -1.5 -0.49 -0.72 0.28 0.078 -0.68 -0.83 -0.7 1.5 1.3e+03 0.00052 0.0061 0.83 + 39 -1.5 -0.5 -0.72 0.28 0.074 -0.68 -0.83 -0.7 1.5 1.3e+03 0.00043 0.0061 0.85 + 40 -1.5 -0.5 -0.72 0.27 0.074 -0.68 -0.83 -0.7 1.5 1.3e+03 0.00044 0.061 0.94 ++ 41 -1.6 -0.55 -0.72 0.26 0.064 -0.68 -0.83 -0.7 1.5 1.3e+03 0.00039 0.61 0.94 ++ 42 -1.6 -0.55 -0.72 0.26 0.064 -0.68 -0.83 -0.7 1.5 1.3e+03 0.00039 0.064 -31 - 43 -1.6 -0.55 -0.72 0.26 0.064 -0.68 -0.83 -0.7 1.5 1.3e+03 0.00039 0.032 -21 - 44 -1.6 -0.55 -0.72 0.26 0.064 -0.68 -0.83 -0.7 1.5 1.3e+03 0.00039 0.016 -9.4 - 45 -1.6 -0.55 -0.72 0.26 0.064 -0.68 -0.83 -0.7 1.5 1.3e+03 0.00039 0.008 -5.4 - 46 -1.6 -0.55 -0.72 0.26 0.064 -0.68 -0.83 -0.7 1.5 1.3e+03 0.00039 0.004 -2.9 - 47 -1.6 -0.55 -0.72 0.26 0.064 -0.68 -0.83 -0.7 1.5 1.3e+03 0.00039 0.002 -1.2 - 48 -1.6 -0.55 -0.72 0.26 0.062 -0.69 -0.83 -0.7 1.5 1.3e+03 0.0003 0.002 0.12 + 49 -1.6 -0.55 -0.72 0.26 0.064 -0.69 -0.83 -0.7 1.5 1.3e+03 7.9e-05 0.002 0.68 + 50 -1.6 -0.55 -0.72 0.26 0.064 -0.69 -0.83 -0.7 1.5 1.3e+03 5.6e-05 0.002 0.72 + 51 -1.6 -0.55 -0.72 0.26 0.064 -0.69 -0.83 -0.7 1.5 1.3e+03 5.6e-05 0.001 -1.5 - 52 -1.6 -0.55 -0.72 0.26 0.064 -0.69 -0.83 -0.7 1.5 1.3e+03 5.6e-05 0.0005 -0.21 - 53 -1.6 -0.55 -0.72 0.26 0.064 -0.69 -0.83 -0.7 1.5 1.3e+03 7.4e-05 0.0005 0.34 + 54 -1.6 -0.55 -0.72 0.26 0.064 -0.69 -0.83 -0.7 1.5 1.3e+03 3.9e-05 0.0005 0.76 + 55 -1.6 -0.55 -0.72 0.26 0.064 -0.69 -0.83 -0.7 1.5 1.3e+03 3.8e-05 0.0005 0.86 + 56 -1.6 -0.55 -0.72 0.26 0.064 -0.69 -0.83 -0.7 1.5 1.3e+03 3.1e-05 0.005 0.96 ++ 57 -1.6 -0.55 -0.72 0.26 0.064 -0.69 -0.83 -0.7 1.5 1.3e+03 3.1e-05 0.0025 -0.043 - 58 -1.6 -0.55 -0.72 0.26 0.063 -0.69 -0.83 -0.7 1.5 1.3e+03 6.1e-05 0.0025 0.53 + 59 -1.6 -0.55 -0.72 0.26 0.063 -0.69 -0.83 -0.7 1.5 1.3e+03 6.1e-05 0.0012 -1.1 - 60 -1.6 -0.55 -0.72 0.26 0.063 -0.69 -0.83 -0.7 1.5 1.3e+03 5.5e-05 0.0012 0.23 + 61 -1.6 -0.55 -0.72 0.26 0.063 -0.69 -0.83 -0.7 1.5 1.3e+03 5.5e-05 0.00062 -0.54 - 62 -1.6 -0.55 -0.72 0.26 0.063 -0.69 -0.83 -0.7 1.5 1.3e+03 5.5e-05 0.00031 -0.16 - 63 -1.6 -0.55 -0.72 0.26 0.063 -0.69 -0.83 -0.7 1.5 1.3e+03 5.1e-05 0.00031 0.47 + 64 -1.6 -0.55 -0.72 0.26 0.063 -0.69 -0.83 -0.7 1.5 1.3e+03 2.2e-05 0.00031 0.63 + 65 -1.6 -0.55 -0.72 0.26 0.063 -0.69 -0.83 -0.7 1.5 1.3e+03 7.8e-06 0.00031 0.84 + 66 -1.6 -0.55 -0.72 0.26 0.063 -0.69 -0.83 -0.7 1.5 1.3e+03 7.7e-06 0.0031 0.9 ++ 67 -1.6 -0.55 -0.72 0.26 0.063 -0.69 -0.83 -0.7 1.5 1.3e+03 7.7e-06 0.00063 -2.2 - 68 -1.6 -0.55 -0.72 0.26 0.063 -0.69 -0.83 -0.7 1.5 1.3e+03 2.5e-06 0.00063 0.87 - Optimization algorithm has converged. Relative gradient: 2.533919056890597e-06 Cause of termination: Relative gradient = 2.5e-06 <= 6.1e-06 Number of function evaluations: 154 Number of gradient evaluations: 85 Number of hessian evaluations: 0 Algorithm: BFGS with trust region for simple bound constraints Number of iterations: 69 Proportion of Hessian calculation: 0/42 = 0.0% Optimization time: 0:00:00.236321 Optimization is complete. Save recoverable results in b02estimation.yaml. File b02estimation.yaml has been generated. Calculate final gradient and BHHH File b02estimation.yaml has been generated. Calculate second derivatives File b02estimation.yaml has been generated. Re-estimate the model 100 times for bootstrapping Bootstraps: 0%| | 0/100 [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_b02estimation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_b02estimation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_