Beruflich Dokumente
Kultur Dokumente
Introduction to Simulation WS05/06 - L 06 1/36 Sanja Lazarova-Molnar Introduction to Simulation WS05/06 - L 06 2/36 Sanja Lazarova-Molnar
Introduction to Simulation WS05/06 - L 06 3/36 Sanja Lazarova-Molnar Introduction to Simulation WS05/06 - L 06 4/36 Sanja Lazarova-Molnar
Linear Congruential Method Linear Congruential Method
The most important type of RNG is called The LCM needs three integer parameters a, c and m
The Linear Congruential Method (LCM)
It generates a sequence of integers 0<Xi <m :
The LCM is used in almost all simulators
Xi = (a ·Xi -1+ c) mod m
It (can) fulfil all the desired properties
The random numbers 0<Ri <1 that we need are then
It is very easy to implement
Ri = Xi / m
Introduction to Simulation WS05/06 - L 06 5/36 Sanja Lazarova-Molnar Introduction to Simulation WS05/06 - L 06 6/36 Sanja Lazarova-Molnar
Xi 4 52 36 20 4
Introduction to Simulation WS05/06 - L 06 7/36 Sanja Lazarova-Molnar Introduction to Simulation WS05/06 - L 06 8/36 Sanja Lazarova-Molnar
Linear Congruential Method The Combined LCM
Introduction to Simulation WS05/06 - L 06 9/36 Sanja Lazarova-Molnar Introduction to Simulation WS05/06 - L 06 10/36 Sanja Lazarova-Molnar
Set yi = 6 xj , j mod 6 = i and compute p(yi): Then the following period P can be achieved:
yi 0 1 2 3 4 5
p(yi) 6 6 6 6 6 6 P = (m1-1) (m2-1) ... (mk-1) / 2k-1
Introduction to Simulation WS05/06 - L 06 11/36 Sanja Lazarova-Molnar Introduction to Simulation WS05/06 - L 06 12/36 Sanja Lazarova-Molnar
Tests for Random Numbers The Null Hypothesis
It is important that the RN generated are The null hypothesis is an important concept in statistics
uniformly distributed on (0..1)
independent We say for example: H0: Ri ~ U [0,1]
Introduction to Simulation WS05/06 - L 06 13/36 Sanja Lazarova-Molnar Introduction to Simulation WS05/06 - L 06 14/36 Sanja Lazarova-Molnar
There are two important tests: Compute the sample distribution SN (x):
Kolmogorov - Smirnov test
Chi-square test SN (x) = (# Ri d x ) / N
Introduction to Simulation WS05/06 - L 06 15/36 Sanja Lazarova-Molnar Introduction to Simulation WS05/06 - L 06 16/36 Sanja Lazarova-Molnar
Kolmogorov–Smirnov Test Kolmogorov–Smirnov Test
Compute N =4
D = max | SN (x) – F (x) | 1
SN (x)
0.75 F (x)
The distribution of D is known when Ri ~ F
Its values depend on N and D 0.5
Introduction to Simulation WS05/06 - L 06 17/36 Sanja Lazarova-Molnar Introduction to Simulation WS05/06 - L 06 18/36 Sanja Lazarova-Molnar
It divides the sample data into k classes The F distr. has a parameter f = k - 1 (d.o.f.)
Introduction to Simulation WS05/06 - L 06 19/36 Sanja Lazarova-Molnar Introduction to Simulation WS05/06 - L 06 20/36 Sanja Lazarova-Molnar
Chi-Squared Test Runs Test
Introduction to Simulation WS05/06 - L 06 21/36 Sanja Lazarova-Molnar Introduction to Simulation WS05/06 - L 06 22/36 Sanja Lazarova-Molnar
Introduction to Simulation WS05/06 - L 06 23/36 Sanja Lazarova-Molnar Introduction to Simulation WS05/06 - L 06 24/36 Sanja Lazarova-Molnar
Runs Test Autocorrelation
Introduction to Simulation WS05/06 - L 06 25/36 Sanja Lazarova-Molnar Introduction to Simulation WS05/06 - L 06 26/36 Sanja Lazarova-Molnar
No test for random numbers is perfect! Plot results for LCM a =37, c =1, m =64 in (x,y) pairs:
Consider the sequence
1
0.2 0.8 0.7 0.3 0.4 0.6 0.9 0.1
0.9
0.7
0.6
Take numbers as (x,y) pairs:
0.5
0.4
(0.2, 0.8) (0.7, 0.3) (0.4, 0.6) (0.9, 0.1)
0.3
0.2
x
0.1
x
0
0 0.2 0.4 0.6 0.8 1
x
x
Introduction to Simulation WS05/06 - L 06 27/36 Sanja Lazarova-Molnar Introduction to Simulation WS05/06 - L 06 28/36 Sanja Lazarova-Molnar
No Test is Perfect! Generating Random Variates
The IBM generator RANDU: a =216+3, c =0, m =231 How to generate random numbers of any distribution:
Plot results in (x, y, z) triplets:
Given:
a U (0,1) random number generator
a cdf F (x) that describes the desired distribution
Then:
1. Generate y ~ U (0,1)
2. Compute x = F -1(y)
Introduction to Simulation WS05/06 - L 06 29/36 Sanja Lazarova-Molnar Introduction to Simulation WS05/06 - L 06 30/36 Sanja Lazarova-Molnar
How to generate random numbers of any distribution: The cdf of the exponential distribution:
F(x) = 1 e Ox
1
F(x)
x
~U(0,1) Inversion:
y = 1 e Ox
x = 1/O · log(1 y)
0 x
~F
Introduction to Simulation WS05/06 - L 06 31/36 Sanja Lazarova-Molnar Introduction to Simulation WS05/06 - L 06 32/36 Sanja Lazarova-Molnar
The Normal Distribution The Weibull Distribution
There is no closed form for the Normal cdf The cdf of the Weibull distribution:
Solutions: E
Approximate numerically
F(x) = 1 e– (x/D)
Approximate using alternative formulae
Introduction to Simulation WS05/06 - L 06 33/36 Sanja Lazarova-Molnar Introduction to Simulation WS05/06 - L 06 34/36 Sanja Lazarova-Molnar
How does the simulator use the RN? Sample each RV and choose the smaller value:
Consider this simple model, starting in state A:
1
0.9
0.8
0.7 X
0.6
0.5
RV X is "fast", RV Y is "slow": 0.4
0.3
X
1
0.2
0.9
0.1
0.8
0.7
0
0.6
0.5
0.4
In this case, almost always, X will be chosen
0.3
0.2
When will the simulator choose Y?
0.1
0 Many replications will be needed!
Introduction to Simulation WS05/06 - L 06 35/36 Sanja Lazarova-Molnar Introduction to Simulation WS05/06 - L 06 36/36 Sanja Lazarova-Molnar