One model among manyΒΆ

We consider the model with 432 specifications defined in everything_spec.py. We select one specification and estimate it. See Bierlaire and Ortelli (2023).

Michel Bierlaire, EPFL Sun Apr 27 2025, 18:38:30

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)

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.

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'
)

the spec_id, and used as usual.

the_biogeme = BIOGEME.from_configuration(
    config_id=SPEC_ID,
    multiple_expression=model_catalog,
    database=database,
)
the_biogeme.model_name = 'my_favorite_model'
Biogeme parameters read from biogeme.toml.

Calculate of the null log-likelihood for reporting.

the_biogeme.calculate_null_loglikelihood(av)
-11093.627345287434

Estimate the parameters.

results = the_biogeme.estimate()
*** 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: {}
Analytical Hessian method: full
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     -9.9    -
   24           -0.88            0.95            0.18           -0.01            -1.1           -0.65           -0.11         0.00025            -1.1            0.17           -0.52           -0.22          -0.054      8.5e+03        0.3     0.76     0.51    +
   25           -0.97             1.3            0.37             0.2            -1.8           -0.48          -0.059        -0.00013           -0.77            0.28              -1            -0.1           -0.26      8.2e+03         17     0.76      0.7    +
   26           -0.97             1.3            0.37             0.2            -1.8           -0.48          -0.059        -0.00013           -0.77            0.28              -1            -0.1           -0.26      8.2e+03         17     0.38       -5    -
   27           -0.97             1.3            0.37             0.2            -1.8           -0.48          -0.059        -0.00013           -0.77            0.28              -1            -0.1           -0.26      8.2e+03         17     0.19     -2.2    -
   28           -0.97             1.3            0.37             0.2            -1.8           -0.48          -0.059        -0.00013           -0.77            0.28              -1            -0.1           -0.26      8.2e+03         17    0.095    -0.53    -
   29           -0.97             1.3            0.37             0.2            -1.8           -0.48          -0.059        -0.00013           -0.77            0.28              -1            -0.1           -0.26      8.2e+03         17    0.048   -0.031    -
   30           -0.97             1.3            0.37             0.2            -1.8           -0.48           -0.11         0.00035           -0.77            0.28              -1            -0.1           -0.26      8.2e+03         17    0.048     0.35    +
   31           -0.97             1.3            0.37             0.2            -1.8           -0.48           -0.11         0.00035           -0.77            0.28              -1            -0.1           -0.26      8.2e+03         17    0.024     -3.6    -
   32           -0.97             1.3            0.37             0.2            -1.8           -0.48           -0.11         0.00035           -0.77            0.28              -1            -0.1           -0.26      8.2e+03         17    0.012     -3.2    -
   33           -0.97             1.3            0.37             0.2            -1.8           -0.48           -0.11         0.00035           -0.77            0.28              -1            -0.1           -0.26      8.2e+03         17    0.006     -3.3    -
   34           -0.97             1.3            0.37             0.2            -1.8           -0.48           -0.11         0.00035           -0.77            0.28              -1            -0.1           -0.26      8.2e+03         17    0.003     -3.5    -
   35           -0.97             1.3            0.37             0.2            -1.8           -0.48           -0.11         0.00035           -0.77            0.28              -1            -0.1           -0.26      8.2e+03         17   0.0015     -3.7    -
   36           -0.97             1.3            0.37             0.2            -1.8           -0.48           -0.11         0.00035           -0.77            0.28              -1            -0.1           -0.26      8.2e+03         17  0.00075     -3.8    -
   37           -0.97             1.3            0.37             0.2            -1.8           -0.48           -0.11         0.00035           -0.77            0.28              -1            -0.1           -0.26      8.2e+03         17  0.00037     -3.1    -
   38           -0.97             1.3            0.37             0.2            -1.8           -0.48           -0.11         0.00035           -0.77            0.28              -1            -0.1           -0.26      8.2e+03         17  0.00019     -1.2    -
   39           -0.97             1.3            0.37             0.2            -1.8           -0.48           -0.11         0.00017           -0.77            0.28              -1            -0.1           -0.26      8.2e+03         31  0.00019      0.4    +
   40           -0.97             1.3            0.37             0.2            -1.8           -0.48           -0.11         0.00026           -0.77            0.28              -1            -0.1           -0.26      8.2e+03         13  0.00019     0.16    +
   41           -0.97             1.3            0.37             0.2            -1.8           -0.48           -0.11         0.00026           -0.77            0.28              -1            -0.1           -0.26      8.2e+03         13  9.3e-05     -1.6    -
   42           -0.97             1.3            0.37             0.2            -1.8           -0.48           -0.11         0.00026           -0.77            0.28              -1            -0.1           -0.26      8.2e+03         13  4.7e-05   -0.062    -
   43           -0.97             1.3            0.37             0.2            -1.8           -0.48           -0.11         0.00022           -0.77            0.28              -1            -0.1           -0.26      8.2e+03        4.8  0.00047      0.9   ++
   44           -0.97             1.3            0.37             0.2            -1.8           -0.48           -0.11          0.0002           -0.77            0.28              -1            -0.1           -0.26      8.2e+03        2.4  0.00047     0.87    +
   45           -0.97             1.3            0.37             0.2            -1.8           -0.48           -0.11          0.0002           -0.77            0.28              -1            -0.1           -0.26      8.2e+03       0.11   0.0047        1   ++
   46           -0.97             1.3            0.37             0.2            -1.8           -0.48            -0.1         0.00018           -0.77            0.28              -1            -0.1           -0.26      8.2e+03       0.62    0.047        1   ++
   47              -1             1.3            0.35            0.21            -1.8            -0.5            -0.1         0.00017           -0.76            0.26              -1           -0.11           -0.27      8.2e+03      0.015     0.47        1   ++
   48            -1.3             1.4             0.5            0.52            -1.7           -0.68            -0.1         0.00019           -0.77             0.2            -1.2          -0.087            -0.5      8.1e+03       0.36      4.7        1   ++
   49            -1.3             1.4            0.52            0.54            -1.7           -0.66            -0.1         0.00019           -0.77            0.19            -1.2          -0.081           -0.54      8.1e+03      0.015       47        1   ++
   50            -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.00055  4.7e+02        1   ++
   51            -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.55      8.1e+03    9.6e-05  4.7e+03        1   ++
   52            -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      2e-05  4.7e+04        1   ++
   53            -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    3.4e-08  4.7e+04        1   ++
Optimization algorithm has converged.
Relative gradient: 3.44534291498072e-08
Cause of termination: Relative gradient = 3.4e-08 <= 6.1e-06
Number of function evaluations: 101
Number of gradient evaluations: 47
Number of hessian evaluations: 23
Algorithm: Newton with trust region for simple bound constraints
Number of iterations: 54
Proportion of Hessian calculation: 23/23 = 100.0%
Optimization time: 0:00:00.833588
Optimization is complete. Save recoverable results in my_favorite_model.yaml.
File my_favorite_model.yaml has been generated.
Calculate final gradient and BHHH
File my_favorite_model.yaml has been generated.
Calculate second derivatives
File my_favorite_model.yaml has been generated.
File my_favorite_model.html has been generated.
File my_favorite_model.yaml has been generated.
print(results.short_summary())
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

Get the results in a pandas table

pandas_results = get_pandas_estimated_parameters(
    estimation_results=results,
)
display(pandas_results)
{'Estimated parameters':                            Name     Value  ...  Robust t-stat.  Robust p-value
0                 asc_train_ref -1.305393  ...      -16.898736    0.000000e+00
1             asc_train_diff_GA  1.389670  ...       19.323493    0.000000e+00
2       asc_train_diff_one_lugg  0.516162  ...        6.435485    1.230798e-10
3   asc_train_diff_several_lugg  0.538600  ...        3.150152    1.631854e-03
4                    b_time_ref -1.693538  ...      -18.726680    0.000000e+00
5         b_time_diff_1st_class -0.666081  ...       -7.582726    3.375078e-14
6                square_tt_coef -0.103594  ...      -20.529542    0.000000e+00
7                  cube_tt_coef  0.000193  ...        6.270080    3.608629e-10
8                        b_cost -0.773719  ...      -13.500580    0.000000e+00
9                   asc_car_ref  0.193084  ...        4.369319    1.246346e-05
10              asc_car_diff_GA -1.194867  ...       -7.573056    3.641532e-14
11        asc_car_diff_one_lugg -0.083528  ...       -1.633954    1.022685e-01
12    asc_car_diff_several_lugg -0.555487  ...       -2.550935    1.074345e-02

[13 rows x 5 columns]}

Total running time of the script: (0 minutes 1.464 seconds)

Gallery generated by Sphinx-Gallery