Note
Go to the end to download the full example code.
Non-monotonic MDCEV estimation¶
Michel Bierlaire, EPFL Fri Jul 25 2025, 17:14:53
Estimation of a MDCEV model with the “non monotonic utility” specification.
from IPython.core.display_functions import display
import biogeme.biogeme_logging as blog
from biogeme.results_processing import get_pandas_estimated_parameters
from non_monotonic_specification import the_non_monotonic
from process_data import database, number_chosen
from specification import consumed_quantities
logger = blog.get_screen_logger(level=blog.INFO)
logger.info('Example: non monotonic utility')
results = the_non_monotonic.estimate_parameters(
database=database,
number_of_chosen_alternatives=number_chosen,
consumed_quantities=consumed_quantities,
tolerance=0.0004,
)
Example: non monotonic utility
Biogeme parameters read from biogeme.toml.
*** Initial values of the parameters are obtained from the file __non_monotonic.iter
Cannot read file __non_monotonic.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. Function Relgrad Radius Rho
0 2.5e+04 0.22 0.5 0 -
1 2.5e+04 0.22 0.25 -5.9 -
2 2.3e+04 1.3 0.25 0.18 +
3 2e+04 0.17 2.5 0.92 ++
4 2e+04 0.17 0.66 -5.5 -
5 2e+04 0.17 0.33 -1.9 -
6 2e+04 0.17 0.17 -0.36 -
7 1.9e+04 0.054 0.17 0.74 +
8 1.9e+04 0.032 1.7 1 ++
9 1.9e+04 0.064 17 1 ++
10 1.8e+04 0.025 17 0.89 +
11 1.8e+04 0.025 0.65 -1.2 -
12 1.8e+04 0.087 0.65 0.51 +
13 1.8e+04 0.083 0.65 0.62 +
14 1.8e+04 0.065 0.65 0.74 +
15 1.8e+04 0.02 6.5 1.1 ++
16 1.8e+04 0.02 2.7 -7.1 -
17 1.8e+04 0.02 1.3 -0.5 -
18 1.7e+04 0.12 1.3 0.46 +
19 1.7e+04 0.12 0.67 -0.21 -
20 1.7e+04 0.15 0.67 0.59 +
21 1.7e+04 0.022 6.7 1 ++
22 1.7e+04 0.022 1.3 -0.044 -
23 1.7e+04 0.097 1.3 0.3 +
24 1.7e+04 0.071 1.3 0.61 +
25 1.7e+04 0.029 13 1 ++
26 1.7e+04 0.0073 1.3e+02 1.1 ++
27 1.7e+04 0.004 1.3e+03 0.99 ++
28 1.7e+04 0.0037 1.3e+04 1 ++
29 1.7e+04 0.002 1.3e+05 1 ++
30 1.7e+04 0.00082 1.3e+06 1 ++
31 1.7e+04 0.0045 1.3e+07 1.1 ++
32 1.7e+04 0.00068 1.3e+08 0.95 ++
33 1.7e+04 0.00064 1.3e+09 1 ++
34 1.7e+04 0.00064 1e+10 0.99 ++
35 1.7e+04 0.0025 1e+10 1 ++
36 1.7e+04 0.00056 1e+10 0.99 ++
37 1.7e+04 0.00077 1e+10 1 ++
38 1.7e+04 0.00056 1e+10 1 ++
39 1.7e+04 0.00055 1e+10 1 ++
40 1.7e+04 0.00053 1e+10 1 ++
41 1.7e+04 0.00054 1e+10 1 ++
42 1.7e+04 0.00052 1e+10 1 ++
43 1.7e+04 0.00053 1e+10 1 ++
44 1.7e+04 0.00052 1e+10 1 ++
45 1.7e+04 0.00084 1e+10 1 ++
46 1.7e+04 0.00052 1e+10 1 ++
47 1.7e+04 0.00055 1e+10 1 ++
48 1.7e+04 0.00049 1e+10 1 ++
49 1.7e+04 0.00053 1e+10 1 ++
50 1.7e+04 0.00048 1e+10 1 ++
51 1.7e+04 0.00051 1e+10 1 ++
52 1.7e+04 0.00047 1e+10 1 ++
53 1.7e+04 0.0005 1e+10 1 ++
54 1.7e+04 0.00046 1e+10 1 ++
55 1.7e+04 0.00049 1e+10 1 ++
56 1.7e+04 0.00095 1e+10 1 ++
57 1.7e+04 0.00046 1e+10 1 ++
58 1.7e+04 0.00044 1e+10 1 ++
59 1.7e+04 0.00046 1e+10 1 ++
60 1.7e+04 0.00044 1e+10 1 ++
61 1.7e+04 0.00045 1e+10 1 ++
62 1.7e+04 0.00043 1e+10 1 ++
63 1.7e+04 0.00044 1e+10 1 ++
64 1.7e+04 0.00043 1e+10 1 ++
65 1.7e+04 0.00045 1e+10 1 ++
66 1.7e+04 0.00043 1e+10 1 ++
67 1.7e+04 0.00044 1e+10 1 ++
68 1.7e+04 0.00042 1e+10 1 ++
69 1.7e+04 0.00045 1e+10 1 ++
70 1.7e+04 0.00042 1e+10 1 ++
71 1.7e+04 0.00049 1e+10 1 ++
72 1.7e+04 0.00041 1e+10 1 ++
73 1.7e+04 0.00076 1e+10 1 ++
74 1.7e+04 0.00041 1e+10 1 ++
75 1.7e+04 0.00045 1e+10 1 ++
76 1.7e+04 0.0004 1e+10 1 ++
77 1.7e+04 0.00045 1e+10 1 ++
78 1.7e+04 0.0004 1e+10 1 ++
79 1.7e+04 0.00042 1e+10 1 ++
80 1.7e+04 0.0004 1e+10 1 ++
Optimization algorithm has converged.
Relative gradient: 0.0003976392774051498
Cause of termination: Relative gradient = 0.0004 <= 0.0004
Number of function evaluations: 224
Number of gradient evaluations: 143
Number of hessian evaluations: 71
Algorithm: Newton with trust region for simple bound constraints
Number of iterations: 81
Proportion of Hessian calculation: 71/71 = 100.0%
Optimization time: 0:00:06.776262
Optimization is complete. Save recoverable results in non_monotonic.yaml.
File non_monotonic.yaml has been generated.
Calculate final gradient and BHHH
File non_monotonic.yaml has been generated.
Calculate second derivatives
File non_monotonic.yaml has been generated.
File non_monotonic.html has been generated.
File non_monotonic.yaml has been generated.
print(results.short_summary())
Results for model non_monotonic
Nbr of parameters: 34
Sample size: 4413
Excluded data: 0
Final log likelihood: -16943.55
Akaike Information Criterion: 33955.11
Bayesian Information Criterion: 34172.45
Get the results in a pandas table
pandas_results = get_pandas_estimated_parameters(
estimation_results=results,
)
display(pandas_results)
{'Estimated parameters': Name Value ... Robust p-value Active bound
0 scale 10.811903 ... 1.335032e-05 False
1 holiday_shopping_mu -0.060776 ... 7.010822e-02 False
2 cte_shopping -0.301633 ... 3.186972e-04 False
3 metropolitan_shopping 0.022621 ... 9.332958e-02 False
4 male_shopping -0.089420 ... 5.264174e-03 False
5 age_15_40_shopping 0.040285 ... 1.001782e-02 False
6 spouse_shopping 0.031216 ... 1.337514e-02 False
7 employed_shopping 0.021878 ... 3.531198e-02 False
8 gamma_shopping 3.722732 ... 3.806626e-03 False
9 alpha_shopping 0.461737 ... 1.300181e-01 False
10 metro_social_mu -0.012025 ... 9.898603e-02 False
11 cte_socializing -0.185935 ... 1.596422e-04 False
12 number_members_socializing 0.007688 ... 3.991392e-03 False
13 male_socializing -0.073052 ... 1.559582e-02 False
14 age_41_60_socializing -0.031454 ... 9.640756e-03 False
15 bachelor_socializing -0.018093 ... 9.841172e-03 False
16 sunday_socializing 0.045714 ... 2.274028e-03 False
17 gamma_socializing 3.856881 ... 4.761856e-08 False
18 alpha_socializing 0.791048 ... 0.000000e+00 False
19 holiday_recreation_mu -0.044869 ... 1.943782e-01 False
20 cte_recreation -0.353538 ... 2.846919e-04 False
21 number_members_recreation 0.009282 ... 1.035368e-02 False
22 male_recreation -0.034303 ... 3.484306e-01 False
23 age_15_40_recreation 0.062320 ... 4.272419e-03 False
24 spouse_recreation -0.031609 ... 1.123736e-02 False
25 gamma_recreation 9.778539 ... 0.000000e+00 False
26 alpha_recreation 0.645019 ... 9.006899e-08 False
27 male_personal_mu -0.102090 ... 1.214020e-05 False
28 age_41_60_personal -0.025015 ... 1.690443e-02 False
29 bachelor_personal -0.017129 ... 1.847860e-02 False
30 white_personal -0.037043 ... 1.443805e-03 False
31 sunday_personal 0.040709 ... 2.942118e-03 False
32 gamma_personal 4.561674 ... 2.758838e-04 False
33 alpha_personal 0.000100 ... 9.998420e-01 True
[34 rows x 6 columns]}
Total running time of the script: (0 minutes 10.306 seconds)