Note
Go to the end to download the full example code.
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).
- author:
Michel Bierlaire, EPFL
- date:
Sat Jul 15 15:46:56 2023
import biogeme.biogeme_logging as blog
import biogeme.biogeme as bio
from everything_spec import model_catalog, database, av
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 = bio.BIOGEME.from_configuration(
config_id=SPEC_ID,
expression=model_catalog,
database=database,
)
the_biogeme.modelName = 'my_favorite_model'
Biogeme parameters read from biogeme.toml.
Calculate of the null log-likelihood for reporting.
the_biogeme.calculate_null_loglikelihood(av)
np.float64(-11093.62734528626)
Estimate the parameters.
results = the_biogeme.estimate()
As the model is not too complex, we activate the calculation of second derivatives. If you want to change it, change the name of the algorithm in the TOML file from "automatic" to "simple_bounds"
*** Initial values of the parameters are obtained from the file __my_favorite_model.iter
Cannot read file __my_favorite_model.iter. Statement is ignored.
As the model is not too complex, we activate the calculation of second derivatives. If you want to change it, change the name of the algorithm in the TOML file from "automatic" to "simple_bounds"
Optimization algorithm: hybrid Newton/BFGS with simple bounds [simple_bounds]
** Optimization: Newton with trust region for simple bounds
Iter. ASC_CAR ASC_CAR_GA ASC_CAR_one_lug ASC_CAR_several ASC_TRAIN ASC_TRAIN_GA ASC_TRAIN_one_l ASC_TRAIN_sever B_COST B_TIME B_TIME_1st_clas cube_tt_coef square_tt_coef Function Relgrad Radius Rho
0 0.28 -1.3 -0.078 -0.48 -1 1.2 0.36 0.33 -0.7 -1.6 -0.62 0.0002 -0.1 8.2e+03 5 10 1 ++
1 0.19 -1.2 -0.083 -0.54 -1.3 1.4 0.5 0.49 -0.77 -1.7 -0.66 0.00018 -0.1 8.1e+03 3.9 1e+02 1 ++
2 0.19 -1.2 -0.082 -0.55 -1.3 1.4 0.52 0.53 -0.77 -1.7 -0.66 0.00019 -0.1 8.1e+03 0.34 1e+03 1 ++
3 0.19 -1.2 -0.084 -0.55 -1.3 1.4 0.52 0.54 -0.77 -1.7 -0.67 0.00019 -0.1 8.1e+03 0.0027 1e+04 1 ++
4 0.19 -1.2 -0.084 -0.55 -1.3 1.4 0.52 0.54 -0.77 -1.7 -0.67 0.00019 -0.1 8.1e+03 1.9e-05 1e+04 1 ++
Results saved in file my_favorite_model.html
Results saved in file my_favorite_model.pickle
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 = results.get_estimated_parameters()
pandas_results
Total running time of the script: (0 minutes 0.685 seconds)