Download as pdf or txt
Download as pdf or txt
You are on page 1of 42

Simulation

IB3200 Lecture
Sampling from
distributions:
1. Empirical continuous
distributions.

Dr Katy Hoad
http://www.wbs.ac.uk/about/person/Kathryn-Hoad/
Join at vevox.app

Or
Search Vevox in the app store

ID: 152-860-971

Join: vevox.app ID: 152-860-971


Sampling values from the chosen empirical /
probability distribution
• Lots of methods for sampling values from a distribution:
– ‘Top-Hat’ sampling
– Inverse transformation method
– Composition method
– Acceptance-Rejection method
– Box-Muller method
– Convolution method
For more detail see:
• Simulation modeling and analysis, e-book, Averill M. Law, 2015, Chapter 8.
• Tools for thinking, modelling in management science, M.Pidd, 2009, Chapter 11: e-book
• Discrete-Event System Simulation, J.Banks et al., 2005, Chapter 8: print book at main library
QA 79.5.B2 +2 others.
Sampling values from the chosen empirical /
probability distribution
• Lots of methods for sampling values from a distribution:
– ‘Top-Hat’ sampling
– Inverse transformation method
– Composition method
– Acceptance-Rejection method
– Box-Muller method
– Convolution method

• Sampling is carried out using random numbers.


What are random numbers?
• A sequence of numbers that appear in a random order.
• Can be whole numbers on a scale of e.g. 0-9, or 0-99.
• Can be real numbers greater or equal to 0 but less than 1, i.e.
[0,1)
• Each number has an equal chance of appearing at any point in
the sequence (Uniform property).
• Once a number has been chosen this doesn’t affect its chance
of being chosen again, or of any other number being chosen
(Independent property).
• Pseudo random numbers can be produced by computer
software.
5
Warm-up activity
times Gym example
revisited…
Warm-up Frequency
time (mins)
[0,2) 10
We can sample activity [2,4) 37
times from this
empirical distribution
[4,6) 23
using random numbers. [6,8) 14
[8,10) 7
[10,12) 5
[12,14) 2
[14,16) 2
Total 100
6
• Lets use random whole numbers from 0-99. Assign them to the 8
activity time intervals in proportion to the observed frequencies.

Activity Percentage Cumulative Random


time frequency % frequency Numbers
[0,2) 10% 10 0-9

[2,4) 37% 47 10-46

[4,6) 23% 70 47-69

[6,8) 14% 84 70-83

[8,10) 7% 91 84-90

[10,12) 5% 96 91-95

[12,14) 2% 98 96-97

[14,16) 2% 100 98-99


7
• What would be our first simulated activity time?
Use these two random numbers streams:
62 43 55 21 50 8 23 71 97
15 70 35 52 7 60 78 76 76
Random Activity time
numbers range (mins)
0-9 [0,2)
• First, select a random number 10-46 [2,4)
to tell us which range the 47-69 [4,6)
activity time will fall in: 70-83 [6,8)
62 → [4,6) min range. 84-90 [8,10)
91-95 [10,12)
96-97 [12,14)
98-99 [14,16)
8
• What would be our first simulated activity time?
Use these two random numbers streams:
62 43 55 21 50 8 23 71 97
15 70 35 52 7 60 78 76 76

• Then, can use a second random


number to obtain a more specific
time… Random Activity time
numbers range (mins)
• For example, divide the range [4,6)
into two identical sections (1 minute 0-49 [4,5)
each) and use a random number to 50-99 [5,6)
select the 1 minute interval that the
activity time will fall into:
43 → [4,5) minute range

9
• What would be our first simulated activity time?
Use these two random numbers streams:
62 43 55 21 50 8 23 71 97
15 70 35 52 7 60 78 76 76
Random
Activity time
• Can further refine the sampled numbers
activity time by further dividing up 0 [4.00, 4.01)
the selected activity time range. 1 [4.01, 4.02)
• For example, divide [4,5) into 100 2 [4.02, 4.03)
smaller intervals = 100th of a minute
each.
54 [4.54, 4.55)
• Sample from this using another
random number: 55 [4.55, 4.56)
55 → 55th hundredth = 4.55 mins.
98 [4.98, 4.99)
99 [4.99, 5.00)
10
Sampling Exercise
• Use these random number streams to obtain the next 5 activity
times & hence complete the table: Random Activity time
numbers range (mins)
62 43 55 21 50 8 23 71 97
0-49 1st min
15 70 35 52 7 60 78 76 76
50-99 2nd min
Activity duration Random Activity time
numbers range (mins)
1 4.55 mins
0-9 [0,2)
2 10-46 [2,4)
47-69 [4,6)
3
70-83 [6,8)
4 84-90 [8,10)
91-95 [10,12)
5
96-97 [12,14)
6 98-99 [14,16)
11
Join: vevox.app ID: 152-860-971
Coming next…

More of sampling values


from the chosen statistical
or empirical distributions:
Focus on discrete
empirical distributions.

12
Simulation
IB3200
Sampling from
distributions:
2. Empirical discrete
distributions.

Dr Katy Hoad
http://www.wbs.ac.uk/about/person/Kathryn-Hoad/
Gym exercise decisions:

Decision rules
Discrete empirical distribution

Number of
Exercise Route
decision customers
(frequency)
Run 1 50
Cycle 2 30
Row 3 20
Total 100

Software will sample (pick a


value) from this distribution to
decide which exercise each
customer undertakes using
random numbers. 14
Gym exercise decisions:
Exercise Route Proportion
decision of customers Discrete empirical distribution
Run 1 0.5
• Lets use random numbers [0,1).
Cycle 2 0.3
• Assign the random numbers to
Row 3 0.2 the 3 routes in proportion to
Total 1 the observed frequencies.

Cumulative Random
Route Probability
probability Numbers
1. Run 0.5 0.5
2. Cycle 0.3 0.8
3. Row 0.2 1
15
Join: vevox.app ID: 152-860-971
Gym exercise decisions:
Here are two random numbers streams:
0.35 0.56 0.68 0.14 0.05 0.03 0.12 0.71 0.97
0.15 0.70 0.35 0.52 0.07 0.60 0.78 0.76 0.86
• What would be our first simulated activity decision (route)?

Cumulative Random
Route Probability
probability Numbers
1. Run 0.5 0.5
2. Cycle 0.3 0.8
3. Row 0.2 1

Join: vevox.app ID: 152-860-971 16


Gym exercise decisions:
Here are two random numbers streams:
0.35 0.56 0.68 0.14 0.05 0.03 0.12 0.71 0.97
0.15 0.70 0.35 0.52 0.07 0.60 0.78 0.76 0.86
• What would be our 2nd simulated activity decision (route)?

Cumulative Random
Route Probability
probability Numbers
1. Run 0.5 0.5
2. Cycle 0.3 0.8
3. Row 0.2 1

Join: vevox.app ID: 152-860-971 17


Coming next…

More of sampling values from


the chosen statistical or
empirical distributions:
Focus on using the inverse
transformation method on
known statistical distributions.
18
Simulation
IB3200
Sampling from
distributions:
3. Inverse Transformation
Method.

Dr Katy Hoad
http://www.wbs.ac.uk/about/person/Kathryn-Hoad/
Inverse-transformation method
• If the inverse of the cumulative function (CDF) F(x) of a
distribution exists we can use this inverse to randomly
sample values (x) from the chosen probability
distribution.
PDF

e.g. Sample a random value from


the Exponential distribution:

0.00 0.46 0.92 1.38 1.84 2.30 2.76 3.22 3.68 4.14

Let & set

Rearrange to find , i.e.


Inverse-transformation method
• If the inverse of the cumulative function (CDF) F(x) of a
distribution exists we can use this inverse to randomly
sample values (x) from the chosen probability
distribution.
PDF

e.g. Sample a random value from


the Exponential distribution:
but since is just another random number
[0,1), then we can write this more simply as:
0.00 0.46 0.92 1.38 1.84 2.30 2.76 3.22 3.68 4.14

Let & set

Rearrange to find , i.e.


Time between
arrivals
Gym example
revisited…

• Assume that an exponential distribution is suitable to represent the


inter-arrival times to the gym. We previously worked out that the
observed mean inter-arrival time was minutes.

• Using the given random number stream and the Inverse of the
Exponential distribution: , we can sample inter-arrival
times for the arrival process in our gym simulation model.

: 0.9532 0.5087 0.0001 0.4057 0.8706 0.3958 0.7872 0.3515


22
Time between
arrivals
Gym example
revisited…

• Observed mean inter-arrival time was minutes.


• Inverse of the Exponential distribution:

: 0.9532 0.5087 0.0001 0.4057 0.8706 0.3958 0.7872 0.3515


23
Time between
arrivals
Gym example
revisited…

• Observed mean inter-arrival time was minutes.


• Inverse of the Exponential distribution:

: 0.9532 0.5087 0.0001 0.4057 0.8706 0.3958 0.7872 0.3515


24
Time between
arrivals
Gym example
revisited…

• Observed mean inter-arrival time was minutes.


• Inverse of the Exponential distribution:

• 1st inter-arrival time 6 (5dp) mins

: 0.9532 0.5087 0.0001 0.4057 0.8706 0.3958 0.7872 0.3515


25
Time between
arrivals
Gym example
revisited…

• Observed mean inter-arrival time was minutes.


• Inverse of the Exponential distribution:

• 1st inter-arrival time 6 (5dp) mins

• 2nd inter-arrival time (5dp) mins

: 0.9532 0.5087 0.0001 0.4057 0.8706 0.3958 0.7872 0.3515


26
Time between
arrivals
Gym example
revisited…

• Observed mean inter-arrival time was minutes.


• Inverse of the Exponential distribution:

• 1st inter-arrival time 6 (5dp) mins

• 2nd inter-arrival time (5dp) mins

• 3rd inter-arrival time (5dp) mins

: 0.9532 0.5087 0.0001 0.4057 0.8706 0.3958 0.7872 0.3515


27
Time between
arrivals
Gym example
revisited…

• If the simulation clock starts at 16:00:00, when would the first


customer enter the gym model?

• 1st inter-arrival time 6 (5dp) minutes

28
Join: vevox.app ID: 152-860-971
Time between
arrivals
Gym example
revisited…

• If the simulation clock starts at 16:00:00, when would the 2nd


customer enter the gym model?
• 2nd inter-arrival time (5dp) minutes

29
Join: vevox.app ID: 152-860-971
Time between
arrivals
Gym example
revisited…

• If the simulation clock starts at 16:00:00, when would the 3rd


customer enter the gym model?

• 3rd inter-arrival time (5dp) minutes

30
Join: vevox.app ID: 152-860-971
Representing Variability Summary

Method Advantages Disadvantages


Traces Reproduce real life Variability is limited to
conditions exactly range in the data collected
(validation) Only one set of
circumstances can be
modelled
Empirical A number of Variability is limited to
distributions circumstances can be range in the data collected
modelled
Statistical Variability can extend Can an appropriate
distributions beyond the range of distribution be found?
data collected
31
• How to collect model realisation
data and possible courses of action
if the data is not available.
• How to represent variation in the
system in a DES model: Trace data,
This week’s Empirical distributions and known
Statistical distributions.
main • Sampling data from empirical /
learning statistical distributions (Top-Hat
sampling and Inverse
points: Transformation method) to produce
activity times, inter-arrival times,
and routing decisions in a DES
model.

32
Next…

Exercises at carrying out a manual


simulation using sampling.

33
Simulation
IB3200
Exercises – manual
simulations with
sampling

Dr Katy Hoad
http://www.wbs.ac.uk/about/person/Kathryn-Hoad/
Exercise 1 – manual simulation
• Fast Track Ltd run a quick fitting service for car
exhausts, tyres and batteries. At present, they only
have one fitting bay, but would like to invest in a
second.
• They have collected some data (time unit used is
minutes) on the pattern of customer arrivals and
used this to estimate the following distribution of
time between arrivals: Exponential (λ = 0.08)
• It takes either 10 or 20 minutes (with equal
probability) to complete a service.

35
Exercise 1 – manual simulation
• Complete the table below, using the random numbers stated
in the table, to sample the arrival times and service times for
the first five customer arrivals (assume the simulation clock
starts at time 9.00 am)
Customer Random Time Between Arrival Random Service
Number Number Arrivals Time Number Time
(minutes) (HH:MM) (minutes)
9:00
1 0.256 0.802
2 0.612 0.150
3 0.801 0.642
4 0.091 0.324
5 0.510 0.947
36
Exercise 1 – manual simulation
• Transfer your calculated arrival times and service times to the
table below and simulate the system for the first five
customers arriving. Determine the total time that the five
customers have to queue.
Customer Arrival Time Service Start Finish Queuing
Number (HH:MM) Time (mins) Service Service Time (mins)
(HH:MM) (HH:MM)
1

5
37
Exercise 1 – manual simulation
• What is the average queuing time?

• Do you think that they should get a 2nd fitting bay?

• Apart from waiting time, what else should the


company take into account when making this decision?

38
Exercise 2 – manual simulation
NOW REPEAT THIS EXERCISE BUT WITH INCREASED PRECISION
– SO WE NOW WORK WITH SECONDS RATHER THAN MINUTES

• Fast Track Ltd run a quick fitting service for car exhausts,
tyres and batteries. At present, they only have one fitting
bay, but would like to invest in a second.

• They have collected some data (time unit used is seconds)


on the pattern of customer arrivals and used this to
estimate the following distribution of time between
arrivals: Exponential(λ = 0.00125)

• It takes either 10 or 20 minutes (i.e. 600 secs or 1200


secs),with equal probability, to complete a service.

39
Exercise 2 – manual simulation
• Complete the table below, using the random numbers stated
in the table, to sample the arrival times and service times for
the first five customer arrivals (assume the simulation clock
starts at time 9am). Round to the nearest whole second.
Customer Random Time Between Arrival Time Random Service Time
Number Number Arrivals (secs) (HH:MM:SS) Number (seconds)

9:00:00
1 0.256 0.802
2 0.612 0.150
3 0.801 0.642
4 0.091 0.324
5 0.510 0.947
40
Exercise 2 – manual simulation
• Transfer your calculated arrival times and service times to
the table below and simulate the system for the first five
customers arriving. Determine the total time that the five
customers have to queue.
Customer Arrival Time Service Start Service Finish Service Queuing
Number (HH:MM:SS) Time (secs) (HH:MM:SS) (HH:MM:SS) Time

1
2
3
4
5
41
Exercise 2 – manual simulation
• What is the average queuing time?

• Do you think that they should get a 2nd fitting bay?

• Apart from waiting time, what else should the


company take into account when making this
decision?

• What are some obvious


assumptions/simplifications that have been made
to run this simulation?
42

You might also like