One model among manyΒΆ

We consider the model with 432 specifications defined in Combination of many specifications. 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: {}
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.
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)
                           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]

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

Gallery generated by Sphinx-Gallery