.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/assisted/plot_b03alt_spec.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_assisted_plot_b03alt_spec.py: Catalog for alternative specific coefficients ============================================= Investigate alternative specific parameters: - two specifications for the travel time coefficient: generic, and alternative specific, - two specifications for the travel cost coefficient: generic, and alternative specific, for a total of 4 specifications. See `Bierlaire and Ortelli (2023) `_. :author: Michel Bierlaire, EPFL :date: Thu Jul 13 16:18:10 2023 .. GENERATED FROM PYTHON SOURCE LINES 22-30 .. code-block:: default import biogeme.biogeme as bio import biogeme.biogeme_logging as blog from biogeme import models from biogeme.expressions import Beta from biogeme.catalog import generic_alt_specific_catalogs from biogeme.results import compile_estimation_results, pareto_optimal .. GENERATED FROM PYTHON SOURCE LINES 31-32 See :ref:`swissmetro_data`. .. GENERATED FROM PYTHON SOURCE LINES 32-48 .. code-block:: default from swissmetro_data import ( database, CHOICE, SM_AV, CAR_AV_SP, TRAIN_AV_SP, TRAIN_TT_SCALED, TRAIN_COST_SCALED, SM_TT_SCALED, SM_COST_SCALED, CAR_TT_SCALED, CAR_CO_SCALED, ) logger = blog.get_screen_logger(level=blog.INFO) .. GENERATED FROM PYTHON SOURCE LINES 49-50 Parameters to be estimated. .. GENERATED FROM PYTHON SOURCE LINES 50-55 .. code-block:: default ASC_CAR = Beta('ASC_CAR', 0, None, None, 0) ASC_TRAIN = Beta('ASC_TRAIN', 0, None, None, 0) B_TIME = Beta('B_TIME', 0, None, None, 0) B_COST = Beta('B_COST', 0, None, None, 0) .. GENERATED FROM PYTHON SOURCE LINES 56-57 Catalog for travel time coefficient. .. GENERATED FROM PYTHON SOURCE LINES 57-61 .. code-block:: default (B_TIME_catalog_dict,) = generic_alt_specific_catalogs( generic_name='B_TIME', beta_parameters=[B_TIME], alternatives=('TRAIN', 'SM', 'CAR') ) .. GENERATED FROM PYTHON SOURCE LINES 62-63 Catalog for travel cost coefficient. .. GENERATED FROM PYTHON SOURCE LINES 63-67 .. code-block:: default (B_COST_catalog_dict,) = generic_alt_specific_catalogs( generic_name='B_COST', beta_parameters=[B_COST], alternatives=('TRAIN', 'SM', 'CAR') ) .. GENERATED FROM PYTHON SOURCE LINES 68-69 Definition of the utility functions. .. GENERATED FROM PYTHON SOURCE LINES 69-84 .. code-block:: default V1 = ( ASC_TRAIN + B_TIME_catalog_dict['TRAIN'] * TRAIN_TT_SCALED + B_COST_catalog_dict['TRAIN'] * TRAIN_COST_SCALED ) V2 = ( B_TIME_catalog_dict['SM'] * SM_TT_SCALED + B_COST_catalog_dict['SM'] * SM_COST_SCALED ) V3 = ( ASC_CAR + B_TIME_catalog_dict['CAR'] * CAR_TT_SCALED + B_COST_catalog_dict['CAR'] * CAR_CO_SCALED ) .. GENERATED FROM PYTHON SOURCE LINES 85-86 Associate utility functions with the numbering of alternatives. .. GENERATED FROM PYTHON SOURCE LINES 86-88 .. code-block:: default V = {1: V1, 2: V2, 3: V3} .. GENERATED FROM PYTHON SOURCE LINES 89-90 Associate the availability conditions with the alternatives. .. GENERATED FROM PYTHON SOURCE LINES 90-92 .. code-block:: default av = {1: TRAIN_AV_SP, 2: SM_AV, 3: CAR_AV_SP} .. GENERATED FROM PYTHON SOURCE LINES 93-95 Definition of the model. This is the contribution of each observation to the log likelihood function. .. GENERATED FROM PYTHON SOURCE LINES 95-97 .. code-block:: default logprob = models.loglogit(V, av, CHOICE) .. GENERATED FROM PYTHON SOURCE LINES 98-99 Create the Biogeme object. .. GENERATED FROM PYTHON SOURCE LINES 99-104 .. code-block:: default the_biogeme = bio.BIOGEME(database, logprob) the_biogeme.modelName = 'b01alt_spec' the_biogeme.generate_html = False the_biogeme.generate_pickle = False .. rst-class:: sphx-glr-script-out .. code-block:: none File biogeme.toml has been parsed. .. GENERATED FROM PYTHON SOURCE LINES 105-106 Estimate the parameters. .. GENERATED FROM PYTHON SOURCE LINES 106-108 .. code-block:: default dict_of_results = the_biogeme.estimate_catalog() .. rst-class:: sphx-glr-script-out .. code-block:: none Estimating 4 models. File biogeme.toml has been parsed. *** Initial values of the parameters are obtained from the file __b01alt_spec_000000.iter Cannot read file __b01alt_spec_000000.iter. Statement is ignored. Optimization algorithm: hybrid Newton/BFGS with simple bounds [simple_bounds] ** Optimization: Newton with trust region for simple bounds Iter. ASC_CAR ASC_TRAIN B_COST_CAR B_COST_SM B_COST_TRAIN B_TIME_CAR B_TIME_SM B_TIME_TRAIN Function Relgrad Radius Rho 0 -0.17 -0.54 -0.52 -0.7 -1 -0.8 -0.39 -0.58 5.4e+03 0.067 10 1.1 ++ 1 -0.27 -0.25 -0.72 -1 -2.2 -1.2 -0.92 -0.83 5.1e+03 0.045 1e+02 1.2 ++ 2 -0.36 -0.11 -0.78 -1.1 -2.9 -1.3 -1.1 -0.89 5.1e+03 0.012 1e+03 1.1 ++ 3 -0.37 -0.078 -0.79 -1.1 -3.1 -1.3 -1.1 -0.89 5.1e+03 0.00076 1e+04 1 ++ 4 -0.37 -0.078 -0.79 -1.1 -3.1 -1.3 -1.1 -0.89 5.1e+03 2.9e-06 1e+04 1 ++ Results saved in file b01alt_spec_000000.html Results saved in file b01alt_spec_000000.pickle File biogeme.toml has been parsed. *** Initial values of the parameters are obtained from the file __b01alt_spec_000001.iter Cannot read file __b01alt_spec_000001.iter. Statement is ignored. Optimization algorithm: hybrid Newton/BFGS with simple bounds [simple_bounds] ** Optimization: Newton with trust region for simple bounds Iter. ASC_CAR ASC_TRAIN B_COST B_TIME Function Relgrad Radius Rho 0 -0.49 -0.92 -0.88 -0.67 5.4e+03 0.041 10 1.1 ++ 1 -0.18 -0.73 -1 -1.2 5.3e+03 0.0072 1e+02 1.1 ++ 2 -0.16 -0.7 -1.1 -1.3 5.3e+03 0.00018 1e+03 1 ++ 3 -0.16 -0.7 -1.1 -1.3 5.3e+03 1.1e-07 1e+03 1 ++ Results saved in file b01alt_spec_000001.html Results saved in file b01alt_spec_000001.pickle File biogeme.toml has been parsed. *** Initial values of the parameters are obtained from the file __b01alt_spec_000002.iter Cannot read file __b01alt_spec_000002.iter. Statement is ignored. Optimization algorithm: hybrid Newton/BFGS with simple bounds [simple_bounds] ** Optimization: Newton with trust region for simple bounds Iter. ASC_CAR ASC_TRAIN B_COST_CAR B_COST_SM B_COST_TRAIN B_TIME Function Relgrad Radius Rho 0 -0.34 -0.62 -0.61 -0.69 -1 -0.69 5.3e+03 0.054 10 1.1 ++ 1 -0.38 -0.044 -0.88 -0.99 -2.2 -1 5.1e+03 0.039 1e+02 1.2 ++ 2 -0.42 0.15 -0.94 -1.1 -2.8 -1.1 5.1e+03 0.0097 1e+03 1.1 ++ 3 -0.43 0.19 -0.94 -1.1 -2.9 -1.1 5.1e+03 0.00053 1e+04 1 ++ 4 -0.43 0.19 -0.94 -1.1 -2.9 -1.1 5.1e+03 1.5e-06 1e+04 1 ++ Results saved in file b01alt_spec_000002.html Results saved in file b01alt_spec_000002.pickle File biogeme.toml has been parsed. *** Initial values of the parameters are obtained from the file __b01alt_spec_000003.iter Cannot read file __b01alt_spec_000003.iter. Statement is ignored. Optimization algorithm: hybrid Newton/BFGS with simple bounds [simple_bounds] ** Optimization: Newton with trust region for simple bounds Iter. ASC_CAR ASC_TRAIN B_COST B_TIME_CAR B_TIME_SM B_TIME_TRAIN Function Relgrad Radius Rho 0 -0.66 -0.81 -0.89 -0.6 -0.74 -0.77 5.4e+03 0.065 10 1.1 ++ 1 -0.26 -0.36 -1 -1.1 -1.1 -1.4 5.3e+03 0.016 1e+02 1.1 ++ 2 -0.27 -0.21 -1.1 -1.1 -1.2 -1.6 5.3e+03 0.0011 1e+03 1 ++ 3 -0.27 -0.21 -1.1 -1.1 -1.2 -1.6 5.3e+03 4.9e-06 1e+03 1 ++ Results saved in file b01alt_spec_000003.html Results saved in file b01alt_spec_000003.pickle .. GENERATED FROM PYTHON SOURCE LINES 109-110 Number of estimated models. .. GENERATED FROM PYTHON SOURCE LINES 110-112 .. code-block:: default print(f'A total of {len(dict_of_results)} models have been estimated') .. rst-class:: sphx-glr-script-out .. code-block:: none A total of 4 models have been estimated .. GENERATED FROM PYTHON SOURCE LINES 113-114 All estimation results .. GENERATED FROM PYTHON SOURCE LINES 114-118 .. code-block:: default compiled_results, specs = compile_estimation_results( dict_of_results, use_short_names=True ) .. GENERATED FROM PYTHON SOURCE LINES 119-121 .. code-block:: default compiled_results .. raw:: html
Model_000000 Model_000001 Model_000002 Model_000003
Number of estimated parameters 8 4 6 6
Sample size 6768 6768 6768 6768
Final log likelihood -5075.704346 -5331.252007 -5083.499937 -5312.894223
Akaike Information Criterion 10167.408692 10670.504014 10178.999875 10637.788446
Bayesian Information Criterion 10221.968379 10697.783857 10219.91964 10678.708211
ASC_CAR (t-test) -0.367 (-3.32) -0.155 (-2.66) -0.427 (-5.55) -0.271 (-2.29)
ASC_TRAIN (t-test) -0.0754 (-0.712) -0.701 (-8.49) 0.189 (2.06) -0.202 (-1.82)
B_COST_CAR (t-test) -0.786 (-5.27) -0.939 (-8.1)
B_COST_SM (t-test) -1.12 (-14.2) -1.09 (-15.5)
B_COST_TRAIN (t-test) -3.08 (-16) -2.93 (-17.4)
B_TIME_CAR (t-test) -1.29 (-7.92) -1.12 (-10.3)
B_TIME_SM (t-test) -1.11 (-6.25) -1.17 (-6.42)
B_TIME_TRAIN (t-test) -0.889 (-7.51) -1.57 (-14.4)
B_COST (t-test) -1.08 (-15.9) -1.07 (-16)
B_TIME (t-test) -1.28 (-12.3) -1.12 (-9.3)


.. GENERATED FROM PYTHON SOURCE LINES 122-123 Glossary .. GENERATED FROM PYTHON SOURCE LINES 123-126 .. code-block:: default for short_name, spec in specs.items(): print(f'{short_name}\t{spec}') .. rst-class:: sphx-glr-script-out .. code-block:: none Model_000000 B_COST_gen_altspec:altspec;B_TIME_gen_altspec:altspec Model_000001 B_COST_gen_altspec:generic;B_TIME_gen_altspec:generic Model_000002 B_COST_gen_altspec:altspec;B_TIME_gen_altspec:generic Model_000003 B_COST_gen_altspec:generic;B_TIME_gen_altspec:altspec .. GENERATED FROM PYTHON SOURCE LINES 127-128 Estimation results of the Pareto optimal models. .. GENERATED FROM PYTHON SOURCE LINES 128-133 .. code-block:: default pareto_results = pareto_optimal(dict_of_results) compiled_pareto_results, pareto_specs = compile_estimation_results( pareto_results, use_short_names=True ) .. rst-class:: sphx-glr-script-out .. code-block:: none No Pareto file has been provided .. GENERATED FROM PYTHON SOURCE LINES 134-136 .. code-block:: default compiled_pareto_results .. raw:: html
Model_000000 Model_000001 Model_000002
Number of estimated parameters 8 4 6
Sample size 6768 6768 6768
Final log likelihood -5075.704346 -5331.252007 -5083.499937
Akaike Information Criterion 10167.408692 10670.504014 10178.999875
Bayesian Information Criterion 10221.968379 10697.783857 10219.91964
ASC_CAR (t-test) -0.367 (-3.32) -0.155 (-2.66) -0.427 (-5.55)
ASC_TRAIN (t-test) -0.0754 (-0.712) -0.701 (-8.49) 0.189 (2.06)
B_COST_CAR (t-test) -0.786 (-5.27) -0.939 (-8.1)
B_COST_SM (t-test) -1.12 (-14.2) -1.09 (-15.5)
B_COST_TRAIN (t-test) -3.08 (-16) -2.93 (-17.4)
B_TIME_CAR (t-test) -1.29 (-7.92)
B_TIME_SM (t-test) -1.11 (-6.25)
B_TIME_TRAIN (t-test) -0.889 (-7.51)
B_COST (t-test) -1.08 (-15.9)
B_TIME (t-test) -1.28 (-12.3) -1.12 (-9.3)


.. GENERATED FROM PYTHON SOURCE LINES 137-138 Glossary. .. GENERATED FROM PYTHON SOURCE LINES 138-140 .. code-block:: default for short_name, spec in pareto_specs.items(): print(f'{short_name}\t{spec}') .. rst-class:: sphx-glr-script-out .. code-block:: none Model_000000 B_COST_gen_altspec:altspec;B_TIME_gen_altspec:altspec Model_000001 B_COST_gen_altspec:generic;B_TIME_gen_altspec:generic Model_000002 B_COST_gen_altspec:altspec;B_TIME_gen_altspec:generic .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.717 seconds) .. _sphx_glr_download_auto_examples_assisted_plot_b03alt_spec.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_b03alt_spec.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_b03alt_spec.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_