Sie sind auf Seite 1von 90

CISY 403 SIMULATION AND MODELLING

KENYA METHODIST UNIVERSITY

FACULTY OF SCIENCES

DEPARTMENT OF COMPUTER INFORMATION SYSTEMS

Course Code: CISY403

Course Title:
Simulation and Modeling

Compiled by: Chao Mbogho, MSc.

Page 1 of 90
CISY 403 SIMULATION AND MODELLING

CISY 403 Simulation and Modeling (3)


Course Purpose:
The course introduces the students to simulation and modeling as the technique of solving
problems by the observation of the performance, over the time, of a dynamic model of the
system.

Course Objectives:
At the end of the course students will be able:
• To analyze computer and communication systems through case studies.
• To demonstrate understanding of system modeling through the competent use of computer
simulation methods in mathematical modeling techniques.

Course Content:
Introduction and basic simulation procedures. Model classification: Monte Carlo simulation,
discrete-event simulation, continuous system simulation, mixed continuous/discrete-event
simulation. Queuing networks: analytical and simulation modeling of queuing systems. Input
and Output Analysis: random numbers, generating and analyzing random numbers, sample
generation, place and execution driven simulation point and internal estimation. Process-
oriented and Parallel simulation.

Teaching Methods:
• Class lectures that involve proper explanation various simulation models.
• Tutorials that entail solving of problems by both students and lecturer.
• Practical sessions in the lab and practical demonstrations.
• Group discussions among the students and active participation in class.
• Regular CATs and assignments that are discussed after grading.

Reference Textbooks:
• Modeling and Simulation: The Computer Science of Illusion
• Raczynski , S.: Modelling and Simulation: The Computer Science of Illusion; John Wiley,
2006.
• Birta, Louis G., Arbez, Gilbert : Modelling and Simulation Exploring Dynamic System Behaviour;
Springer, 2007.

Page 2 of 90
CISY 403 SIMULATION AND MODELLING

• Law and Kelton: Simulation Modeling and Analysis; 3rd Edition, McGraw Hill, 1991.

Teaching Tools:
• Computer installed with a simulator program.

Page 3 of 90
CISY 403 SIMULATION AND MODELLING

List of Contents

Course Outline

Module 1: Introduction

Module 2: Simple Queuing

Module 3: Simple Queuing II

Module 4: Analysis of a Single Server Queue

Module 5: Timeshared Computer Model with SimLib

Module 6: Simple Monte Carlo Simulation with Excel

Module 7: The Central Limit Theorem

Module 8: Conditional Probability

Module 9: Probability Inequalities, Laws of Large Numbers.

Module 10: The t Distribution

Module 11: Random Number Tests

Module 12: Density Distributions

Module 13: Examples and Result Treatments.

Special Instructions:

These notes are brief discussions of the contents of the subjects. You shall be receiving a

weekly update on comprehensive material as the trimester progresses and additional

questions for your practice.

Page 4 of 90
CISY 403 SIMULATION AND MODELLING

Page 5 of 90
CISY 403 SIMULATION AND MODELLING

Page 6 of 90
CISY 403 SIMULATION AND MODELLING

Module 2 – Simple Queueing

Basic Concept

Time

Processing

Discrete Event (DE) Simulation


• Fixed-increment time advance
– Simulation tests events for occurrence during
each time increment
– Multiple occurrences processed as if at end of
time increment
• Next-event time advance
– Calculate all future time values for events
– Update system state at each event

Page 7 of 90
CISY 403 SIMULATION AND MODELLING

Fixed Time Increment

Time
e1 e2 e3 e4
0 ∆t 2∆t 3∆t 4∆t

Example Usage: Economic System Modeling/Reports.

Next Event Time Advance


e1 e2 e3 e4 e5

Time
0 t1 t2 c1 t3 c2

A1 A2 A3

S1 S2
ti = Arrival
ci = Completion D1
Di = Delay

Page 8 of 90
CISY 403 SIMULATION AND MODELLING

Next Event Time Advance


ti = time of arrival of ith item (customer), t0 = 0
Ai = ti – ti-1 = interval time between (i-1)st and ith arrivals of items
(customers)
Si = time that a server actually spends serving ith event (customer)
Di = delay in queue of ith event (customer)
ci = ti + Di + Si = time that ith event (customer) completes service
and departs
ei = time of occurrence of ith event of any type (ith value the
simulation clock takes on, excluding the value e0 = 0)

Variability
• Each defined quantity will generally be a
random variable

F(x) = P(X ≤ x) for -∞ < x < +∞

• A and S each have a distribution F(A), F(S)

Components of a DE Model
• System State – Collection of state
variables
• Simulation Clock – Current value of
simulated time, represents ‘wall’ clock.
• Event list – list of future time event values
• Statistical Counters – accumulators of
simulation results
• Initialization Routine – start up state
definition for time zero (t0)

Page 9 of 90
CISY 403 SIMULATION AND MODELLING

More DE Model Items


• Timing Routine – A subprogram
determining next event list and event times
• Event Routine – Updates system state for
each event type
• Library Routines – random event
generators (dist. functions)
• Report Generator – final performance
report
• Main Program – overall glue

Performance Measures
1. Average delay
2. Expected average queue length
3. Expected utilization

Next Event Time Advance


e1 e2 e3 e4 e5

Time
0 t1 t2 c1 t3 c2

A1 A2 A3

S1 S2
ti = Arrival
ci = Completion D1
Di = Delay

Page 10 of 90
CISY 403 SIMULATION AND MODELLING

Performance Measures
1. Average customer delay (customer concern)

∑D i
dˆ ( n ) = i =1
= D (n )
n

Performance Measures
2. Expected Average Queue Length

• Let qn = average number of customers not


being served over the duration n
• Let Q(t) = number in queue at time t
• Let T(n) = time required for n delays
• Let pi = expected proportion of time that
Q(t) =i

(pi = proportion of time for each i)

Performance Measures
• Observed average • Expected (estimated)
queue length average queue length

∞ ∞

∑ ip
i =0
i ∑ ipˆ
i =0
i
q( n ) = qˆ (n ) =
n n

pi = proportion of time for each i

Page 11 of 90
CISY 403 SIMULATION AND MODELLING

Q(t)=i
Time Dependent Queue
Q(t)
3 Arrivals
Departures

Time →
0
0 1 2 3 4 5 6 7 8 9 10

-1
0.4

1.6

2.1

3.8
4.0

5.6
5.8

7.2
[T(6)]
2.4

3.1
3.3

4.9

8.6
-2 (6 delays)

Performance Measures
• Recast average queue length
• Let Ti = total time that length is I

• Then: T ( n ) = T0 + T1 + T2 + ...

• And: pˆ = Ti / T ( n )
∑ iT
i =0
i
qˆ ( n ) =
T (n )

Page 12 of 90
CISY 403 SIMULATION AND MODELLING

Computing qˆ(n)
• From the example time graph:
– First compute the Ti’s (pick from graph):
T0 = (1.6 − 0.0) + (4.0 − 3.1) + (5.6 − 4.9) = 3.2
T1 = (2.1−1.6) + (3.1− 2.4) + 4.9 − 4.0) + 5.8 − 5.6) = 2.3
T2 = (2.4 − 2.1) + (7.2 − 5.8) = 1.7
T3 = (8.6 − 7.2) = 1.4
– Then the sum:

∑iT = (0 × 3.2) + (1× 2.3) + (2 ×1.7) + (3×1.4) = 9.9


i=0
i

– Finally: qˆ6 = 9.9 / 8.6 = 1.15

Representing qˆ ( n ) Continuously
• Note that from the graph we can consider out
summation as an area under the curve Q(t).
We can then write: ∞ T (n)
∑ iTi = ∫
i =0
0
Q (t )dt
• And our estimator becomes:
T (n)

qˆ (n ) =

0
Q (t )dt
T (n)

Page 13 of 90
CISY 403 SIMULATION AND MODELLING

Performance Measures
3. Expected System Utilization
– The expected amount of time over T(n) in which
the server is busy.

• Define utilization fraction as:


u (n ) | 0 ≤ u( n ) ≤ 1
• Estimated (observed) value is:

uˆ ( n ) | 0 ≤ uˆ (n ) ≤ 1

Computing Utilization Metric


• Define a ‘busy’ function:
B(t) = 1 if the server is busy at time t
0 if the server is idle at time t
• uˆ ( n ) can be expressed as a proportion of
time B(t)=1

(3.3 − 0.4) + (8.6 − 3.8) 7.7


uˆ ( n ) = = = 0.90
8 .6 8 .6

Page 14 of 90
CISY 403 SIMULATION AND MODELLING

Distributing Data
• Any continuous function can be used
– Needs to be contained within [0,1]
– Should resemble real world observations

• Example: Exponential
1
– β = mean
f ( x) = e− x / β
– x = random value [0,1] β

General Exponential Distribution

f(x)

Interval (x)

Use of Exponential
• Insure that output is in [0,1]
f (x ) = 1 if the server is busy at time t
0 if the server is idle at time t

Page 15 of 90
CISY 403 SIMULATION AND MODELLING

Module 3
Simple Queueing II

Basic Concept

Time

Processing

Simple Queuing Snapshots


Shows status at completion of
event processing

Based on event time

Status Items 2

Customers 0.4

Page 16 of 90
CISY 403 SIMULATION AND MODELLING

Q(t)=i
Time Dependent Queue
Q(t)
3 Arrivals
Departures

Time →
0
0 1 2 3 4 5 6 7 8 9 10

-1
0.4

1.6

2.1

3.8
4.0

5.6
5.8

7.2
[T(6)]
2.4

3.1
3.3

4.9

8.6
-2 (6 delays)

Simple Queuing Snapshots


Time = 0.
System State A 0.4
0.0
D
Clock Event
0 0 0 List

Last Statistical Counters


Status Queue
Event 0 0 0 0
Time
Number Total Q(t) B(t)
Arrivals
Delayed Delay Area Area
System Computer Representation

Initialization

Page 17 of 90
CISY 403 SIMULATION AND MODELLING

Simple Queuing Snapshots


Time = 0.4
System State A 1.6
0.4
D 2.4
Clock Event
1 0 0.4 List
0.4
Last Statistical Counters
Status Queue
Event 1 0 0 0
Time
Number Total Q(t) B(t)
Arrivals
Delayed Delay Area Area
System Computer Representation

Arrival 0.4

Simple Queuing Snapshots


Time = 1.6
System State A 2.1
1.6
D 2.4
Clock Event
1.6
1 1 1.6 List
0.4
Last Statistical Counters
Status Queue
Event 1 0 0 1.2
1.6
Time
Number Total Q(t) B(t)
Arrivals
Delayed Delay Area Area
System Computer Representation

Arrival 1.6

Simple Queuing Snapshots


Time = 2.1
System State A 3.8
2.1
D 2.4
Clock Event
0.4 1.6
1 2 2.1 List
2.1
Last Statistical Counters
Status Queue
1.6 Event 1 0 0.5 1.7
Time
2.1 Number Total Q(t) B(t)
Arrivals
Delayed Delay Area Area
System Computer Representation

Arrival 2.1

Page 18 of 90
CISY 403 SIMULATION AND MODELLING

Simple Queuing Snapshots


Time = 2.4
System State A 3.8
2.4
D 3.1
Clock Event
1.6 2.1
1 1 2.4 List

Last Statistical Counters


Status Queue
Event 2 0.8 1.1 2.0
2.1 Time
Number Total Q(t) B(t)
Arrivals
Delayed Delay Area Area
System Computer Representation

Departure 2.4

Simple Queuing Snapshots


Time = 8.6
System State A 9.1
8.6
D 9.2
Clock Event
5.6 5.8
1 2 8.6 List
7.2
Last Statistical Counters
Status Queue
5.8 Event 6 5.7 9.9 7.7
Time
7.2 Number Total Q(t) B(t)
Arrivals
Delayed Delay Area Area
System Computer Representation

Departure 8.6

Modeling
• Single server example has one input stream
• Interarrival times are randomly distributed
– Can be depicted by exponential with a mean β
– Applicable to both arrivals and service

• A single server with exponential times is


called an M/M/1 queue

Page 19 of 90
CISY 403 SIMULATION AND MODELLING

Distributing Data
• Any continuous function can be used
– Needs to be contained within [0,1]
– Should resemble real world observations

• Example: Exponential
1
– β = mean
f ( x) = e−x / β
– x = random value [0,1] β

General Exponential Distribution

f(x)

Interval (x)

Use of Exponential
• Insure that output is in [0,1]
f (x ) = 1 if 0 <= x <= 1
0 otherwise

1 if the server is busy at time t


f (x ) =
0 if the server is idle at time t

Generate random variate U(0,1)

Page 20 of 90
CISY 403 SIMULATION AND MODELLING

Use of Exponential
• Generate random variate U(0,1)
• Invert the exponential distribution f (x )

• Obtain the form


-β lnU

• Used in example 1.4.6 of Law/Kelton

Events and Variables


• Convention – use state diagram graphs
– Event-graph
– Directed arcs
– Nodes

Arrival Departure

Graph Event Simplifications


• A few informal ‘rules’
– Eliminate unnecessary events:
• Depict zero time operations with a thin directive
• Can be eliminated because no delay occurs
– Initialization must occur for nodes without input
Weak
Strong Connection
Connection
Enter
Arrival Departure
Service

End
Simulation

Page 21 of 90
CISY 403 SIMULATION AND MODELLING

An Inventory System
• Variables of concern
– Amount on hand (inventory)
– Cost of inventory (holding cost)
• Insurance, storage rental , maintenance, taxes
– Cost of ordering (process, shipping, etc.)
– Shortage costs (loss of sales)
• Time Cycles
– Weekly, monthly, annually?

An Inventory System
• I(t) = Inventory level at time t
• I+(t) = Maximum inventory == max{I(t),0}
• I-(t) = Backlog (on order) == max{-I(t),0}
• s = minimum threshold of inventory for ordering
n

∫I
+
( t ) dt
+
I = 0
n

S
In v e n to r y M o d e l
I( t )

I+ ( t )

I- ( t )
s

0 10 20 30

P la c e R e c e iv e P la c e

Page 22 of 90
CISY 403 SIMULATION AND MODELLING

Inventory State Diagram

Order
Arrival Demand Evaluate

End
Simulation

Inventory Variables
• Inter-demand time – random exponential
• Demand size – discrete random
– Select weighted value (range) within U{0,1)}
• Delivery lags – Uniform = {a+U(b-a)}

Page 23 of 90
CISY 403 SIMULATION AND MODELLING

Module 4
Analysis of a
Single Server Queue

Some Definitions
New and Review
• IID - Independent and Identically Distributed
– Exponential random distribution – arrivals, departures
• GI – General Independent – arrivals
• G - General – service
• M - Markovian, memoryless of previous events,
exponential distribution
• Ek – k-Erlang – summation of exponential
distributions
• D – Deterministic – fixed times

System Notation
• General model notation
• <Arrival type>/<Service type>/<#servers>
– GI/G/s – general queue
– M/M/1 – single server queue with exponential
arrival and service times.

• For more than one server, s>1


– Therefore, M/M/s

Page 24 of 90
CISY 403 SIMULATION AND MODELLING

An Exception Interlude
• Assume:
• 1: arrivals and services are performed at
a rate per unit time of a and s
– Means are 1/a and 1/s
– Ratio of rates is u = a/s or utilization factor
• 2: we have a steady state of probability
P(n) in which there are n entities in the
system (queues and servers)
– This is actually the limit of Pn(t) as t→∞

Basic rate argument


• If there are k people in the system at time t,
denote this state by Sk(t)
– Call this “state k”
• Over any period of time, # of entries to state k
differs from # of departures from state k by at
most 1
– Why? A departure must separate each pair of
entries, and conversely
• So rates of entry and departure approach
equality as t→∞

Analysis by System State


• Start with states 0 (empty) and 1
– System can enter state 0 only from 1
• Rate at which this happens is sP1
– System can leave state 0 only to 1
• Rate at which this happens is aP0
• At steady state:
– Balance requires sP1 = aP0
• Thus P1 = (a/s)P0 = uP0

Page 25 of 90
CISY 403 SIMULATION AND MODELLING

Convert to General State


• For n = 1,…,k suppose Pn = un P0
– We enter Sk from Sk-1 at rate aPk-1
– We also enter Sk from Sk+1 at rate sPk+1
– We leave Sk to Sk-1 at rate sPk
– We leave Sk to Sk+1 at rate aPk
– Balance requires aPk-1+ sPk+1 =(a+s)Pk
• Then Pk+1 =(1+u)Pk - uPk-1 = uk+1 P0
– Now this holds for all k by induction

Graphically
S = State
s = service rate Arrivals
a = arrival rate
P = probability
k = sequence aPk-1 aPk

Sk-1 Sk Sk+1

sPk sPk+1 aPk-1+ sPk+1 =(a+s)Pk

Service Completions

Computing probabilities
• We still don’t know what the Pk are
– But we know they have to sum to 1!
– Assume |u| < 1
• Then 1 = P0 + P1 + …
= P0 + uP0 + u2 P0 + …
= P0 (1 + u + u2 + … )
= P0 /(1 – u)
• This means that P0 = 1 – u

Page 26 of 90
CISY 403 SIMULATION AND MODELLING

Computing probabilities (2)


• But we know Pn = un P0 for all n
– So then Pn = un (1 – u) for n = 0, 1, 2, …
– So the Pn have the geometric distribution
• From this we can find a lot of interesting
information, e.g.
– Expected number in system, or in queue
– Expected time in system, or in queue

Expected number in system


• We need to sum n Pn for n = 0, 1, …
– This is the sum of n un (1 – u), say L
– A trick: consider sum of n un-1, n = 0, …
• This is the derivative of the sum of un
• But the sum of un is 1/(1-u)
• So this derivative must be 1/(1-u)2
– Then L = [1/(1-u)2 ]u(1-u) = u/(1-u)
• This is the expected number in system

Little’s Law
• To get other quantities, use very important
property of many queuing systems: L =
aW
– L = expected number in system
– W = expected waiting time
– a = arrival rate (usually λ)
• This works for system, queue, etc.

Page 27 of 90
CISY 403 SIMULATION AND MODELLING

Expected waiting time


• In system
– W = L/a = (1/a)[u/(1-u)] = 1/(s-a)
– To see this, recall u = a/s
• In queue
– WQ = W – mean service time
= 1/(s-a) – (1/s)
= (1/s)[u/(1-u)]

Expected number in queue


• A mistake to watch out for
– Suppose one reasons as follows
• We know E(number in system) = u/(1-u)
• System consists of queue + person in service
• So E(number in queue) = u/(1-u) – 1
– This is obviously wrong (e.g. if u is small)
• What’s wrong with the reasoning?
– Let’s see how to do it correctly (next slide)

Expected number in queue


• LQ = a WQ (Little’s Law again)
= a (1/s)[u/(1-u)]
= u2/(1-u)
• Note the 1-u in denominator of these
measures
– What do you expect would happen if a→s?
– Let’s do an experiment!

Page 28 of 90
CISY 403 SIMULATION AND MODELLING

Try running our simulation


• Set mean interarrival time very close to
mean service time
– 1/a = 3.001, 1/s = 3
– Then u = (1/s)/(1/a) = .9997
– So LQ = u2/(1-u) ≈ 2,999
• We don’t get that in our run
– We’d need very long run to see large peaks
– But number in queue is clearly large

An important lesson
• Utilization is very important
– You might think everything is OK as long as
it’s < 1
• Not so: if it’s near 1 then things blow up
– Important to keep it not only < 1 but
comfortably below 1
• This kind of analysis applies also to more
general queues

Other useful information


• What’s the probability that there are at
least k customers in the system?
– Sum Pn = un (1 – u) for n = k, k+1, …
– This is uk (1 – u)(1 + u + u2 + … ) = uk
• Notice what happens as u → 1
– For u = .99, probability of about 37% that
there are at least 100 customers in system!
• For u = .999 the probability is > 90%!

Page 29 of 90
CISY 403 SIMULATION AND MODELLING

Module 5
Timeshared Computer Model
in simlib

What we’ll cover today


• Timeshared computer model in simlib
– Many terminals sending jobs to mainframe
• We’ll see a new service pattern
– Round-robin, not FIFO
– Long jobs get served in increments
• After each increment, go to end of queue
• Question: how many terminals can you put
on with average response < 30 sec?

Overview of system
• Terminal operator ‘thinks’
– Time exp, mean 25 (seconds)
– Then sends job w/svc time exp, mean 0.8
• Mainframe has fixed svc quantum q=.1
– If remaining svc time s≤q, process for s + (τ =
.015) (swap), send job to terminal
– If s > q, process for q+τ and send to end of
the queue

Page 30 of 90
CISY 403 SIMULATION AND MODELLING

Response time R
• This is (finish of job at mainframe) – (time
job left terminal)
– Set number of terminals = 10, 20, …, 80
– (Each case) Observe 1,000 response times
– Get average response time, server utilization,
number of jobs in queue
• Initially all terminals are in think state
• # of terminals for average R < 30?

What are the events?


• Job arrives at mainframe (type 1)
• Job ends period of processing (type 2)
– Not necessarily finished at mainframe
• Simulation ends (type 3)

(n of
these)
End processing End
Arrival simulation
period at CPU

Detail of event scheduling


• Schedule an arrival from each terminal
• Arrival can schedule end of CPU run
– If the CPU is empty
• End CPU run can schedule any of
– Arrival (if job is going back to terminal)
– End CPU run (via non-event function
start_CPU_run)
– Immediate end of simulation (enough jobs)

Page 31 of 90
CISY 403 SIMULATION AND MODELLING

What are the lists/attributes?


• The queue (list 1)
– Arrival time (1), remaining service time (2)
• The server (CPU) (list 2)
– Arrival time of job at mainframe (1)
• Need this to get (eventually) the response time
– Svc time left after this svc (may be <0) (2)
• The event list (list 25)
– (Standard) Event time (1) & type (2)

Streams and statistics


• Two random variates here
– Think time at terminal (stream 1)
– Service time of job (stream 2)
• Use sampst for response time
– So we need a variable
• Use filest for queue length, server util.
– No variables needed

Definitions

/* External definitions for time-shared computer model. */

#include "simlib.h" /* Required for use of simlib.c. */

#define EVENT_ARRIVAL 1 /* Event type for arrival of job to CPU. */


#define EVENT_END_CPU_RUN 2 /* Event type for end of a CPU run. */
#define EVENT_END_SIMULATION 3 /* Event type for end of the simulation.
*/
#define LIST_QUEUE 1 /* List number for CPU queue. */
#define LIST_CPU 2 /* List number for CPU. */
#define SAMPST_RESPONSE_TIMES 1 /* sampst variable for response
times. */
#define STREAM_THINK 1 /* Random-number stream for think times. */
#define STREAM_SERVICE 2 /* Random-number stream for service
times. */

Page 32 of 90
CISY 403 SIMULATION AND MODELLING

Variables and functions


/* Declare non-simlib global variables. */

int min_terms, max_terms, incr_terms, num_terms, num_responses,


num_responses_required, term;
float mean_think, mean_service, quantum, swap;
FILE *infile, *outfile;

/* Declare non-simlib functions. */

void arrive(void);
void start_CPU_run(void); These are functions that
void end_CPU_run(void);
void report(void);
you will have to write to
run the model (also main)

Main function
• First some housekeeping
– Open input/output files
– Read parameters for the simulation
– Print header for the output

/* Run the simulation varying the number of


terminals. */ Key line
for (num_terms = min_terms; num_terms <=
max_terms; num_terms += incr_terms) {
/* Initialize simlib */
init_simlib();
… (further initialization) …

Main function (2)


/* Schedule the first arrival to the CPU from each terminal. */
for (term = 1; term <= num_terms; ++term)
event_schedule(expon(mean_think, STREAM_THINK),
EVENT_ARRIVAL);

Page 33 of 90
CISY 403 SIMULATION AND MODELLING

Main function (3)


/* Run the simulation until it terminates after an end-simulation event
(type EVENT_END_SIMULATION) occurs. */
do {
/* Determine the next event. */
timing();
/* Invoke the appropriate event function. */
switch (next_event_type) {
case EVENT_ARRIVAL:
arrive();
break;
case EVENT_END_CPU_RUN:
end_CPU_run();
break;
case EVENT_END_SIMULATION:
report();
break;
}

Main function (4)


/* If the event just executed was not the end-simulation event (type
EVENT_END_SIMULATION), continue simulating. Otherwise, end the
simulation. */

} while (next_event_type != EVENT_END_SIMULATION);


}

fclose(infile);
fclose(outfile);
This is a (rather unusual) use of
do/while instead of while/break.
return 0; Also, note that at this point we have
no EVENT_END_SIMULATION
scheduled.

Arrival

void arrive(void) /* Event function for arrival of job at CPU after think time. */
{
/* Place the arriving job at the end of the CPU queue.
Note that the following attributes are stored for each job record:
1. Time of arrival to the computer.
2. The (remaining) CPU service time required (here equal to the
total service time since the job is just arriving). */
transfer[1] = sim_time;
transfer[2] = expon(mean_service, STREAM_SERVICE);
list_file(LAST, LIST_QUEUE);

/* If the CPU is idle, start a CPU run. */


if (list_size[LIST_CPU] == 0)
start_CPU_run();
}

Page 34 of 90
CISY 403 SIMULATION AND MODELLING

Beginning a CPU run

void start_CPU_run(void) /* Non-event function to start a CPU run of a job. */


{
float run_time;
/* Remove the first job from the queue. */
list_remove(FIRST, LIST_QUEUE);
/* Determine the CPU time for this pass, including the swap time. */
if (quantum < transfer[2])
run_time = quantum + swap;
else
run_time = transfer[2] + swap;
/* Decrement remaining CPU time by a full quantum. (If less than a full quantum is
needed, this attribute becomes negative. This indicates that the job, after exiting the
CPU for the current pass, will be done and is to be sent back to its terminal.) */
transfer[2] -= quantum;
/* Place the job into the CPU. */
list_file(FIRST, LIST_CPU);
/* Schedule the end of the CPU run. */
event_schedule(sim_time + run_time, EVENT_END_CPU_RUN);
}

Ending a CPU run (1)


void end_CPU_run(void) /* Event function to end a CPU run of a job. */
{
/* Remove the job from the CPU. */
list_remove(FIRST, LIST_CPU);

/* Check to see whether this job requires more CPU time. */


if (transfer[2] > 0.0) {

/* This job requires more CPU time, so place it at the end of the queue
and start the first job in the queue. */

list_file(LAST, LIST_QUEUE);
start_CPU_run();
}

Ending a CPU run (2)

else {
/* This job is finished, so collect response-time statistics and send it back
to its terminal, i.e., schedule another arrival from the same terminal. */
sampst(sim_time - transfer[1], SAMPST_RESPONSE_TIMES);
event_schedule(sim_time + expon(mean_think, STREAM_THINK),
EVENT_ARRIVAL);

/* Increment the number of completed jobs. */


++num_responses;

/* Check to see whether enough jobs are done. */


if (num_responses >= num_responses_required)

/* Enough jobs are done, so schedule the end of the simulation


immediately (forcing it to the head of the event list). */
event_schedule(sim_time, EVENT_END_SIMULATION); Aha!

Slide 20

Page 35 of 90
CISY 403 SIMULATION AND MODELLING

Output
void report(void) /* Report generator function. */
{
/* Get and write out estimates of desired measures of
performance. */

fprintf(outfile, "\n\n%5d%16.3f%16.3f%16.3f",
num_terms,
sampst(0.0, -SAMPST_RESPONSE_TIMES),
filest(LIST_QUEUE), filest(LIST_CPU));
}

Comments
• We never identify the terminals
– When a job ends its run, it just vanishes
– It also schedules another arrival
• The point here is that the mainframe
doesn’t care which terminal a job comes
from
– If it did, we’d have to identify the terminal with
the job, e.g. with an attribute

Page 36 of 90
CISY 403 SIMULATION AND MODELLING

Main points today


• New service pattern
– Round-robin, not FIFO
– Long jobs get done in pieces
– Enforced by decision-making at time job
enters service
• Uses of programming flexibility
– Forcing end-of-simulation event
– Deciding whether job is done or not

Coming up next
• Multiteller bank with jockeying
– Customers at ends of queues can ‘jockey’ to
ends of other queues if shorter
• Illustrates a new use of lists
– Moving customers from one list to another
• Also illustrates slightly more complex use
of event list

Page 37 of 90
CISY 403 SIMULATION AND MODELLING

Module 6

Simple Monte Carlo Simulations with


MS Excel

What we’ll do today


 Really easy simulations
 Monte Carlo (time-sequencing not critical)
 Several applications
 How to use Excel to do these
 There’s some technique involved
 Well worth learning

Review: generating samples


 Let F be a DF that is increasing
 Define a random variable X by X = F-1(U)
 Then P{X ≤ x} = P{F-1(U) ≤ x}
= P{U ≤ F(x)} = F(x)
 So this X has distribution function F
 This gives us our samples of X

Page 38 of 90
CISY 403 SIMULATION AND MODELLING

Generating samples (2)


 Excel has a generator for U(0,1) in the
function RAND()
 Let U be such a sample
 Invert the distribution function
 Can be done easily for some common distributions
 This gives a sample X
 Now use that sample for your simulation

Simple Monte Carlo with Excel


 Very useful for quick static simulations
 Example: You’re considering building a
factory to produce fashionable widgets
 Cost is $1 MM (million); return is $400 K
(thousand) per year as long as fad lasts
 Interest rate is 15% before tax

 Fad will last 2-5 years

 What does NPV look like?(net present value)

Review: continuous cash flow


 Suppose money is flowing at rate of A per
period, compounded continuously at interest
rate r
 NPV factor for time t is e-rt
 NPV of total over interval [0,T] is then
T
∫e
−rt
( Adt) = ( A / r)(1− e−rT )
0

Page 39 of 90
CISY 403 SIMULATION AND MODELLING

Using this to get NPV


 Suppose we knew the length of the interval
 Return flows uniformly in this interval at rate of
$400K per period
 So NPV (in millions) is
–1 + (.4/.15)(1-e-(.15)T) (standard discounted cash evaluation)
 The problem is that we don’t know actual T
 There’s a common (and bad) fix

Recall conditions
 Fad will last 2-5 years. Average = 3.5
 Interest rate on loan is 15% (0.15)
 Loan is 1 million
 Return is 0.4 million per year
 NPV = Net Present Value (what is process
worth at a given time)

How not to think about this


 What not to do:
 Replace uncertain duration by its average of 3.5
years
 Do a standard discounted-cash flow analysis for
15%, 3.5 years (in MM):
-1.0 + (0.4/.15)[1-e-(.15)(3.5)]= 0.089
 “Looks like NPV is about 90K. Let’s do it.”
 What’s wrong with this?

Page 40 of 90
CISY 403 SIMULATION AND MODELLING

Let’s simulate
 No time sequence: not a DEDS
 This is just a Monte Carlo simulation
 Excel is very good for this application
 See “Uniform” tab in spreadsheet
 Start with uniform duration between 2 and 5 years
 Duration = U(2,5) = 2 + 3*RAND()
 Calculate NPV as shown on previous slide
 For this application, continuous cash flow works best

10

What do we find?
 35-40% chance of losing money!
 This is fairly risky; maybe think again
 Sample mean NPV is consistently below
NPV of the mean duration. Why?
 The NPV function is concave
 Using f[average argument] consistently
overestimates average f[argument]
 See graph on next slide

11

Why NPV(3.5) > average NPV


NPV at known duration

0.800
0.600
0.400
0.200
NPV in millions

-
(0.200) $- 1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6

(0.400)
(0.600)
(0.800)
(1.000)
(1.200)
Years

12

Page 41 of 90
CISY 403 SIMULATION AND MODELLING

Maybe U(2,5) isn’t realistic


 We might have a pretty good idea of the
“most likely” duration
 In that case we could use the triangular
distribution
 This has support (part of real line where the
density is > 0) on a finite interval
 Just like the uniform
 But density goes up, then down again

13

Triangular distribution
 Support = [a,b]
 Mode (value with largest density) = m
 Height at m must then be h = 2/(b-a)
 This makes area under density = 1
Density function f

a m b

14

Distribution function
 For triangular distribution T(a, m, b):
 Let k = (m-a)/(b-a)
 If x∈[a, m] then F(x) = k[(x-a)/(m-a)]2
 If x∈[m, b] then
F(x) = 1 - (1-k)[(b-x)/(b-m)]2
 Why? Calculus (integrate the density)
 To generate T(a, m, b), invert this

15

Page 42 of 90
CISY 403 SIMULATION AND MODELLING

Generating T(a, m, b) variates


 Generate sample u from U(0,1)
 If u ∈ [0, k], x = a + (m-a)(u/k)1/2
 If u ∈ [k, 1], x = b - (b-m)[(1-u)/(1-k)]1/2
 We can do this in Excel without coding
 Use IF function: IF(proposition,T,F)
 ‘proposition’ true: formula = T
 ‘proposition’ false: formula = F

16

Setting up the simulation


 Easy with Edit > Move or Copy Sheet
 Now results look different
 See “Triangular 100” tab
 Notice what happens when we change the mode
 But the numbers still jump around a lot
 Can’t we calm them down?
 Yes, by doing more replications

17

Increase replications to 200


 See “Triangular 200” tab
 There’s less variability in distribution of
outcomes
 We’ll see why later, in more generality
 Notice that we really need the distribution
 We’re going to experience one replication!
 So we need to judge risk, not just average

18

Page 43 of 90
CISY 403 SIMULATION AND MODELLING

What did we learn from this?


 Don’t replace variable quantities by their
means and do a deterministic calculation
 You can miss very important things
 Excel is easy and quick for static (Monte
Carlo) simulations
 Excellent graphics, too
 But it doesn’t work well for DEDS

19

What we saw today


 Quick review of random variables
 Using U(0,1) RV to generate others
 Simple Monte Carlo simulations
 Use Excel’s RAND() function to get U(0,1)
variates, T(a,m,b) variates, others
 We can use the spreadsheet to do analysis,
present graphics

20

Next time
 Back to DEDS
 Walk-through of single-server queue
simulation
 Contents of registers
 How and when things get updated
 Event graphs
 Some time for questions, if you want it

21

Page 44 of 90
CISY 403 SIMULATION AND MODELLING

Module 7
Simulation Software

Languages –
General vs. Simulation
• General Purpose – Common coding languages such as
Pascal, Fortran, C++, etc. (The basic algorithmic
languages)
– Require design from ground up
– Require software engineering concepts
– Much more flexible to fit needs
– Cheaper tools, but likely larger project cost
– Efficient
• Simulation Languages provide
– Natural Framework
– Prepared basic features
– Better error detection
– Quicker setup and revision

Simulation Questions
• What are the events?
• Where’s the randomness?
• What are the lists and attributes?
• What statistics do we need?
• What variables do we need to use?
• Are there any special features that we
need to take account of?

Page 45 of 90
CISY 403 SIMULATION AND MODELLING

Ways to describe simulations


• Event scheduling (e.g., simlib)
– Ask what are the events
– Then build routines to handle each of them
– In such routines, no simulated time passes
• Process description (e.g. Extend, ProModel, …)
– Describe what happens to entities over simulated
time
– Use these descriptions to build event routines (behind
the scenes)

Key transformation
• Both approaches end in the same place
– Event list with entries processed in time
sequence; other lists such as queues
• The main difference
– Event scheduling: for each event type, ask
what happens to all kinds of entities
– Process description: for each entity, just
describe what happens to it
• Software transforms descriptions to interactions

Modeling elements
• Entities
– Job (shop), customer (bank), …
• Attributes
– Type (shop), priority class (fin svcs), …
• Resources
– Broker (fin svcs), machine (shop), …
• Queues
• Sources of randomness (usually)

Page 46 of 90
CISY 403 SIMULATION AND MODELLING

Simulation software
• Most popular simulation packages now have
graphical user interfaces (GUI)
– Many ‘housekeeping’ operations hidden from user
• Great advantage in hiding complexity
– Classic example: Excel < MATLAB < C
• But you lose a lot, too
– Simple logic is tough in Excel (VBA!)
– MATLAB is much slower than C

A compromise
• Good simulation packages tend to be
compromises
– Easy enough to use so that people can do
modeling without technical simulation
knowledge
– But with enough flexibility to handle a range of
models
• Danger in modeling without knowledge!

Data handling
• For some applications we need quite a lot
of data
– Example: tables of attribute values for entities
in simulation
• Very desirable to have direct input/output
capability for data
– Not just ease, but avoidance of error
• Also needed for interface w/other apps

Page 47 of 90
CISY 403 SIMULATION AND MODELLING

Comparison of product types


• General purpose packages
– Should be able to simulate a wide variety of
systems
– Extend, GPSS/H, Arena, MODSIM III, etc.
• Packages oriented to particular areas
– AutoMod, ProModel, many others
• Miniature version of tradeoff here also
– Flexibility vs. specialized convenience

Extend screen (Pharmacy)

Page 48 of 90
CISY 403 SIMULATION AND MODELLING

Object-oriented simulation
• Idea: write simulation in ‘blocks’ or ‘pieces’
that fit together in structured ways
– Then you can re-use these blocks in other
simulations without rewriting them
– You can also modify the same simulation
more easily, with less chance of error
• Object-oriented idea originated in SIMULA
– Tutorial at
http://www.informs-cs.org/wsc98papers/018.PDF

Object orientation (blocks)


• Each object has
– State descriptor (data)
– Methods that perform actions
• No object can change another’s state
– Only observe it and/or request changes
• ‘Child’ objects inherit parent’s
characteristics
– These can then be changed if desired

Why would we care?


• Severe organizational problems in
– Lateral (spatial) dimension
– Vertical (temporal) dimension
• Spatial dimension
– Lots of modelers working on pieces of one big
problem
– The code has to fit together and work
– Very difficult if complex interconnections

Page 49 of 90
CISY 403 SIMULATION AND MODELLING

Temporal dimension
• This is even more difficult
– Code maintained over a long period of time by
many different modelers
– Often spatial dimension also large (DOD)
– People quit, die, retire
• How do you keep institutional memory?
– What does this code do? With what data?
• Example of combat simulations

Exhibit: Agency X
• Military modeling
• Has existed for > 30 years
• Maintains some key models used in wide
range of studies
• Key elements
– Written in FORTRAN in 60s and 70s
– For practical purposes, undocumented
• To stop this: JWARS, JSIMS
– Note: language chaos also stimulated ADA

Joint Warfare System (JWARS)


• Simulation of joint theater warfare
• Designed to help with
– Force modeling (effectiveness, tradeoff
studies)
– Acquisition
– Strategy and tactics (for concept and doctrine
development)
• Pieces use object-oriented design
• DOD has had a lot of difficulty with this

Page 50 of 90
CISY 403 SIMULATION AND MODELLING

Jt Simulation System (JSIMS)


• Distributed constructive simulation
– Create Joint Synthetic Battlespace
• Pieces use object-oriented design
– Uses DOD High Level Architecture (HLA)
– Protocol for ensuring interoperability
• For more info on DOD simulations see
http://www.dmso.mil

Session Summary
• Brief review of simlib models
• Start looking at simulation software
– General classification
– Comparison of types of products
– Some things to look for
• How this fits together with organizational
problems

Page 51 of 90
CISY 403 SIMULATION AND MODELLING

Module 8
The Central Limit Theorem
Confidence Intervals

What we’ll cover today


• Central limit theorem
– Why the world is usually normal (sort of)
• Application to confidence intervals
• Simple example of calculating a
confidence interval
• The problem with simulation

Laws of large numbers


• We saw that
– If X1, X2,… is a sequence of IID random
variables having a mean m and variance V,
– And if total service time Sn = X1 + X2 +… + Xn
, so that Yn = Sn/n is the average of 1st n terms
– Then E(Yn) = m and Var(Yn) = V/n
• Moreover, Yn → m w.p. 1 as n → ∞
– But what about the distribution of Yn?

D
D iiss ttrr iibb uu ttiioo nn iinn ffoo rrm
m aa tt io
io nn
•• WW hh aa tt ww ee ’ ’rree gg oo in in gg ttoo ss hh oo ww i iss tthh aa tt i iff ww ee
nn oo rrm m aa l li izz ee YY nn i inn aa cc ee rrttaa i inn ww aa yy,, tthh ee nn i itt hhaa ss
((aa pp pp rroo xx i im m aa ttee l lyy)) aa vv eerr yy ww eel ll l kk nn oo ww nn
dd i iss ttrri ibb uu tti ioonn
–– W W ee ss ta ta rrt t ww i it thh hh oo ww t too nn oo rrm m aa l li izzee i it t
–– TT hh ee nn i innt trroo dd uucc ee t thh ee nn oo rrm m aa l l dd i iss t trri ibbuu t ti ioo nn
–– TT hh ee cc ee nnt trraa l l l li im m t thhee nn t ti iee ss t thh ee ss ee t tww oo
m i it t t thh ee oo rree m
t too ggee t thh ee rr

Page 52 of 90
CISY 403 SIMULATION AND MODELLING

Normalizing RV
• Suppose X is an RV that has a mean and
variance
– Set up a new RV: Z = [X-E(X)]/σ(X)
– Then Z has mean 0 and variance 1
• Chebyshev’s inequality says that for a > 0, the
probability that |Z| ≥ a is ≤ 1/a2
– So the density of Z should drop off sharply as we get
away from 0
– If Z is an average of IID RV, we can say more

Normalizing Yn
• Let’s normalize Yn = Sn/n in the same way

[Y n − E (Y n )] / σ (Y n )
= [( S n / n ) − m ] /[ σ ( X 1 ) / n 1 / 2 ] =: Z n

Key fact: The distribution of Zn actually


converges to the distribution of a unit normal
random variable as n→∞

Page 53 of 90
CISY 403 SIMULATION AND MODELLING

What it looks like

Unit normal density


0.45
0.4
0.35
0.3
Density

0.25
0.2
0.15
0.1
0.05
0
.6

.2

.8

.4

.6

.2

6
-3

-1

3
0.

0.

1.

1.

2.

2.
-2

-2

-1

-1

-0

-0

x (in units of std dev)

What this means for us


• As long as we take n large, this
normalized sample mean is almost
normally distributed
– So we can use the normal distribution (which
we can compute) to approximate the unknown
distribution of the sample mean (which we
can’t compute)
• Lots of applications; today one of the most
important

Page 54 of 90
CISY 403 SIMULATION AND MODELLING

An Example:
• Count the number of people on the KEMU
commons at 3 p.m. each day for 30
consecutive days, do not keep track of the
day of week, compute average value.
– Is the average of these data a correct
representation of true annual average?
– Is the average a true representation of actual
weekday population?
– What if a bus loaded with people shows up at
count time?

Confidence intervals
• Suppose we do our experiment (observing
Xi) n times, and compute the sample mean
Yn = Sn/n
– Theory so far says if n is large then Yn is very
likely close to the true population mean m
– But how close?
• We’ll see how to estimate this

Using approximate normality

• Start with the unit normal distribution Q


• Fix a probability p
• Then, ask what’s the least value of w such
that P{ | Q | ≤ w } ≥ p?
– That is, Q ∈ [-w, w] with probability at least p
– This is a p-confidence interval for Q
– If n is large then it should approximate a p-
confidence interval for Zn also
• Then we can go back from Zn to Yn

Page 55 of 90
CISY 403 SIMULATION AND MODELLING

How to find w
• People have tabulated the distribution
function F of the unit normal RV Q
– So we find w such that F(w) = (1 + p)/2
• Thus, P{Q ≤ w} = (1 + p)/2, so P{Q > w} = (1-p)/2
– The normal density is symmetric
• So, P{Q < - w} = (1-p)/2 also
– Then P{Q ∈ [-w, w] } = 1 - (1-p)/2 - (1-p)/2 = p
• Why? 3 disjoint events, probabilities add to 1
• See next slide for a diagram

Confidence interval geometry

-w w
Probability mass p

Mass (1-p)/2 Mass (1-p)/2

An example
• We’re observing a process and want to
estimate its expected value (mean)
– We’ve taken 40 observations
– Previous experience indicates this process
has a variance of 9
– Our sample mean is 18.6
• Can we get a 90% confidence interval?

Page 56 of 90
CISY 403 SIMULATION AND MODELLING

Finding the interval


• Let the population mean be m
• Our approximately normal RV was

Yn − m σ = Var( X1 )
Zn = σ ( X1 ) ;
n

So for our problem, we have

Zn = (18.6 – m)/(3/6.32) = 2.11(18.6-m)

Now go to tables
• We have p = .90, (1+p)/2 = .95
• Tables of the normal show that
F(1.645) = .95, so w = 1.645
• Then P{Zn ∈ [-1.645, 1.645]} = .90
• We can write this as
-1.645 ≤ 2.11(18.6-m) ≤ 1.645,
• i.e., 17.82 ≤ m ≤ 19.38 (sometimes written
as 18.6 ± 0.78)

How to interpret this?


• It’s not correct to say that “m is in this
interval with probability 90%”
– m is not random!
– It’s either in the interval or it isn’t
• What’s correct is to say that there’s a 90%
probability that, if we do this experiment,
we’ll get a sample mean differing from the
population mean m by no more than 0.78

Page 57 of 90
CISY 403 SIMULATION AND MODELLING

More on interpretation
• So what this methodology does is not to
give us a guarantee
– Rather, it lets us say, “Unless I’ve observed a
rare event (one with probability 10% or less),
I’ve found a sample mean that’s within 0.78 of
the real mean”
• But maybe you saw a rare event?
– Maybe you did … tough luck
– Methodology can’t protect you against that

The problem with simulation

• We can write our interval as


Yn − q(1+ p ) / 2σ ( X 1 )n −1/ 2 ≤ m ≤ Yn + q(1+ p ) / 2σ ( X 1 )n −1/ 2
 Here q(1+p)/2 is the (1+p)/2-quantile of the unit
normal that we found from tables
 In the example this was 1.645

 This means that if we increase the number n


of replications by a factor k, the size of the
confidence interval shrinks by a factor of
only k1/2 … a severe problem for simulation

Unanswered questions
• How large does n have to be?
– There are some answers for common
situations
• How did we get the variance of 9?
– We normally wouldn’t know that
– So we have to use the sample variance
• More on these questions next time

Page 58 of 90
CISY 403 SIMULATION AND MODELLING

Module 9
Conditional Probability
Conditional Expectation

What we’ll cover today


• Conditional probability
– A way of ‘slicing’ a joint distribution
• Conditional expectation
– Expectation taken using the idea of
conditional probability
• Computing expectations by conditioning
– A very useful formula, with an economic
planning application

Conditional probability
• This is a way of taking ‘slices’ of a joint
distribution
– Rough idea: Suppose we have a joint density
f(x,y) for X and Y
– Also suppose we’re only interested in a
certain value y0 for Y
• Try to make the function (of x) f(x, y0) into
a density for x

Page 59 of 90
CISY 403 SIMULATION AND MODELLING

Conditional probability (2)


• But f(x, y0) isn’t a density …
– It doesn’t (usually) integrate to 1
– We can fix that by dividing by its integral:


R
f ( x, y0 )dx = fY ( y0 ) (from last time)
So, the " conditional density"we want is
f X |Y ( x | y0 ) = f ( x, y0 ) / fY ( y0 )

Diagram

This is the ‘slice’ of f(x,y)


that becomes fX|Y(x|y0)

y0 y
x

Conditional probability (3)


• The same idea works for discrete RV:

p X |Y ( x | y0 ) = p ( x, y0 ) / pY ( y0 )

 Here we use the probability mass


functions, rather than densities
 Reasoning is just the same

Page 60 of 90
CISY 403 SIMULATION AND MODELLING

Connection with independence


• If X and Y are independent continuous RV,
then

f X |Y ( x | y ) = f ( x, y ) / f Y ( y )
= f X ( x) fY ( y ) / fY ( y ) = f X ( x)
So (for any y) the conditional distribution of X
given y is just the marginal, and Y is irrelevant.
Similarly for discrete RV. This is a useful way to
think about independence.

Conditional expectation
• The conditional expectation of X given Y is
just the expectation taken with respect to
the conditional distribution:

E ( X | Y = y 0 ) = ∫ xf X |Y ( x | y 0 ) dx
R
Similarly for discrete RV, except that the
sum replaces the integral and we use the
probability mass functions

Expectations by conditioning
• E(X|Y=y) is a function (of the variable y)
– Let’s try taking its expectation, recalling that y is a
value of the random variable Y:

E [ E ( X | Y = y )] = ∫ E ( X | Y = y ) f Y ( y ) dy
R

= ∫ ( ∫ x[ f ( x , y ) / f Y ( y )]dx ) f Y ( y ) dy
R R

= ∫ x ( ∫ f ( x , y ) dy ) dx = ∫ xf X ( x ) dx = E ( X )
R R R

Page 61 of 90
CISY 403 SIMULATION AND MODELLING

Expectations by conditioning
• This means that we could compute E(X) if
we knew the conditional expectation
E(X|Y=y) for all y, and the marginal
distribution of Y
• Similar (easier) proof for discrete RV
• Is this a way to make easy things hard?
– No! it’s extremely useful to know …
– Example follows (how to avoid simulation)

Example: using conditioning


• Your company is considering expanding
its production facilities
– Expansion requires considerable cost, and
company would have to increase debt
– Key question is whether the economic
environment justifies this
– You have assembled some information for
analysis

Information for analysis


• In any year the economy will be in one of
four possible states
– Boom (p = .1)
– Good (p = .35)
– Slow (p = .45)
– Recession (p = .1)
• We’ll assume for the moment that the
yearly states are IID

Page 62 of 90
CISY 403 SIMULATION AND MODELLING

Information for analysis (2)


• Your company uses a discount rate of 12% after
tax for economic decisions
• Depending on your expansion decision,
company’s yearly rate of net income after tax
(flowing continuously, in $millions) will be:

State Boom Good Slow Recession


Expand 5.0 2.5 0.0 -3.1
No Exp 3.0 1.0 0.5 0.1

What do we want?
• We want to know the net present value
(NPV) of the total expected net income
from now on (forever)
– Call it VE for expansion, VN for no expansion
– ‘Forever’ might seem unrealistic, but at 12%
discount, NPV is under 10% after 20 years
• Difficulty: infinite number of different paths
into the future; evaluate each!

Example of event tree

Year 0
(Now)

Year 1 Year 1 Year 1 Year 1


Boom Good Slow Recession

Year 2 Year 2 Year 2 Year 2


Boom Good Slow Recession

Year 3 Year 3 Year 3 Year 3


Boom Good Slow Recession

Every box has 4 successors (most not shown


here), so at level k there are 4k boxes

Page 63 of 90
CISY 403 SIMULATION AND MODELLING

One possibility
• Use simulation
– Simulate a large number of possible paths
• You could use Excel for this
• Maybe go 10 years out into future
• For each of 10 years, use U(0,1) random variate to
draw from the finite distribution of economic states,
then calculate NPV
– Average the NPV over these paths
• Do calculation with/without expansion

Let’s try conditioning instead


• Assume you expand
• Suppose you knew that next year there
would be a boom
– In that year you’d make $5.0 million, whose
NPV is [(5.0)/(0.12)][1-e-(.12)(1)] = $4.71 million
– At end of year your future income would have
value VE ; its NPV now is e-.12 VE

Use conditioning …
• That means that the total expected NPV of
your future income, assuming
– You expand, and
– There will be a boom next year,
is 4.71 + e-.12 VE
• You can do this for each of the other
possibilities too
– See table on next slide

Page 64 of 90
CISY 403 SIMULATION AND MODELLING

Expansion option

• Here’s the NPV you’ll get with expansion,


in each of the four scenarios
Economy next year NPV future income
Boom 4.71 + e-.12 VE
Good 2.36 + e-.12 VE
Slow 0.00 + e-.12 VE
Recession -2.92 + e-.12 VE

Use the theory we developed


• Now compute the expected NPV by
conditioning on states of the economy
(0.10)( 4.71 + e-.12 VE)
+ (0.35)( 2.36 + e-.12 VE)
+ (0.45)( 0.00 + e-.12 VE)
+ (0.10)(-2.92 + e-.12 VE)
= 1.00 + e-.12 VE = VE (!)
• Therefore VE = 1.00/(1- e-.12 ) = 8.84

Do the same for no expansion


• Same calculation yields
VN = 0.83 + e-.12 VN , so VN = 7.34
• Expansion gets you 20% more expected value,
but at a big risk
• What’s the point?
– Sometimes it pays to think before you simulate
– Analysis may be able to do the job
– When it can, it’s almost always better

Page 65 of 90
CISY 403 SIMULATION AND MODELLING

What was wrong with this?


• Look at the assumptions
– Key: think about what you learned in the last
class
– What, if anything, is economically unrealistic?
• Yes, we can fix this
– Use a Markov chain
– Leads to Markov decision processes

Main ideas today


• Conditional probability
– A way of ‘slicing’ a joint distribution
• Conditional expectation
– Expectation taken using the conditional
density (or mass function)
• Computing expectations by conditioning
– Very useful formula: E(X) = E[E(X|Y=y)]
– Application to dynamic economic analysis

Page 66 of 90
CISY 403 SIMULATION AND MODELLING

Module 10
Probability Inequalities
Laws of Large Numbers

What we’ll cover today


• Some probability inequalities
– Very simple, but extremely useful
– They help us see what kinds of events are
very unlikely to occur
• Weak and strong laws of large numbers
– Based on the probability inequalities
– What do averages of IID RV do?
– Why do we trust repeated experiments?

Markov’s inequality
• Start with a RV X that’s always ≥ 0
• Let t > 0 and use definition of expectation:

E( X ) = ∫ xf (x)dx = ∫ xf (x)dx +∫ xf (x)dx


R {x≥t} {0≤ x<t}

≥∫ xf (x)dx ≥ ∫ tf (x)dx = tP{X ≥ t}


{x≥t} {x≥t}

so that if t > 0, P{X ≥ t} ≤ t-1 E(X)

Page 67 of 90
CISY 403 SIMULATION AND MODELLING

Scaling Markov’s inequality


• It’s useful to scale this in units of the mean
– We have P{X ≥ t} ≤ t-1 E(X)
– Introduce a new variable k > 0, defined
by t = kE(X)
– Then P{X ≥ kE(X)} ≤ 1/k
– All of this works also for discrete RV,
with similar proofs

Chebyshev’s inequality
• Here we apply Markov’s inequality to the RV
[X-E(X)]2, which is always ≥ 0, to get
P{[X-E(X)]2≥ ε 2} ≤ Var(X)/ ε 2
– Remember, Var(X) = E([X-E(X)]2)
• We can write this as
– P{ |X-E(X)| ≥ ε } ≤ Var(X)/ ε2 (usual form)
– Or as P{ |X-E(X)|/ σ(X) ≥ k} ≤ 1/k2 (scaled form)
• To see this, take ε = k σ(X)
• This “z-score form” gives a crude confidence interval
• These just require mean and variance, with no
other assumptions

There’s much more


• The Markov and Chebyshev inequalities
are pretty crude, but very broadly
applicable
– Much more sophisticated inequalities exist
• A whole area of probability: “large deviations”
– Key idea: as you get farther away from the
mean E(X), it’s increasingly unlikely that you’ll
find X there

Page 68 of 90
CISY 403 SIMULATION AND MODELLING

Laws of large numbers


• These laws underlie practically all
applications of simulation
– They say, roughly, that the average of a long
sequence of IID random variables is highly
likely to be near the mean
• We’ll come back to the applications after
looking at two forms of the laws

Observing repeated events


• Start with weak law of large numbers
• This is useful, and it’s so elementary that
you can prove it even with what little
probability we’ve done here
• Suppose X1, X2,… is a sequence of IID
random variables having a mean m and
variance V
– Why ‘a’ instead of plural?

The sample mean


• Now let Sn = X1 + X2 +… + Xn
– So Yn = Sn / n is the average of the 1st n terms
– This is the sample mean
• This sample mean is of concern in many
situations in which we’re observing a process
with variation, and averaging observations (as in
simulation)
– From last time, E(Yn)= m, but Var(Yn)= ??
– We need to figure out how to find this

Page 69 of 90
CISY 403 SIMULATION AND MODELLING

Variance of a combination
• Consider RV Z1, Z2, …, Zn and real numbers a1,
a2, …, an
– Let Z = a1Z1 + a2Z2 + … + anZn
• We want to find Var(Z)
– We know Var(Z) = E{[Z-E(Z)]2}
– Also, Z – E(Z) = a1[Z1 –E(Z1)]+…+ an[Zn –E(Zn)]
• Now let’s compute the expectation of [Z-E(Z)]2

Variance of a combination (2)

n n
E{[Z − E( Z )]2 } = E{∑∑ ai [ Z i − E( Z i )][Z j − E( Z j )]a j }
i =1 j =1
n n
= ∑∑ ai E{[Z i − E( Z i )][Z j − E( Z j )]}a j
i =1 j =1
n n
= ∑∑ ai Cov( Z i , Z j )a j
i =1 j =1

We can use matrices to make this simpler

Variance of a combination (3)


• Suppose we let
– Σ be an n x n matrix whose ij-th element is
Cov(Zi,Zj), and
– a be an n-vector whose i-th element is ai
• Then Var(Z) = aTΣ a
– This means we can get the variance of any
linear combination from the matrix of
covariances and the linear coefficients

Page 70 of 90
CISY 403 SIMULATION AND MODELLING

Let’s apply this


• Look at a sum of independent RV
– Say, W = U1 + U2 +… + Un
– Let C be the covariance matrix of the Ui
– Let 1 be an n-vector with components all 1
– Then Var(W) = 1TC1
• But the off-diagonal entries in C are all zero
because the Ui are independent
• The diagonal entries in C are just Var(Ui)
• So Var(W) = Var(U1)+ … + Var(Un)

Apply this to the sample mean


• We have Sn = X1 + X2 +… + Xn
– The Xi are all IID with variance V
– Thus Var(Sn) = nV
• Now the sample mean Yn = Sn / n
– So Var(Yn) = Var(Sn)/n2 = V/n
• As n gets bigger, the variance of the
sample mean goes to 0!
– This is why we do repeated experiments

The effect of correlation


• Worst case is perfect correlation, so ρ(Ui,
Uj) = 1 for all i and j
– Then Cov(Ui, Uj) = σ(Ui)σ(Uj), each i, j
– If we let s be an n-vector whose i-th
component is σ(Ui), then C = ssT
– Then Var(W) = 1TC1 = 1TssT1 = (1Ts)2
– So σ(W) = 1Ts = σ(U1) + … + σ(Un)
• Thus, Var(W/n) doesn’t go to 0!

Page 71 of 90
CISY 403 SIMULATION AND MODELLING

Weak law of large numbers


• We now know that the sample mean Yn
has mean m and variance V/n
– Let ε be a tolerance >0 (maybe small)
– Chebyshev’s inequality says that
P{|Yn – m| ≥ ε } ≤ Var(Yn)/ ε 2 = V/(nε 2),
which goes to 0 as n→∞
• This is the weak law of large numbers

What the weak law says


• The weak law says
– For any fixed tolerance ε,
– You can make the probability that Yn is farther
than ε from its mean m as small as you like
– … by taking n large enough
• But there’s still a (small) probability that Yn
is far from its mean

Strong law of large numbers


• The strong law fixes this hole
– It says that if you look at the sequence {Y1,
Y2, Y3, … } of sample means for larger and
larger n, then with probability 1 this sequence
converges to the mean m
• Stronger statement, harder to prove
• These laws underlie statistical analysis of
experiments

Page 72 of 90
CISY 403 SIMULATION AND MODELLING

Main ideas today


• Some probability inequalities
– These help us see what kinds of events are
very unlikely to occur
• Weak and strong laws of large numbers
– Based on probability inequalities
– What do averages of IID RV do?
– Why do we trust repeated experiments?

Page 73 of 90
CISY 403 SIMULATION AND MODELLING

Module 11
The t Distribution
Confidence Intervals for the Mean

What we’ll cover today


• Basic material on confidence intervals
– Computing the sample variance
– Using the sample variance
– The t distribution vs. the normal
• Example of using this method to find a
confidence interval
• Common errors in interpreting these

What we’d like to do


• Suppose we have some computed data
from which we want to estimate the
population mean
– I.e., expectation of RV giving the sample data
• Obvious estimator seems to be the sample
mean
– Easy to compute, unbiased
• Key question: how reliable is this?

Page 74 of 90
CISY 403 SIMULATION AND MODELLING

Review: Central Limit Thm


• The Central Limit Theorem tells us
something about the relation between
sample mean Yn and the real mean µ:

(Yn − µ ) /(σ / n ) n


→ Standard normal
→∞

We used this before to compute a


confidence interval for µ, using Yn
and the variance σ

Problem: we don’t know σ


• Unfortunately, in general nobody tells us
the standard deviation (SD) σ
– This means we have to estimate it
• This is a little tricky
– How to estimate variance and SD?
• We’ll cover this next
– Does the CLT still work with sample SD?
• No, but we can fix it with the t distribution

Estimating σ2
• We want to compute an estimator S2(n)
that we can use to replace σ2
• An idea: try to mimic the formula for
variance, involving Σ(Xi - Yn)2 divided by
something (what?)
– Key: try to make the expectation = σ2
– Therefore we’ll compute the expectation of
Σ(Xi - Yn)2 to find out what to divide by

Page 75 of 90
CISY 403 SIMULATION AND MODELLING

The expectation of Σ(Xi - Yn)2

Start with ( X i − Yn )2 = X i2 − 2 X iYn + Yn2


Then E[( X i − Yn ) 2 ] = E ( X i2 ) − 2 E ( X iYn ) + E (Yn2 ).
We have E ( X i2 ) = σ 2 +µ 2 (variance formula)
Also, E ( X i X j ) = µ 2if i ≠ j (Cov( X i , X j ) = 0)
So E ( X iYn ) = E[ X i (∑ j =1 X j ) / n] = µ 2 + σ 2 / n.
n

More on expectation

And E (Yn2 ) = n −1 ∑i =1 E ( X iYn ) = µ 2 + σ 2 / n.


n

So E[( X i − Yn ) 2 ] = ( µ 2 + σ 2 ) − 2( µ 2 + σ 2 / n)
+ ( µ 2 + σ 2 / n) = σ 2 (1 − 1 / n ).
Hence E[∑i =1 ( X i − Yn ) 2 ] = nE[( X i − Yn ) 2 ]
n

= ( n − 1)σ 2 .
Therefore E[∑i =1 ( X i − Yn ) 2 /( n − 1)] = σ 2 .
n

The sample variance

• This means that a reasonable estimator


of σ2 is the sample variance,


n
S2 = i =1
( X i − Y n ) 2 /( n − 1)
This is an unbiased estimator (its
expectation is the quantity σ2 that is
being estimated). The n-1 is surprising,
but it comes from dependence

Page 76 of 90
CISY 403 SIMULATION AND MODELLING

Back to CLT
• If we now replace σ2 in the normalized
variable from the CLT by the sample
variance S2, then we get

(Yn − µ ) /( S 2 / n )1 / 2
−1 / 2
 Y −µ   ∑ n ( X i − Yn ) 2 
=  2n 
1/ 2 
n − 1 i =1 2 
 (σ / n )   σ 
 

What about this mess?


• If the first () quantity is unit normal, then
the left side has the Student’s t distribution
with n-1 degrees of freedom
– Actually W. S. Gossett, who published his
paper under the pseudonym of ‘Student’
• The t distribution is tabulated, so this
solves our problem!

The procedure
• What we do is to replace the use of the
normal distribution with the normalized
variable (Yn - µ)/(σ2/n)1/2 by the use of
Student’s t distribution with the normalized
variable (Yn - µ)/(S2/n)1/2
– This solves our problem of not knowing σ2
• The t and normal aren’t very different
– Even less as degrees of freedom increase:

Page 77 of 90
CISY 403 SIMULATION AND MODELLING

Normal vs. t distributions

Standard Normal vs. t

0.45
0.4
0.35
0.3
Normal
Density

0.25
t Distribution (4 df)
0.2
t Distribution (20 df)
0.15
0.1
0.05
0
-3
-2.6
-2.2
-1.8
-1.4
-1
-0.6
-0.2
0.2
0.6
1
1.4
1.8
2.2
2.6
3
Units of S D

Example: CI for mean

• We’ll show an example of computing a


95% confidence interval for a mean
• Let’s suppose we have the following 10
observations:

24.7 22.9 23.1 24.5 23.6


24.4 22.6 23.3 23.7 22.8

Page 78 of 90
CISY 403 SIMULATION AND MODELLING

Setting up the inequality

• Calculation uses the basic inequality:


-2.262 ≤ (Yn - µ)/(S2/n)1/2 ≤ 2.262
• Where does this come from?
– If Z has t dist with 9 df, P{Z ≤ 2.262}=.975
– So P{| Z | ≤ 2.262}= .95 by symmetry
– You can get these quantiles, or percentage
points, of the t distribution from Excel (use
TINV)
– See spreadsheet, “Example data” tab

Using the inequality


• We find by calculation Yn = 23.56 and
(S2/n)1/2 = .2386
• So if |Yn - µ| > (.2386)(2.262) = .540, then
we have observed an event with
probability < 5%
– Our 95% confidence interval for the mean µ is
therefore 23.56 ± 0.540, which in interval form
is [23.02, 24.10]

What does this mean?


• It means that if we conduct such an
experiment numerous times, in
approximately 95% of the cases the
interval we construct in this way will
contain the mean µ
• As we saw last time, we don’t really know
that this interval contains µ
– But if not, we’ve observed a rare event

Page 79 of 90
CISY 403 SIMULATION AND MODELLING

Main ideas today


• More on confidence intervals
– Problem: we usually don’t know the
population variance
– Solution: compute and use the sample
variance instead
– Then use the t distribution instead of normal
• Example of using this method to find a
confidence interval

Page 80 of 90
CISY 403 SIMULATION AND MODELLING

Module 11
Random Number Tests

Issues
• Theory requires (empirical tests):
1. Uniform distribution U(0,1)
• Common flatness of the distribution frequency
2. No serial or dimensional dependency
0.02 0.70 0.23 0.61 0.69 0.13 0.65 0.37 0.85 0.85
0.04 0.30 0.70 0.67 0.04 0.74 0.25 0.73 0.33 0.21
0.66 0.84 0.19 0.67 0.38 0.52 0.93 0.93 0.60 0.76
. . .

3. No linearity of sequence (run-ups)


• 0.86, 0.11, 0.23, 0.03, 0.13, 0.06, 0.55, 0.64, 0.87, 0.10
4. No discernible correlation (covariance) or lag
sequence

Test 1
• Basic chi squared (χ2)
– Divide (0,1) IID into k subintervals (≥ 100)
– Generate U1, U2, …, Un, for n/k ≥ 5
k
χ2 = k
n ∑( f
j =1
j − nk ) 2 ;

f j = count (U i ' s ) in j th subinterval

– Reject null hypothesis if:

χ2 > χ2 k −1 ,1− α

Page 81 of 90
CISY 403 SIMULATION AND MODELLING

How to Generate fj
• Set fj = 0 for j = 1, 2, …, k
• For i = 1, …., n do
– Generate Ui ;random number
– Set J = Ceiling (kUi) ;scaled to bins
– Replace fJ by fJ+1 ;counter in bin
• End do

Test 2
• Multi-dimensional chi squared (χ2)
– Divide (0,1) IID into k subintervals (≥ 100)
– Generate non-overlapping d-tuples
– U1 = (U1, U2,…,Ud), U2 = (Ud+1, Ud+2,…,U2d), … Un…. for
n/kd ≥ 5
• Compute and test
k k k
χ = 2 kd
n ∑∑ ... ∑ ( f
j1 =1 j2 =1 jd =1
j1 j 2... jd − knd ) 2

Test 2
Example:
d = 2; n = 32768, k = 64, df = 642-1=4095
Pairs of values for Ui, i = 1, n
(U1,U2), (U3, U4), … (U2n-1, U2n)

fj1j2 ==

Page 82 of 90
CISY 403 SIMULATION AND MODELLING

Module 12
Density Distributions

Generating Distributions
• Uniform
• Exponential distribution
• Gamma
• Weibull
• Normal
• Lognormal
• Triangular

Uniform Distribution
• Flat valued, a straight line, U(a,b), first approximation
 1
if a ≤ x ≤ b
Density : f (x) =  b − a
 0 otherwise
 0 if x < a
 x − a
Distributi on : F (x) =  if a ≤ x ≤ b
b − a
 1 if b < x
Range : [a , b ]
f(x)
a + b
Mean :
2 1/(b-a)

Mode : not unique


(b − a )2
Variance : a b
12

Page 83 of 90
CISY 403 SIMULATION AND MODELLING

Exponential distribution
• A common and easy model
• Special case of gamma or Weibull distributions
• Inter-arrival times of ‘customers’
 1 e−x/β if x ≥ 0
Density : f (x) =  β
 0 otherwise
1 − e − x / β if x ≥ 0
Distributi on : F (x) = 
 0 otherwise
f(x)

[0 , ∞ ]
1.2

Range : 1

Mean : β 0.8

0.6

Mode : 0 0.4

0.2

2
Variance : β 0
0 1 2 3 4 5 6

Gamma distribution
• Task completion distribution
• Acquires some similarity to small sample distributions
β−αxα−1e−x/ β
 if x > 0
Density
: f (x) =  Γ(α)
 0 otherwise
 −x/ β α−1 (x / β) j
1−e ∑ if x > 0
on: F(x) = 
Distributi j=0 j!
 0 otherwise
f(x)
Range: [0,∞] 1.2 α=1/2

Gamma(α,1)
1

Mean: αβ 0.8

α=1
Mode: β(α −1) if α ≥1, 0if α <1 0.6

0.4
α=2
2 α=3
: αβ
Variance 0.2

0
0 1 2 3 4 5 6

Page 84 of 90
CISY 403 SIMULATION AND MODELLING

Weibull distribution
• Task completion distribution
• Like gamma, but gives emphasis to a mode value
αβ−α xα−1e−( x / β ) if x > 0
α

Density: f ( x) = 
 0 otherwise
1− e−( x / β )
α
if x > 0
on: F( x) = 
Distributi
 0 otherwise
Range: [0, ∞] f(x)
β 1 1.2 Weibull(α,1)
Γ( )
α=3
Mean:
α α 1

  α −11/α 0.8 α=2

β   ifα ≥ 1
Mode:   α  0.6 α=1

0 ifα < 1

0.4
α=1/2

0.2

β 2   2  1   1  
2

Variance: 2Γ  − Γ  
α   α  α   α 
0
0 1 2 3 4 5 6



Normal distribution
• Error terms of various types (uncertainty about a mean)

1 2 2
Density : f (x) = e −( x−µ ) / 2σ
2
2 πσ
Distributi on : no closed form
Range : [− ∞,∞]
f(x)

Mean : µ 0.5
Normal(0,1)

0.4

Mode : µ 0.3

2
Variance : σ
0.2

0.1

0
-3 -2 -1 0 1 2 3

Page 85 of 90
CISY 403 SIMULATION AND MODELLING

Lognormal distribution
• Found to represent many natural phenomena such as
infant mortality vs. age.
1
e −(ln ( x )− µ )
2
/ 2σ 2
Density : f ( x) =
x 2πσ 2
Distributi on : no closed form
f(x)

Range : [0, ∞ ] 1

0.9

0.8
σ=3/2

σ=1/2
Normal(0,σ2)

µ +σ 2 / 2 0.7

Mean : e 0.6

0.5
σ=1
µ −σ 2 0.4

Mode : e 0.3

0.2

Variance : e 2 µ +σ 2 / 2
(e σ2
−1 ) 0.1

0
0 1 2 3 4 5

Triangular Distribution
• Rough model in absence of data
 2 (x − a )
 (b − a )(c − a ) if a ≤ x ≤ c

 2 (b − x )
Density : f ( x) =  if c ≤ x ≤ b
 (b − a )(b − c )
 0 otherwise

 0 if x < a
 (x − a )2 x (b − a )
 if a ≤ x ≤ c ; F ' ( x) =
 (b − a )(c − a ) (c − a )

Distributi on : F (x) =  (b − x )2 x
1− if c < x ≤ b ; F ' ( x) = 1 −
 ( b − a )( b − c ) (c − a )
 1−
 (b − a )
1 if b < x
Range : [a , b ] f(x)
Triangular (3,15,6)
a+b+c 2/(b-a) -
Mean :
3
Mode : c
a 2 + b 2 + c 2 − ab − ac − bc
Variance :
18

a c b

Page 86 of 90
CISY 403 SIMULATION AND MODELLING

Other Distributions
• Beta(α1,α2)
• Pearson type 5 – PT5(α,β)
• Pearson type 6 – PT6(α,β)
• Descrete types, various isolated values (0, 1, etc.)
– Bernoulli(p) - B(p)
– Descrete uniform – DU(i,j)
– Binomial – Binom(t,p)
– Geometric – geom(p)
– Negative binomial – negbin(s,p)
– Poisson - Poi(λ)
• Empirical

Module14
Examples and Result Treatment

Page 87 of 90
CISY 403 SIMULATION AND MODELLING

Example: Finite Distribution


• Variates taking values of 1 for P = .3, 8 for P =.7
• A few randoms of U(0,1): 0.959, 0.269, 0.677
• Generate the variates
• There is no closed form, but discrete ranges
The distribution function F(x) =
0 if x < 1 .3 .7
.3 if 1 ≤ x < 8
1 if 8 ≤ x
Is mapped as x =
1 if 0 ≤ U ≤ .3 .0 .3 1
8 if 0.3 < U ≤ 1 1 8
• The results are: 8, 1, 8 respectively

Example: Exponential distribution

• Mean value 20 (β)


• A few randoms of U(0,1): 0.959, 0.269, 0.677
• Generate the exponent variates
• Invert the function f(x)= 1-exp(-x/β)
– Solve for y in y=1-exp(-x/β)
• y-1 = -exp(-x/β)
• 1-y = exp(-x/β)
• Ln(1-y) = -x/β
• -βLn(1-y) = x
• Revise: f’(x) = -βLn(1-x)
– Populaton U is U(0,1) if and only if 1-U is.
– So, can say x = -20Ln(U)
• Results: 0.84, 26.26, 7.80

Example: Terminating Function


Service Queue
• Two measurement parameters, A, B
• 20 test runs yielding (Ai, Bi) results
• Average values: A = 23 min, B = 34 min.
• Sample variance S2 = 5.1 and 7.5 resp.
• Determine a 95% CI for A
– StdDev = sqrt(5.1/20) = .504
– At 95%CI, use Student t, .975, 19 samples
• (2.093)(.504) = ±1.057
• Range= (23-1.057, 23+1.057)

Page 88 of 90
CISY 403 SIMULATION AND MODELLING

Boniferroni’s Inequality
• A realization of practical inference of means in sets
driven by random events.
• For simulation models, assume multiple test runs k that
have consenus value Is = 100(1-a)
– Obtain a set of result estimators, µs for s = 1, 2, …, k
– Each µs has a confidence interval or uncertainty
• Since all are independently generated, the overall
probability that they are contained in the total
uncertainty for the combination of runs is:
k
– P(µs  Is for all s =1, 2, …, k) ≥1 − ∑α
s =1
s

• We can only guarantee that P() will be greater than


zero!

Multiple Comparison Problem


• Assume we would like a result with a
certain CI such as 100(1-α) per cent.
• We are not sure that a result, µs is within
the target confidence interval for a test
completion suite!
• If a result is not within the target CI then
we need a way of estimating a new CI or
adjusting our target CI

Single Variable Confidence Interval

95

97.5
99

Page 89 of 90
CISY 403 SIMULATION AND MODELLING

Double Confidence Intervals

0.16
0.14
0.12
0.1
0.08
0.06
0.04 S 21
0.02 S 16
0 S 11

1
4
S6

7
10
13
S1

16
19
Example: Terminating Function
Service Queue
• Two measurement parameters, A, B
• 20 test runs yielding (Ai, Bi) results
• Average values: A = 23 min, B = 34 min.
• Sample variance S2 = 5.1 and 7.5 resp.
• Determine a 95% CI for A combined with B
– StdDev A = sqrt(5.1/20) = .504
– StdDev B = sqrt(7.5/20) = .612
– At 95%CI, use Student t, .9875, 19 samples
• (A) (2.433)(.504) = ±1.23
• (A) Range= (23-1.23, 23+1.23)
• Similarly for B

Page 90 of 90

Das könnte Ihnen auch gefallen