Translated MDCEV estimation

Michel Bierlaire, EPFL Fri Jul 25 2025, 17:28:50

Estimation of a MDCEV model with the “translated 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 process_data import database, number_chosen
from specification import consumed_quantities
from translated_specification import the_translated

# %
logger = blog.get_screen_logger(level=blog.INFO)
logger.info('Example: translated utility')

# %
# As the model is numerically complex, we adjust the convergence tolerance of the optimization algorithm.
results = the_translated.estimate_parameters(
    database=database,
    number_of_chosen_alternatives=number_chosen,
    consumed_quantities=consumed_quantities,
    tolerance=0.0004,
)
Example: translated utility
Biogeme parameters read from biogeme.toml.
*** Initial values of the parameters are obtained from the file __translated.iter
Cannot read file __translated.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.1e+04        0.2     0.38     -5.8    -
    1      2.1e+04       0.62     0.38     0.22    +
    2      2.1e+04       0.62     0.19     -1.1    -
    3        2e+04       0.32     0.19     0.44    +
    4      1.9e+04       0.18     0.19     0.19    +
    5      1.9e+04       0.18    0.084      -22    -
    6      1.9e+04       0.12    0.084     0.53    +
    7      1.8e+04      0.028     0.84        1   ++
    8      1.8e+04      0.028      0.3      -13    -
    9      1.8e+04      0.024        3      0.9   ++
   10      1.8e+04      0.024     0.53     -3.7    -
   11      1.8e+04      0.092     0.53     0.22    +
   12      1.7e+04       0.17     0.53     0.29    +
   13      1.7e+04      0.044     0.53     0.59    +
   14      1.7e+04      0.032     0.53     0.52    +
   15      1.7e+04       0.04     0.53     0.73    +
   16      1.7e+04       0.04     0.26      -36    -
   17      1.7e+04       0.04     0.13     -1.1    -
   18      1.7e+04      0.014     0.13     0.68    +
   19      1.7e+04     0.0017      1.3        1   ++
   20      1.7e+04       0.04      1.3     0.87    +
   21      1.7e+04      0.061      1.3     0.28    +
   22      1.7e+04      0.061     0.58 -1.2e+03    -
   23      1.7e+04      0.061     0.29      -31    -
   24      1.7e+04      0.061     0.15     -3.8    -
   25      1.7e+04      0.061    0.073    0.021    -
   26      1.7e+04      0.018    0.073     0.68    +
   27      1.7e+04     0.0024     0.73     0.98   ++
   28      1.7e+04      0.024     0.73     0.77    +
   29      1.7e+04      0.024     0.37     -4.6    -
   30      1.7e+04      0.032     0.37     0.11    +
   31      1.7e+04      0.008      3.7        1   ++
   32      1.7e+04      0.012       37      1.1   ++
   33      1.7e+04     0.0048  3.7e+02      1.1   ++
   34      1.7e+04     0.0041  3.7e+03        1   ++
   35      1.7e+04    0.00071  3.7e+04        1   ++
   36      1.7e+04      0.005  3.7e+05        1   ++
   37      1.7e+04      0.001  3.7e+06     0.99   ++
   38      1.7e+04      0.003  3.7e+07     0.99   ++
   39      1.7e+04    0.00077  3.7e+08     0.99   ++
   40      1.7e+04     0.0037  3.7e+09      1.1   ++
   41      1.7e+04    0.00042    1e+10        1   ++
   42      1.7e+04     0.0011    1e+10        1   ++
   43      1.7e+04     0.0012    1e+10     0.99   ++
   44      1.7e+04     0.0044    1e+10     0.99   ++
   45      1.7e+04     0.0012    1e+10     0.99   ++
   46      1.7e+04      0.003    1e+10     0.99   ++
   47      1.7e+04      0.004    1e+10        1   ++
   48      1.7e+04     0.0024    1e+10        1   ++
   49      1.7e+04     0.0024     0.51    -0.73    -
   50      1.7e+04     0.0069      5.1        1   ++
   51      1.7e+04     0.0007       51        1   ++
   52      1.7e+04     0.0094       51     0.72    +
   53      1.7e+04    0.00025       51        1    +
Optimization algorithm has converged.
Relative gradient: 0.0002547930099126001
Cause of termination: Relative gradient = 0.00025 <= 0.0004
Number of function evaluations: 137
Number of gradient evaluations: 83
Number of hessian evaluations: 41
Algorithm: Newton with trust region for simple bound constraints
Number of iterations: 54
Proportion of Hessian calculation: 41/41 = 100.0%
Optimization time: 0:00:03.884352
Optimization is complete. Save recoverable results in translated.yaml.
File translated.yaml has been generated.
Calculate final gradient and BHHH
File translated.yaml has been generated.
Calculate second derivatives
File translated.yaml has been generated.
File translated.html has been generated.
File translated.yaml has been generated.
print(results.short_summary())
Results for model translated
Nbr of parameters:              30
Sample size:                    4413
Excluded data:                  0
Final log likelihood:           -16966.42
Akaike Information Criterion:   33992.85
Bayesian Information Criterion: 34184.62

Get the results in a pandas table

pandas_results = get_pandas_estimated_parameters(
    estimation_results=results,
)
display(pandas_results)
{'Estimated parameters':                           Name      Value  ...  Robust t-stat.  Robust p-value
0                        scale   5.195758  ...        0.065961    9.474092e-01
1                 cte_shopping  -1.878843  ...       -0.025109    9.799684e-01
2        metropolitan_shopping   0.045584  ...        0.066011    9.473687e-01
3                male_shopping   0.072574  ...        0.065989    9.473862e-01
4           age_15_40_shopping   0.055710  ...        0.066041    9.473453e-01
5              spouse_shopping   0.046008  ...        0.066109    9.472910e-01
6            employed_shopping   0.034243  ...        0.066022    9.473602e-01
7               alpha_shopping   0.517684  ...        0.065719    9.476017e-01
8               gamma_shopping   2.044772  ...        0.656222    5.116810e-01
9              cte_socializing  -2.112096  ...       -0.025158    9.799292e-01
10  number_members_socializing   0.012382  ...        0.065914    9.474465e-01
11            male_socializing   0.093478  ...        0.065962    9.474082e-01
12       age_41_60_socializing  -0.048058  ...       -0.065917    9.474437e-01
13        bachelor_socializing  -0.036390  ...       -0.066153    9.472563e-01
14          sunday_socializing   0.072331  ...        0.065941    9.474250e-01
15           alpha_socializing   0.731456  ...        0.180083    8.570872e-01
16           gamma_socializing   2.887117  ...        6.164771    7.058525e-10
17              cte_recreation  -0.892278  ...       -0.012753    9.898247e-01
18   number_members_recreation   0.014817  ...        0.065923    9.474390e-01
19             male_recreation   0.162427  ...        0.066012    9.473682e-01
20        age_15_40_recreation   0.089262  ...        0.065978    9.473950e-01
21           spouse_recreation  -0.049093  ...       -0.066177    9.472366e-01
22            alpha_recreation   0.456665  ...        0.070290    9.439629e-01
23            gamma_recreation  10.573373  ...        0.277086    7.817142e-01
24          age_41_60_personal  -0.040695  ...       -0.065932    9.474319e-01
25           bachelor_personal  -0.033628  ...       -0.066211    9.472098e-01
26              white_personal  -0.065786  ...       -0.066133    9.472721e-01
27             sunday_personal   0.067394  ...        0.065956    9.474127e-01
28              alpha_personal   0.161665  ...        0.012512    9.900174e-01
29              gamma_personal   1.863171  ...        2.758894    5.799738e-03

[30 rows x 5 columns]}

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

Gallery generated by Sphinx-Gallery