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 13: Comparing Scenarios

Open In Colab

This notebook covers the simplest of the four types of simulation optimization problems: ∣S∣=2|S| = 2, so we only have to decide which of two scenarios is better. We compare them with a confidence interval for the difference, and show how common random numbers give a narrower interval for the same number of runs. Common random numbers return in all following notebooks: Ranking and Selection, Local Search and Gradient Methods. The last two also show a downside: less noise also means less exploration, which can keep a search in a local optimum.

Learning outcomes

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

  • compare two scenarios with a confidence interval for the difference of their expected performances

  • explain why positively correlated matched pairs reduce the variance of the difference

  • use common random numbers in a simulation, and quantify how many runs they save

Independent Samples

With ∣S∣=2|S| = 2, one scenario gives a random performance XX and the other a random performance X′X', for example the throughput of two layouts of a factory. The question is whether one scenario is better than the other, that is, whether EX≠EX′EX \neq EX'.

The most direct approach simulates both scenarios nn times, independently: runs X1,…,XnX_1, \dots, X_n of the first scenario and X1′,…,Xn′X_1', \dots, X_n' of the second. As in Variability (Recap), we write σ2(X)\sigma^2(X) for the (unknown) variance of XX, and Xˉ\bar X and SX2S_X^2 for the sample average and sample variance of the runs, which estimate EXEX and σ2(X)\sigma^2(X); the same for X′X'. To have one notation for this section and the next, let Y=X−X′Y = X - X' and Yi=Xi−Xi′Y_i = X_i - X_i', the difference of the ii-th runs. Then Yˉ=Xˉ−Xˉ′\bar Y = \bar X - \bar X' estimates EY=EX−EX′EY = EX - EX', and because the runs of the two scenarios are independent,

σ2(Y)=σ2(X)+σ2(X′),\sigma^2(Y) = \sigma^2(X) + \sigma^2(X'),

so the sample variance SY2S_Y^2 of the differences is approximately SX2+SX′2S_X^2 + S_{X'}^2. A 95% CI for EYEY is

[Yˉ−1.96SYn, Yˉ+1.96SYn].\left[\bar Y - 1.96 \frac{S_Y}{\sqrt n}, \ \bar Y + 1.96 \frac{S_Y}{\sqrt n}\right].

The test for two independent samples of H0:EX=EX′H_0: EX = EX' comes down to this CI: at significance level 5% (two-sided), we reject H0H_0 exactly when 0 does not lie in the CI. In that case we have evidence that one scenario is better than the other. Writing the test as a CI has an advantage: the width of the CI, 2×1.96 SY/n2 \times 1.96\, S_Y/\sqrt n, shows directly how much a smarter design of the simulation gains. If the design makes σ(Y)\sigma(Y) smaller, the CI gets narrower for the same number of runs nn.

Matched Pairs and Common Random Numbers

We can often do better by comparing the two scenarios in a similar, “fair” test setting. We take matched pairs of samples (Xi,Xi′)(X_i, X_i'), and make sure that the two samples of each pair are positively correlated by simulating them under similar conditions. Then we compute the differences Yi=Xi−Xi′Y_i = X_i - X_i' and make the CI for EYEY from them exactly as above, as in the test for matched pairs. If 0∉CI0 \notin \text{CI}, the difference is significant.

The pairing gives more statistical power because it makes the CI narrower. For XX and X′X' that are not independent,

σ2(Y)=σ2(X−X′)=σ2(X)+σ2(X′)−2 Cov(X,X′).\sigma^2(Y) = \sigma^2(X - X') = \sigma^2(X) + \sigma^2(X') - 2\,\mathrm{Cov}(X, X').

The covariance Cov(X,X′)\mathrm{Cov}(X, X') measures how XX and X′X' move together. If it is positive, a large sample of XX tends to come with a large sample of X′X', so their difference is relatively small. So a positive covariance reduces σ2(Y)\sigma^2(Y) compared to independent samples, where the covariance is 0. A smaller σ(Y)\sigma(Y) gives a narrower CI for the same nn, and as a result, if EY≠0EY \neq 0, the CI excludes 0 after fewer runs: we see earlier that one scenario is better.

In practice, we get this positive correlation with common random numbers (CRN): we use the same underlying random draws for both scenarios (the same simulated demands, the same arrival moments, or in general the same seed), instead of drawing fresh randomness for each scenario.

Example: The Effect of Common Random Numbers

A shop decides between ordering 9 or 10 units of a product. Demand is Poisson with mean 10, a unit is sold for €5 and bought for €3, and unsold units are worthless. We simulate the difference in profit between the two order quantities 1000 times, once with independent demand for the two scenarios and once with CRN, where the same demand feeds both:

independent: s_Y = 11.31, 95% CI for EY: [-1.13, 0.28]
        CRN: s_Y =  2.50, 95% CI for EY: [-0.49, -0.18]

With independent sampling, the CI contains 0: after 1000 runs we cannot tell which order quantity is better. With CRN, the CI lies entirely below 0, so ordering 10 units gives a lower expected profit than ordering 9. Figure 1 and Figure 2 show why: with CRN, a day with high demand raises the profit of both order quantities, and a day with low demand lowers both, so the two profits move together and their difference varies much less.

Loading...

Figure 1:Profit of ordering 9 and 10 units in the first 40 runs, with independent demand for the two order quantities.

Loading...

Figure 2:Profit of ordering 9 and 10 units in the first 40 runs, with common random numbers: both order quantities face the same demand in each run.

How many runs does CRN save here? The CI has width 2×1.96 sY/n2 \times 1.96\, s_Y/\sqrt n, where sYs_Y is the sample standard deviation of the differences. Because of the n\sqrt n, halving the width takes 4 times as many runs, and in general, making the width ff times smaller takes f2f^2 times as many runs. CRN makes sYs_Y, and thus the width, ff times smaller without extra runs, with

f=sY with independent samplingsY with CRN.f = \frac{s_Y \text{ with independent sampling}}{s_Y \text{ with CRN}}.

To get the CI of CRN with independent sampling, we would need f2f^2 times as many runs:

f = 4.5, f^2 = 21
independent runs per scenario for the same width: 20553

CRN makes the CI about 4.5 times narrower, which with independent sampling would take about 20 times as many runs: about 20,500 runs per scenario instead of 1000. And CRN costs nothing extra: we only reuse the demands we drew. The two order quantities are close, so their profits are strongly correlated under CRN; for scenarios that differ more, the savings are smaller.

References

  • Koole, G. (2019). An Introduction to Business Analytics. §8.1.