You are on page 1of 46

ISYE6207

Stochastic Processes
Session 3 - 4
Monte Carlo Simulation

- DLW - 1
Learning Outcome

• LO2: Employ Monte Carlo simulation for probabilistic


modeling tools

2
Outline

• Introduction to Monte Carlo Simulation


• Generation of Random Numbers
• Types of simulation

3
Introduction to Monte Carlo
Simulation

- DLW - 4
Introduction to Monte Carlo
Simulation

• Simulation is one of the most widely used probabilistic modeling


tools in industry. It is used for the analysis of existing systems and
for the selection of hypothetical systems.
– For example, suppose a bank has been receiving complaints
from customers regarding the length of time that customers are
spending in line waiting at the drive in window. Management has
decided to add some extra windows; they now need to decide
how many to add. Simulation models can be used to help
management in determining the number of windows to add
Other Examples of Monte Carlo applications
– In math : estimation of the constant  (3.14159), evaluation of
multiple integrals, matrix inversion, etc
– In finance and banking: to calculate financial risk, to predict
banking financial risk due to bad credit, to determine the risk of
default of an investment instrument, etc
– In industry : to develop new product, queueing etc.

- DLW - 5
Introduction to Monte Carlo
Simulation

• the Monte Carlo simulation is


– a modeling scheme that estimates stochastic or
deterministic parameters based on random sampling.
– a simulation to determine a random number from sample
data with a certain distribution.
• The purpose of the Monte Carlo simulation is to find a value
that is close to the real value, or the value that will occur
based on the distribution of the sampling data.
• it is important to realize that the simulation is simply a
statistical experiment performed so that the expense and
time needed to perform and/or to observe the actual process
can be avoided

- DLW - 6
Simulation by Hand
Example 1

• Consider a microwave oven salesperson who works in a busy


retail store. Of all the people who take up the salesperson’s
time, 50 percent end up buying one of the three models
available and 50 percent do not make a purchase. Of those
customers who actually buy an oven, 25 percent purchase the
plain model, 50 percent purchase the standard model, and 25
percent purchase the deluxe model. The plain model yields a
profit of $30, the standard model yields a profit of $60, and
the deluxe model yields a profit of $75. The salesperson
wishes to determine the average profit per customer.
• To simulate the microwave oven buying decision, a (fair) coin
is tossed with a head representing a customer and a tail
representing a browser; thus, there is a 50–50 chance that an
individual entering the department is a customer.

- DLW - 7
Simulation by Hand
Example 1

• To simulate the type of microwave that is bought by an


interested customer, two fair coins are tossed. Two tails
(which occur 47.25 percent of the time) represent buying the
plain model, a head and a tail (which occur 50 percent of the
time) represent buying the standard model, and two heads
(which occur 25 percent of the time) represent buying the
deluxe model

- DLW - 8
Simulation by Hand
Example 1

• the estimate for the expected profit per customer is calculated to be


$34.50
• the number of interested customers was 12 out of 20, but because there
is a 50-50 chance that any given customer will be interested, we expect
only 10 out of 20
• profit per customer is only $28.125 (0.5*{(0.25*30)+(0.5*60)+(0.25*75)])

- DLW - 9
Simulation by Hand
Example 2

Tossing 2 dice and compute the probability of the sum


Die 1 Die 2 sum sum counts prob actual
3 1 4 2 3 0.15 0.03
1 4 5 3 1 0.05 0.06
3 1 4 4 4 0.2 0.08
6 1 7 5 3 0.15 0.11
5 4 9 6 2 0.1 0.14
5 2 7 7 3 0.15 0.17
3 3 6 8 3 0.15 0.14
1 3 4 9 1 0.05 0.11
4 1 5 10 0 0 0.08
1 1 2 11 0 0 0.06
5 3 8 12 0 0 0.03
1 1 2
1 2 3
4 4 8
1 1 2
6 1 7
5 1 6
1 3 4
2 3 5
4 4 8

- DLW - 10
Exercise 1

A door-to-door salesman sells pots and pans. He only gets in 50


percent of the houses that he visits. Of the houses that he enters,
1/6 of the householders are still not interested in purchasing
anything, 1/2 of them end up placing a $60 order, and 1/3 of
them end up placing a $100 order. Estimate the average sales
receipts per house visit by simulating 25 house visits using a die.
Calculate the theoretical value and compare it with the estimate
obtained from your simulation

- DLW - 11
Generation of Random Numbers

- DLW - 12
Generation of Random Numbers

• System simulation depends heavily on random number


generation to model the stochastic nature of the systems
being studied.
• Manually random number generation can be done by toss a
coin or a die
• A computer, by contrast, must simulate random outcomes by
generating numbers to give the appearance of randomness
• All methods of random number generation in computers
begin with an initial value called the initial random number
seed. Each time a random number is desired, the random
number seed is used to produce the next random number
and the seed is transformed into another number that
becomes the new seed. Thus, the random number seed is
continually changed as the random numbers are generated

- DLW - 13
The Multiplicative Congruential Linear
Method (MCLG)

• Uniform (0, 1) random numbers play a key role in sampling


from distributions.
• The only feasible way for generating 0-1 random numbers for
use in simulation is based on arithmetic operations. Such
numbers are not truly random because the entire sequence
can be generated in advance. It is thus more appropriate to
refer to them as pseudorandom numbers
• The most common arithmetic operation for generating (0, 1)
random numbers is the multiplicative congruential linear
method. Given the parameters u0, b, c, and m, a pseudo
random number Rn can be generated from the formulas:

• The initial value u0 is usually referred to as the seed of the


generator - DLW - 14
example

- DLW - 15
The problems of MCLG

• There are a few problems with this stream of random


numbers. First, the numbers are not very dense. With a
modulus of only 7, at most we can generate the number 1/7,
2/7, etc, so that there is a significant amount of “space”
between two close random numbers. To fix this problems, we
simply increase the modulus.
• A second problem is that the numbers start repeating
themselves after just three values. You should be able to
verify that the next random number that will be generated
will equal 0.7143; in other words, no new numbers will be
generated after the first three. This property is called the
period of the generator

Definition 2.1. The period of a random number generator is the


number of seeds that can be produced before the exact
sequence of seeds repeat themselves
- DLW - 16
The problems of MCLG

• The modulus for an MLCG should always be a prime number


• a multiplier for which the period of the generator equals the
modulus minus one, called a full period generator
• A popular generator for 32-bit machines used for many years
was based on an algorithm by Schrage [9] that gave a
portable code for the MLCG using a modulus of m =
2,147,483,647 and a multiplier of a = 16,807. The modulus is
231 −1 which equals the largest signed integer that can be
stored in a 32-bit machine and it is prime
• Another multiplier that may provide better statistical
properties for the resulting stream of random numbers is a =
630,360,016. Notice that the period of these generators is
slightly more than 2.1 × 109 which seems large;

- DLW - 17
Multiple Recursive Generator (MRG)

• The multiple recursive generators (MRG) is an extension of the


MLCG in that instead of the next seed depending only on the
previous seed, the next seed depends on two or more of the
previous seeds.
• The advantages of MRGs are that they have better statistical
properties than the MLCGs and they can have much longer periods

- DLW - 18
Multiple Recursive Generator

- DLW - 19
Multiple Recursive Generator (MRG)

• When the MRG is used on a 32-bit machine, the modulus


should be m = 2,147,483,647. Five multipliers that work well
with this modulus, are 26,403, 33,236, 36,673, 40,851, or
43,693. These values will yield a period of slightly more than
2.6×1018

- DLW - 20
Composite Generators

• a composite generator combines two other generators

- DLW - 21
Simulation by hand of a Single
Server Model using random number
generator
• The interarrival time of customers at HairKare Barbershop is
exponential with mean 15 minutes. The shop is operated by
only one barber, and it takes between 10 and 15 minutes,
uniformly distributed, to do a haircut. Customers are served
on a first-in, first-out (FIFO) basis. The objective of the
simulation is to compute the following measures of
performance:
1. The average utilization of the shop.
2. The average number of waiting customers.
3. The average time a customer waits in queue

- DLW - 22
Simulation by hand of a Single Server
Model using random number generator

Service Waiting
customer R1 Arrival (p) R2 (q) depart time
1 0 0.6733 13.3665 13.3665
2 0.0589 42.47871 0.9486 57.22171 57.22171
3 0.4799 53.49138 0.5933 70.18821 70.18821 3.730337
4 0.6139 60.81022 0.1782 81.07921 81.07921 9.377989
5 0.9341 61.8328 0.3473 92.81571 92.81571 19.24641
32.35474
average waiting
time 6.470948

average queue length 0.348591


average facility utilization 0.686344

- DLW - 23
Example 2/1
(using random number)

- DLW - 24
Example 2/2

To ensure that all the points in the square are equally probable, the
coordinates x and y of a point in the square are represented by the following
uniform distributions:

- DLW - 25
Example 2/3

- DLW - 26
Example 2/4

Simulation based on 1000 random number


Y 8
8 Chart Title
6
6

4
4

2
2

0
0 -6 -4 -2 0 2 4 6 8
-6 -4 -2 0 2 4 6 8

-2 -2

-4 -4

The area of rectangle=100


The estimate area of circle= 79.1 (=m/n*100)
m=number of sample points fall within the circle, n=
number of all sample point within the rectangle
The area of circle (using formula) = π r2=
3.14*25=78.54 - DLW - 27
Exercise 2

Consider the game in which two players, Jan and Jim, take turns
in tossing a fair coin. If the outcome is heads, Jim gets $10 from
Jan. Otherwise, Jan gets $10 from Jim.
(a) How is the game simulated as a Monte Carlo experiment?
(b) Run the experiment for 5 replications of 10 tosses each. Use
the first five columns of the 0-1 random numbers in Table
19.1, with each column corresponding to one replication

- DLW - 28
Monte Carlo Simulation

• The accuracy of the area estimate can be enhanced by using


procedures from ordinary statistical experiments:
1. Increase the sample size, n.
2. Use replications, N.
• The discussion poses two questions regarding the simulation
experiment:
1. How large should the sample size be?
2. How many replications are needed?
• the golden rule is that higher values of n and N mean more
accurate simulation results.
• the sample size will depend on the cost associated with
conducting the simulation experiment
• The sample size is considered “adequate” if it produces a
relatively “small” standard deviation.

- DLW - 29
Confidence Interval for The Random
Variation

• It is necessary to express the results as a confidence interval


to account for the random variation in the output of the
experiment. Letting and s be the mean and variance of N
replications, then, given a confidence level α, the confidence
interval for the true area A is

• The parameter is determined from the t-distribution tables


given a confidence level a and N - 1 degrees of freedom.
• Note that N equals the number of replications, which is
distinct from the sample size n.

- DLW - 30
Confidence Interval for The Random
Variation

For example, the confidence interval


78.452 <A< 78.68 corresponds to n =
90,000, with N = 5, A = 78.566 cm2 ,
and s = .092 cm, and t.025,4 = 2.776

In general, to realize reasonable


accuracy in the estimation of the
confidence interval, the value of N
should be at least 5

- DLW - 31
Random Number Generator in Excel

• RAND FUNCTION : generate a set of random number


between 0 and 1
• RANDBETWEEN : generate a set of random number between
two specified number rand() randbetween(1;25)
0.933012 19
• Randarray: new in Excel 365 0.664847 16
0.01868 10
0.866104 6
0.628872 3
0.07071 23
0.590332 5
0.450824 1
0.554217 25
0.420346 2
0.958987 24
0.753423 25
0.728619 6
0.322436 11
0.752857 21
0.658356 2

- DLW - 32
Types of simulation

- DLW - 33
Types of Simulation

Two distinct types of simulation models exist:


• Continuous models deal with systems whose behavior
changes continuously with time. These models usually use
difference-differential equations to describe the interactions
among the different elements of the system. A typical
example deals with the study of world population dynamics.
• Discrete models deal primarily with the study of waiting
lines, with the objective of determining such measures as the
average waiting time and length of the queue. These
measures change only when a customer enters or leaves the
system. The instants at which changes take place occur at
specific discrete points in time (arrivals and departure
events), giving rise to the name discrete event simulation.

- DLW - 34
Sampling from Probability Distribution

• Randomness in simulation arises when the interval, t,


between successive events is probabilistic. This section
presents three methods for generating successive random
samples (t = t1, t2, ….) from a probability
distribution f (t):
1. Inverse method.
2. Convolution method.
3. Acceptance–rejection method

- DLW - 35
Inverse method

• To obtain a random sample x from the (continuous or


discrete) probability density function f (x), the inverse method
first determines a closed-form expression of the cumulative
density function F(x)=P(y≤x), where 0≤ F(x)≤1, for all defined
values of y. It can be proved that the random variable z = F(x)
is uniformly distributed in the interval 0≤z≤1. Based on this
result, a random sample from f (x) is determined using the
following steps (F -1 is the inverse of F):
• Step 1. Generate a 0-1 random number, R.
• Step 2. Compute the desired sample x = F -1 (R).

- DLW - 36
example

- DLW - 37
Example (Exponential Distribution)

R -1/λ*ln(1-R)
0.405526 0.2080316 Exponential simulation based
0.847353 0.75185156 on 25 random number
0.499018 0.27647395
0.738291 0.53620867
0.511282 0.28638806 λ 2.5
0.111864 0.04745238
0.938621 1.11627241
1/λ 0.4
0.878735 0.84391175
0.92389 1.03023282 mean 0.410468
0.3067 0.14651683 stdev 0.400547
0.374058 0.18739874
0.986411 1.71940232
0.180746 0.07974453
0.544565 0.31460083
0.561445 0.32970781
0.688797 0.46692336
0.405249 0.20784523
0.178243 0.07852403
0.420911 0.21851944
0.678146 0.4534633
0.303199 0.14450226
0.279909 0.13135096
0.495818 0.27392754
0.14872 0.06440545
0.581087 0.34803662
- DLW - 38
Convolution method.

• The basic idea of the convolution method is to express the


desired sample as the statistical sum of other easy-to-sample
random variables. Typical among these distributions are the
Erlang and the Poisson, whose samples can be obtained from
the exponential distribution samples.

- DLW - 39
Example (Erlang Distribution)

- DLW - 40
example
Erlang distribution simulation based
R1 R2 R3 R1R2R3 -1/λ*ln(R1*R2*R3) on 25 random number
0.114177 0.915382 0.230434 0.024084 0.931553464
0.112674
0.583917
0.325256
0.417054
0.300014
0.670039
0.010995 1.127580365
0.163171 0.453238681
m 3
0.560872 0.168264 0.320109 0.03021 0.87489446 λ 4
0.107231 0.166212 0.969218 0.017274 1.014632025 1/λ 0.25
0.099556 0.507562 0.042366 0.002141 1.536642363
0.910249 0.700342 0.625058 0.398465 0.230033776
0.695084 0.257076 0.575945 0.102915 0.568462641
0.108279 0.108317 0.872366 0.010232 1.145570259 mean 0.745131 m/λ 0.75
0.621014 0.945613 0.565244 0.331933 0.275705536 stdev 0.429218 m/λ2 0.433013
0.787341 0.44244 0.052866 0.018416 0.998636851
0.089052 0.219116 0.972678 0.018979 0.991099028
0.179666 0.156459 0.061528 0.00173 1.589969361
0.148784 0.181704 0.561884 0.01519 1.046772961
0.376506 0.042594 0.501646 0.008045 1.205681825
0.269691 0.519368 0.479651 0.067184 0.675079227
0.760984 0.726314 0.825967 0.456523 0.196028797
0.55771 0.94843 0.468979 0.248066 0.348515194
0.230469 0.865176 0.440455 0.087825 0.608101532
0.068932 0.166929 0.779257 0.008967 1.178557116
0.530892 0.744027 0.974999 0.385122 0.238548505
0.980351 0.360465 0.988422 0.349291 0.262962716
0.806792 0.4511 0.404722 0.147296 0.478827665
0.945452 0.992617 0.502904 0.471961 0.187714853
0.453002 0.616014 0.561293 0.156632 0.463464394

- DLW - 41
Example (Normal
Distribution)

- DLW - 42
Example (Normal
Distribution)
Normal distribution simulation based
on 25 random number
Y=µ+σ(
R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 X (sum) X-6)
0.66 0.36 0.31 0.67 0.86 0.11 0.96 0.10 0.78 0.51 0.24 0.90 6.47 10.94 µ 10
0.88 0.78 0.42 0.48 0.06 0.12 0.38 0.61 0.54 0.37 0.39 0.97 6.01 10.01 σ 2
0.90 0.64 0.91 0.86 0.38 0.66 0.52 0.91 0.14 0.33 0.78 0.99 8.02 14.05
0.15 0.96 0.61 0.02 0.42 0.15 0.26 0.55 0.79 0.03 0.27 0.30 4.51 7.02
0.83 0.21 0.49 0.58 0.68 0.09 0.07 0.34 0.95 0.43 0.02 0.23 4.92 7.83
0.15 0.78 0.05 0.90 0.31 0.26 0.06 1.00 0.73 0.07 0.60 0.77 5.66 9.32
0.81 0.90 0.30 0.49 0.47 0.18 0.95 0.82 0.28 0.83 0.47 0.62 7.10 12.21 mean 10.02121
0.18 0.58 0.09 0.39 0.14 0.40 0.55 0.66 0.08 0.53 0.94 0.73 5.26 8.52 stdev 2.125818
0.03 0.69 0.58 0.82 0.26 0.82 0.80 0.43 0.98 0.49 0.81 0.89 7.59 13.19
0.29 0.17 0.02 0.06 0.83 0.88 0.67 0.55 0.77 0.92 0.45 0.51 6.11 10.21
0.24 0.22 0.07 0.03 0.12 0.59 0.22 0.83 0.54 0.95 0.93 0.55 5.30 8.60
0.38 0.38 0.81 0.46 0.09 0.06 0.57 0.71 0.16 0.17 0.86 0.31 4.97 7.94
0.94 0.86 0.36 0.12 0.89 0.67 0.01 0.98 0.64 0.81 0.75 0.24 7.25 12.51
0.74 0.87 0.19 0.04 0.68 0.67 0.56 0.26 0.73 0.52 0.61 0.71 6.56 11.13
0.86 0.37 0.57 0.61 0.85 0.86 0.03 0.17 0.33 0.95 0.90 0.91 7.40 12.80
0.25 0.72 0.19 0.02 0.69 0.93 0.29 0.08 0.40 0.40 0.02 0.31 4.30 6.60
0.55 0.98 0.37 0.84 0.29 0.85 0.42 0.83 0.01 0.78 0.50 0.11 6.53 11.06
0.19 0.55 0.03 0.75 0.81 0.37 0.11 0.74 0.70 0.61 0.46 0.85 6.18 10.37
0.46 0.04 0.21 0.18 0.23 0.16 0.41 0.49 0.16 0.97 0.26 0.34 3.92 5.83
0.24 0.14 0.92 0.29 0.92 0.98 0.51 0.13 0.45 0.55 0.44 0.39 5.96 9.92
0.93 0.65 0.40 0.65 0.42 0.69 0.44 0.18 0.28 0.41 0.67 0.68 6.41 10.82
0.31 0.86 0.70 0.31 0.15 0.44 0.84 0.73 0.72 0.38 0.30 0.06 5.79 9.59
0.54 0.16 0.34 0.65 0.27 0.55 0.76 0.51 0.98 0.45 0.08 0.54 5.83 9.66
0.74 0.49 0.20 0.10 0.57 0.37 0.66 0.45 0.28 0.98 0.29 0.04 5.16 8.32
0.95 0.96 0.17 0.74 0.94 0.44 0.46 0.77 0.56 0.17 0.66 0.21 7.04 12.08

- DLW - 43
Exercise 3

Consider the following definite integral:

Develop the Monte Carlo experiment to estimate the value of


the integral

- DLW - 44
Thank You

- DLW - 45
Reference

Taha, H. A. (2017). Operations research: an


introduction. Pearson Education.

Feldman, R. M., & Valdez-Flores, C.


(2010). Applied probability and stochastic
processes. New York: Springer.

46

You might also like