Note
Go to the end to download the full example code.
Estimation of the choice modelΒΆ
Choice model without any latent variable.
Michel Bierlaire, EPFL Wed Sept 03 2025, 08:18:01
from choice_model import v
from optima import (
Choice,
read_data,
)
import biogeme.biogeme_logging as blog
from biogeme.biogeme import BIOGEME
from biogeme.models import loglogit
from biogeme.results_processing import (
EstimationResults,
)
logger = blog.get_screen_logger(level=blog.INFO)
database = read_data()
We integrate over omega using numerical integration
log_likelihood = loglogit(v, None, Choice)
Create the Biogeme object
print('Create the biogeme object')
the_biogeme = BIOGEME(database, log_likelihood)
the_biogeme.model_name = 'b02_choice_only'
print('--- Estimate ---')
results: EstimationResults = the_biogeme.estimate()
Create the biogeme object
Biogeme parameters read from biogeme.toml.
--- Estimate ---
*** Initial values of the parameters are obtained from the file __b02_choice_only.iter
Cannot read file __b02_choice_only.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. log_scale_choic log_scale_choic choice_asc_pt_s choice_asc_pt_l choice_beta_tim choice_beta_tim choice_beta_wai choice_asc_car_ choice_asc_car_ choice_beta_tim choice_beta_tim choice_beta_dis Function Relgrad Radius Rho
0 1 0.91 -0.014 -0.083 -0.034 -0.19 -0.022 0.13 0.058 0.076 0.064 -0.68 1.9e+03 0.36 1 0.16 +
1 1 0.91 -0.014 -0.083 -0.034 -0.19 -0.022 0.13 0.058 0.076 0.064 -0.68 1.9e+03 0.36 0.5 -8.5 -
2 0.5 0.41 0.33 0.0079 0.28 0.055 -0.021 -0.37 -0.043 -0.13 -0.081 -0.18 1.3e+03 1.7 0.5 0.76 +
3 -1.1e-16 -0.042 0.3 0.021 0.16 0.087 -0.042 -0.17 -0.076 -0.059 -0.13 -0.2 8.4e+02 0.75 5 1.2 ++
4 -0.28 -0.9 2.1 0.36 -1.1 -0.14 -0.29 1 0.57 -2 -1 -0.25 5.6e+02 0.34 50 1.3 ++
5 -0.66 -1.4 3.5 1.6 -2.4 -1.1 -0.97 2.3 1.1 -5.2 -3 -0.34 4.5e+02 0.16 5e+02 1.3 ++
6 -0.92 -1.7 5 6.5 -3.9 -3.7 -2.6 4.1 4.4 -9.5 -8.5 -0.46 3.9e+02 0.074 5e+03 1.3 ++
7 -1.2 -1.8 6.7 11 -5.4 -6.7 -5.2 6.2 10 -14 -17 -0.62 3.6e+02 0.033 5e+04 1.3 ++
8 -1.4 -2 8.6 15 -7 -9.3 -8.1 8.7 15 -19 -24 -0.79 3.5e+02 0.014 5e+05 1.3 ++
9 -1.6 -2.1 11 17 -8.5 -11 -11 11 18 -23 -30 -0.95 3.5e+02 0.0053 5e+06 1.3 ++
10 -1.7 -2.1 12 18 -9.7 -13 -13 14 18 -27 -33 -1.1 3.4e+02 0.0018 5e+07 1.2 ++
11 -1.8 -2.2 14 19 -11 -14 -14 15 20 -29 -36 -1.2 3.4e+02 0.00055 5e+08 1.1 ++
12 -1.8 -2.2 14 22 -11 -15 -15 16 23 -30 -38 -1.2 3.4e+02 0.00013 5e+09 1.1 ++
13 -1.8 -2.2 14 23 -10 -14 -14 15 24 -29 -38 -1.1 3.4e+02 7.2e-05 1e+10 0.95 ++
14 -1.8 -2.2 14 25 -11 -15 -15 16 26 -29 -39 -1.2 3.4e+02 8.4e-05 1e+10 1 ++
15 -1.8 -2.2 14 26 -10 -15 -14 16 27 -29 -39 -1.1 3.4e+02 2.7e-05 1e+10 0.98 ++
16 -1.8 -2.2 14 26 -11 -15 -15 16 28 -29 -39 -1.1 3.4e+02 0.0001 1e+10 1 ++
17 -1.8 -2.2 14 27 -10 -15 -15 16 28 -29 -39 -1.1 3.4e+02 1.4e-05 1e+10 0.99 ++
18 -1.8 -2.2 14 27 -10 -15 -15 16 29 -29 -40 -1.1 3.4e+02 1.2e-05 1e+10 1 ++
19 -1.8 -2.2 14 28 -10 -15 -15 16 29 -29 -39 -1.1 3.4e+02 1.1e-05 1e+10 0.99 ++
20 -1.8 -2.2 14 28 -10 -15 -15 16 29 -29 -40 -1.1 3.4e+02 3.2e-05 1e+10 1 ++
21 -1.8 -2.2 14 28 -10 -15 -15 16 30 -29 -40 -1.1 3.4e+02 7.1e-06 1e+10 1 ++
22 -1.8 -2.3 14 28 -10 -15 -15 16 30 -29 -40 -1.1 3.4e+02 7.4e-06 1e+10 1 ++
23 -1.8 -2.3 14 28 -10 -15 -15 16 30 -29 -40 -1.1 3.4e+02 3e-06 1e+10 1 ++
Optimization algorithm has converged.
Relative gradient: 2.9917193448014054e-06
Cause of termination: Relative gradient = 3e-06 <= 6.1e-06
Number of function evaluations: 71
Number of gradient evaluations: 47
Number of hessian evaluations: 23
Algorithm: Newton with trust region for simple bound constraints
Number of iterations: 24
Proportion of Hessian calculation: 23/23 = 100.0%
Optimization time: 0:00:00.867998
Calculate second derivatives and BHHH
File b02_choice_only.html has been generated.
File b02_choice_only.yaml has been generated.
Total running time of the script: (0 minutes 2.254 seconds)