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: Ranking and Selection

Open In Colab

Comparing Scenarios chose between two solutions. This notebook covers the second of the four types of problems: a small, discrete set of solutions. We discuss two ways to spend the simulation budget, an equal split over all solutions and a smarter one that discards bad solutions early, and apply both to the newsvendor problem.

Learning outcomes

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

  • formulate the newsvendor problem as a simulation optimization problem

  • apply ranking and selection with an equal split of the simulation budget, and explain its drawbacks

  • formulate the one-sided tests that discard solutions, and explain the Šidák correction for multiple testing

  • apply ranking and selection with discarding, and read and adapt the Python code that does so

The Setting

We solve the simulation optimization problem

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

where E[r(X,π)]E[r(X, \pi)] can only be evaluated by simulation. In this notebook SS is discrete and relatively small, with k=∣S∣k = |S| solutions: the simulation budget of mm runs is much larger than the number of solutions (m≫km \gg k), so it suffices to simulate every solution at least a couple of times. The task is to select the best solution, and on the way we rank the solutions by their estimated performance, hence the name ranking and selection.

The Newsvendor Problem

The newsvendor problem is a typical ranking and selection problem. A newsvendor buys π\pi newspapers in the morning for a price cc each, and sells them during the day for a price p>cp > c. Demand XX is random, and newspapers that are left at the end of the day are worthless. The newsvendor sells min⁡(X,π)\min(X, \pi) papers, so the profit is

r(X,π)=pmin⁡(X,π)−cπ,r(X, \pi) = p \min(X, \pi) - c\pi,

and the newsvendor chooses π\pi from S={0,1,…,K}S = \{0, 1, \dots, K\}. The upper bound KK comes from the newsvendor’s stand: it has room for at most KK newspapers, so ordering more is not possible. The example in Comparing Scenarios was a newsvendor problem with only two order sizes, 9 and 10.

In the code below, simulate simulates the profit of one order size n times:

For this simple example, the expected profit of every order size can also be calculated exactly. How to do this is outside the scope of this course, and for real-life simulation optimization problems it is in general not possible. We use the exact values, stored in true_value by the hidden cell below, only to check how well the methods do.

Source
best order size: 8
expected profit of order size 8: 1.540
expected profit of order size 10: 1.249

Ordering 8 papers is best, not 10: with leftovers worthless and a small margin of €0.25 per sold paper, the newsvendor should order less than the mean demand.

Option 1: Split the Budget Equally

The natural first approach is to simulate every solution m/km/k times, estimate E[r(X,π)]E[r(X, \pi)] for each π\pi by the average of its runs, and return the solution with the highest average. Let y(π)y(\pi) and s2(π)s^2(\pi) denote the sample average and sample variance computed from the runs of π\pi (the Xˉ\bar X and SX2S_X^2 of Comparing Scenarios). With s2(π)s^2(\pi) we can also give a 95% CI for each E[r(X,π)]E[r(X, \pi)].

For the newsvendor, a budget of m=4200m = 4200 runs gives 200 runs per order size:

selected order size: 8
estimated expected profit: 1.600
Loading...

Figure 1:95% CIs for the expected profit of every order size, each based on 200 runs, with the true expected profit.

Figure 1 shows the CIs. The CIs for small order sizes are very narrow (see Exercise 1). Around the optimum, the CIs of order sizes 7, 8 and 9 overlap: the budget is not enough to tell them apart. At the same time, a large part of the budget went to order sizes 14 to 20, whose CIs lie far below the others after a few runs already.

Because of the noise, option 1 shows both problems mentioned in About Simulation Optimization: it may select the wrong order size, and the estimated profit of the selected order size tends to be too high. To see how often this happens, we repeat option 1 1000 times:

fraction best order size selected: 0.54
average overestimation of the profit: 0.056

Option 1 selects the best order size 8 only about half of the time; otherwise it mostly selects 7 or 9. And the estimate of the selected order size’s expected profit is too high on average, because we select the order size whose estimate happened to come out high.

Common Random Numbers

The code above draws new demands for every order size. As in Comparing Scenarios, we can also use common random numbers: simulate one set of demands and evaluate every order size on the same demands. This does not make the individual CIs narrower, but it reduces the variance of the differences between order sizes, and these differences decide which order size is selected. In a discrete-event simulation it is the same: reuse the same customer arrival moments for every candidate solution.

Option 2: Discard Bad Solutions Early

Option 1 spends as many runs on clearly bad solutions as on promising ones. Option 2 first simulates all solutions a limited number of times, discards the solutions that are significantly worse than another solution, and spends the rest of the budget on the remaining ones. In general terms, with k=∣S∣k = |S| solutions and a budget of mm runs:

  1. Simulate every solution m0m_0 times, where m0<⌊m/k⌋m_0 < \lfloor m/k \rfloor is the number of runs per solution in this first round (⌊⋅⌋\lfloor \cdot \rfloor rounds down to an integer). Compute the average y(π)y(\pi) and the sample variance s2(π)s^2(\pi) of each solution.

  2. For every pair of solutions (π,π′)(\pi, \pi'), test whether π\pi is significantly worse than π′\pi'.

  3. Discard every solution that is significantly worse than at least one other solution. The solutions that remain form the set II.

  4. Divide the remaining budget m−km0m - k m_0 evenly over the solutions in II, and return the solution in II with the highest average.

When to Discard a Solution

Consider first one pair of solutions π\pi and π′\pi', each simulated m0m_0 times, independently. We maximize, so π\pi is worse than π′\pi' if E[r(X,π)]<E[r(X,π′)]E[r(X, \pi)] < E[r(X, \pi')]. We only discard π\pi if the data give strong evidence for this, so this is the alternative hypothesis of a one-sided test:

H0(π,π′):E[r(X,π)]≥E[r(X,π′)](π is not worse than π′),H1(π,π′):E[r(X,π)]<E[r(X,π′)](π is worse than π′).\begin{aligned} H_0(\pi, \pi') &: E[r(X, \pi)] \ge E[r(X, \pi')] \quad (\pi \text{ is not worse than } \pi'), \\ H_1(\pi, \pi') &: E[r(X, \pi)] < E[r(X, \pi')] \quad (\pi \text{ is worse than } \pi'). \end{aligned}

The difference of the averages y(π′)−y(π)y(\pi') - y(\pi) has variance (σ2(π)+σ2(π′))/m0(\sigma^2(\pi) + \sigma^2(\pi'))/m_0, which we estimate with the sample variances. So the test statistic

T=y(π′)−y(π)s2(π)+s2(π′)/m0T = \frac{y(\pi') - y(\pi)}{\sqrt{s^2(\pi) + s^2(\pi')}/\sqrt{m_0}}

has approximately a tt-distribution with m0−1m_0 - 1 degrees of freedom if the two expectations are equal, and a large value of TT is evidence for H1H_1. As on the slides, let βq\beta_q be the inverse of this tt-distribution at qq: the number bb with P(T≤b)=qP(T \le b) = q. In Python, βq\beta_q is stats.t.ppf(q, m0 - 1). A one-sided test at significance level α\alpha rejects H0(π,π′)H_0(\pi, \pi') if T≥β1−αT \ge \beta_{1-\alpha}, that is, if

y(π)≤y(π′)−β1−α s2(π)+s2(π′)m0.y(\pi) \le y(\pi') - \beta_{1-\alpha}\, \frac{\sqrt{s^2(\pi) + s^2(\pi')}}{\sqrt{m_0}}.

For α=0.05\alpha = 0.05 and m0=100m_0 = 100, β0.95=1.66\beta_{0.95} = 1.66. For large m0m_0, the tt-distribution is close to the standard normal distribution, so the normal critical values are a good approximation (1.64 here); the exercises use them for calculations by hand.

The Multiple-Testing Problem and the Šidák Correction

With kk solutions, we discard π\pi as soon as one of the k−1k - 1 tests against the other solutions rejects H0(π,π′)H_0(\pi, \pi'). Even if π\pi is the best solution, each of these tests can reject by chance, and the more tests, the larger the probability that at least one of them does. Compare it with a multiple-choice exam that you take together with k−1k - 1 monkeys that answer at random: the more monkeys, the larger the chance that one of them beats you by luck, and we should not conclude from that that this lucky monkey knows more about the exam’s topic than you do. In the same way, a solution that beats π\pi in one of many tests by luck is not necessarily better than π\pi. So if every test is done at level α=0.05\alpha = 0.05, the probability of discarding the best solution is much larger than 5%.

We want the probability of discarding the best solution to be at most α\alpha. Therefore we do each test at a stricter, “conservative” level α∗\alpha^*. If π\pi is the best solution, all k−1k - 1 hypotheses H0(π,π′)H_0(\pi, \pi') are true, and each test does not reject with probability (at least) 1−α∗1 - \alpha^*. The k−1k - 1 tests are not independent: they all use the same average y(π)y(\pi), so if y(π)y(\pi) happens to be low, π\pi looks bad in all comparisons at once. This dependence is positive (the tests tend to reject together), and as a result the probability that none of the k−1k - 1 tests rejects is at least what it would be for independent tests:

P(the best solution is not discarded)≥(1−α∗)k−1.P(\text{the best solution is not discarded}) \ge (1 - \alpha^*)^{k-1}.

The Šidák correction chooses α∗\alpha^* such that this lower bound equals 1−α1 - \alpha:

(1−α∗)k−1=1−α⟹α∗=1−1−αk−1.(1 - \alpha^*)^{k-1} = 1 - \alpha \quad\Longrightarrow\quad \alpha^* = 1 - \sqrt[k-1]{1-\alpha}.

Then the best solution survives with probability at least 1−α1 - \alpha.

You may know the Bonferroni correction from the statistics part of the course, which takes α∗=α/(k−1)\alpha^* = \alpha/(k-1). It also guarantees that the best solution survives with probability at least 1−α1 - \alpha, but the Šidák level is always a bit larger: 1−1−αk−1>α/(k−1)1 - \sqrt[k-1]{1-\alpha} > \alpha/(k-1). So with the Šidák correction each test is slightly less strict and discards bad solutions a bit more often, with the same guarantee for the best solution. Here the difference is small: for k=21k = 21 and α=0.05\alpha = 0.05, Bonferroni gives α∗=0.0025\alpha^* = 0.0025 and Šidák α∗≈0.0026\alpha^* \approx 0.0026.

For the newsvendor, with k=21k = 21 and α=0.05\alpha = 0.05, this gives α∗≈0.0026\alpha^* \approx 0.0026 and, with m0=100m_0 = 100, β1−α∗≈2.86\beta_{1-\alpha^*} \approx 2.86 instead of β0.95=1.66\beta_{0.95} = 1.66: a much stricter bar for declaring a solution worse, because it is tested against many other solutions at once. The set of solutions that survive the first round is

I={π∈S  |  y(π)>y(π′)−β1−α∗s2(π)+s2(π′)m0 for all π′≠π}.I = \left\{ \pi \in S \;\middle|\; y(\pi) > y(\pi') - \beta_{1-\alpha^*} \frac{\sqrt{s^2(\pi)+s^2(\pi')}}{\sqrt{m_0}} \text{ for all } \pi' \ne \pi \right\}.

Option 2 for the Newsvendor

We use the same budget m=4200m = 4200 as for option 1, with m0=100m_0 = 100 runs per order size in the first round. That leaves 4200−21×100=21004200 - 21 \times 100 = 2100 runs for the second round. Steps 1 to 3:

alpha* = 0.0026, beta = 2.86
I = [7, 8, 9, 10, 11]
Loading...

Figure 2:95% CIs for the expected profit of every order size after the first round of option 2 (100 runs each). The grey order sizes are discarded.

Figure 2 shows which order sizes survive. Small order sizes are discarded: because their CIs are so narrow, the data show clearly that they are worse than the best order sizes. In step 4 we divide the remaining 2100 runs over the survivors, add them to the runs of the first round, and select the order size with the highest average:

420 extra runs per surviving order size
selected order size: 8, estimate: 1.498

The five survivors now get 520 runs each instead of 200. To compare the two options fairly, we repeat both 1000 times with the same budget, with option 2 wrapped in a function option_2 that follows the code above line by line:

Source
option 1: best order size selected 0.54
option 2: best order size selected 0.66

With the same budget, option 2 finds the best order size more often than option 1, because it spends more runs where it matters: on the order sizes that are hard to tell apart. It does not remove the problems of noise completely: the expected profits of order sizes 7 and 9 are only €0.03 and €0.08 below that of order size 8, and telling them apart reliably needs many more runs.

References

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

  • Šidák, Z. (1967). “Rectangular confidence regions for the means of multivariate normal distributions.” Journal of the American Statistical Association, 62:626–633.