Professional Documents
Culture Documents
Shusen Wang
Application 1: Calculating Pi
Calculating Pi
𝑦
• Assume 𝑥, 𝑦 is a point sampled from
1
the square uniformly at random.
−1
1
𝑥
−1
Calculating Pi
𝑦
• Assume 𝑥, 𝑦 is a point sampled from
1
the square uniformly at random.
• What is the probability that 𝑥, 𝑦 is in
−1 the circle?
1
𝑥
−1
Calculating Pi
𝑦
• Assume 𝑥, 𝑦 is a point sampled from
1
the square uniformly at random.
• What is the probability that 𝑥, 𝑦 is in
−1 the circle?
𝑥
1 • Area of the square is 𝐴2 = 24 = 4.
• Area of the circle is 𝐴4 = 𝜋𝑟 4 = 𝜋.
78 :
−1 • Probability: 𝑃 = = .
79 ;
Calculating Pi
• Suppose 𝑛 points are uniformly sampled from −1, 1 × −1, 1 .
:>
• Then, in expectation, 𝑃𝑛 = points are in the circle.
;
𝑦
• Assume 𝑥, 𝑦 is a point sampled from
1
the square uniformly at random.
• What is the probability that 𝑥, 𝑦 is in
−1 the circle?
𝑥
1 • Area of the square is 𝐴2 = 24 = 4.
• Area of the circle is 𝐴4 = 𝜋𝑟 4 = 𝜋.
78 :
−1 • Probability: 𝑃 = = .
79 ;
Calculating Pi
• Suppose 𝑛 points are uniformly sampled from −1, 1 × −1, 1 .
:>
• Then, in expectation, 𝑃𝑛 = points are in the circle.
;
𝑦
1
• Given a point 𝑥, 𝑦 , how do you know
whether 𝑥, 𝑦 is in the circle?
−1 • If 𝑥 4 + 𝑦 4 ≤ 1, then it is in the circle.
1
𝑥
−1
Calculating Pi
• Suppose 𝑛 points are uniformly sampled from −1, 1 × −1, 1 .
:>
• Then, in expectation, 𝑃𝑛 = points are in the circle.
;
𝑦
1
• We found 𝑚 points in the circle.
:>
• If 𝑛 is big, then 𝑚 ≈ .
−1 ;
1
𝑥 • Thus, 𝜋 ≈
;B
.
>
−1
Calculating Pi
• Suppose 𝑛 points are uniformly sampled from −1, 1 × −1, 1 .
:>
• Then, in expectation, 𝑃𝑛 = points are in the circle.
;
𝑦
1 • Law of large numbers:
;B
→ 𝜋, as 𝑛 → ∞.
>
−1
1
𝑥
−1
Calculating Pi
• Suppose 𝑛 points are uniformly sampled from −1, 1 × −1, 1 .
:>
• Then, in expectation, 𝑃𝑛 = points are in the circle.
;
𝑦
1 • Law of large numbers:
;B
→ 𝜋, as 𝑛 → ∞.
>
−1
𝑥
1 • Concentration bound:
;B 2
−𝜋 =𝑂 .
> >
−1
Calculating Pi
;B
𝑛 points are sampled from the square; 𝑚 are in the circle. Then 𝜋 ≈ .
>
𝑦
1
−1
1
𝑥
−1
Calculating Pi
;B
𝑛 points are sampled from the square; 𝑚 are in the circle. Then 𝜋 ≈ .
>
𝑦 Algorithm
1
1. User specifies a big 𝑛; reset
counter 𝑚 = 0.
−1
1
𝑥
−1
Calculating Pi
;B
𝑛 points are sampled from the square; 𝑚 are in the circle. Then 𝜋 ≈ .
>
𝑦 Algorithm
1
1. User specifies a big 𝑛; reset
counter 𝑚 = 0.
−1 2. For 𝑖 = 1 to 𝑛:
1
𝑥
a) Randomly generate 𝑥 ∈ −1, 1 .
b) Randomly generate 𝑦 ∈ −1, 1 .
c) If 𝑥 4 + 𝑦 4 ≤ 1, then 𝑚 ← 𝑚 + 1.
−1 ;B
3. Return 𝜋 ≈ .
>
Application 2: Buffon's Needle Problem
Buffon's Needle Problem
𝑑
Buffon's Needle Problem
𝑑
Buffon's Needle Problem
𝑑
needle
Buffon's Needle Problem
4M
With probability 𝑃 = , they are across.
:N
𝑑
needle
• It can be proved using integral.
Buffon's Needle Problem
𝑙
needle
4M
With probability 𝑃 = , they are across.
:N
𝑑
needle
Buffon's Needle Problem
4M
With probability 𝑃 = , they are across.
:N
𝑑
needle
Buffon's Needle Problem
4M
With probability 𝑃 = , they are across.
:N
2
𝑥
1
What is the area of the grey region?
𝑦
2
2
𝑥
1
What is the area of the grey region?
𝑦
• If a point 𝑥, 𝑦 is in the circle, it
2 must satisfy
4 4
𝑥−1 + 𝑦−1 ≤ 1.
1
𝑟=1
2
𝑥
1
What is the area of the grey region?
𝑦
• If a point 𝑥, 𝑦 is in the circle, it
2 must satisfy
4 4
𝑥−1 + 𝑦−1 ≤ 1.
1
• If a point 𝑥, 𝑦 is in the quarter
circle, it must satisfy
𝑥 4 + 𝑦 4 ≤ 24 .
2
𝑥
1
What is the area of the grey region?
𝑦
2 • A point 𝑥, 𝑦 in the grey region
satisfies both of
1. 𝑥−1 4 + 𝑦−1 4 ≤ 1,
2. 𝑥 4 + 𝑦 4 > 24.
1
2
𝑥
1
What is the area of the grey region?
𝑦
2 • A point 𝑥, 𝑦 in the grey region
satisfies both of
1. 𝑥−1 4 + 𝑦−1 4 ≤ 1,
2. 𝑥 4 + 𝑦 4 > 24.
1
2
𝑥
1
What is the area of the grey region?
𝑦
2 • Area of the square: 𝐴2 = 24 = 4.
2
𝑥
1
What is the area of the grey region?
𝑦
2 • Area of the square: 𝐴2 = 24 = 4.
• Area of the grey region: 𝐴4 .
• A point uniformly sampled from the
square falls in the grey region w.p.
1
78 78
𝑃= = .
79 ;
2
𝑥
1
What is the area of the grey region?
𝑦 • Uniformly sample 𝑛 points from the
square 0, 2 × 0, 2 .
2 > 78
• In expectation, 𝑛𝑃 = points fall
;
in the grey region.
2
𝑥
1
What is the area of the grey region?
𝑦 • Uniformly sample 𝑛 points from the
square 0, 2 × 0, 2 .
2 > 78
• In expectation, 𝑛𝑃 = points fall
;
in the grey region.
• We actually observe 𝑚 points in the
1 grey region.
> 78
• If 𝑛 is big, then 𝑚 ≈ .
;
;B
• Thus, 𝐴4 ≈ .
>
2
𝑥
1
What is the area of the grey region?
𝑦 Algorithm
2 1. User specify a big 𝑛; reset
counter: 𝑚 = 0.
2. For 𝑖 = 1 to 𝑛:
a) Randomly generate 𝑥 ∈ 0, 2 .
b) Randomly generate 𝑦 ∈ 0, 2 .
1 c) If both of the following conditions
are satisfied, then 𝑚 ← 𝑚 + 1:
i. 𝑥−1 4+ 𝑦−1 4 ≤ 1.
ii. 𝑥 4 + 𝑦 4 > 24 .
;B
3. Return area = .
>
2
𝑥
1
What is the area of the grey region?
𝑦 Algorithm
2 1. User specify a big 𝑛; reset
counter: 𝑚 = 0.
2. For 𝑖 = 1 to 𝑛:
a) Randomly generate 𝑥 ∈ 0, 2 .
b) Randomly generate 𝑦 ∈ 0, 2 .
1 c) If both of the following conditions
are satisfied, then 𝑚 ← 𝑚 + 1:
i. 𝑥−1 4+ 𝑦−1 4 ≤ 1.
ii. 𝑥 4 + 𝑦 4 > 24 .
;B
3. Return area = .
>
2
𝑥
1
What is the area of the grey region?
𝑦 Algorithm
2 1. User specify a big 𝑛; reset
counter: 𝑚 = 0.
2. For 𝑖 = 1 to 𝑛:
a) Randomly generate 𝑥 ∈ 0, 2 .
b) Randomly generate 𝑦 ∈ 0, 2 .
1 c) If both of the following conditions
are satisfied, then 𝑚 ← 𝑚 + 1:
i. 𝑥−1 4+ 𝑦−1 4 ≤ 1.
ii. 𝑥 4 + 𝑦 4 > 24 .
;B
3. Return area ≈ .
>
2
𝑥
1
Application 4: Integration
Integration
2
• We are given a function, e.g., 𝑓 𝑥 = .
2WXYZ [ ⋅ ]^_` [ 8
c
• Calculate the integral: 𝐼 = ∫d.e 𝑓 𝑥 𝑑𝑥.
Integration
2
• We are given a function, e.g., 𝑓 𝑥 = .
2WXYZ [ ⋅ ]^_` [ 8
c
• Calculate the integral: 𝐼 = ∫d.e 𝑓 𝑥 𝑑𝑥.
• If 𝑓 𝑥 is very involved, there is no way to analytically calculate the
integral.
• Using Monte Carlo to approximate the integral.
Monte Carlo Integration (Univariate)
f
Task: Given a univariate function 𝑓 𝑥 , calculate 𝐼 = ∫g 𝑓 𝑥 𝑑𝑥.
Monte Carlo Integration (Univariate)
f
Task: Given a univariate function 𝑓 𝑥 , calculate 𝐼 = ∫g 𝑓 𝑥 𝑑𝑥.
f
Task: Given a univariate function 𝑓 𝑥 , calculate 𝐼 = ∫g 𝑓 𝑥 𝑑𝑥.
f
Task: Given a univariate function 𝑓 𝑥 , calculate 𝐼 = ∫g 𝑓 𝑥 𝑑𝑥.
f
Task: Given a univariate function 𝑓 𝑥 , calculate 𝐼 = ∫g 𝑓 𝑥 𝑑𝑥.
2 c
Task: Given function 𝑓 𝑥 = , calculate 𝐼 = ∫d.e 𝑓 𝑥 𝑑𝑥.
2WXYZ [ ⋅ ]^_` [ 8
Monte Carlo Integration (Univariate): Example
2 c
Task: Given function 𝑓 𝑥 = , calculate 𝐼 = ∫d.e 𝑓 𝑥 𝑑𝑥.
2WXYZ [ ⋅ ]^_` [ 8
2 c
Task: Given function 𝑓 𝑥 = , calculate 𝐼 = ∫d.e 𝑓 𝑥 𝑑𝑥.
2WXYZ [ ⋅ ]^_` [ 8
2 c
Task: Given function 𝑓 𝑥 = , calculate 𝐼 = ∫d.e 𝑓 𝑥 𝑑𝑥.
2WXYZ [ ⋅ ]^_` [ 8
𝐱 ∈ ℝN is a vector Ω is a subset of ℝN
Monte Carlo Integration (Multivariate)
𝑦
1, if 𝑥 4 + 𝑦 4 ≤ 1;
1 • Let 𝑓 𝑥, 𝑦 = t
0, otherwise.
−1
1
𝑥
−1
Monte Carlo Integration: Bivariate Example
𝑦
1, if 𝑥 4 + 𝑦 4 ≤ 1;
1 • Let 𝑓 𝑥, 𝑦 = t
0, otherwise.
• Let Ω = −1, 1 × −1, 1 .
−1
1
𝑥 • What is 𝐼 = ∫p 𝑓 𝑥, 𝑦 𝑑𝑥 𝑑𝑦?
−1
Monte Carlo Integration: Bivariate Example
𝑦
1, if 𝑥 4 + 𝑦 4 ≤ 1;
1 • Let 𝑓 𝑥, 𝑦 = t
0, otherwise.
• Let Ω = −1, 1 × −1, 1 .
−1
1
𝑥 • What is 𝐼 = ∫p 𝑓 𝑥, 𝑦 𝑑𝑥 𝑑𝑦?
• 𝐼 is the area of the circle:
𝐼 = 𝜋𝑟 4 = 𝜋.
−1
Monte Carlo Integration: Bivariate Example
−1
1
𝑥
−1
Monte Carlo Integration: Bivariate Example
−1
Monte Carlo Integration: Bivariate Example
−1
Monte Carlo Integration: Bivariate Example
Reference
2
𝑥
0 1
What are the areas of the red and blue regions?
𝑦
0
𝑥
1 2
Thank you!