File non_monotonic_estimation.py

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: {}
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.4e+04       0.22      0.5        0    -
    1      2.4e+04       0.22     0.25     -8.1    -
    2      2.4e+04       0.22     0.12    -0.13    -
    3      2.1e+04       0.14     0.12     0.88    +
    4        2e+04       0.14      1.2        1   ++
    5        2e+04       0.14     0.28  -0.0013    -
    6        2e+04       0.54     0.28      0.5    +
    7      1.9e+04       0.31     0.28     0.62    +
    8      1.8e+04      0.088      2.8        1   ++
    9      1.8e+04      0.031       28     0.98   ++
   10      1.8e+04      0.031      1.9     -6.3    -
   11      1.8e+04      0.031     0.93    -0.45    -
   12      1.8e+04       0.14     0.93     0.51    +
   13      1.8e+04      0.072     0.93     0.64    +
   14      1.7e+04      0.039      9.3        1   ++
   15      1.7e+04      0.095      9.3     0.76    +
   16      1.7e+04      0.054       93     0.98   ++
   17      1.7e+04      0.054     0.97    -0.67    -
   18      1.7e+04      0.054     0.49    -0.36    -
   19      1.7e+04      0.083     0.49      0.5    +
   20      1.7e+04      0.013      4.9      1.1   ++
   21      1.7e+04      0.054       49        1   ++
   22      1.7e+04     0.0045  4.9e+02        1   ++
   23      1.7e+04     0.0056  4.9e+03     0.93   ++
   24      1.7e+04     0.0034  4.9e+04        1   ++
   25      1.7e+04     0.0025  4.9e+05     0.99   ++
   26      1.7e+04     0.0015  4.9e+06        1   ++
   27      1.7e+04    0.00076  4.9e+07     0.98   ++
   28      1.7e+04     0.0028  4.9e+08      1.1   ++
   29      1.7e+04    0.00067  4.9e+09     0.99   ++
   30      1.7e+04    0.00068    1e+10     0.99   ++
   31      1.7e+04    0.00065    1e+10        1   ++
   32      1.7e+04     0.0023    1e+10        1   ++
   33      1.7e+04     0.0016    1e+10        1   ++
   34      1.7e+04      0.001    1e+10        1   ++
   35      1.7e+04     0.0019    1e+10      1.1   ++
   36      1.7e+04     0.0019    1e+10        1   ++
   37      1.7e+04    0.00076    1e+10        1   ++
   38      1.7e+04     0.0008    1e+10        1   ++
   39      1.7e+04    0.00045    1e+10        1   ++
   40      1.7e+04    0.00045    1e+10        1   ++
   41      1.7e+04    0.00044    1e+10        1   ++
   42      1.7e+04    0.00044    1e+10        1   ++
   43      1.7e+04    0.00043    1e+10        1   ++
   44      1.7e+04    0.00087    1e+10        1   ++
   45      1.7e+04    0.00043    1e+10        1   ++
   46      1.7e+04    0.00055    1e+10        1   ++
   47      1.7e+04    0.00042    1e+10        1   ++
   48      1.7e+04    0.00043    1e+10        1   ++
   49      1.7e+04    0.00042    1e+10        1   ++
   50      1.7e+04    0.00051    1e+10        1   ++
   51      1.7e+04    0.00041    1e+10        1   ++
   52      1.7e+04    0.00046    1e+10        1   ++
   53      1.7e+04    0.00041    1e+10        1   ++
   54      1.7e+04    0.00059    1e+10        1   ++
   55      1.7e+04     0.0004    1e+10        1   ++
   56      1.7e+04    0.00041    1e+10        1   ++
   57      1.7e+04     0.0004    1e+10        1   ++
Optimization algorithm has converged.
Relative gradient: 0.0003984151665361689
Cause of termination: Relative gradient = 0.0004 <= 0.0004
Number of function evaluations: 159
Number of gradient evaluations: 101
Number of hessian evaluations: 50
Algorithm: Newton with trust region for simple bound constraints
Number of iterations: 58
Proportion of Hessian calculation: 50/50 = 100.0%
Optimization time: 0:00:04.017928
Calculate second derivatives and BHHH
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.87
Akaike Information Criterion:   33955.75
Bayesian Information Criterion: 34173.08

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.808323  ...    1.554312e-15         False
1          holiday_shopping_mu  -0.058864  ...    5.737346e-02         False
2                 cte_shopping  -0.301558  ...    3.096610e-10         False
3        metropolitan_shopping   0.022829  ...    6.234687e-02         False
4                male_shopping  -0.087285  ...    6.186671e-03         False
5           age_15_40_shopping   0.040385  ...    5.358876e-04         False
6              spouse_shopping   0.031314  ...    1.123032e-03         False
7            employed_shopping   0.021882  ...    1.323267e-02         False
8               gamma_shopping   3.727725  ...    2.633315e-04         False
9               alpha_shopping   0.461766  ...    1.356044e-02         False
10             metro_social_mu  -0.012176  ...    7.573101e-02         False
11             cte_socializing  -0.185308  ...    1.059450e-10         False
12  number_members_socializing   0.007671  ...    2.097490e-04         False
13            male_socializing  -0.071066  ...    1.825352e-02         False
14       age_41_60_socializing  -0.031596  ...    1.083248e-03         False
15        bachelor_socializing  -0.017955  ...    4.561434e-03         False
16          sunday_socializing   0.045686  ...    2.917506e-06         False
17           gamma_socializing   3.861608  ...    2.304137e-09         False
18           alpha_socializing   0.790979  ...    0.000000e+00         False
19       holiday_recreation_mu  -0.045269  ...    1.812634e-01         False
20              cte_recreation  -0.353281  ...    6.411227e-11         False
21   number_members_recreation   0.009276  ...    1.758783e-03         False
22             male_recreation  -0.032044  ...    3.565549e-01         False
23        age_15_40_recreation   0.062378  ...    1.986767e-05         False
24           spouse_recreation  -0.031490  ...    9.120338e-04         False
25            gamma_recreation   9.465438  ...    0.000000e+00         False
26            alpha_recreation   0.655938  ...    0.000000e+00         False
27            male_personal_mu  -0.100569  ...    9.814445e-06         False
28          age_41_60_personal  -0.025118  ...    4.900676e-03         False
29           bachelor_personal  -0.017000  ...    1.013348e-02         False
30              white_personal  -0.036868  ...    1.106918e-05         False
31             sunday_personal   0.040796  ...    1.069668e-05         False
32              gamma_personal   4.568080  ...    7.969181e-13         False
33              alpha_personal   0.000100  ...    9.996755e-01          True

[34 rows x 6 columns]}

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

Gallery generated by Sphinx-Gallery