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
Parameter values restored from __my_favorite_model.iter
Starting values for the algorithm: {'asc_train_ref': -1.3053908603711253, 'asc_train_diff_GA': 1.3896663323897733, 'asc_train_diff_one_lugg': 0.5161612078654941, 'asc_train_diff_several_lugg': 0.538605341010333, 'b_time_ref': -1.6935392551106372, 'b_time_diff_1st_class': -0.6660789157644667, 'square_tt_coef': -0.10359359435365205, 'cube_tt_coef': 0.0001927279525931404, 'b_cost': -0.7737187533719376, 'asc_car_ref': 0.1930839407708599, 'asc_car_diff_GA': -1.1948710971894307, 'asc_car_diff_one_lugg': -0.08352763043135125, 'asc_car_diff_several_lugg': -0.5554719996758215}
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
Optimization algorithm has converged.
Relative gradient: 1.9428528864122147e-07
Cause of termination: Relative gradient = 1.9e-07 <= 6.1e-06
Number of function evaluations: 1
Number of gradient evaluations: 1
Number of hessian evaluations: 0
Algorithm: Newton with trust region for simple bound constraints
Number of iterations: 0
Optimization time: 0:00:00.286146
Calculate second derivatives and BHHH
File my_favorite_model~00.html has been generated.
File my_favorite_model~00.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.541 seconds)

Gallery generated by Sphinx-Gallery