Simulation Notes
Simulation Notes
Simulation Notes
1. Introduction
If we look at the dictionary, following is given as definition of simu-
lation.
top after previous symbol touches the ground (of the screen). There
are 12 symbols. I decide to use probability theory and random
numbers. I fix a random variable with 12 observed values. As an
example assume that my fixed variable is X which has binomial dis-
tribution, say Bin(n = 11, p = .35). Now my job is to write algorithm
in such a way that every time given a random number u in between
0 and 1 (such number is generated using Random Number Generator
by computer), one value in between 0 and 11 would be generated and
accordingly, one of the following symbol would be displayed on the
computer screen. For example, if value 3 is generated then N would
appear on the screen. If value 7 is generated then V would appear on
the screen and so on.
Suppose I want to do similar thing for the game Duck hunt. Suppose
length of the rectangle is L and every time one duck comes out from
a ground, I am supposed to decide from what point (from left) duck
would fly out. I again fix a random variable. Let’s fix X ∼ U ((0, L)).
In this case given a random number u ∈ [0, 1], we want to generated a
real number r ∈ [0, L].
SIMULATION 3
2. Method
Following are the methods that we would follow
• Find the CDF function F for the random variable and its inverse
F −1 .
3. Examples
1. Problem. Let X be a (discrete) uniform over {1, 2, . . . , 1389}. Use
random number .674 to simulate a value of X.
Hint: (n − 1) ≤ 1389(u) < n then simulated value corresponding to u
is n.
2. Problem. Simulate observations from the exponential distribution
using numbers 0.532, 0.345, 0.987, 0.123.
3. Problem. Let X has geometric distribution with parameter p = .20.
Use random numbers .345, .834, .243 in the given order to simulate
values of X.
Hint: n − 1 ≤ ln(1−u)
ln(q)
< n then simulated value corresponding to u is
n.
4. Problem. Suppose that the probabilities are 0.2466, 0.3452, 0.2417,
0.1128, 0.0395, 0.0111, 0.0026 and 0.0005 that there will be 0, 1, 2, 3, 4, 5, 6
or 7 polluting spills in the Great lakes on any one day. Simulate this
model for the four digit numbers 1189, 2431, 2022, 6541, 6937, 7851, 8551,
4183, 9642, 6799, 9969. Find the total number of polluting spills in the
Great lakes in 11 days.
Solution:
We have rule which says that we read random number given, say u as
probability and simulated valus is n where F (n − 1) ≤ u < F (n). After
SIMULATION 5
Xi 0 1 2 3 4 5 6
F [Xi ] 0.368 0.736 0.920 0.981 0.996 0.999 1.000
Yi denote the number of units accepted on ith day. Then, Yi ∼ Bin(xi , .8).
Let U1 ∼ U ((0, 1)). We are given u1 = 0.20.
Now, 0.20 < F (X1 = 0) hence simulated value of X1 is 0.
Proceeding in similar manner, we see that u2 = 0.75 hence we get
x2 = 2 as F (X2 = 1) ≤ u2 < F (X2 = 2).
We have Y2 ∼ Bin(2, 0.8).
Y2 0 1 2
F [Y2 ] 0.04 0.36 1
Using u3 = 0.66, we get that y2 = 2.
Hence, total units accepted in first and second day= 0+ 2= 2.
7. Problem. Suppose the claims are made to an insurance company
according to a Poisson process with rate 3 per day. The amount of
the claim is a continuous variable with density U (($1000, $1500)). The
6 M. GOEL AND S. GONDHALI
Xi 0 1 2 3 4 5 6 7 8 9 10
F [Xi ] 0.0498 0.1991 0.4232 0.6472 0.8153 0.9161 0.966 0.988 0.996 0.999 1
Let Y denote amount of claim. Then, Y ∼ U (($1000, $1500)).
Let u = F (y). Then, we get F −1 (u) = 500u + 1000. We are supposed
to use following random numbers
u1 = 0.22 u2 = 0.50 u3 = 0.75 u4 = 0.12 u5 = 0.20
u6 = 0.53 u7 = 0.10 u8 = 0.21 u9 = 0.32 u10 = 0.01
u11 = 0.31 u12 = 0.80 u13 = 0.71
Let Ui ∼ U ((0, 1)) and we view ui as an observed value of Ui . We do
simulation as per instruction and we get following
Day Money available Number of Amount of Money after settlement
(i) claims xi claim y
1 2000 u1 2 u2 1250
u3 1375 1000- (1250+ 1375)= -625
2 2000 u4 1 u5 1100 2000- 1100= 900
3 900+ 2000= 2900 u6 3 u7 1050
u8 1105
u9 1160 2900- 3315= -415
4 2000 u10 0 2000
5 2000+ 2000= 4000 u11 2 u12 1400
u13 1355 4000- 2755= 1245
Hence, total amount at the end of day 5 is 1245.
Total money borrowed is 625 + 415 = 1040.
4. Mathematical justification
We must ask ourselves whether there is any mathematical reason for
making choices that we made in our method or is it an algorithm? In
later case, we will have to be careful as this method might fail for vari-
ous cases. We discuss mathematics which motivate us to make choices
SIMULATION 7
that we did.
10. Observation. Given a continuous variable X, take Y = FX (X) and
α = FX and we see that FW ≡ FX and hence as random variables X =
W. That is, the value that we obtain using the inverse transformation
method is indeed an observed value of the distribution that we started
with.
n
P
11. Lemma. Let 0 ≤ p1 , p2 , · · · pn be such that pi = 1. Fix x1 <
i=1
· · · < xn real numbers. Let U ∼ ((0, 1)). We define a function X of u
as
j−1 j
X X
X(u) = xj for pi ≤ u < pi .
i=1 i=1
Check that P [X = xj ] = pj .
Proof. By definition, we see that
j
P
pi
i=1
j−1
X j
X Z
P [X = xj ] = P pi ≤ u < pi = du = pj .
i=1 i=1 j−1
P
u= pi
i=1
12. Observation. (i) Given a discrete variable X, take pj = fX (xj ) and
we see that the value that we obtain using our method is indeed an
observed value of the distribution that we started with.
(i) This lemma tells us that if we assign observed value c to u such
that F (xj−1 ) ≤ u < F (xj ) then c must have property that P [X = c] =
P [X = xj ] so naturally we take c = xj .
13. Remark. In the case of discrete random variable, we developed
method using U ∼ U ((0, 1)). This is classical method which is univer-
sally accepted. It might be possible to develop some other method for
simulation of discrete random variable by taking some other appropri-
ate distribution for U.
5. Practice problems
14. Problem. A car manufacturing produce 1 to 8 units daily accord-
ing to uniform distribution. The number of vehicles available to ship
the manufactured cars from the factory to market daily follows Poisson
distribution with mean 1. Capacity of a shipping vehicle is 2 cars. The
probability of a shipped car being sold in a day is .75 independent of
all sales. If each sold car gives net profit of 2 Lakhs, whereas each
unshipped or shipped but unsold car has a storage cost 2000 or 4000
per day resp. Using random numbers .80, .82 and .59 once in the given
order, Simulate the net profit for the manufacturing firm in a day.
SIMULATION 9
in last 6 hour period. For instance, price of the product for the time
interval 6AM to 12 noon is revised based on the total units sold during
12 midnight to 6AM. So, as per this strategy price will be decided at
12 midnight and will be revised at 6AM, 12 noon and 6PM of every
day. It is decided, if total units sold in a 6 hour period is more than 2
units, then the price per unit will increase by 10% else it will decrease
by 10%. From past experience, we know that the total number of units
sold during any 6 hour period follows Poisson process with λ = 0.2 per
hour. Every day, if you check the price of this product online on this
t
shopping site at a random hour T with density f (t) = 288 , 0 < t < 24,
then based on three days simulation find the average price you ob-
served. Use the following random numbers exactly once in the given
order: random numbers to generate the price process (i.e. price and
demand) are 0.50, 0.70, 0.76, 0.93, 0.75, 0.72, 0.91, 0.45, 0.45, 0.57. Ran-
dom numbers to generate the time at which you access the site are
0.73, 0.39 and 0.20.
20. Problem. Suppose two friends A and B are waiting for their friend
C. The waiting time for C follows uniform distribution with minimum
0 to maximum 2 hours. The two friends A and B decide to play a series
of “dice” game during this waiting period. In each “dice” game either
one (A or B) is owner and other one is called player. Owner always
bet over number 1 and throws an unbiased die, if 1 appears on the die,
owner wins and receives $6 from player else owner need to pay $3 to
the player. The winner of the game will be the next game’s owner and
looser will be the player. If the total number of games played during
waiting time follows Poisson distribution with mean 3 per hour and the
owner of the first game is A then simulate the total profit for A and B
using random numbers 0.50, 0.75, 0.30, 0.01, 0.10, 0.20 exactly once in
the given order.
If there is any typo, error, query or suggestion then please feel free
to contact us.
References
[1] Baron, Michel; Probability and Statistics for Computer Scientists, Second Edi-
tion Chapman & Hall/CRC (ISBN:1439875901 9781439875902).
[2] Sheldon M. Ross; Simulation 6th Edition.
SIMULATION 11