Bandit Algorithms

Bandit algorithms are policies for the multi-armed bandit problem: choose one arm, observe reward only for the arm shown, and update the policy before the next round. This page focuses on the concrete policies. The base notation, partial-feedback setup, and regret definition live on Multi-Armed Bandits.

In recommendation systems, these policies are useful when the product must learn from live exposure: a new headline, notification template, recommendation module, or item bucket may be better than the current winner, but the system cannot know that without showing it to users.

Shared state

For each arm , a basic bandit policy maintains:

QuantityMeaning
number of times arm has been shown
number of observed successes, such as clicks
empirical reward rate
current round or total number of decisions so far

Different algorithms use this same state differently. Greedy trusts immediately. Epsilon-greedy injects random exploration. UCB adds an uncertainty bonus. Thompson sampling samples from a posterior belief.

Greedy, epsilon-greedy, UCB, and Thompson sampling use the same arm statistics but choose the next recommendation through different decision rules.

The diagram shows the distinction between estimate, uncertainty, and randomized belief. The algorithm changes how the next arm is chosen; the underlying bandit feedback remains the same partial-feedback loop from Multi-Armed Bandits.

Greedy

A greedy policy always chooses the arm with the largest empirical reward:

It is simple and cheap, but brittle. If a mediocre arm gets a few lucky early clicks, greedy can keep exploiting it and never gather enough evidence about the other arms. Greedy is useful as a baseline, not as a safe default for cold-start or changing content.

Epsilon-Greedy

Epsilon-greedy chooses randomly with probability and otherwise chooses the current empirical winner:

The parameter is the exploration rate. Larger learns more about alternatives but spends more traffic on arms that currently look worse. Smaller protects short-term reward but can converge slowly or prematurely. In production, is often bounded by eligibility, safety, fatigue, and product-quality rules rather than applied to every possible item.

UCB

Upper-confidence-bound policies choose the arm with the largest optimistic score:

The first term, , exploits high empirical reward. The second term,

is the exploration bonus: it is larger for arms with fewer observations and shrinks as grows. The UCB score is the sum of the empirical reward estimate and this bonus. The policy then chooses the arm with the largest UCB score. As grows, arms that have been neglected become worth checking again. UCB is deterministic once the observed rewards are fixed, which makes it easier to debug than random exploration.

Thompson Sampling

Thompson sampling is randomized, but not uniformly random. It samples one plausible reward rate for each arm from the current posterior belief, then chooses the arm with the largest sampled value.

For binary rewards, a common model is a Beta-Bernoulli bandit:

Here is a sampled plausible click rate for arm . After a click, update . After a non-click, update . Arms with little data have wider posterior distributions, so they occasionally sample high values and get explored. Arms with much data have tighter posteriors, so the policy becomes more stable.

Worked example

Suppose a homepage can show one of three modules. The product optimizes immediate clicks, and the current logged state is:

ArmShows Clicks Empirical CTR
A: sports roundup12060.050
B: finance tips4030.075
C: weather alerts810.125

At first glance, arm C has the largest empirical CTR. But it also has only eight observations, so the estimate is uncertain. Different policies make different next decisions:

PolicyDecision ruleNext armReason
Greedychoose largest Chighest observed CTR
Epsilon-greedyusually greedy, sometimes randomusually Crandom exploration may choose A or B
UCBchoose empirical CTR plus confidence bonusChigh CTR and high uncertainty
Thompson samplingsample plausible CTRs from posteriorsoften C, sometimes BC has a wide posterior; B still has plausible upside

Now imagine C receives 30 more impressions and no more clicks. Its empirical CTR drops from to . A greedy policy would stop showing it only after the damage is visible. UCB and Thompson sampling are designed to make that trial bounded: early uncertainty earns C a chance, but disappointing evidence reduces its future score.

This example also shows why bandit logs need action propensities. If yesterday’s policy rarely showed C, ordinary supervised evaluation cannot infer what would have happened had C been shown more often. See Offline Versus Online Evaluation for replay and inverse-propensity evaluation.

Choosing a policy

PolicyStrengthWeaknessGood fit
Greedysimple and stable after exploration is completecan lock onto early noisemature arms with enough randomized history
Epsilon-greedyeasy to reason about and controlwastes exploration uniformlysimple experiments and low-risk surfaces
UCBexplores uncertain arms more deliberatelyconfidence formula assumes a clean reward processsmall arm sets with fast feedback
Thompson samplingnaturally balances uncertainty and rewardneeds a reward model and randomized servingclick, conversion, or binary success rewards

For personalized ranking, move to Contextual Bandits: the policy should condition on user, item, query, device, and time features rather than treating every request as exchangeable.

Production considerations

  • Define the reward before choosing the algorithm: clicks, saves, purchases, retention, and satisfaction can point to different arms.
  • Keep eligibility filters outside the bandit: exploration should not show unavailable, unsafe, or permission-ineligible items.
  • Log the chosen arm, reward, timestamp, policy version, and selection probability when available.
  • Separate exploration traffic from final product ranking when the cost of mistakes is high.
  • Use minimum exposure floors or priors for new arms so cold-start items can be evaluated without taking over the surface.
  • Watch non-stationarity: stale arms, news cycles, seasonality, and product changes can make old reward estimates misleading.

Caveats

Bandit algorithms optimize observed rewards, not necessarily user welfare. A click reward can over-promote sensational content, repeated notifications, or short-term engagement at the cost of trust. Delayed rewards, repeated exposure, interference between users, and position effects violate the clean assumptions behind the simplest algorithms. For high-impact recommenders, combine bandits with guardrails, diversity constraints, and online experiments.

References