Categories of examples
Swissmetro
01logit.pyFile 01logit.py

Author: Michel Bierlaire, EPFL
Date: Thu Sep 6 15:14:39 2018

Example of a logit model.
Three alternatives: Train, Car and Swissmetro
SP data
01logitBis.pyFile 01logitBis.py

Author: Michel Bierlaire, EPFL
Date: Thu Sep 6 15:14:39 2018

Logit model
Three alternatives: Train, Car and Swissmetro
SP data
01logit_allAlgos.pyFile 01logit_allAlgos.py

Author: Michel Bierlaire, EPFL
Date: Sat Sep 7 17:57:16 2019

Logit model
Three alternatives: Train, Car and Swissmetro
SP data
01logit_simul.pyFile 01logit_simul.py

Author: Michel Bierlaire, EPFL
Date: Sat Sep 7 18:06:08 2019

Example of simulation with a logit model
Three alternatives: Train, Car and Swissmetro
SP data
02weight.pyFile 02weight.py

Author: Michel Bierlaire, EPFL
Date: Sat Sep 7 18:11:18 2019

Example of a logit model with Weighted Exogenous Sample Maximum Likelihood (WESML).
Three alternatives: Train, Car and Swissmetro
SP data
03scale.pyFile 03scale.py

Author: Michel Bierlaire, EPFL
Date: Thu Sep 6 15:14:39 2018

Illustrates heteroscedastic specification. A different scale is
associated with different segments of the sample.
Three alternatives: Train, Car and Swissmetro
SP data
04modifVariables.pyFile 04modifVariables.py

Author: Michel Bierlaire, EPFL
Date: Sat Sep 7 18:20:41 2019

Illustrates the modification of variables.
Three alternatives: Train, Car and Swissmetro
SP data
05normalMixture.pyFile 05normalMixture.py

Author: Michel Bierlaire, EPFL
Date: Sat Sep 7 18:23:01 2019

Example of a mixture of logit models, using Monte-Carlo integration.
Three alternatives: Train, Car and Swissmetro
SP data
05normalMixtureIntegral.pyFile 05normalMixtureIntegral.py

Author: Michel Bierlaire, EPFL
Date: Sat Sep 7 18:23:01 2019

Example of a mixture of logit models, using numerical integration.
Three alternatives: Train, Car and Swissmetro
SP data
05normalMixture_allAlgos.pyFile 05normalMixture_allAlgos.py

Author: Michel Bierlaire, EPFL
Date: Mon Dec 23 15:48:59 2019

Example of a mixture of logit models, using Monte-Carlo integration.
Three alternatives: Train, Car and Swissmetro
SP data
05normalMixture_simul.pyFile 05normalMixture_simul.py

Author: Michel Bierlaire, EPFL
Date: Sat Sep 7 18:42:55 2019

Example of a mixture of logit models, using Monte-Carlo integration, and
used for simulatiom
Three alternatives: Train, Car and Swissmetro
SP data
06unifMixture.pyFile 06unifMixture.py

Author: Michel Bierlaire, EPFL
Date: Sat Sep 7 18:23:01 2019

Example of a mixture of logit models, using Monte-Carlo integration.
The mixing distribution is uniform.
Three alternatives: Train, Car and Swissmetro
SP data
06unifMixtureIntegral.pyFile 06unifMixtureIntegral.py

Author: Michel Bierlaire, EPFL
Date: Sat Sep 7 20:45:18 2019

Example of a mixture of logit models, using numerical integration.
The mixing distribution is uniform.
Three alternatives: Train, Car and Swissmetro
SP data
06unifMixtureMHLS.pyFile 06unifMixtureMHLS.py

Author: Michel Bierlaire, EPFL
Date: Sat Sep 7 18:23:01 2019

Example of a mixture of logit models, using Monte-Carlo integration.
The mixing distribution is uniform.
The draws are from the Modified Hypercube Latin Square
Three alternatives: Train, Car and Swissmetro
SP data
07discreteMixture.pyFile 07discreteMixture.py

Author: Michel Bierlaire, EPFL
Date: Sun Sep 8 00:06:20 2019

Example of a discrete mixture of logit (or latent class model)
Three alternatives: Train, Car and Swissmetro
SP data
08boxcox.pyFile 08boxcox.py

Author: Michel Bierlaire, EPFL
Date: Sun Sep 8 00:33:03 2019

Example of a logit model, with a Box-Cox transform of variables.
Three alternatives: Train, Car and Swissmetro
SP data
09nested.pyFile 09nested.py

Author: Michel Bierlaire, EPFL
Date: Sun Sep 8 00:36:04 2019

Example of a nested logit model.
Three alternatives: Train, Car and Swissmetro
Train and car are in the same nest.
SP data
09nested_allAlgos.py
10nestedBottom.pyFile 10nestedBottom.py

Author: Michel Bierlaire, EPFL
Date: Sun Sep 8 00:36:04 2019

Example of a nested logit model where the normalization is done at the bottom level.
Three alternatives: Train, Car and Swissmetro
Train and car are in the same nest.
SP data
11cnl.pyFile 11cnl.py

Author: Michel Bierlaire, EPFL
Date: Sun Sep 8 11:10:42 2019

Example of a cross-nested logit model.
Three alternatives: Train, Car and Swissmetro
Train and car are in the same nest.
SP data
11cnl_simul.pyFile 11cnl_simul.py

Author: Michel Bierlaire, EPFL
Date: Sun Sep 8 11:13:22 2019

Example of simulation with a cross-nested logit model.
Three alternatives: Train, Car and Swissmetro
Train and car are in the same nest.
SP data
11cnl_sparse.pyFile 11cnl.py

Author: Michel Bierlaire, EPFL
Date: Sun Sep 8 11:10:42 2019

Example of a cross-nested logit model.
Three alternatives: Train, Car and Swissmetro
Train and car are in the same nest.
SP data
12panel.pyFile 12panel.py

Author: Michel Bierlaire, EPFL
Date: Sun Sep 8 18:55:38 2019

Example of a mixture of logit models, using Monte-Carlo integration.
The datafile is organized as panel data.
Three alternatives: Train, Car and Swissmetro
SP data
12panelIntegral.pyFile 12panelIntegral.py

Author: Michel Bierlaire, EPFL
Date: Sun Sep 8 18:55:38 2019

Example of a mixture of logit models, using numerical integration.
The datafile is organized as panel data.
Three alternatives: Train, Car and Swissmetro
SP data
12panel_bis.pyFile 12panel_bis.py

Author: Michel Bierlaire, EPFL
Date: Sun Sep 8 18:55:38 2019

Example of a mixture of logit models, using Monte-Carlo integration.
The agent effect, accounting for serial correlation, is included.
The datafile is organized as panel data.
Three alternatives: Train, Car and Swissmetro
SP data
13panelNormalized.pyFile 13panelNormalized.py

Author: Michel Bierlaire, EPFL
Date: Sun Sep 8 19:20:13 2019

Example of a mixture of logit models, using Monte-Carlo integration.
The agent effect, accounting for serial correlation, is included.
The term with the smallest variance has been normalized.
The datafile is organized as panel data.
Three alternatives: Train, Car and Swissmetro
SP data
14selectionBias.pyFile 14selectionBias.py

Author: Michel Bierlaire, EPFL
Date: Sun Sep 8 19:26:25 2019

Example of a nested logit model, with the corrections for endogenous sampling.
Three alternatives: Train, Car and Swissmetro
Train and car are in the same nest.
SP data
15panelDiscrete.pyFile 15panelDiscrete.py

Author: Michel Bierlaire, EPFL
Date: Sun Sep 8 19:30:31 2019

Example of a discrete mixture of logit models, also called latent class model.
The datafile is organized as panel data.
Three alternatives: Train, Car and Swissmetro
SP data
15panelDiscrete_bis.pyFile 15panelDiscrete_bis.py

Author: Michel Bierlaire, EPFL
Date: Sun Sep 8 19:44:03 2019

Example of a discrete mixture of logit models, also called latent class model.
The datafile is organized as panel data.
Here, we integrate before the discrete mixture to show that it is equivalent.
Three alternatives: Train, Car and Swissmetro
SP data
16panelDiscreteSocioEco.pyFile 16panelDiscreteSocioEco.py

Author: Michel Bierlaire, EPFL
Date: Sun Sep 8 19:40:48 2019

Example of a discrete mixture of logit models, also called latent class model.
The class membership model includes socio-economic variables.
The datafile is organized as panel data.
Three alternatives: Train, Car and Swissmetro
SP data
17lognormalMixture.pyFile 17lognormalMixture.py

Author: Michel Bierlaire, EPFL
Date: Sat Sep 7 18:23:01 2019

Example of a mixture of logit models, using Monte-Carlo integration.
The mixing distribution is distributed as a log normal.
Three alternatives: Train, Car and Swissmetro
SP data
17lognormalMixtureIntegral.pyFile 17lognormalMixtureIntegral.py

Author: Michel Bierlaire, EPFL
Date: Mon Sep 9 10:08:21 2019

Example of a mixture of logit models, using numerical integration.
The mixing distribution is distributed as a log normal.
Three alternatives: Train, Car and Swissmetro
SP data
18ordinalLogit.pyFile 18ordinalLogit.py

Author: Michel Bierlaire, EPFL
Date: Mon Sep 9 08:08:40 2019

Example of an ordinal logit model.
This is just to illustrate the syntax, as the data are not ordered.
But the example assume, for the sake of it, that they are 1->2->3
Three alternatives: Train, Car and Swissmetro
SP data
21probit.pyFile 21probit.py

Author: Michel Bierlaire, EPFL
Date: Mon Sep 9 10:14:57 2019

Example of a binary probit model.
Two alternatives: Train and Car
SP data
24haltonMixture.pyFile 24haltonMixture.py

Author: Michel Bierlaire, EPFL
Date: Mon Sep 9 11:02:37 2019

Example of a mixture of logit models, using quasi Monte-Carlo integration with
Halton draws (base 5).
The mixing distribution is normal.
Three alternatives: Train, Car and Swissmetro
SP data
25triangularMixture.pyFile 25triangularMixture.py

Author: Michel Bierlaire, EPFL
Date: Mon Sep 9 10:19:24 2019

Example of a mixture of logit models, using Monte-Carlo integration.
The mixing distirbution is specified by the user. Here, a triangular
distribution.
Three alternatives: Train, Car and Swissmetro
SP data
26triangularPanelMixture.pyFile 26triangularPanelMixture.py

Author: Michel Bierlaire, EPFL
Date: Mon Sep 9 10:27:40 2019

Example of a mixture of logit models, using Monte-Carlo integration.
THe micing distribution is user-defined (triangular, here).
The datafile is organized as panel data.
Three alternatives: Train, Car and Swissmetro
SP data
Calculating indicators
01nestedEstimation.pyFile 01nestedEstimation.py

Author: Michel Bierlaire, EPFL
Date: Wed Sep 11 09:59:55 2019

Estimation of a nested logit model, that will be used for simuation.
Three alternatives: public transporation, car and slow modes.
RP data.
02nestedPlot.pyFile 02nestedPlot.py

Author: Michel Bierlaire, EPFL
Date: Wed Sep 11 10:15:18 2019

We use a previously estimated nested logit model.
Three alternatives: public transporation, car and slow modes.
RP data.
We simulate pricing scenarios and their impact on the revenues.
02nestedSimulation.pyFile 02nestedSimulation.py

Author: Michel Bierlaire, EPFL
Date: Wed Sep 11 10:23:51 2019

We use a previously estimated nested logit model.
Three alternatives: public transporation, car and slow modes.
RP data.
We simulate market shares and revenues.
03nestedElasticities.pyFile 03nestedElasticities.py

Author: Michel Bierlaire, EPFL
Date: Wed Sep 11 10:28:11 2019

We use a previously estimated nested logit model.
Three alternatives: public transporation, car and slow modes.
RP data.
We calculate disaggregate and aggregate direct point elasticities.
04nestedElasticities.pyFile 04nestedElasticities.py

Author: Michel Bierlaire, EPFL
Date: Wed Sep 11 13:37:43 2019

We use a previously estimated nested logit model.
Three alternatives: public transporation, car and slow modes.
RP data.
We calculate disaggregate and aggregate cross point elasticities.
05nestedElasticities.pyFile 05nestedElasticities.py

Author: Michel Bierlaire, EPFL
Date: Wed Sep 11 13:41:33 2019

We use a previously estimated nested logit model.
Three alternatives: public transporation, car and slow modes.
RP data.
We calculate disaggregate and aggregate direct arc elasticities.
05nestedElasticitiesCI_Bootstrap.pyFile 05nestedElasticitiesCI_bootstrap.py

Author: Michel Bierlaire, EPFL
Date: Wed Sep 11 15:57:46 2019

We use a previously estimated nested logit model.
Three alternatives: public transporation, car and slow modes.
RP data.

We calculate disaggregate and aggregate direct arc elasticities, and
the confidence intervals. The difference with
05nestedElasticitiesConfidenceIntervals is that the simulated betas
used to calculated the confidence intervals are drawn from a normal
distribution based on the bootstrap estimate of the variance
covariance matrix.
05nestedElasticitiesConfidenceIntervals.pyFile 05nestedElasticitiesConfidenceIntervals.py

Author: Michel Bierlaire, EPFL
Date: Wed Sep 11 15:57:46 2019

We use a previously estimated nested logit model.
Three alternatives: public transporation, car and slow modes.
RP data.
We calculate disaggregate and aggregate direct arc elasticities, and
the confidence intervals.
06nestedWTP.pyFile 06nestedWTP.py

Author: Michel Bierlaire, EPFL
Date: Wed Sep 11 14:01:00 2019

We use a previously estimated nested logit model.
Three alternatives: public transporation, car and slow modes.
RP data.
We calculate and plot willingness to pay.
Monte-Carlo integration
01simpleIntegral.pyFile: 01simpleIntegral.py
Author: Michel Bierlaire, EPFL
Date: Wed Dec 11 16:20:24 2019

Calculation of a simple integral using Monte-Carlo integration.
02simpleIntegral.pyFile: 02simpleIntegral.py

Author: Michel Bierlaire, EPFL
Date: Wed Dec 11 16:57:51 2019

Calculation of a simple integral using numerical integration and
Monte-Carlo integration with various types of draws, including Halton
draws base 13. It illustrates how to use draws that are not directly
available in Biogeme.
03antithetic.pyFile: 03antithetic.py

Author: Michel Bierlaire, EPFL
Date: Wed Dec 11 17:00:05 2019

Calculation of a simple integral using Monte-Carlo integration with
Halton draws base 13. It illustrates how to use draws that
are not directly available in Biogeme.
03antitheticExplicit.pyFile: 03antitheticExplicit.py

Author: Michel Bierlaire, EPFL
Date: Wed Dec 11 17:04:40 2019

Calculation of a simple integral using Monte-Carlo integration with
antithetic Halton draws base 13. It illustrates how to use draws that
are not directly available in Biogeme.
04normalMixtureNumerical.pyFile: 04normalMixtureNumerical.py

Author: Michel Bierlaire, EPFL
Date: Wed Dec 11 17:06:52 2019

Calculation of a mixtures of logit models where the integral is
calculated using numerical integration.
05normalMixtureMonteCarlo.pyFile: 05normalMixtureMonteCarlo.py

Author: Michel Bierlaire, EPFL
Date: Wed Dec 11 17:11:45 2019

Calculation of a mixtures of logit models where the integral is
calculated using numerical integration and Monte-Carlo integration
with various types of draws.
06estimationIntegral.pyFile: 06estimationIntegral.py

Author: Michel Bierlaire, EPFL
Date: Wed Dec 11 17:17:05 2019

Estimation of a mixtures of logit models where the integral is
calculated using numerical integration.
07estimationMonteCarlo.pyFile: 07estimationMonteCarlo.py

Author: Michel Bierlaire, EPFL
Date: Wed Dec 11 17:25:14 2019

Estimation of a mixtures of logit models where the integral is
approximated using MonteCarlo integration.
07estimationMonteCarlo_500.pyFile: 07estimationMonteCarlo_500.py

Author: Michel Bierlaire, EPFL
Date: Wed Dec 11 17:25:04 2019

Estimation of a mixtures of logit models where the integral is
approximated using MonteCarlo integration.
07estimationMonteCarlo_anti.pyFile: 07estimationMonteCarlo_anti.py

Author: Michel Bierlaire, EPFL
Date: Wed Dec 11 17:24:55 2019

Estimation of a mixtures of logit models where the integral is
approximated using MonteCarlo integration, with antithetic draws.
07estimationMonteCarlo_anti_500.pyFile: 07estimationMonteCarlo_anti_500.py

Author: Michel Bierlaire, EPFL
Date: Wed Dec 11 17:24:43 2019

Estimation of a mixtures of logit models where the integral is
approximated using MonteCarlo integration, with antithetic draws.
07estimationMonteCarlo_halton.pyFile: 07estimationMonteCarlo_halton.py

Author: Michel Bierlaire, EPFL
Date: Wed Dec 11 17:24:32 2019

Estimation of a mixtures of logit models where the integral is
approximated using MonteCarlo integration, with Halton draws.
07estimationMonteCarlo_halton_500.pyFile: 07estimationMonteCarlo_halton_500.py

Author: Michel Bierlaire, EPFL
Date: Wed Dec 11 17:24:22 2019

Estimation of a mixtures of logit models where the integral is
approximated using MonteCarlo integration, with Halton draws.
07estimationMonteCarlo_mlhs.pyFile: 07estimationMonteCarlo_mlhs.py

Author: Michel Bierlaire, EPFL
Date: Wed Dec 11 17:24:11 2019

Estimation of a mixtures of logit models where the integral is
approximated using MonteCarlo integration, with Modified Latin
Hypercube Sampling draws.
07estimationMonteCarlo_mlhs_500.pyFile: 07estimationMonteCarlo_mlhs_500.py

Author: Michel Bierlaire, EPFL
Date: Wed Dec 11 17:24:00 2019

Estimation of a mixtures of logit models where the integral is
approximated using MonteCarlo integration, with Modified
Latin Hypercube Sampling draws.
07estimationMonteCarlo_mlhs_anti.pyFile: 07estimationMonteCarlo_mlhs_anti.py

Author: Michel Bierlaire, EPFL
Date: Wed Dec 11 17:23:45 2019

Estimation of a mixtures of logit models where the integral is
approximated using MonteCarlo integration, with antithetic Modified
Latin Hypercube Sampling draws.
07estimationMonteCarlo_mlhs_anti_500.pyFile 07estimationMonteCarlo_mlhs_anti_500.py

Author: Michel Bierlaire, EPFL
Date: Wed Dec 11 17:21:52 2019

Estimation of a mixtures of logit models where the integral is
approximated using MonteCarlo integration, with antithetic Modified
Latin Hypercube Sampling draws.
Choice models with latent variables
00factorAnalysis.pyFile 00factorAnalysis.py

Preliminary analysis of the indicators using factor analysis.

Author: Michel Bierlaire, EPFL
Date: Mon Sep 9 16:04:57 2019
01oneLatentRegression.pyFile 01oneLatentRegression.py

Measurement equation where the indicators are assumed continuous.
Linear regression.

Author: Michel Bierlaire, EPFL
Date: Mon Sep 9 16:30:04 2019
02oneLatentOrdered.pyFile 02oneLatentOrdered.py

Measurement equation where the indicators are discrete.
Ordered probit.

Author: Michel Bierlaire, EPFL
Date: Mon Sep 9 16:52:36 2019
03choiceOnly.pyFile 03choiceOnly.py

Choice model with the latent variable.
Mixture of logit.
No measurement equation for the indicators.

Author: Michel Bierlaire, EPFL
Date: Thu Sep 6 15:14:39 2018
04latentChoiceSeq.pyFile 04latentChoiceSeq.py

Choice model with the latent variable.
Mixture of logit.
Measurement equation for the indicators.
Sequential estimation.

Author: Michel Bierlaire, EPFL
Date: Tue Sep 10 08:13:18 2019
05latentChoiceFull.pyFile 05latentChoiceFull.py

Choice model with the latent variable.
Mixture of logit.
Measurement equation for the indicators.
Maximum likelihood (full information) estimation.

Author: Michel Bierlaire, EPFL
Date: Wed Sep 11 08:22:28 2019
06serialCorrelation.pyFile 06serialCorrelation.py

Choice model with the latent variable.
Mixture of logit, with agent effect to deal with serial correlation.
Measurement equation for the indicators.
Maximum likelihood (full information) estimation.

Author: Michel Bierlaire, EPFL
Date: Wed Sep 11 08:27:18 2019
07problem.pyFile 07problem.py

This file is the same as 02oneLatentOrdered.py, where The starting
values for the sigma have been change in order to illustrate a common
issue with the estimation of such models.

We set the starting value of a scale parameter (SIGMA_STAR_Envir02)
to a small value: 0.01. The resulting likelihood is so close to zero
that taking the log generates a numerical issue.

Make sure to set large initial values for scale parameters.

Author: Michel Bierlaire, EPFL
Date: Wed Sep 11 15:40:43 2019
07problem_simul.pyFile 07problem_simul.py

This file is an updated version of 07problem.py, where
the probabilities are simulated in order to
investigate the numerical issue.

Author: Michel Bierlaire, EPFL
Date: Wed Sep 11 15:40:43 2019
Jupyter Notebooks

The following Jupyter notebooks contain illustrations of the use of the different modules available in the Biogeme package. They are designed for programmers who are interested to exploit the functionalities of Biogeme.

Consult also the documentation of the code.