Chapter 11 · Part 4: Doing it honestly
Evaluating RL honestly
Learn why a single RL result is a small, skewed sample over runs, and how to report it with intervals, robust aggregates and honest tests.
Chapters 1 to 10 asked what an agent is estimating and how well. This last chapter turns the question on ourselves. We train an algorithm a handful of times, get a handful of numbers, and want to say "method B beats method A". That sentence is an inference about a population of runs, made from a very small sample, and it deserves the care we would give any clinical-trial-sized comparison. Most of the tools are ones you already know. What is new is how badly RL breaks the assumptions behind the default versions of them.
What is the random variable, and what is the unit of replication?
Fix an algorithm, an environment and a budget (say one million environment steps). Run training once with a random seed. The seed drives the network initialisation, the exploration noise, the order of minibatches and often the environment's own randomness. At the end, evaluate the final policy and record a score : for example the mean return over 10 evaluation episodes.
Run the whole procedure again with a new seed and you get a different . So is a random variable whose distribution is over runs. Write for the algorithm's population mean score. Doing runs gives iid draws and the usual estimator .
Two sources of noise get conflated here:
- Between-run noise: different seeds produce different policies. This is what we want to generalise over.
- Within-run evaluation noise: given one trained policy, its 10 evaluation episodes are noisy estimates of that policy's true return.
Evaluating one policy on 1,000 episodes instead of 10 shrinks the second kind of noise and does nothing to the first. If runs are the units, the evaluation episodes inside a run are like repeated measurements on one subject: they reduce measurement error on that subject but add no subjects. Treating 10 seeds times 100 episodes as 1,000 independent observations is pseudoreplication, and it produces intervals that are far too narrow. The effective sample size for a claim about the algorithm is the number of seeds.
(Henderson et al., 2018) made this vivid. They ran one algorithm many times, split the runs into two groups of 5, and compared the groups' average learning curves. The two groups could look clearly different even though both came from the same algorithm. Five seeds per arm is a number that looks like a sample size and behaves like noise.
Why are run scores badly behaved?
Three features of RL run scores break the textbook recipe.
Skew and heavy tails. Return is often bounded below and unbounded above, and one lucky run that finds a good strategy can dwarf the others. Means of heavy-tailed variables converge slowly, and the -interval's coverage depends on the sample mean being close to normal. At that is a weak assumption.
Bimodality from failures. Many algorithms either solve a task or get stuck. The distribution of final scores is a mixture: with probability the run fails and lands near the floor, with probability it succeeds and lands near some success level. Two algorithms can share a success level and differ only in . A mixture of this kind has a large variance, and its mean and median can be far apart.
Heteroscedasticity. Algorithms differ in how variable they are, not just in their mean. The pooled-variance two-sample -test assumes equal variances; use the Welch version, which does not.
The experiment below uses exactly this mixture. A run fails with probability and scores ; otherwise it scores with , which is lognormal with median 100. Algorithm A has and algorithm B has , so B is better by about 9 points on a scale where the run-to-run standard deviation is about 48.
How do we get a confidence interval over runs?
With run scores , the classical interval for the mean is
It is exact for normal data. For skewed data it is only asymptotically right, and with in single digits the quantile is large (4.30 at , 2.78 at ) and the interval is very wide. The second feature is more important than coverage. A 95% interval of width 117 around a mean of 78, which is what gives in the experiment below, is the honest statement of what five seeds say.
The percentile bootstrap avoids a distributional assumption. Resample the runs with replacement times, compute the statistic on each resample, and take the 2.5% and 97.5% quantiles of those values. It works for any statistic: a mean, a median, an IQM. Its weakness is the small-sample regime we care about. A resample of 5 runs can only contain values you have seen, so it cannot produce the unseen failure or the unseen lucky run, and percentile intervals are systematically too narrow at small . The experiment shows this: undercoverage that disappears slowly.
What should we report instead of the mean?
The interquartile mean
(Agarwal et al., 2021) argued that the median and the mean are both poor aggregates: the median ignores most of the data, and the mean is dominated by outliers. They propose the interquartile mean (IQM): sort the scores, discard the lowest 25% and highest 25%, average the rest. It is a 25%-trimmed mean. It is more efficient than the median for roughly normal data and much less sensitive to a single outlier than the mean. In their setting the scores are normalised returns pooled over runs and tasks. In this chapter's code, for a single task, the IQM drops values from each end, so for it equals the mean.
A trimmed mean estimates a different population quantity than the mean does. If the score distribution is skewed, the IQM and the mean disagree, and that is the point: the IQM answers "what does a typical run achieve", the mean answers "what is the expected score, rare failures and windfalls included". Choose the target before looking at the data, and say which one it is. Whichever you choose, put an interval on it.
Stratified bootstrap across tasks
Often there are several tasks (games, control problems) and several runs on each. The same ideas apply with two levels of randomness. Agarwal et al. use a stratified bootstrap: for each task, resample that task's runs with replacement, keeping the number of runs per task fixed, then aggregate across tasks, and repeat. This resamples runs but never tasks, so it quantifies uncertainty from seeds on this task suite. It does not say how the algorithm would do on a different suite of tasks, which is a separate and usually larger source of uncertainty.
Performance profiles
An aggregate hides shape. A performance profile plots, for each score threshold , the fraction of runs (or run-task pairs) with score above . This is one minus the empirical CDF of scores. With bimodal outcomes it shows two things at once: the failure rate (where the curve first drops) and the success level (where it falls to zero). Bootstrap bands around it are pointwise intervals on a CDF. Where one profile lies above the other at every , one algorithm stochastically dominates the other; where they cross, no single number ranks them.
Probability of improvement
Agarwal et al. also report the probability of improvement of algorithm Y over X: for a randomly drawn run of each. The estimator is the Mann–Whitney statistic,
This is the area under the ROC curve for classifying a run as coming from X or Y using its score, and means the two samples are indistinguishable. It uses only ranks, so a lucky outlier cannot dominate it. It also answers a question practitioners ask: "if I run both once, how likely is it that the new method wins?". For a small true gap relative to the spread, that probability is modest, which is the honest summary of "slightly better".
Worked example by hand: five seeds, two algorithms
Final scores of five seeds each:
| Seed | A | B |
|---|---|---|
| 1 | 52 | 48 |
| 2 | 58 | 50 |
| 3 | 61 | 53 |
| 4 | 65 | 57 |
| 5 | 94 | 62 |
Means: and . The A mean is pulled up by the 94.
Sample variances (divide by ). For A the deviations from 66 are , with squares , sum 1070, so and . For B the deviations from 54 are , squares , sum 126, so and .
Welch's standard error of the difference:
The statistic is . The Welch–Satterthwaite degrees of freedom are
The two-sided 5% critical value of is about 2.58, and the -value is about 0.18. We do not reject. Note how much of A's lead is one seed: remove the 94 and A's mean falls from 66 to 59, so the gap shrinks from 12 to 5.
IQM with : drop value from each end. For A we drop 52 and 94 and average 58, 61, 65: . For B we drop 48 and 62 and average 50, 53, 57: . The gap shrinks from 12 to 8 because the outlier no longer counts. The IQM is still not a significance test, and with five values per arm its bootstrap interval would be wide and too narrow at the same time. This is as much as five seeds can give.
How many seeds do we need? Errors and power
A hypothesis test makes two kinds of error. A type I error (false positive) is declaring a difference when the algorithms are identical. A type II error (false negative) is missing a real difference. The type I rate is set by the significance level (if assumptions hold). The power is , where is the type II rate, and it depends on the true gap , the standard deviation of run scores, and .
(Colas, Sigaud and Oudeyer, 2018) wrote a tutorial on exactly this for deep RL: how the number of seeds controls these error rates for Welch's -test and for a bootstrap-interval test, and what happens when assumptions fail. Their follow-up (Colas et al., 2019) compares a range of tests on false-positive rate and power as functions of sample size and effect size, checks robustness to non-normality and unequal variances, and gives a practical procedure.
For a rough sample-size calculation, use the normal approximation for a two-sided test at and power 0.8. The required number of seeds per algorithm is
With this chapter's populations, and , giving seeds per algorithm. That sounds absurd for deep RL where a run can cost days of compute. It is not absurd: it is what a gap of 0.19 standard deviations costs in any field. The sensible conclusions are that either the effect you care about is larger (a method that moves the mean by one standard deviation needs about 16 seeds per arm) or that a small difference will remain unresolved, and the report should say so.
Multiple comparisons
Suppose you compare two algorithms on 20 tasks and report the tasks where . If nothing differs anywhere and the tests are independent, you expect one false discovery and the chance of at least one is . The remedies are the usual ones. Bonferroni compares each to . Holm–Bonferroni is uniformly more powerful with the same family-wise guarantee: sort the -values , find the first with , and reject all hypotheses before it. If the question is a count of wins over many tasks, you may prefer to estimate an aggregate over tasks with a stratified bootstrap, which avoids running many tests at all.
Hyperparameter tuning is selective inference
Every algorithm in a benchmark comes with hyperparameters, and the usual practice is to tune and then report. If the same seeds are used to choose the best configuration and to report its score, the reported score is the maximum of several noisy estimates. This is the winner's curse and the maximisation bias from chapter 7: . It is also the garden of forking paths: each choice (learning rate, network width, which seeds to discard as "unlucky") is a test you ran and did not count.
The fix is the one from the bandit and regression chapters: sample splitting. Choose configurations on one set of seeds. Report the chosen configuration's score on a fresh set of seeds that played no role in the choice. A weaker but common fix is to give baselines the same tuning budget as the proposed method, since an under-tuned baseline is another source of bias, in the direction authors prefer.
Experiment: four ways five seeds mislead
The file ch11_evaluation.py simulates run scores from the mixture above. It implements Welch's test from scratch: the Student- CDF comes from the regularised incomplete beta function, so -values use the reference distribution with Welch–Satterthwaite degrees of freedom. That is an approximation, since run scores are not normal; part (b) measures how good it is. Here is the output.
Population: run score = Uniform(0,30) w.p. p_fail, else 100*LogNormal(0,0.3)
A: p_fail=0.30 mean= 77.72 IQM= 79.88
B: p_fail=0.20 mean= 86.68 IQM= 90.65
gap in means = 8.96
(a) P(correct ranking: B ranked above A), 4000 replications
n seeds mean IQM
3 0.593 0.593
5 0.611 0.599
10 0.655 0.660
30 0.761 0.761
(b) Welch t-test, alpha=0.05, 2000 replications
n seeds false pos (A vs A) power (A vs B)
3 0.036 0.037
5 0.044 0.050
10 0.043 0.074
30 0.048 0.109
100 0.046 0.267
(c) 95% interval coverage for algorithm A, 1000 replications, 1000 bootstrap draws
n seeds t-int mean width boot mean width boot IQM width
3 0.947 223.4 0.740 84.4 0.746 84.4
5 0.943 116.8 0.840 72.3 0.900 91.2
10 0.950 68.8 0.914 56.1 0.937 69.2
30 0.954 36.7 0.934 34.4 0.951 44.0
(d) Best of 5 configs picked on the same seeds, 4000 replications
configs differ in p_fail; reported = mean over the seeds used to choose,
fresh = mean over new seeds for the chosen config; truth = its population mean
spread configs: p_fail = [0.2, 0.225, 0.25, 0.275, 0.3]
n seeds reported fresh truth optimism
3 114.40 82.27 82.64 31.76
5 107.37 82.91 82.81 24.56
10 100.03 83.28 83.15 16.88
30 92.97 83.58 83.63 9.35
identical configs: p_fail = [0.25, 0.25, 0.25, 0.25, 0.25]
n seeds reported fresh truth optimism
3 114.21 81.44 82.20 32.01
5 107.26 82.11 82.20 25.05
10 99.86 82.21 82.20 17.66
30 92.30 82.19 82.20 10.10Ranking (a). With 3 seeds per algorithm, B is ranked above A in 59% of experiments. With 5 seeds it is 61%, with 10 it is 66%, and even 30 seeds rank them correctly only 76% of the time. The gap is real and favours B in every one of these experiments, and the sample means still disagree with the truth a quarter of the time at . The IQM does about as well as the mean here, not better. That is worth saying plainly: the IQM's robustness helps when there are outliers within the success mode, and here the dominant noise is the failure rate itself, which the IQM sees as clearly as the mean does.
Test (b). The Welch test controls the false positive rate when the two algorithms are identical, even with this skewed bimodal distribution: the rates are 3.6% to 4.8%, at or slightly below the nominal 5%, and they get closer to 5% as grows. At it is conservative. That is good news for validity and bad news for power: the test almost never detects the real gap. Power is 3.7% at , 5% at , 7% at , 11% at , and 27% at . At 100 seeds we would still miss the gap three times out of four. This matches the sample-size formula above (about 450 seeds for 80% power). The type I rate of a test says nothing about whether it is useful; a test that always says "no difference" has a perfect type I rate.
A caution about what this result does not show. The type I rate here is acceptable because the skew is moderate and the two samples have the same distribution. With a heavier tail, or when the two algorithms have different shapes, Welch's test can have false-positive rates well off nominal at small , and you can check this by changing in the code. Check the type I rate by simulation when you can, not by assertion.
Intervals (c). The -interval for the mean has coverage between 94% and 95% for all , even at where it is 223 units wide around a mean of 78. The coverage is fine and the interval is nearly useless: it contains most of the plausible score range. The percentile bootstrap for the mean has coverage of 74% at , 84% at , 91% at and 93% at . The bootstrap interval for the IQM is similar at (where the IQM is the mean) and gets better faster: 90% at , 94% at , 95% at . These intervals are narrower than the interval at small precisely because they undercover. They are wider than the bootstrap mean at larger because the IQM has a different target and a different sampling distribution, and the extra width buys coverage. So neither one dominates: the -interval is the safer choice for the mean at small in this simulation, and the bootstrap should be trusted only at of around 10 or more. The IQM interval is a reasonable choice for the IQM from .
Tuning (d). With five configurations that all have the same true mean, picking the best on 5 seeds reports a score of 107.3 for something whose true mean is 82.2, an optimism of 25 points. With 3 seeds the optimism is 32, with 30 seeds it is 10. The bias is the expected maximum of five noisy estimates and it is roughly times the expected maximum of five standard normals (about 1.16). The fresh-seed column recovers the truth in each row: 82.1 against 82.2 at . When the configurations really do differ (p_fail from 0.20 to 0.30), the optimism is still 25 points at , and selection chooses a configuration whose true mean is 82.8 whereas the best available is 86.7 (the one with ). Tuning on 5 seeds finds the best configuration only slightly better than at random. Report numbers like "107" and you have published a number that no replication will reproduce.
A reporting checklist
- State the unit: number of independent runs (seeds) per algorithm per task, and how seeds were chosen. Never count evaluation episodes as replications.
- Pick the aggregate and the question in advance: mean (expected score), median or IQM (typical run), probability of improvement (which wins). Say which.
- Give an interval for every number, and say what kind it is: -interval, percentile or BCa bootstrap, stratified across tasks. Say whether shaded bands are standard deviation or standard error.
- Show the distribution, not only a summary: a performance profile, a strip plot of run scores, or the failure rate. For failure-prone algorithms report the fraction of runs that failed.
- Compare with an appropriate test (Welch, not pooled variance; or a rank or permutation test for skew) and report the effect size with its interval, not only the -value.
- Report power or the sample size justification. If you cannot detect the effect size you care about, say so.
- Correct for multiple comparisons across tasks and metrics (Holm), or aggregate across tasks instead.
- Separate tuning from reporting. Choose hyperparameters on seeds that are not used for the final numbers, give baselines the same tuning budget, and report how many configurations were tried.
- Don't drop runs after seeing their results. If a run is excluded, the rule must be fixed before looking at scores.
- Release the per-run scores and the code, so someone can recompute the intervals.
Closing: what the course was about
Every chapter had the same plot. An agent wants a quantity (a return, a value, a gradient, a reward model, a policy's score) and gets only noisy, often biased and often dependent samples of it, collected by a process that itself depends on what it has learned so far. That last clause is what separates RL from textbook estimation. The data are generated under feedback: the policy affects which data arrive (chapter 2), targets are built from the estimator itself (chapter 4 and the chapters after), and the objective is only observed through its own samples (chapter 8).
This chapter applies that lesson to the people. A researcher also learns under feedback: runs a few seeds, looks at the numbers, adjusts the method, tries again, and reports the best-looking result. Every problem in the course has an analogue in that loop. The sample mean of a small number of runs is a noisy estimate. The best of several tuned configurations is a winner's curse. Looking at results and then deciding what to test is adaptive data collection. The cure in each case is the one the statistician already had: define the estimand, count the units of replication, put an interval on the estimate, and hold out data that played no role in selection. RL is estimation under feedback, and so is the practice of doing RL research.
Exercises
- Pen and paper. Using the worked example, compute the probability of improvement for the two five-seed samples. Compare it with what the Welch test said.
- Pen and paper. An algorithm's run scores have standard deviation 20. You care about a gap of 5 points. How many seeds per arm give 80% power at with the normal approximation? What if the gap is 10?
- Change the code and predict. Set
P_B = 0.30so the algorithms are identical, and look at the output of (a) and (b). What should the ranking probability be at every ? Then change the failure score range or the lognormal to make the skew much heavier and check whether Welch's false-positive rate moves away from 5% at . - Change the code and predict. In (d), the
pslist sets the number of configurations. Try 2 and 20 configurations at . How does the gap between the reported and fresh columns change? Predict the direction before running. - Change the code and predict. Add a Mann–Whitney test or a permutation test of the difference in means to (b). Is it more powerful than Welch's test for this distribution? Why or why not?
Sources
- Henderson, P., Islam, R., Bachman, P., Pineau, J., Precup, D., Meger, D. (2018). Deep Reinforcement Learning that Matters. AAAI 2018.
- Agarwal, R., Schwarzer, M., Castro, P. S., Courville, A., Bellemare, M. G. (2021). Deep Reinforcement Learning at the Edge of the Statistical Precipice. NeurIPS 2021 (outstanding paper award).
- Colas, C., Sigaud, O., Oudeyer, P.-Y. (2018). How Many Random Seeds? Statistical Power Analysis in Deep Reinforcement Learning Experiments.
- Colas, C., Sigaud, O., Oudeyer, P.-Y. (2019). A Hitchhiker's Guide to Statistical Comparisons of Reinforcement Learning Algorithms.