5.1.7 · D4Reinforcement Learning Foundations

Exercises — Exploration vs exploitation tradeoff

2,472 words11 min readBack to topic

Before we start, one glossary of every symbol so nothing appears un-earned:


Level 1 — Recognition

Recall Solution 1.1

(a) Exploitation — it uses known good info, no new information gained. (b) Exploration — uncertain outcome, gathers information. (c) Exploration — landing in the band forces a random pick to gather data.

Recall Solution 1.2

, and the optimal arm is .


Level 2 — Application

Recall Solution 2.1

Sample mean = sum of rewards / number of pulls. Greedy picks the highest estimate → arm .

Recall Solution 2.2

-greedy plays the best action with probability , and otherwise picks uniformly among all actions (which can re-select the best one). (a) (b) Each non-greedy action: Sanity: . ✓

Recall Solution 2.3

The agent starts exploring half the time and, by step 100, explores only ~18% of the time — exactly the "explore early, exploit later" schedule.


Level 3 — Analysis

Recall Solution 3.1

With : Chosen: Action 2 (highest UCB ). Why: Actions 2 and 3 were tried only 10 times, so their exploration bonus () is huge compared with Action 1's (). The bonus is the optimistic width of the confidence interval — under-sampled arms get the benefit of the doubt.

Edge case : the bonus divides by , so an untried arm would divide by zero. The standard convention is to treat an untried arm's UCB as — equivalently, UCB pulls every arm once first before the formula takes over. This guarantees no arm is ignored for lack of a single sample, and it removes the division-by-zero.

Reading the figure below. The chart stacks each arm's score into two coloured pieces: the cyan base is the estimate , the amber block on top is the exploration bonus . Notice the amber blocks for Actions 2 and 3 are almost three times taller than Action 1's — that visual gap is exactly why Action 2's total (dashed line) overtakes Action 1 despite a lower cyan base. The amber annotation marks the winner.

Figure — Exploration vs exploitation tradeoff
Recall Solution 3.2

Recall from the glossary that — the running sum of gaps. Here every wrong pull has gap , so regret is just times the number of wrong pulls. The whole question reduces to: how many wrong pulls does each strategy make?

  • Pure exploit stuck on the wrong arm: it plays the arm all steps → wrong pulls . Grows proportional to → linear.
  • Pure explore (random forever): on average half the pulls hit the wrong arm → wrong pulls . Still proportional to → linear.
  • Balanced (UCB/decaying ): here the number of wrong pulls does not grow like — it grows like . Why ? Sketch: UCB stops preferring the wrong arm once its exploration bonus drops below the gap (below that, the bonus can no longer lift the wrong arm's optimistic score above the true best arm). Setting bonus and solving for : . With the standard constant this gives the classic bound . Because counts wrong pulls, the regret is Plugging and (so ): The magnitude here happens to sit between the two extremes, but the point is not the number — it is the shape: this term grows like , so as keeps rising it eventually falls far below the linear lines, and the per-step regret . That flattening is .

Reading the figure below. Three curves share one axis: cumulative regret vs steps . The amber and cyan straight lines are the two extremes — both climb without bending, the signature of . The white curve (balanced) shoots up early while it is still learning, then bends into the gentle shape of . The bending is the whole point: after the agent is confident, extra steps add almost no regret.

Figure — Exploration vs exploitation tradeoff

Level 4 — Synthesis

Recall Solution 4.1

Posterior update: . Mean With only 10 observations the distribution is still moderately wide, so sampled draws scatter around . Occasionally a high draw is produced → the agent still explores. As more data arrive, grows, the Beta narrows, and exploration fades automatically — no manual schedule needed.

Recall Solution 4.2

Both -greedy and UCB rely on already observing some reward difference to guide choices. In Montezuma's Revenge the probability of stumbling onto reward by random action is , so stays for every action — neither method has a signal to act on. The fix is an intrinsic reward for novelty: , i.e. curiosity-driven exploration. UCB/-greedy work when rewards are dense enough to differentiate arms (e.g. bandits); curiosity is needed when they are not.


Level 5 — Mastery

Recall Solution 5.1

Arm 2 is selected. Principle: when values tie, UCB breaks the tie toward the less-explored option. Optimism-under-uncertainty says the arm you know least about deserves a look — its true mean might be far above the tie value.

Recall Solution 5.2

Per suboptimal pull, the gap . Using with only the wrong pulls contributing: Total regret Average regret per step The count of exploratory pulls () does not scale with ; if it grows like the total regret stays while the per-step regret . Since (what pure-exploit-on-wrong-arm would cost) and the per-step loss shrinks toward , this is sublinear () — the hallmark of a good exploration schedule.

Recall Quick self-check clozes

UCB's exploration bonus grows with ::: — up with time, down with visits. Thompson sampling explores because its posterior is ::: wide when data is scarce. Balanced strategies achieve regret of order ::: (sublinear). The per-step regret of a good strategy tends to ::: as .