Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Lecture 12: Why Simulate?

Open In Colab

In Lectures 8 to 11, every parameter of a model was known: durations, demands and distances were fixed numbers. In practice, many of them are uncertain. This notebook describes the setting of the simulation part of the course, where the inputs of a model are random, and shows with the flaw of averages why we cannot simply replace each random input by its average. The probability concepts it uses are summarized in Variability (Recap). The next notebooks cover how to sample random inputs (Sampling a Random Variable) and the two types of simulation (Monte Carlo Simulation and Discrete-Event Simulation).

Learning outcomes

On completion of this notebook, you will be able to:

  • describe the simulation setting: random inputs XX, a model rr and the expected output E[r(X)]E[r(X)]

  • explain the four steps of a simulation study

  • explain the flaw of averages, and recognize when E[r(X)]E[r(X)] differs from r(EX)r(EX)

The Simulation Setting

The optimization problems so far had the form max⁡r(π)\max r(\pi) subject to π∈S\pi \in S, where SS is the set of feasible decisions: a model rr computes the output of a decision π\pi for some fixed parameters. When some parameters are random, we collect them in a random variable XX (usually a vector, one component per random parameter), and the output r(X,π)r(X, \pi) is random as well. A natural goal is then to maximize the expected output:

max⁡π∈S E[r(X,π)].\max_{\pi \in S} \ E[r(X, \pi)].

In the problems of Lectures 12 and 13, E[r(X,π)]E[r(X, \pi)] can only be computed by simulation: imitating the random behavior of the real system many times on a computer. Lecture 13 is about choosing the decision π\pi. In Lecture 12 the decision is fixed, so we drop π\pi and study the random output r(X)r(X) itself: its expectation E[r(X)]E[r(X)], and probabilities such as P(r(X)>10)P(r(X) > 10). There are two types of simulation:

  • Monte Carlo simulation, when rr is a known function of a fixed number of random inputs, for example the finish time of a project as a function of the durations of its activities;

  • discrete-event simulation, for processes that are too complex to write down as one function, such as a queue of customers that evolves over time.

Every simulation study goes through the same four steps:

  1. Fit a distribution to historical data for each random input, for example a lognormal distribution for activity durations. This is part of the statistics part of the course; Canvas has Python code that finds the best-fitting distribution for a dataset. In these notes, the distributions are given.

  2. Sample realizations x1,x2,…,xnx_1, x_2, \dots, x_n of XX from the fitted distribution, so that they are in line with the real-life data (Sampling a Random Variable).

  3. Process every sample in the model, giving the output samples r(x1),r(x2),…,r(xn)r(x_1), r(x_2), \dots, r(x_n).

  4. Analyze the output samples statistically, for example by averaging them to estimate E[r(X)]E[r(X)] and computing a confidence interval.

Why fit a distribution in step 1, instead of reusing the historical data directly (called bootstrapping)? A fitted distribution gives an unlimited stream of new, realistic samples. Reusing the same limited history risks overfitting: once we optimize decisions (Lecture 13), the best decision for the historical data is not necessarily the best one for the future.

The Flaw of Averages

Why simulate at all? A tempting shortcut is to replace every random input by its expected value and to compute the output once, as if the inputs were fixed parameters. This shortcut gives the wrong answer, because in general

E[r(X)]≠r(EX).E[r(X)] \ne r(EX).

Assuming that they are equal is a mistake common enough to have its own name: the flaw of averages (Savage, 2012). Savage illustrates it with a drunk walking down the middle of a highway, swaying from side to side. The drunk’s average position is on the middle line, where no car can hit them. But they are rarely at their average position, and one sway into a lane with a car is enough.

Simulation avoids the flaw of averages without much effort: instead of computing rr once for the average input, it computes rr for many samples of XX and averages the outputs. That average estimates E[r(X)]E[r(X)] itself, not r(EX)r(EX).

Equality does hold when rr is linear: E[aX+bY+c]=aEX+bEY+cE[aX + bY + c] = aEX + bEY + c, by the rules for sums. A maximum, a minimum (sales are the minimum of demand and stock), a threshold or a product of random inputs breaks it. For such a model there is usually no formula for E[r(X)]E[r(X)], especially when XX has many components, and simulation is the way to compute it.

References

  • Koole, G. (2019). An Introduction to Business Analytics. Chapter 5, “Simulation.”

  • Savage, S. (2012). The Flaw of Averages: Why We Underestimate Risk in the Face of Uncertainty. Wiley.