Topic4-Monte Carlo Simulation
Topic4-Monte Carlo Simulation
This is called Monte Carlo Simulation (MCS) – powerful for reliability analysis.
The key is how to draw samples of 𝒙 based on its PDF.
Let:
Limitation:
It is a CDF-based method;
when 𝒙𝒊 = 𝑭−𝟏 𝒖𝒊 is difficult to
calculate, it is hard to implement
Example 1
Suppose the crack width of soil follows the exponential distribution with a CDF:
𝐹𝑋 𝑥 = 1 − exp −𝜆𝑥
where 𝜆 = 0.2 mm-1. Generate the samples 𝑥 using the inverse transformation
Excel implementation
Results
Crack width
Example 2
10 samples are generated for a normal distribution with 𝜇=10 and 𝜎=5
2. Calculate 10 samples of 𝑥 by
the excel function norminv,
which is the inverse of the
CDF of normal distribution
Example 3 – WeChat Red Packet
Example 3 – WeChat Red Packet
Send CNY 200 to 8 friends; assume everyone’s red packet money follows the
same probability distribution. Let 𝑀𝑖 be the red packet obtained by the i-th friend
8
𝑀𝑖 = 200
𝑖=1
Send CNY 200 to 8 friends; assume everyone’s red packet money follows the
same probability distribution. Let 𝑀𝑖 be the red packet obtained by the i-th friend
8
𝑀𝑖 = 200
𝑖=1
A PDF-based method
Proof:
𝑃 𝑎𝑐𝑐𝑒𝑝𝑡|𝑥 𝑃 𝑥
Based on the Bayes’ theorem: 𝑃 𝑥|𝑎𝑐𝑐𝑒𝑝𝑡 =
𝑃 𝑎𝑐𝑐𝑒𝑝𝑡
𝑓𝑋 𝑥
By A-R theorem, the probability of 𝑥 being accepted: 𝑃 𝑎𝑐𝑐𝑒𝑝𝑡|𝑥 =
𝑐𝑠𝑋 𝑥
The cohesion of a soil (𝑥) sometimes can be modelled as a Beta random variable
with the following PDF:
𝑥−𝑎 𝑞−1 𝑏−𝑎 𝑟−1
𝑓𝑋 𝑥 = , where 𝑎=10, 𝑏=20, 𝑞=6 and 𝑟=2, and the beta function:
𝐵 𝑞,𝑟 𝑏−𝑎 𝑞+𝑟−1
1
𝐵 𝑞, 𝑟 = න 𝑥 𝑞−1 1 − 𝑥 𝑟−1 𝑑𝑥
0
𝑓𝑋 𝑥
The figure below shows the ; the maximum value is smaller than 3; 𝑐 can be
𝑠𝑋 𝑥
adopted as 3 to ensure the inequality 𝒄 ≥ 𝒎𝒂𝒙 𝒇 𝒙 /𝒔 𝒙
By Matlab
Markov Chain Monte Carlo (MCMC)
Various algorithms exist for MCMC, among which the widely-used Metropolis-
Hastings algorithm is introduced.
Compared with the A-R algorithm that abandons partial samples, all samples in
MCMC will be used.
Revisit of Example 3
Excel implementation
Monte Carlo Simulation
𝑓𝑋1 , 𝑋2 , …, 𝑋𝑛 𝑥1 , 𝑥2 , …, 𝑥𝑛 = ෑ 𝑓𝑋1 𝑥𝑖
𝑖=1
The above equation shows that the join PDF of SI variables is the product of
the PDF of these variables.
In such a case, we can generate the samples for each variable; the collection
of these samples constitutes the samples of the random variables 𝑋1 , 𝑋2 , …, 𝑋𝑛
Example 5
Suppose the cohesion (𝑋1 ) and friction angle (𝑋2 ) of a soil both follow the
normal distribution with 𝜇𝑋1 = 20 kPa, 𝜎𝑋1 = 5 kPa, 𝜇𝑋2 = 30o, 𝜎𝑋2 = 6o. Suppose 𝑋1
and 𝑋2 are SI. Generate the samples of 𝑋1 and 𝑋2 .
Matlab implementation
Example 5
Excel implementation
Vectors with correlated variables
Basics
Revisit: eigenvalue and eigenvector
Excel implementation
Excel implementation
Suppose the cohesion (𝑋1 ) and friction angle (𝑋2 ) of a soil both follow the
normal distribution with 𝜇𝑋1 = 20 kPa, 𝜎𝑋1 = 5 kPa, 𝜇𝑋2 = 30o, 𝜎𝑋2 = 6o. Suppose 𝑋1
and 𝑋2 have a correlation coefficient of -0.5. Generate the samples of 𝑋1 and 𝑋2 .
Matlab implementation
Monte Carlo Simulation
𝐸 𝑎 = න 𝑎 𝑥 𝑓 𝑥 𝑑𝑥 = 𝐸 𝑎 = න ℎ 𝑥 𝑑𝑥
when ℎ 𝑥 = 𝑎 𝑥 𝑓(𝑥). This shows that an integral can also be considered as the
average of a function
𝐻 = න ℎ 𝑥 𝑑𝑥
1 𝑁 ℎ 𝑥𝑖 1 1 𝑁 ℎ 𝑥𝑖 2
=
𝐻 σ The variance of 𝐻: 𝑉𝑎𝑟 𝐻
= σ 2
−𝐻
𝑁 𝑖=1 𝑠𝑋 𝑥𝑖 𝑁 𝑁 𝑖=1 𝑠𝑋 𝑥𝑖
Example 8
Excel implementation
Failure probability estimation with MCS
Based on the Monte Carlo Simulation, the failure probability can be estimated:
1 𝑁 ෞ𝑓
1−𝑝
𝑝
ෞ𝑓 ≈ σ 𝐼 𝑥𝑖 𝑐𝑜𝑣 𝑝
ෞ𝑓 ≈
𝑁 𝑖=1 ෞ𝑓
𝑁𝑝
Statistical error
Example 9
Recall that the COV of 𝒑𝒇 estimated based on the MCS depends on the number
of samples:
ෞ𝑓
1−𝑝
𝑐𝑜𝑣 𝑝
ෞ𝑓 ≈ ෞ𝑓
𝑁𝑝
Suppose:
Excel implementation
Monte Carlo Simulation
Importance sampling
Importance sampling
1 1 𝑁 ℎ 𝑥𝑖 2
Based on: 𝑉𝑎𝑟 𝐻
= σ 2
−𝐻
𝑁 𝑁 𝑖=1 𝑠𝑋 𝑥𝑖
Rubinstein (1981) showed that the optimal sampling function that can minimise
𝑉𝑎𝑟 𝐻 is:
𝑠𝑋 𝑥 = 𝑘|ℎ 𝑥 |
1 𝑁 1 1 𝑁 2
𝑝
ෞ𝑓 ≈ σ 𝐼 𝑥𝑖 𝑤 𝑥𝑖 𝑣𝑎𝑟 𝑝
ෞ𝑓 ≈ σ 𝐼 𝑥𝑖 𝑤 𝑥𝑖 ෞ𝑓 2
−𝑝
𝑁 𝑖=1 𝑁 𝑁 𝑖=1
Harbitz (1986) suggests that one can first find the design point and then
centre the sampling function at the design point with its covariance matrix
being the same as that of the uncertain variables
AFORM analysis shows that its design point (or MPP; c.f. Topic 3, slides 10 - 26) is
Based on 1000
samples, the 𝒑𝒇 is
5.94% with a cov of
4.35%.