Foundations/Bandit Exploration Algorithms

Lesson 1.42,240 words

Bandit Exploration Algorithms

Better ways to explore than picking at random. Upper-confidence-bound selection explores by optimism about what it hasn't measured; gradient bandits learn action preferences by stochastic gradient ascent on reward.

╌╌╌╌

This builds on Multi-Armed Bandits, which set up the k-armed bandit, sample-average value estimates, the incremental update rule, ε-greedy exploration, and optimistic initialization. Those methods all explore bluntly — uniformly at random, or once at the start. Here we look at exploration that is targeted by uncertainty, and at how to measure exploration well.

Upper-confidence-bound selection

ε-greedy exploration is blunt: when it explores, it picks uniformly at random, with no preference for actions that are nearly greedy or that carry high uncertainty. It would be better to explore among the non-greedy actions according to how likely each one is to actually be optimal — weighing both how close its estimate is to the maximum and how uncertain that estimate is. Upper-confidence-bound (UCB) selection does exactly this:

where is the number of times has been selected before , and controls the degree of exploration. (If , then is treated as a maximizing action, so every arm is tried once at the start.) The square-root term is a measure of the uncertainty in the estimate of 's value: it is an upper bound on how good might plausibly be, with setting the confidence level.

The dynamics are self-correcting. Each time is selected, grows and the uncertainty term shrinks. Each time some other action is selected, grows but does not, so 's uncertainty term slowly rises — the arm gets a nudge back up for having been neglected. Because grows without bound but ever more slowly, all actions are eventually selected, but those with lower estimates or that have already been sampled often are chosen with decreasing frequency.

UCB adds an uncertainty bonus to each estimate — a well-sampled arm (left) has a tight interval and is judged near its estimate, while a rarely tried arm (right) has a wide interval and can be selected on the strength of its optimistic upper end even with a lower estimate.

UCB by hand

For example, take a -armed problem after plays, with , current estimates and counts

Arm is greedy on the estimate. But the selection maximizes , and with the bonuses are

UCB selects arm — the one with the lowest estimate — purely because a single sample leaves its value the most uncertain, and the bonus swamps the gap in estimates. Pull it, and becomes : its next bonus falls to , a large drop from one observation. The bonus falls off as , so the first few pulls of a neglected arm shrink its uncertainty fast, and selection increasingly depends on the estimates themselves. This is the self-correction described above.

UCB often outperforms ε-greedy on the bandit, but it is harder to extend to the full RL problem: it does not cope gracefully with nonstationarity, and its per-action counts become impractical once the state space is large and values are represented by function approximation rather than a table.

Gradient bandit algorithms

Every method so far estimates action values and selects from them. A different idea is to learn a numerical preference for each action, with no interpretation as a reward. Only relative preferences matter: adding a constant to every preference leaves behavior unchanged, because actions are selected in proportion to a soft-max (Gibbs, or Boltzmann) distribution over the preferences,

where is the probability of taking action at time . Initially all preferences are equal ( for all ), so every action is equally likely.

There is a natural learning rule based on stochastic gradient ascent. After selecting and receiving , update all preferences by

where is a step size and is the average of all rewards through step , computed incrementally. The term is a baseline: if the reward beats the baseline, the probability of is raised and the others lowered; if it falls short, 's probability is lowered. The baseline makes the algorithm invariant to a shift in the overall reward level — add to every reward and the gradient bandit adapts instantly, whereas without the baseline the same shift badly degrades performance.

The gradient bandit compares the received reward against a running baseline — a reward above baseline pushes the taken arm's preference up and the softmax probabilities of all others down; a reward below baseline does the reverse.

Why the preferences follow the gradient

The update is not an arbitrary heuristic — it is a sampled version of exact gradient ascent on expected reward, and the derivation explains why it converges. In exact gradient ascent each preference would move proportionally to the effect of that move on performance:

We cannot compute this directly, because is unknown. But the expected value of the actual update equals this gradient. Expanding the derivative and inserting an arbitrary baseline (which changes nothing, since the softmax probabilities always sum to so ):

Choosing the baseline and substituting for (permitted since ), then using the softmax derivative , the whole expectation collapses to

The bracketed quantity reproduces the per-step gradient-bandit update. So the algorithm's expected update equals the true gradient of expected reward — it is genuine stochastic gradient ascent, which is why it has sound convergence behavior.1 The baseline can be any quantity not depending on the selected action; it does not change the expected update, but it does reduce the update's variance, and the running reward average is a simple choice that works well in practice.

A gradient-bandit update by hand

Take arms with preferences , so the softmax gives . Use step size and suppose the running baseline is . Select arm (each arm equally likely at the start) and receive reward , well above baseline, so . The taken arm rises and the others fall:

The new preferences re-normalize through the softmax to : arm 's probability rose from to , the other two fell symmetrically, and the three still sum to . Now add to every reward. The received reward becomes , but the baseline climbs toward as well, so is unchanged and the update is identical — the baseline makes the algorithm blind to the overall reward level. Drop the baseline (set ) and the same shift makes , an update larger and dominated by the offset rather than the arm's relative merit. That is the failure the baseline prevents.

One gradient-bandit step from a uniform start. A reward above the baseline raises the taken arm's softmax probability (arm 2, blue) and lowers the others' (red) by half as much each, keeping the distribution normalized. The shift is proportional to , so a constant offset added to all rewards leaves it unchanged.

Associative search: contextual bandits

Everything so far is nonassociative: there is one situation, and the task is either to find the single best action or to track it as it drifts. The full reinforcement learning problem has more than one situation, and the goal is to learn a policy — a mapping from situations to the actions best in each.

The bridge between the two is associative search, now usually called the contextual bandit problem. Suppose that on each step you face one of several different bandit tasks, chosen at random, and you are given a distinctive clue about which task it is (but not its action values). That clue is what separates the setting from a plain bandit. Imagine a slot machine that changes the color of its display as it changes its payouts: seeing the color, you can learn a policy of the form if red, pull arm 1; if green, pull arm 2, and do far better than any single fixed choice could.

This sits between the plain bandit and full reinforcement learning. Like the full problem, it involves learning a policy over situations; like the plain bandit, each action affects only the immediate reward and nothing else. The one remaining ingredient is the piece we deliberately removed at the start: allow an action to affect the next situation as well as the reward, and the contextual bandit becomes the full reinforcement learning problem.

Regret, UCB1, and Thompson sampling

Sutton and Barto measure a method by its average reward and its optimal-action rate on the testbed. The theoretical bandit literature measures it by a single scalar, regret, and the results there sharpen every idea in this lesson. Define the regret after steps as the reward lost relative to always pulling the best arm,

where is an optimal arm and is arm 's suboptimality gap. In words: regret is the number of times each suboptimal arm is pulled, weighted by its gap. A good method pulls the bad arms rarely.

Regret accumulates only on suboptimal pulls. The dashed line is the reward of always pulling the best arm (); the solid curve is the method's cumulative reward. The vertical gap is the regret, and it grows only when a pull lands on an arm with gap .

Lai and Robbins (1985) proved that no method can do better than logarithmic regret: for any consistent policy, asymptotically, where is a KL-divergence between arm 's reward distribution and the best arm's.2 Regret must grow at least like , so -greedy with a fixed is provably suboptimal: it explores a constant fraction of the time, pulling each bad arm times, for linear regret . That is the formal statement of what the learning curves showed — a fixed ceilings below the optimum. (A schedule recovers logarithmic regret, which is why decaying is standard practice.)

Auer, Cesa-Bianchi, and Fischer (2002) showed that the UCB rule of this lesson achieves the logarithmic bound with no schedule to tune. Their UCB1 algorithm, using the bonus (the same form as ours with ), satisfies a finite-time bound: for any ,

The first term is the unavoidable ; the second is a constant. This theorem is why UCB performs well: it is within a constant factor of optimal on every bandit, for every horizon. Lattimore and Szepesvári (2020) give the modern, tightened form of these bounds and the matching lower bounds in a full-length treatment.3

A different route to the same optimality is older than all of it. Thompson sampling, proposed by Thompson (1933), keeps a Bayesian posterior over each arm's value and, on each step, draws one sample from every posterior and pulls the arm with the largest sample.4 An arm with a wide posterior sometimes draws high and gets explored; as its posterior concentrates, it is pulled only when its estimated value warrants it. For Bernoulli rewards the posterior is a Beta distribution updated by simple success/failure counts, so the method is a few lines of code. Chapelle and Li (2011) demonstrated empirically that Thompson sampling matches or beats UCB on real display-advertising and news data, which returned it to wide use;5 Agrawal and Goyal (2012) then proved it also attains the optimal regret. Thompson sampling and UCB are the two default modern answers to the exploration problem this lesson poses.

Contextual bandits in practice

The associative-search setting is how large-scale recommendation and ad-placement are formalized. Li, Chu, Langford, and Schapire (2010) introduced LinUCB, which assumes each arm's expected reward is linear in a context feature vector , , and applies a UCB-style bonus derived from the confidence ellipsoid of a ridge-regression estimate of .6 Deployed on Yahoo's front-page news module, it raised click-through over a context-free bandit by a double-digit percentage. LinUCB is the direct ancestor of the contextual-bandit services now standard for recommendation, and it realizes the clue about which task you face idea of associative search, made linear and equipped with the UCB confidence bound.

What the bandit leaves out

The bandit is reinforcement learning with two things deleted, and naming them sharpens what the rest of the subject is about.

IngredientBanditFull RL
State / situationnone — every step identicala state observed each step
Consequences of an actionimmediate reward onlyreward and the next state
What is learneda value per arm, or a preferencea policy over states
The hard problemexploration vs. exploitationthat, plus credit assignment over time

The one problem present here in pure form — how much to explore — survives intact into the full setting; the bandit is where we could study it without the distraction of states and delayed consequences. Add a state that the action moves you through, so that a reward now can depend on a choice made many steps ago, and you get the central new difficulty of reinforcement learning: temporal credit assignment, which is where the Markov decision process picks up.

Footnotes

  1. Sutton & Barto, §2.8 — Gradient Bandit Algorithms and the box The Bandit Gradient Algorithm as Stochastic Gradient Ascent: the softmax preference model, the baseline-subtracted update, and the derivation showing the expected update equals the gradient of expected reward.
  2. Lai, T. L. & Robbins, H. (1985), Asymptotically efficient adaptive allocation rules, Advances in Applied Mathematics 6(1), 4–22 — the asymptotic lower bound on the number of pulls of a suboptimal arm, establishing that regret must grow at least logarithmically.
  3. Lattimore, T. & Szepesvári, C. (2020), Bandit Algorithms, Cambridge University Press — a book-length modern treatment of stochastic and adversarial bandits, with tightened UCB regret bounds and the matching minimax and instance-dependent lower bounds.
  4. Thompson, W. R. (1933), On the likelihood that one unknown probability exceeds another in view of the evidence of two samples, Biometrika 25(3–4), 285–294 — the original posterior-sampling rule (Thompson sampling): maintain a posterior over each arm's value and pull the arm whose single posterior draw is largest.
  5. Chapelle, O. & Li, L. (2011), An empirical evaluation of Thompson sampling, Advances in Neural Information Processing Systems (NeurIPS) 24 — experiments on display-advertising and news data showing Thompson sampling matches or exceeds UCB, which renewed practical interest in the method. Optimal regret for Thompson sampling was later proved by Agrawal, S. & Goyal, N. (2012), Analysis of Thompson sampling for the multi-armed bandit problem, Conference on Learning Theory (COLT).
  6. Li, L., Chu, W., Langford, J. & Schapire, R. E. (2010), A contextual-bandit approach to personalized news article recommendation, Proceedings of the 19th International Conference on World Wide Web (WWW), 661–670 — the LinUCB algorithm, assuming rewards linear in a context vector with a UCB bonus from the ridge-regression confidence ellipsoid, deployed on Yahoo's news module.

╌╌ END ╌╌