Professional Documents
Culture Documents
Generating Random Variables I: Anatoli Iambartsev
Generating Random Variables I: Anatoli Iambartsev
Anatoli Iambartsev
IME-USP
Aula 1. Generating random variables I. 1
X X
F (x) = P(X = xi) = p(xi )
xi ≤x xi ≤x
X
P(a < X ≤ b) = p(xi )
a<xi ≤b
Aula 1. Generating random variables I. 3
• ect.
Aula 1. Generating random variables I. 4
0
Aula 1. Generating random variables I. 7
1 1
F(x)
f(x)
1 1
Aula 1. Generating random variables I. 8
Uniform simulation.
> set.seed(2)
> runif(5)
> set.seed(1)
> runif(5)
> set.seed(2)
> runif(5)
1 1
F (x) = 21 + π1 arctan x−µ
• Cauchy: f (x) = πσ 1+( x−µ )2
, σ
;
σ
γ
• Pareto(γ): f (x) = (1+x)γ+1
, F (x) = 1 . . .
Aula 1. Generating random variables I. 14
Thus
0, if U ≤ p;
X = F −1 (U ) = ∼ B(p).
1, if U > p,
Aula 1. Generating random variables I. 16
Accept-reject method.
Accept-reject method.
[RC, Ch.2.3] Constraints:
f (x)
• there is a constant M with g(x)
≤ M for all x.
X ∼ f is simulated as follows.
• generate Y ∼ g;
1 f (Y )
• if U ≤ M g(Y )
, then we set X = Y , otherwise we
discard Y and U and start again.
Aula 1.
Aula 1. Generating random variables I. 20
20
Accept-reject method.
method.
f Mg
f
g
Aula 1. Generating random variables I. 21
Accept-reject method.
Proof.
P(Y ≤ x) = P(Y ≤ x | Y accepted)
= P(Y ≤ x | U ≤ f (Y )/M g(Y ))
R∞
P(Y ≤ x ∩ U ≤ f (Y )/M g(Y ) | Y = y)g(y)dy
= −∞
P(U ≤ f (Y )/M g(Y ))
Rx Rx
−∞ (f (y)/M g(y)) g(y)dy −∞
f (y)dy
= =
P(U ≤ f (Y )/M g(Y )) M P(U ≤ f (Y )/M g(Y ))
in the same way
Z ∞
P(U ≤ f (Y )/M g(Y )) = P(U ≤ f (Y )/M g(Y ) | Y = y)g(y)dy
−∞
Z ∞ Z ∞
1 1
= (f (y)/M g(y)) g(y)dy = f (y)dy = .
−∞ M −∞ M
Aula 1. Generating random variables I. 22
Accept-reject method.
Accept-reject method.
1
The maximum is attained at x = 2(1−λ)
, and
f (x) K e−1/2
M = max = · → min
x g(x) λ (2(1 − λ))1/2 λ
Accept-reject method.
√
√2 e−x /2 , x
2
Example. Let X ∼ f (x) = π
> 0. And let
instrumental variable be Y ∼ Exp(1)
r
f (x) f (1) 2e
M = max = = ≈ 1.32
x g(x) g(1) π
f (x) x2 1 (1 − x)2
= exp x − − = exp − .
M g(x) 2 2 2
Thus, the algorithm:
References: