The Gittins Index
The exact Bayes-optimal policy for discounted bandits, and why it is an index.
Suppose the prior is true and future rewards are discounted by a factor per pull. Then exploration stops being a heuristic: the best policy solves an MDP whose states are posteriors, an MDP far too large to solve directly for more than a few arms. Gittins discovered that it decomposes. Each arm gets a number computed from that arm alone, and always pulling the arm with the largest number is optimal. This lesson defines the index by calibration, computes it for Beta arms, proves the theorem by an interchange argument, and shows where index policies break.
What you’ll learn
- Formulate the discounted Bayesian bandit as an MDP over posterior states, and explain why solving it directly scales exponentially with the number of arms.
- Define the Gittins index by calibration against a known arm and as a maximal reward rate over stopping times, and compute it for Beta–Bernoulli arms by backward induction.
- State the Gittins index theorem with its assumptions, and reconstruct an interchange proof for finite-state arms.
- Explain why index policies fail for restless arms, switching costs, multiple plays and finite horizons, and define the Whittle index.
- Compare the Gittins policy with Thompson sampling and UCB, including why discounting lets it stop learning.
Exploration as planning over beliefs
Give each arm a prior, independent across arms, and score a policy by its expected discounted reward , averaged over the prior. For Bernoulli arms with Beta priors, all the history says about arm is its posterior . The posterior parameters are therefore a sufficient statistic, and the bandit becomes an MDP whose states are belief states:
- state: ;
- action: pull an arm ;
- transition: with probability the pull pays 1 and grows by one, otherwise grows by one, and every other arm's state stays frozen;
- reward: the payout, with expected value .
Think first A known arm pays 0.6 per pull forever. A new arm has a uniform prior, so its mean is 0.5, and . Should a Bayes-optimal player ever pull the new arm?
Yes, and right away. Sticking with the known arm is worth . Pulling the new arm once and then acting optimally is worth about 6.39 (by backward induction). The first pull costs 0.1 in expectation, but with probability 1/2 it pays, the posterior becomes Beta(2, 1), and the player keeps a promising arm for as long as it stays promising; if it fails, the player returns to the known arm for good. The option to keep a good discovery outweighs the expected cost of looking. The new arm stops being worth a try only when the known arm pays more than about 0.703, the new arm's Gittins index.
Calibrating an arm against a sure thing
The reveal suggests how to score one arm in isolation: find the payout of a known arm that would make you indifferent. Attach to a single arm in state a retirement option (Whittle, 1980): at any time you may stop for good and collect per step forever, worth . The known arm is Gittins's standard bandit, and the index is the rate at which it calibrates the arm.
def gittins_index(a, b, gamma, depth=300, tol=1e-6):
"""Gittins index of a Bernoulli arm with posterior Beta(a, b), by calibration:
the largest payout lam of a known arm for which pulling this arm once more still pays."""
def worth_pulling(lam):
R = lam / (1 - gamma) # retire to the known arm forever
# after depth more pulls, treat the posterior mean as exact
V = [max(R, (a + s) / (a + b + depth) / (1 - gamma)) for s in range(depth + 1)]
for d in range(depth - 1, -1, -1): # d pulls from now: s successes, d - s failures
new = []
for s in range(d + 1):
p = (a + s) / (a + b + d) # posterior mean: chance the next pull pays
cont = p * (1 + gamma * V[s + 1]) + (1 - p) * gamma * V[s]
new.append(cont if d == 0 else max(R, cont))
V = new
return V[0] > R # V[0]: pull now, then act optimally
lo, hi = a / (a + b), 1.0 # the index lies between the mean and 1
while hi - lo > tol:
lam = (lo + hi) / 2
lo, hi = (lam, hi) if worth_pulling(lam) else (lo, lam)
return (lo + hi) / 2Bisection on , with backward induction over the posterior lattice for each trial value: about states per evaluation. Treating the mean as exact after depth more pulls changes the value by at most , about for depth 300 at . Katehakis and Veinott (1987) gave an equivalent "restart-in-state" characterization that computes an index with a single MDP solve.
With , an effective horizon of 100 pulls, how much must a known arm pay per pull before a brand-new arm with prior Beta(1, 1), mean 0.5, is no longer worth trying? That threshold is the new arm's Gittins index.
Show the answer
0.87
About 0.870, computed with the code above. With a hundred pulls' worth of future at stake, the chance of discovering a good arm is worth a lot: a new arm deserves a try against any known arm paying less than 0.87, although it pays only 0.5 on average. At the threshold is 0.703, and at it is 0.761.
| Posterior | Mean | |||
|---|---|---|---|---|
| Beta(1, 1) | 0.500 | 0.703 | 0.761 | 0.870 |
| Beta(2, 1) | 0.667 | 0.800 | 0.838 | 0.910 |
| Beta(1, 2) | 0.333 | 0.500 | 0.560 | 0.701 |
| Beta(2, 2) | 0.500 | 0.635 | 0.681 | 0.784 |
| Beta(10, 10) | 0.500 | 0.537 | 0.554 | 0.605 |
| Beta(30, 30) | 0.500 | 0.513 | 0.520 | 0.543 |
Why one number per arm suffices
The best state goes first. Among all states of all arms, let have the largest expected reward . Suppose an arm sits in , but a policy plays other arms first and pulls it only at a later, possibly random, time (or never, ), collecting expected rewards meanwhile. The waiting arm is frozen, so its pull at still pays in expectation. Move that pull to the front and delay the intervening pulls by one step; nothing after changes. The gain is
So an arm in should be pulled at once, and : no stretch of play can beat the best single reward. Splice it out. Since a visit to is always followed immediately by its pull, merge into the states that lead to it: a transition into and the pull that follows become one longer step. Each step of the spliced arm has a random duration, and its reward rate is computed from that arm alone:
The spliced arm has one state fewer and steps of random length: a semi-Markov arm. The interchange works the same way for such arms, with the largest rate in the role of , and that rate is the removed state's index. Repeat: states leave one at a time, in order of priority, and splicing one arm never touches another arm's states. By induction on the total number of states, playing the arm whose current state has the highest priority is optimal, and the priorities are the Gittins indices, each computed from its own arm.
Other proofs illuminate other facets. Gittins's original argument was also an interchange. Whittle (1980) gave every arm the retirement option at once and showed that the derivative of the multi-arm value with respect to the retirement reward is the product of the single-arm derivatives. Weber (1992) charged each arm a "prevailing" fee, and Bertsimas and Niño-Mora (1996) obtained the indices from a linear program over achievable performance. The same peeling of states, run on a single finite-state arm, computes its indices, as in the algorithm of Varaiya, Walrand and Buyukkoc (1985).
In the interchange step, why can moving the pull of the arm in to the front never hurt?
- Because discounting makes every early reward worth more than every late one
- Because is the largest expected reward of all states, so bringing it forward gains at least what delaying the intervening rewards by one step loses, and the frozen arm still offers it
- Because the intervening pulls were suboptimal anyway
- Because the policy has no information about the arm in
Show the answer
B. Because is the largest expected reward of all states, so bringing it forward gains at least what delaying the intervening rewards by one step loses, and the frozen arm still offers it
Bringing forward from time to time 0 gains ; delaying the intervening rewards by one step loses , which is at most because every . Both halves need the arm to be frozen while it waits, so that its reward is still at time .
Where index policies break
The theorem's assumptions are not technicalities: drop any one of them, and in general no index policy is optimal.
In a restless bandit every arm moves whether or not it is pulled, under different dynamics when active and passive, and of the arms must be active in every step: machines that wear out unless maintained, patients whose condition evolves whether or not they are treated. Whittle (1988) relaxed the constraint to hold only on average over time and priced it with a Lagrange multiplier , a subsidy paid for each passive arm in each step. The relaxed problem decouples into single-arm problems. An arm is indexable if the set of states in which passivity is optimal grows steadily from empty to everything as rises; its Whittle index in state is then the subsidy at which active and passive are equally good in . For a rested arm, frozen when passive, passivity with subsidy is exactly retirement at rate , so the Whittle index is the Gittins index.
Activating the arms with the largest Whittle indices is a heuristic, not an optimal policy. Weber and Weiss (1990) proved it asymptotically optimal as the number of arms grows with fixed, under a condition on a deterministic approximation of the dynamics, and showed that it can fail when the condition does not hold. Exact optimality is out of reach in general: computing an optimal policy for restless bandits is PSPACE-hard (Papadimitriou & Tsitsiklis, 1999).
| Change to the model | Index policy optimal? | Why the decomposition fails |
|---|---|---|
| Arms move when not pulled (restless) | No; the Whittle index is a heuristic | Waiting changes an arm's value, so the interchange no longer just reorders rewards |
| Switching between arms costs something | No index policy is, in general (Banks & Sundaram, 1994) | An arm's value depends on which arm was played last |
| arms are pulled in every step | Not in general | Pulls happen in parallel, and single-pull interchanges do not compare parallel schedules |
| A finite horizon without discounting | Not in general | The time left is shared by all arms and changes even for arms not pulled |
| Correlated priors | No | A pull of one arm moves the posteriors of others, so the arms are not independent |
Gittins, Thompson sampling and UCB
If the Gittins policy is Bayes-optimal, why do practitioners reach for Thompson sampling or UCB?
- A different objective. Bayes-optimality is for discounted reward averaged over the prior. An unpulled arm's index never changes, so with fixed the policy can rationally stop exploring: if an unlucky start pushes the best arm's index below the mean of a well-explored rival, the rival's index stays above it and the best arm is never pulled again. That happens with positive probability, and on such runs the regret grows linearly.
- Dependence on and the prior. The index tables change with both. When the right discount is unclear, as for a deployed system that should keep learning indefinitely, so is the policy.
- Fragile structure. Correlated arms, contexts, delayed feedback and drift all break the decomposition, while posterior sampling and optimism carry over.
- Computation. Indices of Beta states can be tabulated offline, but richer posteriors need a dynamic program per state, and close to 1 needs deep lattices.
The two traditions meet in Bayesian index policies with frequentist guarantees. Bayes-UCB (Kaufmann, Cappé & Garivier, 2012) uses as its index a quantile of the posterior, at a level that tightens over time, and is asymptotically optimal for Bernoulli arms. Lattimore (2016) analyzed the finite-horizon Gittins index for Gaussian arms and proved finite-time regret guarantees comparable to UCB's; his experiments suggest that one version is a modest improvement on UCB and Thompson sampling.
Key takeaways
- A discounted Bayesian bandit is an MDP over posterior states. Its Bayes-optimal policy explores exactly as much as the prior and justify, but the joint belief space grows exponentially with the number of arms.
- The Gittins index of a state is the payout of a known arm that makes you indifferent, equivalently the best discounted reward rate over a stretch of play you may stop at will. For Beta(1, 1) at it is 0.703, far above the mean 0.5: the bonus prices information.
- The index theorem: for independent arms that stay frozen when not pulled, one pull per step and geometric discounting, always pulling the arm with the largest index is optimal. In Tsitsiklis's proof the state with the highest reward goes first by an interchange argument, is spliced out of its arm, and the argument repeats.
- Index optimality breaks for restless arms, switching costs, multiple plays and undiscounted finite horizons. For indexable restless arms the Whittle index gives a heuristic that is asymptotically optimal under conditions, while optimal restless policies are PSPACE-hard to compute.
- In practice Thompson sampling and UCB are preferred: they need no discount, carry frequentist guarantees and extend to structured problems. Under a fixed discount the Gittins policy can stop learning and suffer linear regret, while Bayes-UCB and finite-horizon Gittins variants recover good frequentist behavior.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
A known arm pays 0.65 per pull forever. A new arm has prior Beta(1, 1), and . What does the Bayes-optimal player do first?
- Pull the known arm, because 0.65 exceeds the new arm's mean of 0.5
- Either: the two are equally good
- Pull the new arm, because its Gittins index, about 0.703, exceeds 0.65
- It depends on how many pulls remain in total
Show the answer
C. Pull the new arm, because its Gittins index, about 0.703, exceeds 0.65
The comparison is between indices, and a known arm's index is its payout. The new arm's index includes the value of information: if it turns out good, the player keeps it; if not, the player returns to the known arm. Here that option is worth more than the 0.15 expected shortfall of the first pull.
Switching from one arm to another now costs a fixed amount . What becomes of the Gittins index policy?
- It is no longer optimal in general, and in general no index policy is
- It stays optimal once is subtracted from every index
- It stays optimal, because switching costs do not depend on the arms' states
- It becomes optimal only for close to 1
Show the answer
A. It is no longer optimal in general, and in general no index policy is
The value of moving to an arm now depends on which arm was played last, so an arm can no longer be scored in isolation. Banks and Sundaram (1994) showed that with switching costs no index policy is optimal in general; good policies use hysteresis, staying with the current arm until a rival's advantage exceeds the cost.
With fixed below 1, can the Gittins index policy abandon the best arm forever?
- No: the index policy is optimal, so it always finds the best arm
- No: every arm's index rises while it is not pulled, as in UCB
- Only if the prior is misspecified
- Yes: if an unlucky start pushes the best arm's index below the mean of a well-explored rival, the rival's index stays above it and the best arm, frozen, is never pulled again
Show the answer
D. Yes: if an unlucky start pushes the best arm's index below the mean of a well-explored rival, the rival's index stays above it and the best arm, frozen, is never pulled again
An unpulled arm's index never changes, unlike UCB's bonus, which grows with time. Abandoning a seemingly poor arm is the Bayes-optimal response to discounting, since the remote future in which the knowledge would pay off is worth little; but on that instance the regret then grows linearly. This is one reason regret-minimizing algorithms do not use a fixed discount.
In Whittle's relaxation of a restless bandit, what is the Whittle index of a state of an indexable arm?
- The arm's expected reward in that state
- The subsidy for staying passive at which being active and being passive are equally good in that state
- The Gittins index of the same state computed as if the arm were frozen when passive
- The Lagrange multiplier of the constraint that exactly arms are active in every step
Show the answer
B. The subsidy for staying passive at which being active and being passive are equally good in that state
Relaxing "exactly arms active per step" to "on average" and pricing it with a subsidy for passivity decouples the arms. Indexability means the states where passivity is optimal increase steadily with ; the Whittle index of a state is the subsidy at which it switches. For rested arms it coincides with the Gittins index, but for restless arms the passive dynamics matter.
Further reading
- J. C. Gittins, "Bandit processes and dynamic allocation indices," Journal of the Royal Statistical Society, Series B 41(2), 148–177 (1979).
- J. C. Gittins, K. Glazebrook & R. Weber, Multi-armed Bandit Allocation Indices, 2nd ed. (Wiley, 2011).
- J. N. Tsitsiklis, "A short proof of the Gittins index theorem," Annals of Applied Probability 4(1), 194–199 (1994).
- P. Whittle, "Restless bandits: Activity allocation in a changing world," Journal of Applied Probability 25(A), 287–298 (1988).
- T. Lattimore & C. Szepesvári, Bandit Algorithms, ch. 35 (Cambridge University Press, 2020).