Simple Algorithm
Reinforcement Learning · Fixed Point · 28 min

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 γ\gamma 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 E[∑t≥0γtRt+1]\E\big[\sum_{t\ge0}\gamma^tR_{t+1}\big], averaged over the prior. For Bernoulli arms with Beta priors, all the history says about arm ii is its posterior Beta(ai,bi)\mathrm{Beta}(a_i,b_i). The posterior parameters are therefore a sufficient statistic, and the bandit becomes an MDP whose states are belief states:

  • state: x=(a1,b1,…,aK,bK)\mathbf x=(a_1,b_1,\dots,a_K,b_K);
  • action: pull an arm ii;
  • transition: with probability pi=ai/(ai+bi)p_i=a_i/(a_i+b_i) the pull pays 1 and aia_i grows by one, otherwise bib_i grows by one, and every other arm's state stays frozen;
  • reward: the payout, with expected value pip_i.
V(x)  =  max⁡i { pi(1+γ V(x+ei+))  +  (1−pi) γ V(x+ei−) },pi=aiai+biV(\mathbf x)\;=\;\max_{i}\ \Big\{\,p_i\big(1+\gamma\,V(\mathbf x+\mathbf e^{+}_i)\big)\;+\;(1-p_i)\,\gamma\,V(\mathbf x+\mathbf e^{-}_i)\,\Big\},\qquad p_i=\frac{a_i}{a_i+b_i}
The Bellman optimality equation of the Bayesian bandit: x+ei+\mathbf x+\mathbf e^+_i adds a success to arm ii, x+ei−\mathbf x+\mathbf e^-_i a failure. This is a Bayes-adaptive MDP in its simplest form, and its optimal policy explores exactly as much as the prior and the discount justify. Solving it directly is hopeless: with 10 arms and up to 100 pulls of each, the belief states number about 103710^{37}.
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 γ=0.9\gamma=0.9. Should a Bayes-optimal player ever pull the new arm?

Yes, and right away. Sticking with the known arm is worth 0.6/(1−γ)=60.6/(1-\gamma)=6. 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 λ\lambda of a known arm that would make you indifferent. Attach to a single arm in state xx a retirement option (Whittle, 1980): at any time you may stop for good and collect λ\lambda per step forever, worth λ/(1−γ)\lambda/(1-\gamma). The known arm is Gittins's standard bandit, and the index is the rate at which it calibrates the arm.

python
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) / 2

Bisection on λ\lambda, with backward induction over the posterior lattice for each trial value: about depth2/2\text{depth}^2/2 states per evaluation. Treating the mean as exact after depth more pulls changes the value by at most γdepth/(1−γ)\gamma^{\text{depth}}/(1-\gamma), about 2×10−132\times10^{-13} for depth 300 at γ=0.9\gamma=0.9. Katehakis and Veinott (1987) gave an equivalent "restart-in-state" characterization that computes an index with a single MDP solve.

Predict before you look

With γ=0.99\gamma=0.99, 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 γ=0.9\gamma=0.9 the threshold is 0.703, and at γ=0.95\gamma=0.95 it is 0.761.

PosteriorMeanγ=0.9\gamma=0.9γ=0.95\gamma=0.95γ=0.99\gamma=0.99
Beta(1, 1)0.5000.7030.7610.870
Beta(2, 1)0.6670.8000.8380.910
Beta(1, 2)0.3330.5000.5600.701
Beta(2, 2)0.5000.6350.6810.784
Beta(10, 10)0.5000.5370.5540.605
Beta(30, 30)0.5000.5130.5200.543
Gittins indices of Bernoulli arms, computed with the code above. The index exceeds the posterior mean by an exploration bonus, the value of what further pulls will reveal. The bonus grows with the effective horizon 1/(1−γ)1/(1-\gamma), here 10, 20 and 100 pulls, and shrinks as evidence accumulates: Beta(1, 1), Beta(10, 10) and Beta(30, 30) all have mean 0.5, but at γ=0.9\gamma=0.9 their bonuses are 0.20, 0.037 and 0.013.

Why one number per arm suffices

DerivationAn interchange proof for finite-state arms (after Tsitsiklis, 1994)
  1. r(s⋆)(1−γτ)−(1−γ)∑t<τγt rt  ≥  r(s⋆)(1−γτ)−(1−γ)∑t<τγt r(s⋆) = 0r(s^\star)\big(1-\gamma^\tau\big)-(1-\gamma)\sum_{t<\tau}\gamma^t\,r_t\ \ \ge\ \ r(s^\star)\big(1-\gamma^\tau\big)-(1-\gamma)\sum_{t<\tau}\gamma^t\,r(s^\star)\ =\ 0

    The best state goes first. Among all states of all arms, let s⋆s^\star have the largest expected reward r(s⋆)r(s^\star). Suppose an arm sits in s⋆s^\star, but a policy plays other arms first and pulls it only at a later, possibly random, time τ\tau (or never, τ=∞\tau=\infty), collecting expected rewards r0,…,rτ−1r_0,\dots,r_{\tau-1} meanwhile. The waiting arm is frozen, so its pull at τ\tau still pays r(s⋆)r(s^\star) in expectation. Move that pull to the front and delay the intervening pulls by one step; nothing after τ\tau changes. The gain is

  2. rate(s)  =  E[discounted reward of one step from s]E[∑t<Dγt],D=the step’s duration\text{rate}(s)\;=\;\frac{\E\big[\text{discounted reward of one step from } s\big]}{\E\big[\textstyle\sum_{t<D}\gamma^t\big]},\qquad D=\text{the step's duration}

    So an arm in s⋆s^\star should be pulled at once, and ν(s⋆)=r(s⋆)\nu(s^\star)=r(s^\star): no stretch of play can beat the best single reward. Splice it out. Since a visit to s⋆s^\star is always followed immediately by its pull, merge s⋆s^\star into the states that lead to it: a transition into s⋆s^\star 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:

  3. 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 r(s⋆)r(s^\star), 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. ■\blacksquare

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).

Check your understanding

In the interchange step, why can moving the pull of the arm in s⋆s^\star to the front never hurt?

  1. Because discounting makes every early reward worth more than every late one
  2. Because r(s⋆)r(s^\star) 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
  3. Because the intervening pulls were suboptimal anyway
  4. Because the policy has no information about the arm in s⋆s^\star
Show the answer

B. Because r(s⋆)r(s^\star) 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 r(s⋆)r(s^\star) forward from time τ\tau to time 0 gains r(s⋆)(1−γτ)r(s^\star)(1-\gamma^\tau); delaying the intervening rewards by one step loses (1−γ)∑t<τγtrt(1-\gamma)\sum_{t<\tau}\gamma^tr_t, which is at most r(s⋆)(1−γτ)r(s^\star)(1-\gamma^\tau) because every rt≤r(s⋆)r_t\le r(s^\star). Both halves need the arm to be frozen while it waits, so that its reward is still r(s⋆)r(s^\star) at time τ\tau.

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 mm of the KK 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 λ\lambda, a subsidy paid for each passive arm in each step. The relaxed problem decouples into KK single-arm problems. An arm is indexable if the set of states in which passivity is optimal grows steadily from empty to everything as λ\lambda rises; its Whittle index in state xx is then the subsidy at which active and passive are equally good in xx. For a rested arm, frozen when passive, passivity with subsidy λ\lambda is exactly retirement at rate λ\lambda, so the Whittle index is the Gittins index.

Activating the mm 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 m/Km/K 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 modelIndex policy optimal?Why the decomposition fails
Arms move when not pulled (restless)No; the Whittle index is a heuristicWaiting changes an arm's value, so the interchange no longer just reorders rewards
Switching between arms costs somethingNo index policy is, in general (Banks & Sundaram, 1994)An arm's value depends on which arm was played last
m>1m>1 arms are pulled in every stepNot in generalPulls happen in parallel, and single-pull interchanges do not compare parallel schedules
A finite horizon without discountingNot in generalThe time left is shared by all arms and changes even for arms not pulled
Correlated priorsNoA pull of one arm moves the posteriors of others, so the arms are not independent
Each row removes one assumption of the theorem. The finite-horizon row is the setting of most regret analyses, which is one reason the regret literature uses other algorithms.

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 γ\gamma 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 γ\gamma 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 γ\gamma 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 γ\gamma 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 γ=0.9\gamma=0.9 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.

Question 1

A known arm pays 0.65 per pull forever. A new arm has prior Beta(1, 1), and γ=0.9\gamma=0.9. What does the Bayes-optimal player do first?

  1. Pull the known arm, because 0.65 exceeds the new arm's mean of 0.5
  2. Either: the two are equally good
  3. Pull the new arm, because its Gittins index, about 0.703, exceeds 0.65
  4. 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.

Question 2

Switching from one arm to another now costs a fixed amount c>0c>0. What becomes of the Gittins index policy?

  1. It is no longer optimal in general, and in general no index policy is
  2. It stays optimal once cc is subtracted from every index
  3. It stays optimal, because switching costs do not depend on the arms' states
  4. It becomes optimal only for γ\gamma 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.

Question 3

With γ\gamma fixed below 1, can the Gittins index policy abandon the best arm forever?

  1. No: the index policy is optimal, so it always finds the best arm
  2. No: every arm's index rises while it is not pulled, as in UCB
  3. Only if the prior is misspecified
  4. 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.

Question 4

In Whittle's relaxation of a restless bandit, what is the Whittle index of a state of an indexable arm?

  1. The arm's expected reward in that state
  2. The subsidy for staying passive at which being active and being passive are equally good in that state
  3. The Gittins index of the same state computed as if the arm were frozen when passive
  4. The Lagrange multiplier of the constraint that exactly mm 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 mm arms active per step" to "on average" and pricing it with a subsidy λ\lambda for passivity decouples the arms. Indexability means the states where passivity is optimal increase steadily with λ\lambda; 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).