This webpage is for programmers who need examples of use of the functions of the package. The examples are designed to illustrate the syntax. They do not correspond to any meaningful model. For examples of models, visit biogeme.epfl.ch.
import datetime
print(datetime.datetime.now())
import biogeme.version as ver
print(ver.getText())
import biogeme.draws as dr
import numpy as np
np.random.seed(90267)
draws = dr.getUniform(sampleSize=3,numberOfDraws=10,symmetric=False)
draws
draws = dr.getUniform(sampleSize=3,numberOfDraws=10,symmetric=True)
draws
The Modified Latin Hypercube Sampling (MLHS, Hess et al, 2006) provides U[0,1] draws from a perturbed grid, designed for Monte-Carlo integration.
latinHypercube = dr.getLatinHypercubeDraws(sampleSize=3,numberOfDraws=10)
latinHypercube
The same method can be used to generate draws from U[-1,1]
latinHypercube = dr.getLatinHypercubeDraws(sampleSize=5,numberOfDraws=10,symmetric=True)
latinHypercube
The user can provide her own series of U[0,1] draws.
myUnif = np.random.uniform(size=30)
myUnif
latinHypercube = dr.getLatinHypercubeDraws(sampleSize=3,numberOfDraws=10,symmetric=False,uniformNumbers=myUnif)
latinHypercube
The uniform draws can also be arranged in a two-dimension array
myUnif = dr.getUniform(sampleSize=3,numberOfDraws=10)
myUnif
latinHypercube = dr.getLatinHypercubeDraws(sampleSize=3,numberOfDraws=10,uniformNumbers=myUnif)
latinHypercube
One Halton sequence
halton = dr.getHaltonDraws(sampleSize=2,numberOfDraws=10,base=3)
halton
Several Halton sequences
halton = dr.getHaltonDraws(sampleSize=3,numberOfDraws=10)
halton
Shuffled Halton sequences
halton = dr.getHaltonDraws(sampleSize=3,numberOfDraws=10,shuffled=True)
halton
The above sequences were generated using the default base: 2. It is possible to generate sequences using different prime numbers.
halton = dr.getHaltonDraws(sampleSize=1,numberOfDraws=10,base=3)
halton
It is also possible to skip the first items of the sequence. This is desirable in the context of Monte-Carlo integration.
halton = dr.getHaltonDraws(sampleSize=1,numberOfDraws=10,base=3,skip=10)
halton
Antithetic draws can be generated from any function generating uniform draws
draws = dr.getAntithetic(dr.getUniform,sampleSize=3,numberOfDraws=10)
draws
Antithetic MLHS
draws = dr.getAntithetic(dr.getLatinHypercubeDraws,sampleSize=3,numberOfDraws=10)
draws
Antithetic Halton.
draws = dr.getAntithetic(dr.getHaltonDraws,sampleSize=1,numberOfDraws=10)
draws
As antithetic Halton draws may be correlated, it is a good idea to skip the first draws
def halton(sampleSize,numberOfDraws):
return dr.getHaltonDraws(numberOfDraws,sampleSize,skip=100)
draws = dr.getAntithetic(halton,sampleSize=3,numberOfDraws=10)
draws
Generate pseudo-random numbers from a normal distribution N(0,1) using the Algorithm AS241 Appl. Statist. (1988) Vol. 37, No. 3 by Wichura
draws = dr.getNormalWichuraDraws(sampleSize=3,numberOfDraws=10)
draws
The antithetic version actually generates half of the draws and complete them with their antithetic version
draws = dr.getNormalWichuraDraws(sampleSize=3,numberOfDraws=10,antithetic=True)
draws
The user can provide her own series of U[0,1] draws. In this example, we use the MLHS procedure to generate these draws. Note that, if the antithetic version is used, only half of the requested draws must be provided.
myUnif = dr.getLatinHypercubeDraws(sampleSize=3,numberOfDraws=5)
myUnif
draws = dr.getNormalWichuraDraws(sampleSize=3,numberOfDraws=10,uniformNumbers=myUnif,antithetic=True)
draws
The same with Halton draws
myUnif = dr.getHaltonDraws(sampleSize=2,numberOfDraws=5,base=3,skip=10)
myUnif
draws = dr.getNormalWichuraDraws(numberOfDraws=10,sampleSize=2,uniformNumbers=myUnif,antithetic=True)
draws