2 MS2 (Sampling)
2 MS2 (Sampling)
• Sampling Techniques
• Initiation to MCMC
1 / 17
2 Sampling from the posterior
2.1 Introduction
Introductory problem
Let Y = (Y1 , ..., Yn )|θ ∼ N (θ, 1) a conditional iid sample, and θ a
random variable with a Gamma prior P(θ) = Γ(θ; α, β):
2 / 17
2 Sampling from the posterior
2.1 Introduction
Introductory problem
Let Y = (Y1 , ..., Yn )|θ ∼ N (θ, 1) a conditional iid sample, and θ a
random variable with a Gamma prior P(θ) = Γ(θ; α, β):
2 / 17
2 Sampling from the posterior
2.2 Monte Carlo integration
Monte Carlo
3 / 17
2 Sampling from the posterior
2.2 Monte Carlo integration
Monte Carlo
Example:
R1 1
Pn
The integral 0 xdx can be approximated by n i=1 Xi
iid
where (Xi )ni=1 ∼ U[0,1]
3 / 17
2 Sampling from the posterior
2.2 Monte Carlo integration
2. Find a probability distribution P such that P(x) > 0 for all x ∈ (a, b)
1
Pn f (Xi )1(a,b) (Xi )
3. Approximate the integral by n i=1 P(Xi ) for large values of n
By√the Central Limit Theorem, the method has a rate of convergence of
1/ n
4 / 17
2 Sampling from the posterior
2.2 Monte Carlo integration
2. Find a probability distribution P such that P(x) > 0 for all x ∈ (a, b)
1
Pn f (Xi )1(a,b) (Xi )
3. Approximate the integral by n i=1 P(Xi ) for large values of n
By√the Central Limit Theorem, the method has a rate of convergence of
1/ n
4 / 17
2 Sampling from the posterior
2.2 Monte Carlo integration
Z
θ̂ = E[θ|y ] = θP(θ|y )dθ
Z
L(θ|y )P(θ)
= θR dθ
L(ϑ|y )P(ϑ)dϑ
R
θL(θ|y )P(θ)dθ
= R
L(θ|y )P(θ)dθ
1
Pn
θi L(θi |y )
≈ n1 Pi=1
n
n i=1 L(θi |y )
5 / 17
2 Sampling from the posterior
2.2 Monte Carlo integration
Z
θ̂ = E[θ|y ] = θP(θ|y )dθ
Z
L(θ|y )P(θ)
= θR dθ
L(ϑ|y )P(ϑ)dϑ
R
θL(θ|y )P(θ)dθ
= R
L(θ|y )P(θ)dθ
1
Pn
θi L(θi |y )
≈ n1 Pi=1
n
n i=1 L(θi |y )
5 / 17
2 Sampling from the posterior
2.2 Monte Carlo integration
6 / 17
2 Sampling from the posterior
2.2 Monte Carlo integration
• a posterior probability
6 / 17
2 Sampling from the posterior
2.3 Sampling methods
Inverse CDF
7 / 17
2 Sampling from the posterior
2.3 Sampling methods
Inverse CDF
Proposition 2.3
Let F be a cdf, and let F −1 be its inverse function
7 / 17
2 Sampling from the posterior
2.3 Sampling methods
4. Compute θ̃ := F̂ −1 (U)
8 / 17
2 Sampling from the posterior
2.3 Sampling methods
4. Compute θ̃ := F̂ −1 (U)
Using the Law of Large Numbers, we see that
N→∞
θ̃ → P(θ|y )
8 / 17
2 Sampling from the posterior
2.3 Sampling methods
Proposition 2.4
Let (Yi )N
i=1 iid sample from the distribution P and let Q a distribution
dominated by P (P Q). If (Ik )nk=1 ∼ M(1, PNw1 w , ..., PwN N w ), with
i=1 i i=1 i
wi = Q(Yi )/P(Yi ) then
N→∞
(YIk )nk=1 → Q,
9 / 17
2 Sampling from the posterior
2.3 Sampling methods
SIR Algorithm
2. Draw the iid sample (Ik )nk=1 from M(1, w1 , ..., wN ) with N n
L(θi |y )
wi = Pn
i=1 L(θi |y )
10 / 17
2 Sampling from the posterior
2.3 Sampling methods
SIR Algorithm
2. Draw the iid sample (Ik )nk=1 from M(1, w1 , ..., wN ) with N n
L(θi |y )
wi = Pn
i=1 L(θi |y )
10 / 17
2 Sampling from the posterior
2.3 Sampling methods
Accept-Reject Method
Let f , g two continuous pdf functions on X such that there exists M > 0
satisfying
f (x)
∀x ∈ X ≤ M.
g (x)
11 / 17
2 Sampling from the posterior
2.3 Sampling methods
Accept-Reject Method
Let f , g two continuous pdf functions on X such that there exists M > 0
satisfying
f (x)
∀x ∈ X ≤ M.
g (x)
Imagine we want to obtain a sample from the distribution with pdf f
using samples from the distribution with pdf g
I If U ≥ f (Y )
Mg (Y ) , then reject Y and start from the beginning
11 / 17
2 Sampling from the posterior
2.3 Sampling methods
Lemma 2.5
Let f , g two continuous pdf functions on X such that there exists M > 0
satisfying
f (x)
∀x ∈ X ≤ M.
g (x)
Let Y a random variable with pdf g and U a uniform random variable on
(0, 1); then
f (Y ) 1
P U≤ =
Mg (Y ) M
12 / 17
2 Sampling from the posterior
2.3 Sampling methods
Proposition 2.6
Let f , g two continuous pdf functions on X such that there exists M > 0
satisfying
f (x)
∀x ∈ X ≤ M.
g (x)
Let Y a random variable with pdf g and U a uniform random variable on
(0, 1); then
Z y
f (Y )
P Y ≤ y |U ≤ = F (y ) := f (t)dt.
Mg (Y ) −∞
13 / 17
2 Sampling from the posterior
2.3 Sampling methods
Accept-Reject Sample
I If U < L(θ̃|y )
M , then accept θ̃ as a sample from the posterior
I If U ≥ L(θ̃|y )
M , then reject θ̃ and start from the beginning
14 / 17
2 Sampling from the posterior
2.4 MCMC
15 / 17
2 Sampling from the posterior
2.4 MCMC
P(Xn+1 ∈ B | Xn = x) = P(X1 ∈ B | X0 = x)
for all n ∈ N.
15 / 17
2 Sampling from the posterior
2.4 MCMC
16 / 17
2 Sampling from the posterior
2.4 MCMC
16 / 17
2 Sampling from the posterior
2.4 MCMC
17 / 17