Foundations/Multi-Armed Bandits

Lesson 1.32,233 words

Multi-Armed Bandits

A bandit is reinforcement learning stripped to a single decision, repeated: no state, no consequences, only the tension between exploiting the arm that looks best and exploring the ones that might be better. We build up the whole toolkit — sample-average value estimates, the incremental update rule, ε-greedy, optimistic initialization, UCB, and gradient bandits — and use it to study exploration in isolation, the one problem that carries over to the full setting.

╌╌╌╌

The single feature that separates reinforcement learning from every other kind of learning is that its feedback evaluates the action taken rather than instructs which action was correct.1 A supervised label tells you the right answer independent of what you guessed; an evaluative reward tells you only how good your choice was, and says nothing about the choices you didn't make. That single difference is what forces an agent to search — to try things in order to find out whether they are good.

This lesson studies evaluative feedback in the simplest possible setting: one that has no notion of state, where the same decision is faced over and over with no lasting consequences. Stripping the problem this far removes almost everything that makes reinforcement learning hard and leaves exactly one thing behind, in isolation, where we can see it clearly: the need to balance exploration against exploitation. Everything built here — value estimates, the incremental update rule, the exploration schemes — carries forward to the full RL problem; what is missing here is precisely what the next lessons add back.

The k-armed bandit problem

Consider being faced repeatedly with a choice among different actions. After each choice you receive a numerical reward drawn from a stationary probability distribution that depends on the action you selected, and your objective is to maximize expected total reward over some number of selections — say, over time steps.2

The name comes by analogy to a slot machine, a one-armed bandit, except that this one has levers. Each play of a lever pays off from that lever's own reward distribution, and by playing repeatedly you concentrate your pulls on the levers that pay best. (A less cheerful analogy, from Sutton and Barto: a doctor choosing among experimental treatments for a series of seriously ill patients, where each reward is a patient's survival.)

Each of the actions has an expected reward given that it is selected; call this the value of the action. Write for the action selected at step and for the resulting reward. The value of an arbitrary action , denoted , is the expected reward given that is chosen:

If you knew every the problem would be trivial: always pick the action with the largest value. The difficulty is that you do not know the values, and must estimate them from experience. Write for the estimated value of action at step . We want to be close to , and we get there only by selecting and watching what comes back.

The bandit interaction loop — at each step the agent selects an arm and the environment returns a reward drawn from that arm's fixed distribution with mean . There is no state and no next situation.

Estimating action values

The most natural way to estimate is to average the rewards actually received from . If, prior to step , action has been chosen with rewards , the sample-average estimate is

where is when the predicate holds and otherwise. If the denominator is zero (the action has never been tried) we set to a default such as . By the law of large numbers, as the count of -selections grows, . This is only one estimator among many, but it is the one to build intuition on.

Given estimates, the simplest action-selection rule is to take a greedy action — one whose estimated value is currently largest:

Greedy selection always exploits current knowledge to maximize immediate reward; it spends no time sampling apparently inferior actions to check whether they are secretly better.

Exploration versus exploitation

At any step, at least one action's estimate is the greatest. Selecting a greedy action is exploiting your current knowledge. Selecting a non-greedy action is exploring, because it improves your estimate of that action's value. Exploitation is the right move for maximizing the reward on this one step, but exploration may yield more reward in the long run.

The conflict is genuine and unavoidable. Suppose a greedy action's value is known with certainty, while several alternatives are estimated to be nearly as good but with large uncertainty. At least one of those uncertain actions is probably better than the greedy one — you just don't yet know which. Spend a few steps finding out, and you can exploit the winner for all the steps that remain. Because you cannot both explore and exploit on a single selection, every method must decide how to split its selections between the two.

ε-greedy action selection

The simplest way to force some exploration is to behave greedily most of the time but, on a small fraction of steps, select uniformly at random among all the actions:

These ε-greedy methods have a useful asymptotic guarantee: because every action is eventually sampled infinitely often, every converges to , and the probability of selecting the optimal action converges to more than . That is only an asymptotic statement, though; what matters in practice is how the methods behave over a finite run.

ε-greedy selection — the greedy arm is chosen with probability ; with probability an arm is drawn uniformly at random, guaranteeing every arm is sampled indefinitely.

The 10-armed testbed

To compare greedy against ε-greedy quantitatively, Sutton and Barto use a standard benchmark: the 10-armed testbed.3 It is a suite of randomly generated -armed bandit problems. For each problem the true values , , are drawn independently from a standard normal distribution (mean , variance ). When a method selects action on a given problem, the reward is drawn from a normal distribution with mean and variance . A method is run for steps on one problem — one run — and its behavior is averaged over all runs to measure how it improves with experience.

Two curves summarize a method's learning: the average reward per step, and the percentage of steps on which the optimal action was chosen. Comparing a greedy method () against two ε-greedy methods ( and ), all using sample-average estimates, gives the characteristic result.

Average reward on the 10-armed testbed over 1000 steps (schematic, after Sutton and Barto, Figure 2.2). The greedy method () climbs fast then plateaus low near ; explores most and ends highest; improves slowly but overtakes greedy. The best possible reward-per-step on this testbed is about .

The greedy method improves slightly faster at the very start but plateaus at a reward-per-step of about , well below the best possible . It gets stuck because it often locks onto a suboptimal action after a few unlucky early samples of the true best one and never reconsiders — on this testbed greedy finds the optimal action only about a third of the time. The ε-greedy methods do worse at first (they waste steps exploring) but keep improving their estimates and eventually pull ahead. The method explores more, finds the best arm sooner, but caps its optimal-action rate at (it keeps exploring of the time); climbs more slowly but would eventually exceed on both measures.

Percentage of steps on which the optimal arm was selected (schematic, after Sutton and Barto, Figure 2.2). rises fastest but ceilings near ; climbs slowly toward a higher final level; greedy stalls near .

A worked ε-greedy trace

The learning curves average over problems, which hides the mechanics. It helps to watch a single run step by step. Take a -armed bandit with true values , , , so arm is optimal. Run -greedy with , sample-average estimates, all , ties broken toward the lowest index. The rewards below are the values actually sampled from each arm's unit-variance normal on this run.

greedy?update's
tie
argmax
argmax
explore
argmax
argmax
explore
argmax

Two things stand out. On step every estimate is tied at , so the greedy rule picks arm by the tie-break, and three straight exploits of arm lock in before any exploration happens — a greedy method () would have stayed on arm forever from this start, never discovering that arm pays more. The lone exploratory step at is what rescues the run: one pull of arm returns , its estimate jumps above arm 's, and from then on the greedy action is the optimal arm. By step the estimates () already order the arms correctly, and further pulls will tighten toward its true . This is the whole argument for exploration in miniature: a single non-greedy pull changed which action the method commits to for the rest of the run.

The worked trace above, plotted. Each estimate (three lines) moves only on steps that pull arm ; the sample-average step shrinks each move as counts grow. The exploratory pull of arm 2 at step 4 lifts above , after which the greedy choice tracks the optimal arm.

The advantage of exploring depends on the task. With noisier rewards it takes more exploration to identify the best arm, so ε-greedy wins by more. With deterministic rewards greedy would know each action's value after one try and never need to explore — except that even then, if the problem is nonstationary (the true values drift over time), exploration is needed to catch an action that has quietly become the best. Nonstationarity is the case most often met in reinforcement learning, which is one reason exploration never goes away.

Incremental implementation

Storing every reward and re-averaging would cost memory and computation that grow without bound. The average can instead be rewritten so each new reward nudges the old estimate a little, with no history stored — a shape that recurs throughout the subject. Concentrate on a single action and let denote the estimate of its value after it has been selected times, so . Given the new reward , the updated average can be computed from alone:

This requires memory only for and , and a small constant computation per step. The last line has a form that recurs throughout reinforcement learning — the general update rule:

The bracketed quantity is an error in the estimate, reduced by taking a step of size toward the Target (here the new reward ). For the sample average the step size is , shrinking as more rewards accumulate. Almost every method in the rest of the subject is an instance of this one line; only the target and the step size change.

Algorithm:Simple-Bandit\textsc{Simple-Bandit}ε\varepsilon-greedy action-value method
  1. 1
    Q(a)0Q(a) \gets 0, N(a)0N(a) \gets 0, for a=1a = 1 to kk
  2. 2
    loop
    forever
  3. 3
    with probability 1ε1 - \varepsilon do
  4. 4
    AargmaxaQ(a)A \gets \arg\max_a Q(a)
    ties broken at random
  5. 5
    else
  6. 6
    AA \gets a random action
  7. 7
    Rbandit(A)R \gets \text{bandit}(A)
  8. 8
    N(A)N(A)+1N(A) \gets N(A) + 1
  9. 9
    Q(A)Q(A)+1N(A)[RQ(A)]Q(A) \gets Q(A) + \frac{1}{N(A)}\big[R - Q(A)\big]

Nonstationary problems

The sample average weights every past reward equally — the right choice for a stationary problem, the wrong one where the true values drift. When the problem is nonstationary it makes sense to weight recent rewards more heavily than old ones. The standard way to do this is to use a constant step size in place of :

To see why a fixed favors recent rewards, expand the recursion — each step back multiplies by another factor of , so a reward's influence fades the older it gets. Unrolling the recursion shows what the constant step size does to the weights:

This is a weighted average — the weights together with sum to . The weight on reward decays by a factor of for each intervening step, so older rewards contribute exponentially less. For this reason a constant step size is called an exponential recency-weighted average: it tracks a moving target instead of converging to a fixed one.

With a constant step size the weight on a reward decays exponentially with its age — the most recent reward carries weight and each earlier one is discounted by a further factor of , so the estimate tracks recent rewards and forgets the distant past.

For a step-size sequence , convergence to the true values with probability requires (steps large enough to overcome initial conditions) and (steps small enough to settle). The sample-average choice meets both. A constant meets the first but not the second — so the estimate never fully converges and keeps responding to the latest rewards, which is precisely what you want when the target is moving.

Optimistic initial values

Every method so far depends on the initial estimates , which introduces a bias. For sample averages that bias vanishes once each action has been tried; for constant it is permanent but fades over time. The initial values are usually a nuisance parameter to be set to zero — but they can also be turned into a cheap exploration trick.

Suppose that on the 10-armed testbed, where the true values are near zero, we set every initial estimate to . That is wildly optimistic: whatever action is tried first returns a reward well below , so its estimate drops, and the learner becomes disappointed and switches to another still-optimistic action. Every action gets tried several times before the estimates settle — the system explores at the start even if it acts greedily throughout.

Optimistic initialization is effective and simple on stationary problems, but it is not a general solution to exploration. It works exactly once, and any task that changes later gets no benefit from it. This lesson built the value-estimation core of the bandit and the two simplest ways to force exploration. Smarter exploration — optimism under uncertainty, learned preferences, adding context, and the regret theory that ranks these methods — continues in Bandit Exploration Algorithms.

Footnotes

  1. Sutton & Barto, Reinforcement Learning (2nd ed.), Ch. 2 introduction — the defining feature of reinforcement learning is evaluative feedback (how good the action taken was) as opposed to instructive feedback (what the correct action was), which is what creates the need for active exploration.
  2. Sutton & Barto, §2.1 — A k-armed Bandit Problem: the repeated choice among actions with stationary reward distributions, the action value , and the estimate .
  3. Sutton & Barto, §2.3 — The 10-armed Testbed: 2000 randomly generated 10-armed problems with and unit-variance rewards, averaged to produce the reward and optimal-action learning curves of Figure 2.2.

╌╌ END ╌╌