Annotated_L18
Annotated_L18
Sampling
28 Mar 2025
Recap
• Previous
1 / 20
Recap
• Previous
↭ Change of Variables (Discrete)
1 / 20
Recap
• Previous
↭ Change of Variables (Discrete)
↭ Change of Variables (Continuous)
1 / 20
Recap
• Previous
↭ Change of Variables (Discrete)
↭ Change of Variables (Continuous)
• Inverse CDF Sampling/Inverse transform Sampling/Smirnov Sampling/
1 / 20
Recap
• Previous
↭ Change of Variables (Discrete)
↭ Change of Variables (Continuous)
• Inverse CDF Sampling/Inverse transform Sampling/Smirnov Sampling/
• Rejection Sampling
1 / 20
Recap
• Previous
↭ Change of Variables (Discrete)
↭ Change of Variables (Continuous)
• Inverse CDF Sampling/Inverse transform Sampling/Smirnov Sampling/
• Rejection Sampling
• Monte Carlo Sampling
1 / 20
References
2 / 20
Sampling Uniform Distribution
3 / 20
Sampling Uniform Distribution
Mersenne Twister
3 / 20
Sampling Non-Uniform Distribution
How to sample any distribution assuming we can sample from Uniform Distribution?
4 / 20
Inverse transform sampling
4 / 20
Inverse transform sampling
4 / 20
Inverse transform sampling
4 / 20
Inverse transform sampling
↓ F ↔1 : (0, 1) ↑ R s.t. F ↔1 ( F ( x )) = x, ↗ x ↘ R
4 / 20
Inverse transform sampling
↓ F ↔1 : (0, 1) ↑ R s.t. F ↔1 ( F ( x )) = x, ↗ x ↘ R
4 / 20
Inverse transform sampling
↓ F ↔1 : (0, 1) ↑ R s.t. F ↔1 ( F ( x )) = x, ↗ x ↘ R
Theorem 5
4 / 20
Invertible CDF
• X → Uni f ( a, b) (viz)
5 / 20
Invertible CDF
• X → Uni f ( a, b) (viz)
• X → Normal (µ, σ) ?
5 / 20
CDF
• Exponential
• Discrete
6 / 20
Inverse Transform Sampling
7 / 20
Inverse Transform Sampling
7 / 20
Inverse Transform Sampling
7 / 20
Inverse Transform Sampling
7 / 20
Inverse Transform Sampling
Theorem 10
If U → Uni f (0, 1) then G (U ) → F i.e., G (U ) has a CDF F.
7 / 20
Inverse CDF
Examples
• Discrete
xi 1 2 3 4
pi 0.1 0.4 0.2 0.3
8 / 20
Inverse CDF
Examples
• Discrete
xi 1 2 3 4
pi 0.1 0.4 0.2 0.3
8 / 20
Inverse CDF
Examples
• Discrete
xi 1 2 3 4
pi 0.1 0.4 0.2 0.3
8 / 20
Inverse CDF
Examples
• Discrete
xi 1 2 3 4
pi 0.1 0.4 0.2 0.3
8 / 20
Inverse CDF
Examples
• Discrete
xi 1 2 3 4
pi 0.1 0.4 0.2 0.3
8 / 20
Box-Muller Algorithm
9 / 20
Box-Muller Algorithm
9 / 20
Rejection Sampling
10 / 20
Rejection Sampling
10 / 20
Rejection Sampling
Mandelbrot Set
10 / 20
Rejection Sampling
Uniform Distribution
• If A ⇐ B
11 / 20
Rejection Sampling
Uniform Distribution
• If A ⇐ B
• Y1 , Y2 , . . . are independently and uniformly drawn from B
11 / 20
Rejection Sampling
Uniform Distribution
• If A ⇐ B
• Y1 , Y2 , . . . are independently and uniformly drawn from B
• X = YK where K = min{k : Yk ↘ A}
11 / 20
Rejection Sampling
Uniform Distribution
• If A ⇐ B
• Y1 , Y2 , . . . are independently and uniformly drawn from B
• X = YK where K = min{k : Yk ↘ A}
• Then X → Uni f ( A)
11 / 20
Rejection Sampling
Uniform Distribution
• If A ⇐ B
• Y1 , Y2 , . . . are independently and uniformly drawn from B
• X = YK where K = min{k : Yk ↘ A}
• Then X → Uni f ( A)
• Note that K is a random variable
11 / 20
Rejection Sampling
12 / 20
Rejection Sampling
12 / 20
Rejection Sampling
12 / 20
Rejection Sampling
12 / 20
Rejection Sampling
12 / 20
Rejection Sampling
12 / 20
Rejection Sampling
12 / 20
Rejection Sampling
• Z→ f
12 / 20
Rejection Sampling (Intuition)
13 / 20
Rejection Sampling (Intuition)
13 / 20
Rejection Sampling
14 / 20
Rejection Sampling
14 / 20
Expectation
!
∑ x x f ( x ); X is discrete
E[X] = "∞
↔∞ x f ( x ) dx; X is continuous
15 / 20
Expectation
!
∑ x x f ( x ); X is discrete
E[X] = "∞
↔∞ x f ( x ) dx; X is continuous
Linearity: E [ aX + Y ] = aE [ X ] + E [Y ]
15 / 20
Examples
16 / 20
Monte Carlo Sampling
17 / 20
Monte Carlo Sampling
18 / 20
Monte Carlo Sampling
Goal: Approximate E [ f ( X )]
19 / 20
Monte Carlo Sampling
Goal: Approximate E [ f ( X )]
• If X1 , X2 , . . . , Xn are sampled from a distribution p
19 / 20
Monte Carlo Sampling
Goal: Approximate E [ f ( X )]
• If X1 , X2 , . . . , Xn are sampled from a distribution p
• Xi⇑ s are independent and identically distributed
19 / 20
Monte Carlo Sampling
Goal: Approximate E [ f ( X )]
• If X1 , X2 , . . . , Xn are sampled from a distribution p
• Xi⇑ s are independent and identically distributed
• The approximate expectation is given by,
1 n
n i∑
µ̂ = f ( Xi )
=1
19 / 20
Monte Carlo Sampling
Goal: Approximate E [ f ( X )]
• If X1 , X2 , . . . , Xn are sampled from a distribution p
• Xi⇑ s are independent and identically distributed
• The approximate expectation is given by,
1 n
n i∑
µ̂ = f ( Xi )
=1
• µ̂ is an estimator for E[ f ( X )]
19 / 20
Unbiased Estimator
20 / 20
Unbiased Estimator
20 / 20
Unbiased Estimator
1 2
• n σ ( f ( X )) ↑0
20 / 20