Module-5 - Simulation Techniques
Module-5 - Simulation Techniques
1
Basics of System simulation and Modelling
A Simulation is the imitation (duplication) of the operation of a real-world process or system
over time.
Modelling is the process of representing a model which includes its construction and working.
This model is similar to a real system, which helps the analyst predict the effect of changes to
the system. In other words, modelling is creating a model which represents a system including
their properties. It is an act of building a model.
Simulation of a system is the operation of a model in terms of time or space, which helps
analyze the performance of an existing or a proposed system. In other words, simulation is the
process of using a model to study the performance of a system. It is an act of using a model for
simulation.
Systems simulation is a set of techniques that uses computers to imitate the operations of
various real-world tasks or processes through simulation. Computers are used to generate
numeric models for the purpose of describing or displaying complex interaction among
multiple variables within a system. The complexity of the system arises from
the stochastic (probabilistic) nature of the events, rules for the interaction of the elements and
the difficulty in perceiving the behaviour of the systems as a whole with the passing of time.
2
Components of system are
• Entity: An object of interest in the system is called an entity of the system.
Example: Machines in factory
• Attribute: The property of an entity is called Attribute.
Example: Attribute of speed, capacity of machines
• Activity: A time period of specified length
Example: welding, stamping the Machines
• State: A collection of variables that describe the system in any time :
Status of machine
Example: status of machine (busy, idle, down,…)
• Event: A instantaneous occurrence that might change the state of the system
Example: breakdown of machine
• Endogenous: Activities and events occurring with the system.
• Exogenous: Activities and events occurring with the environment.
3
Steps in Simulation
4
Problem formulation: Every study should begin with a statement of the problem. If the statement is
provided by policymakers, or those that have the problem, the analyst must ensure that the problem
being described is clearly understood. If a problem statement is being developed by the analyst, it is
important that the policymaker understand and agree with the formulation. Although not shown in the
figure there are occasions where the problem must be reformulated as the study progresses. In many
instances, policymakers and analysts are aware that there is a problem long before the nature of
problem is known.
Setting of objectives and overall project plan: The objective indicate the questions to be answered. At
this point, a determination should be made concerning whether simulation is the appropriate
methodology for the problem as formulated and objectives as stated. Assuming that it is decided that
simulation is appropriate, the overall project plan should include a statement of the alternative systems
to be considered and of a method for evaluating the effectiveness of these alternatives. It should also
include the plans for the study in terms of the number of people involved, the cost of the study, and the
number of days required to complete each phase of the work, along with the result expected at the end
of each stage.
Model conceptualization: The construction of a model of a system is probably as much art as science. The
art of modelling is enhanced by an ability to abstract the essential features of a problem, to select and
modify basic assumption results. Thus, it is best to start with a simple model and build toward greater
complexity. It is not necessary to have a one to one mapping between the model and the real system.
Only the essence of real system is needed. It is advisable to involve the model user in model
conceptualization. Involving the model user will both enhance the quality of the resulting model and
increase the confidence of the model user in the application of the model.
5
Data collection: There is a constant interplay between the construction of the model and the collection
of the needed input data. As the complexity of the model changes, the required data elements can
also change. Also, since data collection takes such a large portion of the total time required to
perform simulation, it is necessary to begin it as early as possible, usually together with the early
stages of model building. The objective study dictates, in a large way, the kind of data to be
collected. In study of bank, for example, if the desire is to learn about the length of waiting lines as
the number of tellers change, the types of data needed would be the distributions of inter-arrival
times, the service time distribution for the tellers, and the historic distributions on the lengths of
waiting lines under varying conditions. This last type of data will be used to validate the simulation
model.
Model translation: Most real world systems results in models that require a great deal of information
storage and computation, so the model must be entered into a computer recognizable format. We use
the word “program” even though it is possible to accomplish the desire result in many instances with
little or no actual coding. The modeler must decide whether to program the model in simulation
language, such as GPSS/H, or to use special purpose simulation software.
Verified: Verification pertains to the computer program prepared for the simulation model. Is the
computer program performing properly? With complex models, it is difficult, if not impossible, to
translate the model successfully in its entirety without a good deal of debugging; if the input
parameters and logical structure of model are correctly represented in the computer, verification has
been completed. For the most part, common sense is used in completing this step.
6
Validated: Validation usually is achieved through the calibration of the model, an iterative process of comparing the
model against the actual system behaviour and using the discrepancies between the two, and the insight gained, to
improve the model. This process is repeated until model accuracy is judged acceptable.
Experimental design: The alternatives that must be simulated must be determined. Often, the decisions concerning which
alternatives to simulate will be a function of runs that have been completed and analysed. For each system design that
is simulated, decisions need to be made concerning the length of the initialisation period, the length of simulation runs,
and the replication to be made of each run.
Production runs and analysis: Production runs and their subsequent analysis are used to estimate measures of
performance for the system designs that are being simulated.
More runs: Given the analysis of runs that have been completed, the analyst determines whether additional runs are
needed and what design those additional experiments should follow.
Documentation and reporting: There are two types of documentation: program and progress. Program document is
necessary to understand how program operate. The program modification is much easier. Model users can change
parameters if required to determine the relationship between input parameters and output measures of performance, or
to determine the relationship between input parameter and output measures of performance. The result of all the
analysis should be reported clearly and concisely in a final report. This will enable model users to review the final
formulation, the alternative system that were addressed, the criterion by which the alternatives were compared, the
results of the experiments, and the recommended solution to the problem.
Implementation: The success of implementation phase completely depends upon how well the previous 11 steps are
performed. It is also contingent upon how thoroughly the analyst has involved the ultimate model user during the entire
simulation process. If the model user has been thoroughly involved during the model building process and if the model
user understands the nature of the model and its output, likelihood of a vigorous implementation is enhanced.
7
Developing Simulation Models
Simulation models consist of the following components: system entities, input variables, performance
measures, and functional relationships. Following are the steps to develop a simulation model.
Step 1 − Identify the problem with an existing system or set requirements of a proposed system.
Step 2 − Design the problem while taking care of the existing system factors and limitations.
Step 3 − Collect and start processing the system data, observing its performance and result.
Step 4 − Develop the model using network diagrams and verify it using various verifications techniques.
Step 5 − Validate the model by comparing its performance under various conditions with the real
system.
Step 6 − Create a document of the model for future use, which includes objectives, assumptions, input
variables and performance in detail.
Step 8 − Induce experimental conditions on the model and observe the result.
8
Performing Simulation Analysis
Following are the steps to perform simulation analysis.
Step 2 − Choose input variables and create entities for the simulation process. There are two types of variables
- decision variables and uncontrollable variables. Decision variables are controlled by the programmer, whereas
uncontrollable variables are the random variables.
Step 3 − Create constraints on the decision variables by assigning it to the simulation process.
Step 5 − Collect data from the real-life system to input into the simulation.
Step 8 − Verify the simulation model by comparing its result with the real-time system.
Step 9 − Perform an experiment on the model by changing the variable values to find the best solution.
Easy to understand − Allows to understand how the system really operates without
working on real-time systems.
Easy to test − Allows to make changes into the system and their effect on the
output without working on real-time systems.
Easy to diagnose problems − Certain systems are so complex that it is not easy to
understand their interaction at a time. However, Modelling & Simulation allows to
understand all the interactions and analyze their effect. Additionally, new policies,
operations, and procedures can be explored without affecting the real system.
10
Modelling & Simulation ─ Disadvantages
Operations are performed on the system using random number, hence difficult
to predict the result.
11
Advantages Disadvantages
Simulation helps to learn about real system, without Model building requires special training. It is an art
having the system at all. that is learned over time and through experience.
For Instance: Globe, that imitates the Earth.
In many situations experimenting with actual system Sometimes simulation results is difficult to
may not be possible at all. interpret the simulation results.
Eg: Nuclear explosion
In the real system, the changes we want to study Expensive to build a simulation model
may take place too slowly or too fast to be observed
conveniently.
Ex: Solar system study ,Chemical reactions
Many managerial decision making problems are too Simulation is used in some cases when an
complex to be solved by mathematical analytical solution is possible, or even preferable.
programming.
Ex: Decision Support System
Easy to perform ``What-If'' analysis. Expensive to conduct simulation.
12
Modelling & Simulation ─ Application Areas
Modelling & Simulation can be applied to the following areas − Military applications,
training & support, designing semiconductors, telecommunications, civil engineering
designs & presentations, and E-business models.
13
Problems on Simulation
• It is an experiment on chance
• Uses random number and requires decision making under uncertainties.
14
1. A confectioner sells confectionery items, past data of demand per week in hundred kilograms with
frequency is given below.
Frequency 2 11 8 21 5 3
Using the following sequence of random number. Generate the demands for the next 10 weeks. Also find
out the average demand per week. Use the following random numbers for handling above problem. 35, 52,
13, 90, 23, 73, 34, 57, 35 and 83.
0 2
5 11
10 8
15 21
20 5
25 3
sum of
sum of probability=1
frequency=50 15
1. A confectioner sells confectionery items, past data of demand per week in hundred kilograms with
frequency is given below.
Frequency 2 11 8 21 5 3
Using the following sequence of random number. Generate the demands for the next 10 weeks. Also find
out the average demand per week. Use the following random numbers for handling above problem. 35, 52,
13, 90, 23, 73, 34, 57, 35 and 83.
0 2 0.04
5 11 0.22
10 8 0.16
15 21 0.42
20 5 0.1
25 3 0.06
sum of
sum of probability=1
frequency=50 16
1. A confectioner sells confectionery items, past data of demand per week in hundred kilograms with
frequency is given below.
Frequency 2 11 8 21 5 3
Using the following sequence of random number. Generate the demands for the next 10 weeks. Also find
out the average demand per week. Use the following random numbers for handling above problem. 35, 52,
13, 90, 23, 73, 34, 57, 35 and 83.
0 2 0.04 0.04
5 11 0.22 0.26
10 8 0.16 0.42
15 21 0.42 0.84
20 5 0.1 0.94
25 3 0.06 1
sum of
sum of probability=1
frequency=50 17
1. A confectioner sells confectionery items, past data of demand per week in hundred kilograms with
frequency is given below.
Frequency 2 11 8 21 5 3
Using the following sequence of random number. Generate the demands for the next 10 weeks. Also find
out the average demand per week. Use the following random numbers for handling above problem. 35, 52,
13, 90, 23, 73, 34, 57, 35 and 83.
Random
Weeks Demand
Number
1 35
2 52
3 13
4 90
5 23
6 73
7 34
8 57
9 35
10 83
19
Simulated value for next 10 weeks are
Random
Weeks Demand
Number
1 35 10
2 52 15
3 13 5
4 90 20
5 23 5
6 73 15
7 34 10
8 57 15
9 35 10
10 83 15
120
20
2. Strong is a dentist who schedules all her patients for 30 minutes appointments some of the
patients take more or less than 30 minutes depending on the type of dental work to be done. The
following summary shows the various categories of work, their probabilities and the time actually
needed to complete the work:
Time required(in
Category Number of patients
minutes)
Filling 45 40
Crown 60 15
Cleaning 15 15
Extracting 45 10
Check up 15 20
Simulate the dentist’s clinic for four hours and find out the average waiting time for the patients as
well as the idleness of the doctor. Assume that all the patents show up at the clinic at exactly their
scheduled, arrival time starting at 8:00 am. Use the following random numbers for handling above
problem.40, 82, 11, 34, 25, 66, 17 and 79.
21
Solution:
Time Random
Number of cumulative
Category required(in probability number
patients probability
minutes) Range
Filling 45 40
Crown 60 15
Cleaning 15 15
Extracting 45 10
Check up 15 20
22
Solution:
Time Random
Number of cumulative
Category required(in probability number
patients probability
minutes) Range
Filling 45 40 0.4
Crown 60 15 0.15
Cleaning 15 15 0.15
Extracting 45 10 0.1
Check up 15 20 0.2
23
Solution:
Time Random
Number of cumulative
Category required(in probability number
patients probability
minutes) Range
Check up 15 20 0.2 1
24
Solution:
Time Random
Number of cumulative
Category required(in probability number
patients probability
minutes) Range
25
Scheduled Random Service Time
Patient category
Arrival Number Needed(in min)
1 08:00
2 08:30
3 09:00
4 09:30
5 10:00
6 10:30
7 11:00
8 11:30
26
Scheduled Random Service Time
Patient category
Arrival Number Needed(in min)
1 08:00 40
2 08:30 82
3 09:00 11
4 09:30 34
5 10:00 25
6 10:30 66
7 11:00 17
8 11:30 79
27
Scheduled Random Service Time
Patient category
Arrival Number Needed(in min)
1 08:00 40 Crown
2 08:30 82 Check up
3 09:00 11 Filling
4 09:30 34 Filling
5 10:00 25 Filling
6 10:30 66 Cleaning
7 11:00 17 Filling
8 11:30 79 Extracting
28
Scheduled Random Service Time
Patient category
Arrival Number Needed(in min)
1 08:00 40 Crown 60
2 08:30 82 Check up 15
3 09:00 11 Filling 45
4 09:30 34 Filling 45
5 10:00 25 Filling 45
6 10:30 66 Cleaning 15
7 11:00 17 Filling 45
8 11:30 79 Extracting 45
29
Service
Service Service Waiting
Patient Arrival duration idle time
Start ends (In min)
(in min)
30
Service
Service Service Waiting
Patient Arrival duration idle time
Start ends (In min)
(in min)
31
Service
Service Service Waiting
Patient Arrival duration idle time
Start ends (In min)
(in min)
32
Service
Service Service Waiting
Patient Arrival duration idle time
Start ends (In min)
(in min)
33
Service
Service Service Waiting
Patient Arrival duration idle time
Start ends (In min)
(in min)
34
Service
Service Service Waiting
Patient Arrival duration idle time
Start ends (In min)
(in min)
35
3. After observing heavy congestion of customer over a period of time in a petrol station. Mr. Petro has decided
to set up a petrol pump facility on his own in a nearby site. He has compiled statistics relating to potential
customer arrival pattern and service pattern as given below. He has also decided to evaluate the operations
using simulation technique.
Arrivals Services
2 0.22 4 0.28
4 0.30 6 0.40
6 0.24 8 0.22
8 0.14 10 0.10
10 0.10
36
Assume:
• The clock starts at 8:00.
• Only one pump is setup.
• The following 12 random numbers are to be used to depict
the customer arrival pattern
78,26,94,08,46,63,18,35,59,12,97and 82.
• The following 12 random numbers are to be used to depict
the service arrival pattern 44,21,73,96, 63,35,57,31,84,24,05
and 37.
Find average of the pump being idle and average time spent by
a customer waiting in queue for 12 customer.
37
Inter arrival time (in minutes) Service Time
Random Random
cumulative cumulative
Minutes Probability number Minutes Probability number
probability probability
Range Range
2 0.22 4 0.28
4 0.30 6 0.40
6 0.24 8 0.22
8 0.14 10 0.10
10 0.10
38
Inter arrival time (in minutes) Service Time
Random Random
cumulative cumulative
Minutes Probability number Minutes Probability number
probability probability
Range Range
2 0.22 0.22 00-21 4 0.28 0.28 00-27
4 0.30 0.22+0.30=0.52 22-51 6 0.40 0.28+0.40=0.68 28-67
6 0.24 0.52+0.24=0.76 52-75 8 0.22 0.68+0.22=0.90 68-89
8 0.14 0.76+0.14=0.90 76-89 10 0.10 0.90+0.10=1.00 90-99
10 0.10 0.90+0.10=1.00 90-99
39
Random Entry Random
Inter Service Service Waiting
Number time Number Service Idle
SL.NO arrival start End Time of
for Inter Start For Time Time
time time Time Customer
arrival time Service
1 78 8 08:08 08:08 44 6 08:14 0 8
2
3
4
5
6
7
8
9
10
11
12
40
Random Entry Random
Inter Service Service Waiting
Number time Number Service Idle
SL.NO arrival start End Time of
for Inter Start For Time Time
time time Time Customer
arrival time Service
1 78 8 08:08 08:08 44 6 08:14 0 8
2 26 4 08:12 08:14 21 4 08:18 2 0
3
4
5
6
7
8
9
10
11
12
41
Random Entry Random
Inter Service Service Waiting
Number time Number Service Idle
SL.NO arrival start End Time of
for Inter Start For Time Time
time time Time Customer
arrival time Service
1 78 8 08:08 08:08 44 6 08:14 0 8
2 26 4 08:12 08:14 21 4 08:18 2 0
3 94 10 08:22 08:22 73 8 08:30 0 4
4 08 2 08:24 08:30 96 10 08:40 6 0
5 46 4 08:28 08:40 63 6 08:46 12 0
6 63 6 08:34 08:46 35 6 08:52 12 0
7 18 2 08:36 08:52 57 6 08:58 16 0
8 35 4 08:40 08:58 31 6 09:04 18 0
9 59 6 08:46 09:04 84 8 09:12 18 0
10 12 2 08:48 09:12 24 4 09:16 24 0
11 97 10 08:58 09:16 05 4 09:20 18 0
12 82 8 9:06 09:20 37 6 09:26 14 0
140 12
42
Random Entry Random
Inter Service Service Waiting
Number time Number Service Idle
SL.NO arrival start End Time of
for Inter Start For Time Time
time time Time Customer
arrival time Service
1 78 8 08:08 08:08 44 6 08:14 0 8
2 26 4 08:12 08:14 21 4 08:18 2 0
3 94 10 08:22 08:22 73 8 08:30 0 4
4 08 2 08:24 08:30 96 10 08:40 6 0
5 46 4 08:28 08:40 63 6 08:46 12 0
6 63 6 08:34 08:46 35 6 08:52 12 0
7 18 2 08:36 08:52 57 6 08:58 16 0
8 35 4 08:40 08:58 31 6 09:04 18 0
9 59 6 08:46 09:04 84 8 09:12 18 0
10 12 2 08:48 09:12 24 4 09:16 24 0
11 97 10 08:58 09:16 05 4 09:20 18 0
12 82 8 9:06 09:20 37 6 09:26 14 0
140 12
Average = 140/12 =11.67 min
Idle time for petrol bunk =12/86=0.1395 43
The able- baker call center problem.
This example illustrates the simulation procedure when there is more than one service channel. Consider a computer
technical support centre where personnel takes calls and provide service. The time between calls ranges from 1 to 4 minutes,
with distribution as shown in table 1.there are two technical support people able and baker. Able is more experienced and
can provide service faster than baker. The distributions of their service faster than baker. The distributions of their service
times are shown in table 2 and table 3.times are usually a continuous measure. But, in this and other time based examples,
we make them discrete for ease of explanation the simulation proceeds in more complex way because of the two servers. A
simplifying rule is that able gets the call if both technical support people are idle able has seniority (the solution would be
different if the decision were made at random or by any other rule).the problem is to find how well the current arrangement
is working.to estimate the system measures of performance, a simulation of the first 6 callers is made. A simulation of the
first 6 callers is made. A simulation with more callers would yield more reliable results, but for purpose of illustration a 6
caller simulation has been selected. Random digits for time arrival are 26, 98, 90, 26, and 42. Random digits for service time
are 95, 21, 51, 92, 89 and 38.
Time Arrival 1 2 3 4
Table 1
Probability 0.25 0.40 0.20 0.15
Service time 2 3 4 5
Table 2
Probability 0.30 0.28 0.25 0.17
Service time 3 4 5 6
Table 3
Probability 0.35 0.25 0.20 0.20
44
Solution:
Able – Baker Problem:
• More than one channel of work / service.
• Able being faster than Baker, Able is preferred.
Steps:
1. A customer arrives at time K.
2. If both Able and Baker are free, then service goes to Able.
3. If Able is busy, then service goes to Baker.
4. If both Able and Baker are busy, then customer waits for one of them to be free.
Calculate arrivals time distribution and assign random number.
Time
cumulative Random Number
between Probability
probability Range
arrivals
1 0.25
2 0.40
3 0.20
4 0.15
45
Solution:
Able – Baker Problem:
• More than one channel of work / service.
• Able being faster than Baker, Able is preferred.
Steps:
1. A customer arrives at time K.
2. If both Able and Baker are free, then service goes to Able.
3. If Able is busy, then service goes to Baker.
4. If both Able and Baker are busy, then customer waits for one of them to be free.
Calculate arrivals time distribution and assign random number.
Time
cumulative Random Number
between Probability
probability Range
arrivals
1 0.25 0.25 00-24
2 0.40 0.25+0.40=0.65 25-64
3 0.20 0.85 65-84
4 0.15 1.00 85-99
46
Calculate service time distribution and assign Random Numbers
cumulative Random Number
Service Time Probability
probability Range
2 0.30
Able
3 0.28
4 0.25
5 0.17
cumulative Random Number
Service Time Probability
probability Range
3 0.35
Baker
4 0.25
5 0.20
6 0.20
47
Calculate service time distribution and assign Random Numbers
cumulative Random Number
Service Time Probability
probability Range
2 0.30 0.30 0-29
Able
3 0.28 0.58 30-57
4 0.25 0.83 58-82
5 0.17 1.00 83-99
cumulative Random Number
Service Time Probability
probability Range
3 0.35 0.35 0-34
Baker
4 0.25 0.60 35-59
5 0.20 0.80 60-79
6 0.20 1.00 80-99
Inter Arrival Time Determination
Random Inter Arrival
Customer
Number Time
1 - -
2 26 2
3 98 4
4 90 4
5 26 2
6 42 2 48
Able Baker
Custom Inter Time at Time at Time at Time at
Arrival Random service service Caller Time in
er Arrival Service Service Service Service
Time no. Time Time Delay system
Number Time Begins Ends Begins Ends
1 - 0 95 0 5 5 0 5
2
3
4
5
6
49
Able Baker
Custom Inter Time at Time at Time at Time at
Arrival Random service service Caller Time in
er Arrival Service Service Service Service
Time no. Time Time Delay system
Number Time Begins Ends Begins Ends
1 - 0 95 0 5 5 0 5
2 2 2 21 2 3 5 0 3
3
4
5
6
50
Able Baker
Custom Inter Time at Time at Time at Time at
Arrival Random service service Caller Time in
er Arrival Service Service Service Service
Time no. Time Time Delay system
Number Time Begins Ends Begins Ends
1 - 0 95 0 5 5 0 5
2 2 2 21 2 3 5 0 3
3 4 6 51 6 3 9 0 3
4
5
6
51
Able Baker
Custom Inter Time at Time at Time at Time at
Arrival Random service service Caller Time in
er Arrival Service Service Service Service
Time no. Time Time Delay system
Number Time Begins Ends Begins Ends
1 - 0 95 0 5 5 0 5
2 2 2 21 2 3 5 0 3
3 4 6 51 6 3 9 0 3
4 4 10 92 10 5 15 0 5
5
6
52
Able Baker
Custom Inter Time at Time at Time at Time at
Arrival Random service service Caller Time in
er Arrival Service Service Service Service
Time no. Time Time Delay system
Number Time Begins Ends Begins Ends
1 - 0 95 0 5 5 0 5
2 2 2 21 2 3 5 0 3
3 4 6 51 6 3 9 0 3
4 4 10 92 10 5 15 0 5
5 2 12 89 12 6 18 0 6
6
53
Able Baker
Custom Inter Time at Time at Time at Time at
Arrival Random service service Caller Time in
er Arrival Service Service Service Service
Time no. Time Time Delay system
Number Time Begins Ends Begins Ends
1 - 0 95 0 5 5 0 5
2 2 2 21 2 3 5 0 3
3 4 6 51 6 3 9 0 3
4 4 10 92 10 5 15 0 5
5 2 12 89 12 6 18 0 6
6 2 14 38 15 3 18 1 4
54
RANDOM NUMBER
A Real Number between 0 to 1 is called the Random Number.
Notation: R , R Belongs to (0, 1)
Source: Calculator
Command: RAN#
Procedure:
Enter the shift and . In display it will show RAN# then keep on pressing = you will get random number between 0 to 1.
55
1. If 𝑚 = 102 ,𝑎 = 19,𝑐 = 0and 𝑋0 = 63then generate a sequence of random numbers using the
linear congruential method
Solutions:
Wkt, By Linear Congruent Method
𝑋𝑖+1
𝑋𝑖+1 = (𝑎𝑋𝑖 + 𝑐) 𝑚𝑜𝑑 𝑚 and 𝑅𝑖+1 = 𝑚
We have,
𝑋0 = 63 ,𝑎 =19, 𝑐 = 0 and 𝑚 = 100
Now
𝑋0 = 63, 𝑋1 = (𝑎𝑋0 + 𝑐) 𝑚𝑜𝑑 𝑚
56
𝑋𝑖+1 Substitute the value of 𝑋𝑖+1
Xi = (𝑎𝑋𝑖 + 𝑐) 𝑚𝑜𝑑 𝑚 simplification Xi+1 𝑅𝑖+1 =
a, c, m and Xi 𝑚
R1 =
X0=63 X1 = (aX0 +c) mod m (19(63)+0) mod 100 1197 mod 100 X1 = 97
97/100=0.97
57
𝑋𝑖+1 Substitute the value of 𝑋𝑖+1
Xi = (𝑎𝑋𝑖 + 𝑐) 𝑚𝑜𝑑 𝑚 simplification Xi+1 𝑅𝑖+1 =
a, c, m and Xi 𝑚
R1 =
X0=63 X1 = (aX0 +c) mod m (19(63)+0) mod 100 1197 mod 100 X1 = 97
97/100=0.97
X1 = 97 X2 = (aX1 +c) mod m (19(97)+0) mod 100 1843 mod 100 X2 = 43 R2 = 0.43
58
𝑋𝑖+1 Substitute the value of 𝑋𝑖+1
Xi = (𝑎𝑋𝑖 + 𝑐) 𝑚𝑜𝑑 𝑚 simplification Xi+1 𝑅𝑖+1 =
a, c, m and Xi 𝑚
R1 =
X0=63 X1 = (aX0 +c) mod m (19(63)+0) mod 100 1197 mod 100 X1 = 97
97/100=0.97
X1 = 97 X2 = (aX1 +c) mod m (19(97)+0) mod 100 1843 mod 100 X2 = 43 R2 = 0.43
X2 = 43 X3 = (aX2 +c) mod m (19(43)+0) mod 100 817 mod 100 X3 = 17 R3 = 0.17
59
𝑋𝑖+1 Substitute the value of 𝑋𝑖+1
Xi = (𝑎𝑋𝑖 + 𝑐) 𝑚𝑜𝑑 𝑚 simplification Xi+1 𝑅𝑖+1 =
a, c, m and Xi 𝑚
R1 =
X0=63 X1 = (aX0 +c) mod m (19(63)+0) mod 100 1197 mod 100 X1 = 97
97/100=0.97
X1 = 97 X2 = (aX1 +c) mod m (19(97)+0) mod 100 1843 mod 100 X2 = 43 R2 = 0.43
X2 = 43 X3 = (aX2 +c) mod m (19(43)+0) mod 100 817 mod 100 X3 = 17 R3 = 0.17
X3 = 17 X4 = (aX3 +c) mod m (19(17)+0) mod 100 323 mod 100 X4 = 23 R4 = 0.23
60
𝑋𝑖+1 Substitute the value of 𝑋𝑖+1
Xi = (𝑎𝑋𝑖 + 𝑐) 𝑚𝑜𝑑 𝑚 simplification Xi+1 𝑅𝑖+1 =
a, c, m and Xi 𝑚
R1 =
X0=63 X1 = (aX0 +c) mod m (19(63)+0) mod 100 1197 mod 100 X1 = 97
97/100=0.97
X1 = 97 X2 = (aX1 +c) mod m (19(97)+0) mod 100 1843 mod 100 X2 = 43 R2 = 0.43
X2 = 43 X3 = (aX2 +c) mod m (19(43)+0) mod 100 817 mod 100 X3 = 17 R3 = 0.17
X3 = 17 X4 = (aX3 +c) mod m (19(17)+0) mod 100 323 mod 100 X4 = 23 R4 = 0.23
X4 = 23 X5 = (aX4 +c) mod m (19(23)+0) mod 100 437 mod 100 X5 = 37 R5 = 0.37
61
𝑋𝑖+1 Substitute the value of 𝑋𝑖+1
Xi = (𝑎𝑋𝑖 + 𝑐) 𝑚𝑜𝑑 𝑚 simplification Xi+1 𝑅𝑖+1 =
a, c, m and Xi 𝑚
R1 =
X0=63 X1 = (aX0 +c) mod m (19(63)+0) mod 100 1197 mod 100 X1 = 97
97/100=0.97
X1 = 97 X2 = (aX1 +c) mod m (19(97)+0) mod 100 1843 mod 100 X2 = 43 R2 = 0.43
X2 = 43 X3 = (aX2 +c) mod m (19(43)+0) mod 100 817 mod 100 X3 = 17 R3 = 0.17
X3 = 17 X4 = (aX3 +c) mod m (19(17)+0) mod 100 323 mod 100 X4 = 23 R4 = 0.23
X4 = 23 X5 = (aX4 +c) mod m (19(23)+0) mod 100 437 mod 100 X5 = 37 R5 = 0.37
X5 = 37 X6 = (aX5 +c) mod m (19(37)+0) mod 100 703 mod 100 X6 = 3 R6 = 0.03
62
𝑋𝑖+1 Substitute the value of 𝑋𝑖+1
Xi = (𝑎𝑋𝑖 + 𝑐) 𝑚𝑜𝑑 𝑚 simplification Xi+1 𝑅𝑖+1 =
a, c, m and Xi 𝑚
R1 =
X0=63 X1 = (aX0 +c) mod m (19(63)+0) mod 100 1197 mod 100 X1 = 97
97/100=0.97
X1 = 97 X2 = (aX1 +c) mod m (19(97)+0) mod 100 1843 mod 100 X2 = 43 R2 = 0.43
X2 = 43 X3 = (aX2 +c) mod m (19(43)+0) mod 100 817 mod 100 X3 = 17 R3 = 0.17
X3 = 17 X4 = (aX3 +c) mod m (19(17)+0) mod 100 323 mod 100 X4 = 23 R4 = 0.23
X4 = 23 X5 = (aX4 +c) mod m (19(23)+0) mod 100 437 mod 100 X5 = 37 R5 = 0.37
X5 = 37 X6 = (aX5 +c) mod m (19(37)+0) mod 100 703 mod 100 X6 = 3 R6 = 0.03
X6 = 3 X7 = (aX6 +c) mod m (19(3)+0) mod 100 57 mod 100 X7 = 57 R7 = 0.57
X7 = 57 X8 = (aX7 +c) mod m (19( 57 )+0) mod 100 1083mod 100 X8 = 83 R8 = 0.83
X8 = 83 X9 = (aX8 +c) mod m (19( 83)+0) mod 100 1577mod 100 X9 = 77 R9 = 0.77
X9 = 77 X10 = (aX9 +c) mod m (19( 77 )+0) mod 100 1463mod 100 X10= 63 R10 = 0.63
The sequence of Random numbers are 0.97, 0.43, 0.17, 0.23, 0.37, 0.03, 0.57, 0.83, 0.77, 0.63.
63
Generate pseudo random numbers by Linear congruential method taking seed value
𝑥0 = 6, 𝑥𝑛 = 10 + 21𝑥𝑛−1 , 𝑚𝑜𝑑 2 5
Solutions:
Wkt,
By Linear Congruent Method
𝑋𝑖+1
𝑋𝑖+1 = (𝑎𝑥𝑖 + 𝑐) 𝑚𝑜𝑑 𝑚 and 𝑅𝑖+1 = 𝑚
Given 𝑥𝑛 = 10 + 21𝑥𝑛−1 , 𝑚𝑜𝑑 2 5 replace n by n+1
Rearrange 𝑥𝑛+1 = 10 + 21𝑥𝑛 , 𝑚𝑜𝑑 2 5
𝑥𝑛+1 = (21𝑥𝑛 + 10) 𝑚𝑜𝑑 2 5 Replace n by i
𝑥𝑖+1 = (21𝑥𝑖 + 10) 𝑚𝑜𝑑 2 5
We have,
𝑋0 = 6 ,𝑎 = 21 , 𝑐 = 10 and 𝑚 =25
64
Substitute the 𝑋𝑖+1
Xi 𝑋𝑖+1 = (𝑎𝑋𝑖 + 𝑐) 𝑚𝑜𝑑 𝑚 value of a, c, m and simplification Xi+1 𝑅𝑖+1 =
𝑚
Xi
R1 =
X0= 6 X1 = (aX0 +c) mod m (21(6)+10)mod25 136 mod25 X1 = 11
0.44
Note:
136 mod 25
Step 1: 136/25=5.44
Step 2: 5.44 – 5 =0.44
Step 3: 0.44*25=11
65
Substitute the 𝑋𝑖+1
Xi 𝑋𝑖+1 = (𝑎𝑋𝑖 + 𝑐) 𝑚𝑜𝑑 𝑚 value of a, c, m and simplification Xi+1 𝑅𝑖+1 =
𝑚
Xi
R1 =
X0= 6 X1 = (aX0 +c) mod m (21(6)+10)mod25 136 mod25 X1 = 11
0.44
X1 = 11 X2 = (aX1 +c) mod m (21(11)+10)mod25 241 mod 25 X2 =16 R2 = 0.64
X2 = 16 X3 = (aX2 +c) mod m (21(16)+10)mod25 346 mod 25 X3 = 21 R3 = 0.84
X3 = 21 X4 = (aX3 +c) mod m (21(21)+10)mod25 451 mod 25 X4 = 1 R4 = 0.04
X4 = 1 X5 = (aX4 +c) mod m (21(1)+10)mod25 31 mod 25 X5 = 6 R5 = 0.24
X5 = 6 X6 = (aX5 +c) mod m (21(6)+10)mod25 136 mod25 X6 = 11 R6 = 0.44
X6 = 11 X7 = (aX6 +c) mod m (21(11)+10)mod25 241 mod 25 X7 = 16 R7 = 0.64
X7 = 16 X8 = (aX7 +c) mod m (21(16)+10)mod25 346 mod 25 X8 = 21 R8 = 0.84
X8 = 21 X9 = (aX8 +c) mod m (21(21)+10)mod25 451 mod 25 X9 = 1 R9 = 0.04
X9 = 1 X10 = (aX9 +c) mod m (21(1)+10)mod25 136 mod25 X10 = 6 R10 = 0.24
66
GENERATION OF RANDOM VARIABLES
Random variables
A random variable, usually written X, is a variable whose possible values are numerical
outcomes of a random phenomenon.
Example: tossing a coin: we could get heads or tails.
Random variable X
Possible outcome 0 1
Possible events head tail
In short:
X = {0, 1}
There are two types of random variables,
• Discrete random variables
• Continuous random variables
67
Discrete random variables
A discrete random variable is one which may take on only a countable number of distinct values
such as 0,1,2,3,4,........
Discrete random variables are usually (but not necessarily) counts.
If a random variable can take only a finite number of distinct values, then it must be discrete.
Examples of discrete random variables include the number of children in a family, the Friday
night attendance at a cinema, the number of patients in a doctor's surgery, the number of
defective light bulbs in a box of ten.
68
Inverse-transform Technique
• The inverse-transform technique can be used in principle for any distribution.
• Most useful when the CDF F(x) has an inverse F -1(x) which is easy to compute.
• Required steps
1. Compute the CDF of the desired random variable X
2. Set F(X) = R on the range of X
3. Solve the equation F(X) = R for X in terms of R
4. Generate uniform random numbers R1, R2, R3, ... and compute
the desired random variate by Xi = F-1(Ri)
69
1. Generate 15 random variables 𝑋
𝑋 2 5 6 8
𝑝 0.15 0.2 0.37 0.28
Solution:
𝑋 2 5 6 8
𝑝 0.15 0.2 0.37 0.28
CP 0.15 0.35 0.72 1
70
Random number Random Variables
R1 = 0.678 X1 = 6
R2 = 0.71 X2 = 6
R3 = 0.376 X3 = 6
R4 = 0.10 X4 = 2
R5 = 0.75 X5 = 8
R6 = 0.794 X6 = 8
R7 = 0.117 X7 = 2
R8 = 0.694 X8 = 6
R9 = 0.982 X9 = 8
R10 = 0.148 X10 = 2
R11 = 0.965 X11 = 8
R12 = 0.71 X12 = 6
R13 = 0.199 X13 = 5
R14 = 0.824 X14 = 8
R15 = 0.29 X15 = 5
71
2. The statistics of timing taken over a month of arrival of a train in a particular station is as
follows Simulate this problem for 7 days starting from Monday. Random numbers are 0.327,
0.542, 0.197, 0.911, 0.964, 0.177 and 0.762
Days 6 12 7 5
Solutions:
Days(F) 6 12 7 5
72
Hint: 6+12+7+5=30 PROBI= FAV/TOTAL=6/30=0.2
73
GENERATION OF DISCRETE RANDOM VARIABLES
Suppose we want to generate the value of a random variable X having Probability mass function
𝒙𝟏 𝒊𝒇𝑼 ≤ 𝒑𝟏
𝒙𝟐 𝒊𝒇𝒑𝟏 < 𝑼 ≤ 𝒑𝟏 + 𝒑𝟐
𝒙𝟑 𝒊𝒇𝒑𝟏 < 𝑼 ≤ 𝒑𝟏 + 𝒑𝟐 + 𝒑𝟑
.
.
𝑿=
.
.
𝒙𝒊 𝒊𝒇𝒑𝟏 + 𝒑𝟐 +. . . . . . . . 𝒑𝒊−𝟏 < 𝑼 ≤ 𝒑𝟏 + 𝒑𝟐 +. . . . . . . . 𝒑𝒊−𝟏 + 𝒑
.
.
74
Because U is uniformly distributed on (0,1), it follows that for 0<a<b<1
𝑷(𝒂 < 𝑼 ≤ 𝒃) = 𝒃 − 𝒂
Consequently
𝒊−𝟏 𝒊
𝑷 𝒑𝒋 < 𝑼 ≤ 𝒑𝒋 = 𝒑𝒊
𝒋=𝟏 𝒋=𝟏
Which shows that X has the desired probability mass function. This method of generating X
is called the discrete Inverse Transform Method.
75
1. If 𝑋 is a discrete random variables taking integers 1, 5, 10, 15, 20, 25 having a
frequency 2,11,8,21,5,3. Generate 20 values of𝑋.
Given 0.3159 0.8793 0.6117 0.5056 0.1648
Random 0.176 0.1592 0.6844 0.8966 0.5782
Numbers 0.5559 0.5391 0.1145 0.7514 0.7961
0.8296 0.4050 0.3156 0.7123 0.3545
Solution:
𝑋 1 5 10 15 20 25
F 2 11 8 21 5 3
P 2/50=0.04 0.22 0.16 0.42 0.10 0.06
CP 0.04 0.26 0.42 0.84 0.94 1
Hint: 2+11+8+21+5+3=50
76
Random number Random Variables
R1 =0.3159 X1 = 10
R2 = 0.8793 X2 = 20
R3 = 0.6117 X3 = 15
R4 = 0.5056 X4 = 15
R5 = 0.1648 X5 =5
R6 = 0.176 X6 = 5
R7 = 0.1592 X7 = 5
R8 = 0.6844 X8 = 15
R9 = 0.8966 X9 = 20
R10 = 0.5782 X10 = 15
R11 = 0.5559 X11 = 15
R12 = 0.5391 X12 = 15
R13 = 0.1145 X13 = 5
R14 = 0.7514 X14 = 15
R15 = 0.7961 X15 = 15
R16 = 0.8296 X16 =15
R17 =0.4050 X17 =10
R18 =0.3156 X18 =10
R19 =0.7123 X19 =15
R20 =0.3545 X20 =10
Random Variables are
10,20,15,15,5,5,5,15,20,15,15,15,5,15,15,15,10,10,15,10, 77
2 .If 𝑋 is a discrete uniform random variables taking integers 3, 5, 8, 12, 15, 20 uniformly.
Generate 20 values of𝑋
Solution:
𝑋 3 5 8 12 15 20
78
Random number Random Variables
R1 =0.3159 X1 = 5
R2 = 0.8793 X2 = 20
79
Random number Random Variables
R1 =0.3159 X1 = 5
R2 = 0.8793 X2 = 20
R3 = 0.6117 X3 = 12
R4 = 0.5056 X4 = 12
R5 = 0.1648 X5 =3
R6 = 0.176 X6 = 5
R7 = 0.1592 X7 = 3
R8 = 0.6844 X8 = 15
R9 = 0.8966 X9 = 20
R10 = 0.5782 X10 = 12
R11 = 0.5559 X11 = 12
R12 = 0.5391 X12 = 12
R13 = 0.1145 X13 = 3
R14 = 0.7514 X14 = 15
R15 = 0.7961 X15 = 15
R16 = 0.8296 X16 =15
R17 =0.4050 X17 =8
R18 =0.3156 X18 =5
R19 =0.7123 X19 =15
R20 =0.3545 X20 =8
Random Variables are
5,20,12,12,3,5,3,15,20,12,12,12,3,15,15,15,8,5,15,8. 80
UNIFORM RANDOM VARIABLE BETWEEN a AND b
• If 𝑋 is a Discrete uniform random variable between a and b is given by 𝑋 = 𝑎 + (𝑏 − 𝑎 + 1)𝑅
• If 𝑋 is a continuous uniform random variable between a and b is given by 𝑋 = 𝑎 + (𝑏 − 𝑎)𝑅
NOTE: 𝑋 is Flooring X (Greatest integer less than X OR Equal to X.)
EXAMPLES: 3.46 =3, 3.88 =3 and 3.90 =3
81
1.If 𝑋 is a discrete uniform random variable between 4 and 12 then Generate 20 values of 𝑋
82
Random Variables𝑋 =
Random number 4+9R
4 + 9𝑅
R1 = 0.033 4+9(0.033)=4.297 X1 = 4
R2 = 0.066 4.594 X2 = 4
83
Random Variables𝑋 =
Random number 4+9R
4 + 9𝑅
R1 = 0.033 4+9(0.033)=4.297 X1 = 4
R2 = 0.066 4.594 X2 = 4
R3 = 0.399 7.591 X3 = 7
R4 = 0.256 6.304 X4 = 6
R5 = 0.72 10.48 X5 = 10
R6 = 0.894 12.046 X6 = 12
R7 = 0.38 7.42 X7 = 7
R8 = 0.053 4.477 X8 = 4
R9 = 0.662 9.958 X9 = 9
R10 = 0.07 4.63 X10 = 4
R11 = 0.717 10.453 X11 = 10
R12 = 0.969 12.721 X12 = 12
R13 = 0.33 6.97 X13 = 6
R14 = 0.83 11.47 X14 = 11
R15 = 0.397 7.573 X15 = 7
R16 = 0.359 7.231 X16 =7
R17 =0.643 9.787 X17 =9
R18 =0.156 5.404 X18 =5
R19 =0.363 7.267 X19 =7
R20 =0.51 8.59 X20 =8
Random Variables are 4,4,7,610,12,7,4,9,4,4,10,12,6,11,7,7,9,5,7,8
Random Variables are 4 to 12 84
If 𝑋 is a continuous uniform random variable between 3 and 10 then Generate 20 values of 𝑋.
Solution:
Wkt, Discrete Uniform Random integer between a & b is
a=3 and b=10, 𝑋 = 𝑎 + (𝑏 − 𝑎)𝑅
𝑋 = 3 + (10 − 3)𝑅
𝑋 = 3 + (7)𝑅
85
Random Variables𝑋 =
Random number 3+7R
3 + (7)𝑅
R1 = 0.033 3+7(0.033)=3.231 X1 = 3
R2 = 0.062 3.434 X2 = 3
86
Random Variables𝑋 =
Random number 3+7R
3 + (7)𝑅
R1 = 0.033 3+7(0.033)=3.231 X1 = 3
R2 = 0.062 3.434 X2 = 3
R3 = 0.399 5.793 X3 = 5
R4 = 0.256 4.792 X4 = 4
R5 = 0.72 8.04 X5 = 8
R6 = 0.894 9.258 X6 = 9
R7 = 0.38 5.66 X7 = 5
R8 = 0.053 3.371 X8 = 3
R9 = 0.662 7.634 X9 = 7
R10 = 0.07 3.49 X10 = 3
R11 = 0.717 8.619 X11 = 8
R12 = 0.969 9.783 X12 = 9
R13 = 0.33 5.31 X13 = 5
R14 = 0.83 8.81 X14 = 8
R15 = 0.397 5.779 X15 = 5
R16 = 0.359 5.51 X16 =5
R17 =0.643 7.501 X17 =7
R18 =0.156 4.092 X18 =4
R19 =0.363 5.541 X19 =5
R20 =0.51 6.57 X20 =6
Random Variables are 3 TO 10
87
GENERATION OF CONTINUOUS RANDOM VARIABLES BY INVERSE
TRANSFORM METHOD.
If 𝑓(𝑥) is a probability density function of a continuous random variable, then
∞
−∞ 𝑓(𝑥) 𝑑𝑥 = 1
Cumulative density function is given by
𝑥
𝐹(𝑥) = න 𝑓(𝑥) 𝑑𝑥
0
Inverse-transform Technique
88
1.If 𝑓(𝑥) = 𝑘𝑥 5 ; 0 ≤ 𝑥 ≤ 1 is a probability density function of the continuous random variable
X, then find 𝑘and generate six continuous random variables by inverse transform method for the
following random numbers 0.756, 0.012, 0.475, 0.96, 0.121,0.323.
Solution:
Wkt
𝑥
𝐹(𝑥) = 0 𝑓(𝑥) 𝑑𝑥
𝑥
= 0 𝑘𝑥 5 𝑑𝑥
𝑥6 𝑥
=𝑘 )
6 0
𝑘
= 6 𝑥 6 − 06
𝑘𝑥 6
𝐹(𝑥) = IS REQUIRED CDF
6
89
and To find k
∞
−∞ 𝑓(𝑥) 𝑑𝑥 = 1
∞
0 𝑓(𝑥) 𝑑𝑥 = 1
1 ∞
0 𝑓(𝑥) 𝑑𝑥 + 1 𝑓(𝑥) 𝑑𝑥 = 1 R 𝑥 = 𝑅1/6
1
0 𝑘𝑥 5 𝑑𝑥 + 0 = 1 0.756 0.9544
𝑥6 1
0.012 0.4784
𝑘 6 )0 =1
0.475 0.8833
K=6
0.96 0.9932
6𝑥 6
Put k = 6 in 𝐹(𝑥) = 0.121 0.7032
6
𝐹(𝑥) = 𝑥 6 0.323 0.8283
Set 𝐹(𝑥) = 𝑅
𝑥6 = 𝑅
𝑥 = 𝑅1/6
90
Acceptance-Rejection Technique to Generate Random Variable
Motivation:
The majority of c.d.f.’s cannot be inverted efficiently. A-R Samples from a distribution that is “almost” the
one we want, and then Adjusts by “accepting” only a certain proportion of those samples.
Continuous random variables
As we already know, finding an explicit formula for F−1(y) for the cdf of a rv X we wish to generate F (x) = P (X<=
x), is not always possible. Moreover, even if it is, there may be alternative methods for generating a rv distributed as
F that is more efficient than the inverse transform method or other methods we have come across. Here we present a
very clever method known as the acceptance-rejection method.
We start by assuming that the F we wish to simulate from has a probability density function f (x); that is, the
continuous case.
The basic idea is to find an alternative probability distribution G, with density function g(x), from which we already
have an efficient algorithm for generating from (e.g., inverse transform method or whatever), but also such that the
function g(x) is “close” to f (x). In particular, we assume that the ratio f(x)/g(x) is bounded by a constant c > 0; supx
{ f (x)/g(x)}<= c. (And in practice we would want c as close to 1 as possible.)
Here then is the algorithm for generating X distributed as F :
91
Acceptance-Rejection Algorithm for continuous random variables
1. Generate a RV, Y distributed as G.
𝑓(𝑌)
3. If U ≤ 𝑐𝑔(𝑌)
92
Acceptance-Rejection Algorithm for discrete random variables
1. Generate a RV, Y distributed as q(k).
𝑝(𝑌)
3. If U ≤𝑐𝑞(𝑌) then set X = Y; otherwise go back to 1.
93
distributed over [1/4, 1]?
The efficiency: use this method in this particular example, the rejection probability is 1/4 on
the average for each number generated. The number of rejections is a geometrically
distributed random variable with probability of ``success'' being p = 3/4, mean number of
rejections is (1/p - 1) = 4/3 - 1 = 1/3 (i.e. 1/3 waste).
For this reason, the inverse transform (X = 1/4 + (3/4) R) is more efficient method.
94
Example:
Generate a U( 2/3 , 1) RV.
(You would usually do this via inverse transform) Here’s the A-R algorithm:
1. Generate R- U(0, 1).
2. If R>=2/3 , Accept X=R
3. OTHERWISE, Reject and go to Step 1.
Exercise:
• If 𝑓(𝑥) = 𝑘𝑥 7 ; 2 ≤ 𝑥 ≤ 5is a probability density function of the continuous random variable X, then find 𝑘and
generate six continuous random variables by inverse transform method.
(Hint: Use calculator to generate 6 random Number (command : RAN#))
𝑥
Hint: 𝐹(𝑥) = 0 𝑓(𝑥) 𝑑𝑥
𝑥
𝐹(𝑥) = න 𝑓(𝑥) 𝑑𝑥
2
𝑥
𝐹(𝑥) = න 𝑘𝑥 7 𝑑𝑥
2
After simplifying
𝑘(𝑥 8 −256)
𝐹(𝑥) =
8
1/8
X= 390369 ∗ 𝑅 + 256 95
Thank you
Any doubts?
96