Introduction to information system
Introduction to Monte Carlo Simulation
Bowei Chen
School of Computer Science
University of Lincoln
CMP3036M/CMP9063M Data Science 2016 – 2017
Week B10 Workshop
Today’s Objective
Do the following two exercises. They will give you a better understanding of
how to implement and analyse a Monte Carlo Simulation
Ex1: Implement Droprain Experiment (1/3)
We now do a simple experiment to use Monte
Carlo to compute the mathematical constant 𝜋.
Consider there is a unit circle inscribed within a
square. The ratio of the area of the circle to the
area of the square is
𝜋
4
. We will use this key fact in
order to estimate 𝜋 by randomly selecting points
with the square, and checking whether they are
within the circle.
If you need further explanation about this
experiment, please check the following video:
Ex1: Implement Droprain Experiment (2/3)
Question 1
Compute the estimate of 𝜋. You can set the experiment size to be 5000 (i.e.,
𝑛 = 50000), and you may consider the follow steps:
• Initialise 𝑛
• Set a for loop through procedure 𝑛 times
– Generate a point by two uniformly distributed variables
– Check if the point is within the circle
• Return the estimate of 𝜋
Ex1: Implement Droprain Experiment (3/3)
Question 2
How accurate is this method?
Hint: You need to use the confidence interval (CI)
to further examine this. Let 𝑥1, ⋯ , 𝑥𝑛 be a random
sample from the distribution of an random variable
𝑋 ∼ 𝐵𝑒𝑟(𝑝). Then 𝒑 = 𝑋 ∼ 𝑁 𝑝,
𝑝 1−𝑝
𝑛
, and an
approximate 100(1 − 𝛼)% CI for 𝑝 is
𝒑 − 𝑧𝛼
2
𝑝 1− 𝑝
𝑛
, 𝒑 + 𝑧𝛼
2
𝑝 1− 𝑝
𝑛
Ex2: Implement Random Walk Experiment
We now work on another experiment. Consider
you are going to create a simple random walk
starting from 0, and at each step moves +1 or −1
with equal probability.
Question 1
Please plot the right-hand side figure
Question 2
If you plot 5000 simple random walks (i.e., 5000
paths of simple random walk), what is the average
value of the 10000th steps?
If you need further explanation about random
walk, please check the following link:
https://en.wikipedia.org/wiki/Random_walk
https://en.wikipedia.org/wiki/Random_walk
Thank You
bchen@lincoln.ac.uk
mailto:bchen@lincoln.ac.uk