5.1.8 · D1Reinforcement Learning Foundations

Foundations — Epsilon-greedy strategy

3,288 words15 min readBack to topic

This page assumes you have seen none of the notation in the parent note. We build every symbol, one at a time, each from the picture it stands for, so that when you re-read the parent note every squiggle already means something.


The story before the symbols

You sit in front of several buttons. Press a button, a coin-machine spits out some reward (money, points, dopamine). Each button has its own hidden average payout. You cannot see the averages — you can only see what came out this press. Your job: over many presses, collect as much as possible.

That is the whole setting. Every symbol below is just a careful name for one piece of this picture. This setting is the multi-armed bandit problem.

Figure — Epsilon-greedy strategy

Symbol 1 — an action , and the set of all of them

The picture: one button in the row above. Pressing it is taking the action.

Read this aloud: " is the set containing , , up to ." The curly braces always mean "the set of things listed inside."

  • Why the topic needs it. Epsilon-greedy has to choose among options. You can't talk about choosing until you've named the pile of things to choose from.

Symbol 2 — how many actions, (and )

The vertical bars mean "the size of the set " — count its members. So . Same idea, two notations.

  • Why the topic needs it. When epsilon-greedy explores "at random," it picks one out of buttons with equal chance. That equal chance is , and you can't write without .

Symbol 3 — reward , and the true average

But one press is noisy — the same button gives different each time. What we really care about is the button's long-run average.

The picture: each button has a secret dial set to its true average. In the figure above those secret dials are the shaded bars — you the player never see them.

  • Why the topic needs it. "Best button" means the one with the highest . Exploration only matters because is hidden from us.

Symbol 4 — our estimate and

We can't see . So we keep our own running guess.

Two Q's, remember the difference:

Which Q is the hidden truth we can never see?
(little q, with a star)
Which Q is the guess we build from data?
(big Q, no star)

The subscript in just tags time: = our guess after presses total. As time grows, the guess improves. So and are the same notebook — we write the bare when the moment in time doesn't matter, and add the (as ) exactly when we need to point at "the guess at that particular turn."

The figure below shows exactly this improvement. Read it as one story: the green dots are the raw rewards you saw press by press for a single button (they scatter wildly — one press tells you little). The purple curve is , the running average of all green dots seen so far; watch it wobble a lot early (few samples) then steady. The red dashed line is the hidden truth you never see. The whole point of the picture: as the press-count grows left-to-right, the purple crawls onto the red . That is the definition of in action — a guess made of averaged rewards, tightening toward the dial with time.

Figure — Epsilon-greedy strategy
  • Why the topic needs it. Epsilon-greedy's "exploit" move is "press the button with the biggest ." So is the thing the whole strategy stares at.

Symbol 5 — the average that builds

How do we turn observed rewards into ? Just average them.

Unpacking the new marks:

  • = the count of how many times button was pressed up to time (" for number, subscript = for that button").
  • = the summation sign. The big Greek (sigma) says "add up." The underneath and on top say "let walk from 1 to ." So means .
  • Multiplying the total by divides by how many there were → that's the average.

(Whenever the exact turn doesn't matter we'll drop the and just write — same quantity.)

  • Why the topic needs it. This averaging is why trying an action more often makes its trustworthy — the engine behind "explore to learn." And it forces us to say what happens on step zero, before any data exists.

Symbol 6 — argmax, picking the winner (and breaking ties)

Break the word: max = the biggest value; arg = "argument," i.e. which input produced it. So argmax = "which button gives the max."

  • The little underneath reads "for ranging over the set " — check every button.
  • Picture: line up the bars of ; argmax is your finger pointing at the tallest bar.
  • Why the topic needs it. "Exploit = pick current best" is literally "press " — and without a tie rule, step one (all-zero ) has no defined answer.

Symbol 7 — probability and the parameter

The picture: a biased coin. It lands "explore" a fraction of the time and "exploit" the remaining fraction .

Figure — Epsilon-greedy strategy
  • Why the topic needs it. is the knob epsilon-greedy is named after. Everything — regret, convergence, tuning — is a story about this one number.

Symbol 8 — the indicator and the gap

Example: is exactly when our current-best guess happens to be the truly-best button, else . It's the tidy way to say "count this term only when it applies."

  • Why the topic needs it. The policy formula must say "add the exploit-probability only for the one button that is currently best, and add nothing for the rest." The indicator is exactly that switch: it flips the term on for the argmax button and off for every other button, letting us write the whole rule as one clean line instead of a two-way if/else.

Picture: the height difference between the best dial and button 's dial. For the best button itself (no regret). For a bad button, a tall gap.

  • Why the topic needs it. Regret — the running cost of exploring — is built by multiplying each button's gap by how often you press it. No , no way to measure the price of learning.

Gluing it all together — the policy

Now that every symbol exists, we can write the whole algorithm in one line. A policy (Greek pi, no relation to ) is simply the probability that the epsilon-greedy rule presses button on turn .

Before the formula, one tiny housekeeping symbol. Inside the argmax we need a name for "some button we're scanning over," and we already used for the button in question — so we use a fresh letter purely as a dummy scanning index: just walks over all buttons in so we can find the tallest . It stands for no particular button; it's a loop variable, and once the scan finds the winner, is done.

Reading the coin from Symbol 7 and the argmax from Symbol 6:

Read it left to right using the symbols you now own:

  • Explore branch : with probability (Symbol 7) we ignore the notebook and throw a dart at the -slice pie (Symbol 2), landing on button with chance . Every button gets at least this slice — that's the guarantee that no button is ever abandoned.
  • Exploit branch : with the leftover probability we press the current-best button (Symbol 6). The scan-index ranges over all buttons to locate the top ; the indicator (Symbol 8) is a switch: it is only for the argmax button and for everyone else, so this whole term is for non-best buttons and for the best one.

Two sanity checks a novice can run:

  • The best button (when it is also the estimated best) gets — most of the pie, but never all of it.
  • Any other button gets just — a thin but non-zero slice, forever.

And the slices add up to a whole pie: one best button at plus others each at sums to exactly . That is the parent note's action-selection formula — now every piece of it is a symbol you defined.


How the pieces feed the topic

The map below is just the reading order of this page, drawn as arrows. Trace it top to bottom: the top boxes are raw setup, arrows point from a symbol to whatever symbol uses it, and everything funnels into the final policy box. Read each arrow as "feeds into."

Buttons a and set A -- Symbol 1

Count k -- Symbol 2

Reward r each press -- Symbol 3

True hidden value q-star -- Symbol 3

Sample average -- Symbol 5

Estimate Q -- Symbol 4

argmax picks best -- Symbol 6

Explore rate epsilon -- Symbol 7

Policy pi -- one line rule

Gap Delta and regret -- Symbol 8

Epsilon-greedy strategy

Walking the arrows in words: buttons () give you both a count and, per press, a reward . Rewards do two jobs — they define the hidden truth , and they get averaged into the estimate . The estimate feeds argmax (who's currently best). Argmax plus the explore rate glue into the one-line policy . Finally the policy and the hidden truth together produce the gap/regret . Every box is a symbol you met above; the topic sits where all arrows meet.


Where these symbols go next

  • The same and averaging reappear in Q-Learning, where depends on both a state and an action.
  • The explore-vs-exploit tension is the whole subject of Exploration vs Exploitation.
  • Smarter answers to the same bandit picture are UCB and Thompson Sampling — they replace the blind coin with a cleverer choice.
  • Averaging rewards toward a hidden target echoes Stochastic Gradient Descent, and the "keep old experiences" idea grows into Experience Replay.

Equipment checklist

Cover the right side; can you answer each before reading on?

What does stand for?
The set of all actions (buttons) you may choose from.
What is ?
The number of available actions; .
Difference between and ?
is the true hidden average reward; is our data-built guess of it.
What does the subscript in add?
It tags the moment in time — the guess after presses; same notebook as .
How is computed from rewards?
Average the observed rewards: .
What breaks when , and how do we fix it?
The average divides by zero (undefined); fix by initializing (zero or optimistic) before any press.
What does mean?
Add the rewards through together.
What does return — a value or an action?
An action: the button owning the largest .
How do you break an argmax tie?
Pick uniformly at random among the tied top buttons (or lowest-index by convention).
What is and its range?
The exploration rate, a probability in .
What does do, and what does do?
is pure greedy (never explores); is pure random (ignores ).
Why is the exploit probability ?
The two coin outcomes must sum to 1, so exploit gets the leftover.
What is the dummy index in ?
A scanning loop variable ranging over all buttons to find the tallest ; not any particular button.
What does the one-line policy equal?
.
What is the chance of picking any one button while exploring?
(uniform over buttons).
What does equal?
if the condition is true, otherwise.
What is and when is it zero?
, the reward lost by choosing ; it is for the best action .