Stochastic Simulation Generation of random variables Continuous sample space
Bo Friis Nielsen
Institute of Mathematical Modelling Technical University of Denmark 2800 Kgs. Lyngby – Denmark Email: bfn@imm.dtu.dk
Stochastic Simulation Generation of random variables Continuous - - PowerPoint PPT Presentation
Stochastic Simulation Generation of random variables Continuous sample space Bo Friis Nielsen Institute of Mathematical Modelling Technical University of Denmark 2800 Kgs. Lyngby Denmark Email: bfn@imm.dtu.dk Plan W1.1-2 Plan W1.1-2
Institute of Mathematical Modelling Technical University of Denmark 2800 Kgs. Lyngby – Denmark Email: bfn@imm.dtu.dk
02443 – lecture 4 2
DTU
Random number generation Independent Random variable Output Independent, uniformly distributed RN Model Distribution
02443 – lecture 4 3
DTU
X1, X2, ... Xn with a given distribution, Fx(x), (or probability density function [pdf]).
independent samples from the uniform distribution on ]0, 1[.
02443 – lecture 4 4
DTU
02443 – lecture 4 5
DTU
Our norm distribution or building brick, Ui ∼ U(0, 1) f(x) = 1 F(x) = x for 0 ≤ x ≤ 1
1 1
E(Ui) = 1
2
Var(Ui) =
1 12
02443 – lecture 4 6
DTU
x
x F(x) x F(x) = P(X<=x)
02443 – lecture 4 7
DTU
X F(X) X F(X) = U
02443 – lecture 4 8
DTU
U * U = F(X) * U = F(X) * X = F (U)
−1
02443 – lecture 4 9
DTU
The random variable U = F(X)
U=F(X) X
U = F(X) F(x) = P(X ≤ x) P(U ≤ u) = P(F(X) ≤ u) = P(X ≤ F −1(u)) = F(F −1(u)) = u I.e. F(X) is uniformly distributed.
02443 – lecture 4 10
DTU
Assume g continuous and increasing and let: X = g(Y ) Y ∼ FY (y) = P(Y ≤ y) then FX(x) = P(X ≤ x) = P(g(Y ) ≤ x) = P(Y ≤ g−1(x)) = FY (g−1(x)) If Y = U then FU(u) = u, and FX(x) = g−1(x). If X = F −1(U) then X will have the cdf F(x) ((F −1(x))−1 = F(x)).
02443 – lecture 4 11
DTU
Now, focus on U(a, b). f(x) = 1 b − a a ≤ x ≤ b F(x) = x − a b − a F −1(u) = a + (b − a)u X = a + (b − a)U ∼ U(a, b)
02443 – lecture 4 12
DTU
The time between events in a Poisson process is exponentially
F(x) = 1 − e(−λx) E(X) = 1 λ F −1(u) = −1 λ log(1 − u) So (both 1 − U and U are uniformly distributed) X = −log(U) λ ∼ exp(λ)
0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Exponential distribution 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 1 2 3 4 5 6 7 8 9 1002443 – lecture 4 13
DTU
Is often used in connection to description of income (over a certain level). X ∼ Pa(k, β) F(x) = 1 − β x k x ≥ β X = β
k
k k − 1β Var(X) = k (k − 1)2(k − 2)β2 k > 1, 2
1 2 3 4 5 6 7 8 9 10 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Pareto distribution, Par(1,1)Pareto with X ≥ 0 F(x) = 1−
β −k X = β
k − 1
02443 – lecture 4 14
DTU
X a result of many (∞) independent sources (Central limit theorem) X ∼ N(µ, σ2) Z ∼ N(0, 1) X = µ + σZ Z = Φ−1(U)
−3 −2 −1 1 2 3 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Gaussian distribution02443 – lecture 4 15
DTU
a random variable with a certain distribution.
(θ = 2πU2, r =
coordinates (X = Z1 and Y = Z2). Z1 Z2 =
cos(2πU2) sin(2πU2) Z1, Z2 ∼ N(0, 1)
X =
n
Ui − n 2
02443 – lecture 4 16
DTU
Sine and cosine can be calculated by the following acceptance/rejection algorith m:
1 + V 2 2
R , sin (2πU2) = V2 R
02443 – lecture 4 17
DTU
Y ∼ LN(α, β2) log(Y ) ∼ N(α, β2) Y = eX X = α + β Z Z ∼ N(0, 1)
02443 – lecture 4 18
DTU
distribution,Zi ∼ N(0, 1).
j=1 cijZj
Σ, Σ = CC′
02443 – lecture 4 19
DTU
F(x) = 1 −
m
pie−λix =
m
pi
Formally we can express Z = XI where I ∼ {1, 2, . . . , m} with P(I = i) = pi and XI ∼ exp (λI)
λI log (U)
02443 – lecture 4 20
DTU
distribution with integer valued shape parameter
sum of independent exponential variables
adding n exponential random variates. Y ∼ Erln(λ) E(Y ) = n λ Var(Y ) = n λ2 with λi = λ Y =
n
Xi =
n
−1 λ log (Ui) = −1 λ log (Πn
i=1Ui)
02443 – lecture 4 21
DTU
Generalization: f(x) =
X given Y : f(x|y) Y : f(y) Y is typically a parameter (eg. the conditional distribution of X given Y = µ is N(µ, σ2)) Generate:
02443 – lecture 4 22
DTU
Problem: we would like to generate X from pdf f, but it is much faster to generate Y with pdf g. NB. X and Y have the same sample space. If f(y) g(y) ≤ c for all y and some c
cg(Y ) set X = Y .Otherwise return to step 1.
g(y)dy f(y) cg(y) = f(y)dy c
02443 – lecture 4 23
DTU Statistics Toolbox Version 4.0 (R13) 20-Jun-2002 . . . Random Number Generators. betarnd
binornd
chi2rnd
exprnd
frnd
gamrnd
geornd
hygernd
iwishrnd
lognrnd
(a) Exponential distribution (b) Normal distribution (at least with standard Box-Mueller) (c) Pareto distribution, with β = 1 and experiment with different values of k values: k = 2.05, k = 2.5, k = 3 and k = 4. Verify the results by comparing histograms with analytical results and perform tests for distribution type.
mean value and variance, with analytical results, which can be calculated as E(X) = β
k k−1 (for k > 1) and
Var(X) = β2
k (k−1)2(k−2) (for k > 2)
intervals for the mean and variance, each based on 10