RLS RL, Read as Statistics

Chapter 02 · Part 1: Estimating from experience

Bandits as sequential experiments

A bandit is a sequential experiment whose allocation adapts to the data; UCB1 turns a Hoeffding confidence bound into a decision rule, and adaptivity biases the sample mean.

Chapter 1 described RL as estimation plus decision under feedback and promised a special case with no future to worry about. This is it. Take an MDP with a single state: the action affects only the reward you get now, not where you will be next. What is left is the cleanest version of the central conflict. You must learn which action is best by trying them, and every trial of a worse action costs you. Think of a clinical trial that can reassign patients, or a site choosing which headline to show.

What is a multi-armed bandit?

There are KK arms (actions). Arm aa has an unknown reward distribution PaP_a with mean μa\mu_a. In each round t=1,…,Tt = 1, \dots, T the learner picks an arm AtA_t and observes a reward Rt∼PAtR_t \sim P_{A_t}, drawn independently of the past given AtA_t. In a bandit the reward of round tt is written RtR_t, as in the notation page, since there is no next state to index against. Only the pulled arm's reward is observed.

Write μ∗=max⁡aμa\mu^* = \max_a \mu_a and Δa=μ∗−μa\Delta_a = \mu^* - \mu_a for the gap of arm aa: how much you lose per pull by choosing aa instead of the best arm. Let Na(t)N_a(t) be the number of times arm aa was pulled in the first tt rounds, and μ^a(t)\hat\mu_a(t) the sample mean of the rewards from those pulls. The learner's choice AtA_t may depend on everything seen before round tt: that is what a policy means here, and it is where the statistical difficulty enters.

In this chapter rewards lie in [0,1][0,1] (for example Bernoulli). That is what makes Hoeffding's inequality applicable.

How does a bandit differ from an A/B test?

A classical A/B/n test fixes the design in advance. It allocates nn units to each of the KK arms, estimates each μa\mu_a with Xˉn\bar X_n, tests, and then acts on the result. The design is non-adaptive, so each Xˉn\bar X_n is a plain sample mean of i.i.d. draws: unbiased, with standard error σa/n\sigma_a / \sqrt{n}, and the usual intervals and tests apply. What you pay is the allocation. During the whole experiment, a fraction (K−1)/K(K-1)/K of the units go to arms that are not the best, and if the test never stops (a "uniform" policy over a horizon TT), you lose a constant fraction of the best arm's reward forever.

A bandit algorithm adapts: it shifts allocation toward arms that look better as data accumulate. This cuts the loss from experimentation dramatically, but destroys the fixed design. Which units go to arm aa is now a random function of earlier outcomes, so the data are not i.i.d. in the usual sense. The price is paid in estimation, and the last half of this chapter is about that price.

What is regret?

The learner's performance is measured against an oracle that knows the means and always pulls the best arm. The expected regret over TT rounds is

Regret(T)=Tμ∗−E[∑t=1TRt].\mathrm{Regret}(T) = T\mu^* - \mathbb{E}\Big[\sum_{t=1}^{T} R_t\Big].

The expectation is over the rewards and any randomisation in the policy. Regret has a decomposition that is used constantly.

Regret decomposition. Regret(T)=∑aΔa E[Na(T)]\mathrm{Regret}(T) = \sum_{a} \Delta_a\, \mathbb{E}[N_a(T)].

Proof. Conditional on the past and on AtA_t, the reward has mean μAt\mu_{A_t}, so E[Rt∣At]=μAt\mathbb{E}[R_t \mid A_t] = \mu_{A_t} (tower property; this is where "the reward is drawn from PAtP_{A_t} independently of the past" is used). Hence E[∑tRt]=E[∑tμAt]=∑aμaE[Na(T)]\mathbb{E}[\sum_t R_t] = \mathbb{E}[\sum_t \mu_{A_t}] = \sum_a \mu_a \mathbb{E}[N_a(T)]. Since ∑aNa(T)=T\sum_a N_a(T) = T, Tμ∗−∑aμaE[Na(T)]=∑a(μ∗−μa) E[Na(T)]T\mu^* - \sum_a \mu_a \mathbb{E}[N_a(T)] = \sum_a (\mu^* - \mu_a)\,\mathbb{E}[N_a(T)]. □\square

So regret is a sum over suboptimal arms of gap times expected number of pulls. To have small regret you must pull each bad arm rarely, and the smaller its gap the more pulls you need to rule it out. The conflict is quantitative: to tell an arm with gap Δ\Delta from the best one takes on the order of 1/Δ21/\Delta^2 samples, which costs about Δ⋅(1/Δ2)=1/Δ\Delta \cdot (1/\Delta^2) = 1/\Delta in regret. Hold that scaling in mind; it reappears in every bound below.

A policy that allocates uniformly has regret (T/K)∑aΔa(T/K)\sum_a \Delta_a, linear in TT. The goal is sublinear regret, ideally O(log⁡T)O(\log T) for fixed gaps.

In simulations we use the pseudo-regret ∑tΔAt\sum_t \Delta_{A_t}, which replaces the observed rewards by their means. It has the same expectation as the regret (by the decomposition) and removes reward noise from the estimate.

What does Hoeffding's inequality say, and where does it come from?

To decide whether an arm is worse, we need to bound how far a sample mean can sit from its true mean. Hoeffding's inequality (Hoeffding, 1963) does so for bounded variables: if X1,…,XnX_1, \dots, X_n are independent with Xi∈[0,1]X_i \in [0,1] and mean μ\mu, then for ε>0\varepsilon > 0

Pr⁡(Xˉn−μ≥ε)≤e−2nε2,Pr⁡(Xˉn−μ≤−ε)≤e−2nε2.\Pr(\bar X_n - \mu \ge \varepsilon) \le e^{-2n\varepsilon^2}, \qquad \Pr(\bar X_n - \mu \le -\varepsilon) \le e^{-2n\varepsilon^2}.

Unlike the CLT it holds at every nn with no normality assumption, at the price of using only the range, not the variance.

Sketch of the derivation. This is the Chernoff method, with one lemma.

  1. Hoeffding's lemma. If X∈[0,1]X \in [0,1] and E[X]=μ\mathbb{E}[X] = \mu, then E eλ(X−μ)≤eλ2/8\mathbb{E}\, e^{\lambda (X - \mu)} \le e^{\lambda^2/8} for every real λ\lambda. (Proof idea: the log of the moment-generating function is 00 with derivative 00 at λ=0\lambda = 0, and its second derivative is the variance of an exponentially tilted copy of XX, a variable on an interval of length 11, hence at most 1/41/4. Taylor's theorem then gives λ2/8\lambda^2/8.)
  2. Chernoff step. For λ>0\lambda > 0, Markov's inequality applied to eλn(Xˉn−μ)e^{\lambda n (\bar X_n - \mu)} gives

Pr⁡(Xˉn−μ≥ε)≤e−λnε E eλ∑i(Xi−μ)=e−λnε∏i=1nE eλ(Xi−μ)≤e−λnε+nλ2/8,\Pr(\bar X_n - \mu \ge \varepsilon) \le e^{-\lambda n \varepsilon}\, \mathbb{E}\, e^{\lambda \sum_i (X_i - \mu)} = e^{-\lambda n\varepsilon} \prod_{i=1}^n \mathbb{E}\, e^{\lambda (X_i - \mu)} \le e^{-\lambda n \varepsilon + n\lambda^2/8},

using independence for the product and the lemma for each factor. 3. Optimise λ\lambda. The exponent −λnε+nλ2/8-\lambda n\varepsilon + n\lambda^2/8 is minimised at λ=4ε\lambda = 4\varepsilon and equals −2nε2-2n\varepsilon^2. □\square

Inverting it gives a confidence bound. Setting the right-hand side to δ\delta and solving for ε\varepsilon, with probability at least 1−δ1-\delta,

μ≤Xˉn+ln⁡(1/δ)2n.\mu \le \bar X_n + \sqrt{\frac{\ln(1/\delta)}{2n}}.

This is a one-sided confidence bound whose width shrinks like 1/n1/\sqrt{n}, as in the CLT interval.

What is UCB1, and why is it a confidence bound?

If you had a valid upper confidence bound on each arm's mean, a natural rule would be to behave as if each arm were as good as its bound allows, and pull the arm whose bound is highest. This is the principle of optimism in the face of uncertainty. It is self-correcting: an arm with few pulls has a wide interval, so its upper bound is high and it gets sampled; as it is sampled the interval shrinks, and if the arm really is bad its bound falls below the best arm's and sampling stops. An arm is pulled either because it looks good or because we do not know enough about it, and the algorithm needs no separate "explore" switch.

UCB1 (Auer, Cesa-Bianchi and Fischer, 2002) makes this concrete. Pull each arm once. Then, at round tt, pull

At=arg⁡max⁡a  μ^a(t−1)+2ln⁡tNa(t−1)⏟UCB index.A_t = \arg\max_a \; \underbrace{\hat\mu_a(t-1) + \sqrt{\frac{2\ln t}{N_a(t-1)}}}_{\text{UCB index}}.

The width is Hoeffding's with δ=t−4\delta = t^{-4}: ln⁡(t4)/(2n)=2ln⁡t/n\sqrt{\ln(t^4)/(2n)} = \sqrt{2\ln t / n}. The confidence level rises with tt, so that over the whole run only finitely many "bad events" are expected.

Why it works (sketch). Fix a suboptimal arm aa with gap Δa>0\Delta_a > 0. If arm aa is pulled at round tt with NaN_a pulls so far, then its index is at least the index of a best arm. That can happen only if at least one of three things holds:

  1. the best arm's index is below its true mean, μ^∗+w∗<μ∗\hat\mu^* + w^* < \mu^* (its confidence bound failed), which by Hoeffding has probability at most t−4t^{-4} for each possible count of pulls;
  2. arm aa's sample mean is too high (μ^a>μa+wa\hat\mu_a > \mu_a + w_a), also with probability at most t−4t^{-4} for each count;
  3. neither failed, but the width itself is large: 22ln⁡t/Na≥Δa2\sqrt{2\ln t / N_a} \ge \Delta_a, that is, Na≤8ln⁡t/Δa2N_a \le 8\ln t / \Delta_a^2.

Summing the failure probabilities over all rounds and all pairs of pull counts gives at most 2∑tt2⋅t−4=π2/32\sum_t t^2 \cdot t^{-4} = \pi^2/3. Case 3 can only occur while NaN_a is below 8ln⁡T/Δa28\ln T / \Delta_a^2. So E[Na(T)]≤8ln⁡T/Δa2+1+π2/3\mathbb{E}[N_a(T)] \le 8\ln T / \Delta_a^2 + 1 + \pi^2/3, and by the decomposition:

Regret(T)≤∑a: Δa>08ln⁡TΔa+(1+π23)∑aΔa.\mathrm{Regret}(T) \le \sum_{a:\,\Delta_a > 0} \frac{8 \ln T}{\Delta_a} + \Big(1 + \frac{\pi^2}{3}\Big)\sum_{a} \Delta_a.

This is a finite-time bound: it is valid for every TT, with no asymptotics. The regret grows like ln⁡T\ln T, so the per-round regret goes to zero.

Worked example by hand: two UCB indices

Suppose there are two arms with Bernoulli rewards and the algorithm has run for 1010 rounds. Arm 11 was pulled 66 times with 44 successes, arm 22 was pulled 44 times with 11 success. At round t=11t = 11:

  • μ^1=4/6≈0.667\hat\mu_1 = 4/6 \approx 0.667, N1=6N_1 = 6. Width 2ln⁡11/6\sqrt{2\ln 11 / 6}. Since ln⁡11≈2.398\ln 11 \approx 2.398, 2ln⁡11≈4.7962\ln 11 \approx 4.796 and the width is 0.799≈0.894\sqrt{0.799} \approx 0.894. Index ≈1.561\approx 1.561.
  • μ^2=1/4=0.25\hat\mu_2 = 1/4 = 0.25, N2=4N_2 = 4. Width 4.796/4=1.199≈1.095\sqrt{4.796/4} = \sqrt{1.199} \approx 1.095. Index ≈1.345\approx 1.345.

Arm 11 has the larger index and is pulled.

Now take a different state at t=22t = 22: arm 11 pulled 2020 times with sample mean 0.60.6, arm 22 pulled only twice with sample mean 0.50.5. Here 2ln⁡22≈6.1822\ln 22 \approx 6.182.

  • Arm 11: width 6.182/20=0.3091≈0.556\sqrt{6.182/20} = \sqrt{0.3091} \approx 0.556, index ≈1.156\approx 1.156.
  • Arm 22: width 6.182/2=3.091≈1.758\sqrt{6.182/2} = \sqrt{3.091} \approx 1.758, index ≈2.258\approx 2.258.

Arm 22 is pulled, even though its sample mean is lower, because it has hardly been tried. This is optimism at work. The script reproduces both calculations (they are the first block of output below).

What is the best any algorithm can do? The Lai–Robbins lower bound

UCB1's bound has the form const×ln⁡T\text{const} \times \ln T. Can any algorithm do better? Not in the following sense. Call a policy consistent over a class of bandit instances if for every instance in the class and every p>0p > 0, Regret(T)=o(Tp)\mathrm{Regret}(T) = o(T^p): it learns on every instance, whichever is the truth. This rules out "always pull arm 1", which has zero regret on some instances and linear regret on others.

Lai–Robbins (1985). For a consistent policy over, say, Bernoulli bandits, on every instance with a unique best arm,

lim inf⁡T→∞Regret(T)ln⁡T  ≥  ∑a: Δa>0Δakl(μa,μ∗),kl(p,q)=pln⁡pq+(1−p)ln⁡1−p1−q.\liminf_{T\to\infty} \frac{\mathrm{Regret}(T)}{\ln T} \;\ge\; \sum_{a:\,\Delta_a > 0} \frac{\Delta_a}{\mathrm{kl}(\mu_a, \mu^*)}, \qquad \mathrm{kl}(p, q) = p\ln\frac{p}{q} + (1-p)\ln\frac{1-p}{1-q}.

Here kl\mathrm{kl} is the KL divergence between Bern⁡(p)\operatorname{Bern}(p) and Bern⁡(q)\operatorname{Bern}(q). This is the result of Lai and Robbins (1985); for general reward families, kl(μa,μ∗)\mathrm{kl}(\mu_a, \mu^*) is replaced by the infimum of KL(Pa,P′)\mathrm{KL}(P_a, P') over distributions P′P' with mean above μ∗\mu^* (see Lattimore and Szepesvári, 2020, Chapter 16).

In words: any consistent policy must pull each suboptimal arm at least about ln⁡T/kl(μa,μ∗)\ln T / \mathrm{kl}(\mu_a, \mu^*) times. The reason is a hypothesis-testing one. The data from arm aa must rule out the alternative world in which arm aa is slightly better than the best arm, since there neglecting it would cost linear regret. Distinguishing Bern⁡(μa)\operatorname{Bern}(\mu_a) from Bern⁡(μ∗)\operatorname{Bern}(\mu^*) at an error level that tightens like 1/T1/T takes about ln⁡T/KL\ln T / \mathrm{KL} samples, by the likelihood-ratio logic of Neyman and Pearson.

Compare constants. By Pinsker's inequality kl(μa,μ∗)≥2Δa2\mathrm{kl}(\mu_a, \mu^*) \ge 2\Delta_a^2, so the lower bound is at most ∑a1/(2Δa)\sum_a 1/(2\Delta_a), while UCB1's is 8∑a1/Δa8 \sum_a 1/\Delta_a. Both scale as ∑a1/Δa\sum_a 1/\Delta_a, but UCB1's constant is up to 1616 times larger in the worst case. Auer et al. note that UCB2 reduces the leading constant to nearly 1/(2Δa2)1/(2\Delta_a^2) per arm. Closing that constant gap takes indices built from KL divergences rather than Hoeffding widths; chapter 3 approaches the same goal from the Bayesian side.

Why is the sample mean of an adaptively sampled arm biased?

Back to estimation. After the bandit run, you hold μ^a(T)\hat\mu_a(T) for each arm and might want to report it, with an interval, as the estimate of μa\mu_a. Under a fixed design that is a textbook sample mean. Under adaptive allocation it is biased.

A three-round example by hand. Two arms, both Bern⁡(0.5)\operatorname{Bern}(0.5), so both true means are 0.50.5. The policy: pull arm 1 once (reward XX), arm 2 once (reward YY), then pull again the arm whose first reward was higher (ties go to arm 1), and stop after three rounds. Let ZZ be the third reward. The four equally likely first outcomes give:

(X,Y)(X, Y)arm pulled thirdμ^1\hat\mu_1μ^2\hat\mu_2Eμ^1\mathbb{E}\hat\mu_1Eμ^2\mathbb{E}\hat\mu_2
(0,0)(0,0)1(0+Z)/2(0+Z)/2000.250.2500
(0,1)(0,1)200(1+Z)/2(1+Z)/2000.750.75
(1,0)(1,0)1(1+Z)/2(1+Z)/2000.750.7500
(1,1)(1,1)1(1+Z)/2(1+Z)/2110.750.7511

Averaging over the four rows (probability 1/41/4 each): Eμ^1=(0.25+0+0.75+0.75)/4=0.4375\mathbb{E}\hat\mu_1 = (0.25 + 0 + 0.75 + 0.75)/4 = 0.4375, and by the same arithmetic Eμ^2=0.4375\mathbb{E}\hat\mu_2 = 0.4375. Both estimators are biased by −0.0625-0.0625, with no difference between the arms. The mechanism is visible in the table. When arm 2's first reward is a 00, it is not pulled again, so its low value is frozen into the estimate. When arm 1's first reward is 11, it is pulled again and has a chance to regress towards the truth. Bad luck gets locked in; good luck gets diluted.

Why the sum is fine and the ratio is not. Let Sa(T)=∑t≤T1{At=a}RtS_a(T) = \sum_{t \le T} \mathbf{1}\{A_t = a\} R_t. The process ∑t≤T1{At=a}(Rt−μa)\sum_{t\le T} \mathbf{1}\{A_t = a\}(R_t - \mu_a) is a martingale (the indicator is determined by the past, and Rt−μaR_t - \mu_a has conditional mean zero when At=aA_t = a), so it has mean zero:

E[Sa(T)−μaNa(T)]=0,\mathbb{E}\big[S_a(T) - \mu_a N_a(T)\big] = 0,

a version of Wald's identity. But the sample mean is μ^a=Sa/Na\hat\mu_a = S_a / N_a, and μ^a−μa=(Sa−μaNa)/Na\hat\mu_a - \mu_a = (S_a - \mu_a N_a)/N_a. The numerator has mean zero, but the denominator is random and correlated with it: arms that did badly get a small NaN_a. This is the classical failure of a ratio estimator when the denominator depends on the data, as in E[S/N]≠E[S]/E[N]\mathbb{E}[S/N] \ne \mathbb{E}[S]/\mathbb{E}[N].

Naive intervals μ^a±1.96 σ^/Na\hat\mu_a \pm 1.96\,\hat\sigma/\sqrt{N_a} therefore lose their stated coverage after an adaptive run. Remedies exist, none free: sample splitting, inverse-propensity weighting when allocation probabilities are known (the subject of chapter 6), and the selective-inference correction of Nie et al. (2018).

Experiment: regret and bias

The companion code, ch02_bandits.py, runs these policies on five Bernoulli arms with means (0.60,0.50,0.45,0.40,0.30)(0.60, 0.50, 0.45, 0.40, 0.30) and horizon T=5000T = 5000, averaged over 20002000 runs:

  • uniform: round-robin allocation forever, an A/B/n test that never acts on its result;
  • explore-then-commit (ETC): pull each arm mm times, then commit to the arm with the best sample mean (m=25m = 25 and m=100m = 100);
  • epsilon-greedy: with probability ε\varepsilon pull a uniformly random arm, otherwise the arm with the best sample mean; constant ε=0.1\varepsilon = 0.1, and a decaying εt=min⁡(1,5K/t)\varepsilon_t = \min(1, 5K/t);
  • UCB1, with the index above.

The second part measures the bias of the final sample mean at T=200T = 200 for two-armed problems, under uniform allocation (as a control), epsilon-greedy, UCB1 and pure greedy (always pull the best sample mean after one pull of each arm). Verbatim output:

Output
1. UCB1 indices (value = mean + sqrt(2 ln t / N)) for the worked example
  case A: t=11  N=(6, 4)  means=(0.667, 0.25)  indices=(1.561, 1.345)  -> pull arm 1
  case B: t=22  N=(20, 2)  means=(0.6, 0.5)  indices=(1.156, 2.258)  -> pull arm 2

2. Expected regret, K=5 Bernoulli arms mu=(0.6, 0.5, 0.45, 0.4, 0.3), T=5000, 2000 runs
   entries: mean pseudo-regret (standard error)
algorithm                                  T=100           T=500          T=1000          T=5000
uniform (A/B/n, no stopping)         15.0 ( 0.0)     75.0 ( 0.0)    150.0 ( 0.0)    750.0 ( 0.0)
ETC, m=25 per arm                    15.0 ( 0.0)     26.3 ( 0.3)     33.3 ( 0.7)     86.5 ( 3.9)
ETC, m=100 per arm                   15.0 ( 0.0)     75.0 ( 0.0)     76.6 ( 0.2)     80.6 ( 1.0)
eps-greedy, eps=0.1                   8.1 ( 0.1)     25.9 ( 0.5)     40.7 ( 0.8)    112.8 ( 1.6)
eps-greedy, eps_t=min(1,5K/t)        11.1 ( 0.1)     25.1 ( 0.4)     34.1 ( 0.7)     74.7 ( 3.1)
UCB1                                 12.2 ( 0.0)     48.5 ( 0.1)     80.8 ( 0.2)    199.6 ( 0.6)

   Reference curves (not simulated):
Lai-Robbins slope: sum Delta/kl             56.6            76.3            84.8           104.6
UCB1 bound (Auer et al. Thm 1)             924.3          1246.1          1384.8          1706.7
   Lai-Robbins coefficient sum_a Delta_a / kl(mu_a, mu*) = 12.28  (regret ~ coef * ln T)
   UCB1 coefficient 8 * sum_a 1 / Delta_a = 200.0

3a. Exact toy: two Bernoulli(0.5) arms, pull each once, pull the arm with the
    higher first reward a third time (tie: arm 1). Exact E[mean_a] after 3 rounds.
    E[mean_1] = 0.4375, E[mean_2] = 0.4375, true mean 0.5, bias = -0.0625 each

3b. Bias of the final sample mean, T=200, 40000 runs. bias = E[mean_a - mu_a] (se)
arms mu     policy                        bias arm 1        bias arm 2   E[N_1]
(0.5, 0.5)  uniform                 +0.0003 (0.0002)  -0.0002 (0.0002)    100.0
(0.5, 0.5)  eps-greedy 0.1          -0.0359 (0.0004)  -0.0499 (0.0005)    111.3
(0.5, 0.5)  UCB1                    -0.0087 (0.0003)  -0.0089 (0.0003)    100.1
(0.5, 0.5)  greedy                  -0.1377 (0.0011)  -0.2614 (0.0012)    125.5
(0.6, 0.4)  uniform                 +0.0001 (0.0002)  -0.0000 (0.0002)    100.0
(0.6, 0.4)  eps-greedy 0.1          -0.0105 (0.0003)  -0.0304 (0.0006)    170.7
(0.6, 0.4)  UCB1                    -0.0020 (0.0002)  -0.0189 (0.0004)    150.1
(0.6, 0.4)  greedy                  -0.1027 (0.0011)  -0.2275 (0.0011)    160.4

Fixed allocation is expensive. Uniform allocation has regret exactly T×T \times the mean gap, 0.15 T0.15\,T: 750750 at T=5000T = 5000, with no randomness in the pseudo-regret. By T=1000T = 1000 every other row is at or below 8181 against 150150. ETC with m=100m = 100 is uniform for its first 500500 rounds, hence the identical 75.075.0 at T=500T = 500.

Constant-ε\varepsilon has linear regret. Between T=1000T = 1000 and 50005000 it adds 7272 regret over 40004000 rounds, about 0.0180.018 per round, close to the ε×\varepsilon \times (mean gap 0.150.15) =0.015= 0.015 you would expect from pure random exploration plus occasional wrong greedy choices. Decaying εt\varepsilon_t fixes this, and at this horizon it is among the best, but its schedule uses constants we chose by hand.

ETC is excellent here, and fragile. With m=100m = 100 the policy pays 7575 to explore, almost always commits to the right arm, and ends at 80.680.6. With m=25m = 25 the exploration is cheap (1515 per 100100 rounds) but the commitment sometimes goes to the wrong arm. Its standard error at T=5000T = 5000 (3.93.9, against 1.01.0 for m=100m = 100) reveals a heavy-tailed outcome: most runs commit well, a few lock onto a bad arm for the remaining 4,8754{,}875 rounds. Tuning mm needs the gaps in advance, which is what you do not know.

UCB1 has the slowest start and the weakest numbers here, but the most robust guarantee. Its regret at T=5000T = 5000 is 199.6199.6, higher than ETC and decaying ε\varepsilon, which exploit tuned constants. Its growth from T=1000T = 1000 to T=5000T = 5000 is 118.8118.8 over ln⁡5≈1.61\ln 5 \approx 1.61 units of ln⁡T\ln T, a slope near 7474 per unit of ln⁡T\ln T. That is between the Lai–Robbins coefficient (12.312.3) and UCB1's guaranteed coefficient (200200), consistent with both, and the proved bound (1706.71706.7) is loose by almost an order of magnitude. UCB1 needs no tuning and no knowledge of the gaps or TT. Its width is conservative for Bernoulli rewards (Hoeffding uses only the range); shrinking it helps in practice, as exercise 3 shows, but voids the guarantee.

The Lai–Robbins line is an asymptotic lower bound, not a finite-TT floor. Some finite-horizon rows lie below it: ETC at T=5000T = 5000 (80.680.6) and decaying epsilon-greedy (74.774.7) are under 104.6104.6. That is not a contradiction: the bound constrains consistent policies as T→∞T \to \infty. ETC with a fixed mm has a positive probability of committing to a wrong arm forever, so it is not consistent and its regret is linear in the long run; at T=5000T = 5000 it simply has not yet paid for that.

Adaptive sampling biases the sample mean. The toy (3a) shows the exact bias, −0.0625-0.0625 per arm, from the hand calculation, matching the table above. Table 3b shows it at T=200T = 200: uniform allocation is unbiased within noise (all entries within two standard errors of 00); every adaptive policy is negative, by 0.0090.009 for UCB1 up to −0.14-0.14 and −0.26-0.26 for greedy sampling. Three patterns:

  • More aggressive exploitation, more bias. Greedy locks onto an arm after a few lucky pulls and never revisits the other, which stays frozen near whatever its early noise said. UCB1 keeps revisiting every arm, so its bias is smallest.
  • The weaker arm is more biased. With means (0.6,0.4)(0.6, 0.4), UCB1's bias is −0.002-0.002 for the best arm and −0.019-0.019 for the worse one, which is pulled less (E[N1]=150[N_1] = 150 of 200200) and so has less opportunity to correct a bad start.
  • Tie-breaking can matter. In the (0.5,0.5)(0.5, 0.5) epsilon-greedy row, arm 2 is biased more than arm 1 (−0.050-0.050 against −0.036-0.036) even though the arms are identical, because ties in the greedy step go to arm 1 in this code. The design is not symmetric.

All the biases above are negative, consistent with the sampling mechanism studied in the cited papers. We did not simulate optimistic stopping or choosing, where Shin et al. show the bias can be positive.

Exercises

  1. (Pen and paper.) Two arms with gap Δ\Delta. ETC pulls each arm mm times, then commits to the arm with the higher sample mean, for horizon T≥2mT \ge 2m. Show Regret(T)≤mΔ+TΔ e−mΔ2/2\mathrm{Regret}(T) \le m\Delta + T\Delta\, e^{-m\Delta^2/2} (apply Hoeffding to the mm i.i.d. variables Xi−Yi∈[−1,1]X_i - Y_i \in [-1, 1]). Then choose mm to make the two terms comparable and say how the resulting regret scales with TT.
  2. (Pen and paper.) At round t=16t = 16, arm 1 has N1=10N_1 = 10 pulls and sample mean 0.50.5; arm 2 has N2=5N_2 = 5 pulls and sample mean 0.40.4. Compute both UCB1 indices and say which arm is pulled. How many successes would arm 2's five pulls need for its sample mean to match arm 1's?
  3. (Change the code and predict.) In the UCB1 index replace the constant 22 in 2ln⁡t/N\sqrt{2\ln t/N} by 0.50.5. Predict whether regret at T=5000T = 5000 goes up or down, and whether the standard error changes. Then run it and also try 0.10.1.
  4. (Pen and paper.) In the three-round toy, show that E[μ^1N1]=0.5 E[N1]\mathbb{E}[\hat\mu_1 N_1] = 0.5\,\mathbb{E}[N_1] (Wald) while E[μ^1]≠0.5\mathbb{E}[\hat\mu_1] \ne 0.5. Write down the first quantity from the table.

Sources