Monte Carlo Sampling Methods
Monte Carlo Sampling Methods
Monte Carlo
Sampling Methods
Jasmina L. Vujic
Nuclear Engineering Department
University of California, Berkeley
Email: [email protected]
phone: (510) 643-8085
fax: (510) 643-9685
UCBNE, J. Vujic
[2]
Monte Carlo
Monte Carlo is a computational technique based on
constructing a random process for a problem and
carrying out a NUMERICAL EXPERIMENT by N-fold
sampling from a random sequence of numbers with a
PRESCRIBED probability distribution.
x - random variable
N
∑x
1
x̂ = ---- i
N
i=1
Monte Carlo
• Monte Carlo techniques came from the complicated diffusion
problems that were encountered in the early work on atomic energy.
• 1772 Compte de Bufon - earliest documented use of random
sampling to solve a mathematical problem.
• 1786 Laplace suggested that π could be evaluated by random
sampling.
• Lord Kelvin used random sampling to aid in evaluating time
integrals associated with the kinetic theory of gases.
• Enrico Fermi was among the first to apply random sampling
methods to study neutron moderation in Rome.
• 1947 Fermi, John von Neuman, Stan Frankel, Nicholas Metropolis,
Stan Ulam and others developed computer-oriented Monte Carlo
methods at Los Alamos to trace neutrons through fissionable
materials
UCBNE, J. Vujic
Monte Carlo
[4]
UCBNE, J. Vujic
Monte Carlo
[5]
fmax
f(x)
y1 • reject
• accept
a x1 b
b
I =
∫ f( x )dx - area uder the function f(x),R = ( b – a )f
a
max - area of rectangle
I
P = ---- - is a probability that a random point lies under f(x), thus I = RP
R
UCBNE, J. Vujic
Major Components of Monte Carlo
[7]
UCBNE, J. Vujic
Probability Distribution Functions
[8]
P{a ≤ x ≤ b}
P { x = xi } = pi
UCBNE, J. Vujic
Probability Distribution Functions
[9]
• F(x) =
∫ f( x' )dx' = P{ x' ≤ x } 1
–∞
• 0 ≤ F(x) ≤ 1 F(x)
d
• 0≤ F(x) = f(x)
dx 0
b x→
•
∫ f( x' )dx' = P{ a ≤ x ≤ b } = F( b ) – F( a )
a
UCBNE, J. Vujic
Probability Distribution Functions
[10]
• 0 ≤ f ( xi ) p3
• ∑ f( x )( ∆x ) = 1 or ∑ p
i
i i
i
i = 1 f(x)
p1
p2
x1 x2 x3
Cumulative Distribution Function (CDF) - discrete
F(x)
• F(x) = ∑ p = ∑ f( x )∆x
xi < x
i
xi < x
i i p1+p2+p3 1
p1+p2
• 0 ≤ F(x) ≤ 1 p1
•
x1 x2 x3
UCBNE, J. Vujic
Monte Carlo & Random Sampling
[11]
Given f ( x i ) = p i and ∑p
i
i = 1 , i = 1, 2, ..., N
and 0 ≤ ξ ≤ 1 , then P ( x = x k ) = p k = P ( ξ ∈ d k ) or
k–1 k
∑p ≤ ξ < ∑p
i i
i=1 i=1
UCBNE, J. Vujic
Monte Carlo & Random Sampling
[12]
If f(x) and F(x) represent PDF and CDF od a random variable x, and if ξ is a random
number distributed uniformly on [0,1] with PDF g( ξ )=1, and if x is such that
F(x) = ξ
than for each ξ there is a corresponding x, and the variable x is distribute according
to the probability density function f(x).
Proof:
For each ξ in ( ξ , ξ +∆ ξ ), there is x in (x,x+∆x). Assume that PDF for x is q(x). Show
that q(x) = f(x):
UCBNE, J. Vujic
Monte Carlo & Random Sampling
[13]
UCBNE, J. Vujic
Random Sampling Methods
[14]
Pseudo-Random Numbers
• Not strictly "random", but good enough 1
— pass statistical tests f(x)
— reproducible sequence
0 1
• Uniform PDF on [0,1]
• Must be easy to compute, must have a large period 1
Sampling Procedure: 1
• Generate ξ ξ
• Determine x̂ such that F ( x̂ ) = ξ F(x)
0
x→ x̂
Advantages
• Straightforward mathematics & coding
• "High-level" approach
Disadvantages
• Often involves complicated functions
• In some cases, F(x) cannot be inverted (e.g., Klein-Nishina)
UCBNE, J. Vujic
Random Sampling Methods
[16]
Rejection Sampling
Used when the inverse of CDF is costly ot impossible to find.
Select a bounding function, g(x), such that
• c ⋅ g ( x ) ≥ f ( x ) for all x
• g(x) is an easy-to-sample PDF
Sampling Procedure:
–1
• sample x̂ from g(x): x̂ ← g ( ξ 1 )
cg ( x )
• test: ξ 2 ⋅ cg ( x̂ ) ≤ f ( x̂ )
• accept
Advantages
x→
• Simple computer operations
Disadvantages
• "Low-level" approach, sometimes hard to understand
UCBNE, J. Vujic
Random Sampling Methods
[17]
Table Look-Up
Used when f(x) is given in a form of a histogram
f1 fi
f(x) f2
x1 x2 xi-1 xi
F(x)
ξ
x1 x2 xi-1 x xi
UCBNE, J. Vujic
Random Sampling Methods
[18]
If the random quantity is a function of two or more random variables that are
independent, the joint PDF and CDF can be written as
f ( x, y ) = f 1 ( x )f 2 ( y )
F ( x, y ) = F 1 ( x )F 2 ( y )
Ω = Ω ( θ, ϕ ) = Ω x i + Ω y j + Ω z k = v + w + u ,
dΩ sin θdθdϕ – d ( cos θ )dϕ – dµdϕ
-------- = -------------------------- = -------------------------------- = ------------------
4π 4π 4π 4π
1 1
f ( Ω ) = f 1 ( µ )f 2 ( ϕ ) = --- ------
2 2π
µ
∫
1
F1 ( µ ) = f 1 ( µ' ) dµ' = --- ( µ + 1 ) = ξ 1 or µ = 2ξ 1 – 1
–1 2
ϕ ϕ
F1 ( ϕ ) =
0 ∫f 2 ( ϕ' ) dϕ' = ------ = ξ 2 , or ϕ = 2πξ 2
2π
UCBNE, J. Vujic
Random Sampling Methods
[19]
3D Isotropic: u ← 2 ξ1 – 1
1
(I1, I2) f ( Ω ) = ------ , Ω = ( u, v, w ) 2
4π v ← 1 – u cos 2πξ 2
2
w ← 1 – u sin 2πξ 2
Maxwellian: x π
f ( x ) = ----------- --- e –x / T, 0<x x ← T ( – log ξ 1 – log ξ 2 cos2 --ξ 3)
2
(M1, M2, M3)
T π T
2
Normal: 1 x – µ
2
– - -----------
- x ← µ + σ – 2 log ξ 1 cos 2πξ 2
1
------------- e σ
(N1, N2)
f(x) =
2
σ 2π
UCBNE, J. Vujic
← ξ
Random Sampling Examples
[20]
Example — 2D Isotropic
1 ,
f ( ρ ) = ----- ρ = ( u, v )
2π
Rejection (mcnp)
• Based on Algorithm R12 from 3rd Monte Carlo Sampler, Everett & Cashwell
• Define K = 1 + ab ⁄ 8 , L = a { K + ( K 2 – 1 )1 / 2 } , M = L ⁄ a – 1
Rejection
(strictly — this is not "rejection", but has the same flavor)
if ξ 1 ≥ ξ 2 , then x̂ ← ξ 1
else x̂ ← ξ 2
or
x̂ ← max ( ξ 1, ξ 2 )
or
x̂ ← ξ 1 – ξ 2
Direct Inversion
F( x ) = x2 , 0≤x≤1
← ξ
UCBNE, J. Vujic
Random Sampling Examples
[23]
µ tot = µ cs + µ fe + µ pp
Define
µ cs µ fe µ pp
p 1 = --------
- , p = --------- , and p = ---------
µ tot 2 µ tot 3 µ tot
3
with
∑p i = 1.
i=1
Then
0 p1 p1+p2 p1+p2+p3=1
p1 < ξ < p1 + p2
UCBNE, J. Vujic
[24]
UCBNE, J. Vujic
Transport Equation
[25]
1∂
--- ψ ( r, E, Ω, t ) + Ω • ∇ψ ( r, E, Ω, t ) + Σ t ( E )ψ ( r, E, Ω, t ) =
v∂t
∞
∫
0 4π
s ∫
dE' Σ ( E' → E, Ω' → Ω )Ψ ( r, E', Ω', t ) dΩ' +
∞
χ(E)
4π ∫ 0
∫
------------ dE' υΣ f ( E' )Ψ ( r, E', Ω', t ) dΩ' +
4π
1
------Q ( r, E, t )
4π
UCBNE, J. Vujic