Skip to main content
Deep Reinforcement Learning

Elements of RL and Multi-Armed Bandits

📅 Published: 2026-07-20
🎓 Level: postgraduate
👥 Audience: Postgraduate students in Deep Reinforcement Learning

Elements of RL and Multi-Armed Bandits

2.1 Recap of the Previous Class and the Agent-Environment Interface

2.1.1 Definition and Explanation

Hook: How do you learn to ride a bicycle without someone handing you a manual? You try, wobble, fall, adjust — and eventually ride. That trial-and-error loop is the beating heart of reinforcement learning.

Reinforcement learning is a learning paradigm that is different from both supervised and unsupervised learning, and it is the one that most closely matches the way humans actually learn — by trying things, seeing what works, and adjusting. The first class established this contrast and introduced the *agent-environment interface*, the loop at the centre of every RL problem.

Intuition: Think of the agent-environment interface like a conversation. The agent speaks "I'll do action " and the environment replies with two pieces of information: "here's where you are now" (the new state ) and "here's how good that was" (the reward ). The agent cannot directly see everything about the world — only the state the environment chooses to report.

The interface works as follows. The *agent* is the learner and decision-maker. The *environment* is everything outside the agent that the agent interacts with. The *agent* acts on the environment through an *action*. The environment responds in two ways: it changes its internal situation and returns a new *state* telling the agent "this is how I look now", and it optionally returns a *reward*, a number telling the agent how good the just-completed action was. So the four elementary entities are agent, environment, action, and (state, reward) — the agent talks to the environment via actions and the environment talks back via states and rewards.

Formal summary: At each discrete time step :
  1. Agent observes state .
  2. Agent selects action .
  3. Environment transitions to a new internal situation and returns:
  • New state
  • Reward

This cycle repeats. The agent's goal is to maximise cumulative reward over time.

2.1.2 Symbol Registry

  • — state — — what the environment reports after an action; domain depends on problem
  • — action — — the agent's choice at a state
  • — reward — — a scalar the environment returns
  • — time step — — discrete decision point
Scope: The state reported to the agent is not necessarily everything the environment knows internally — it may be partial or noisy. This is a crucial distinction: the agent sees what the environment *tells* it, not necessarily the full reality.

2.1.3 The Five (or Six) Core Elements of RL

The five core elements of RL are:

Element What it is Example (tic-tac-toe)
Agent The learner and decision-maker Your program playing X
Environment Everything outside the agent The board + opponent + rules
Policy () The agent's rule for choosing actions "If board looks like this, play there"
Value function How desirable each state is Board score: 0.9 = likely win
Model (optional) The agent's representation of how the environment works "If I play here, opponent will probably do that"

A sixth element — the reward signal — is sometimes listed separately from the environment. The professor listed agent, environment, value function, policy, and (optionally) model.

The previous class discussed four of them but did not really develop the *model of the environment*; we cover that in section 2.3. The *value function* carries the notion of *long-term desirability of a state*: a high value state is one the agent is happy to be in, because from there it expects high future reward. In the tic-tac-toe example used previously, the value function was initialised to numbers and then iteratively updated and improved as the agent played.

Pitfall: Beginners often confuse "reward" with "value". Reward is the immediate feedback from one action. Value is the *long-term* expected cumulative reward starting from state . A state can have low immediate reward but high long-term value (e.g., sacrificing a chess piece to win later).

2.1.4 Intuition for the Value Number

If the agent is playing crosses in tic-tac-toe and the board is in a configuration from which five winning replies are possible, the value of that state might be . That is high (the cap is ), so the state represents a configuration from which the agent will likely win. The successor move with the highest value is the move the agent should pick. At any state the agent asks: "What are all the possible actions, which states do they lead to, and what is the value of each of those resulting states?" The best action is the one that takes the agent to the highest-value state. So *having good values is the most important job of an RL learner*. This is the single most important takeaway from the previous class.

Visual intuition: Imagine a topographic map where each cell (state) has an altitude (value). Gold is a tall peak (value 1.0), losing positions are valleys (value 0). The agent always walks uphill — climbing toward the peak. The value function is the altitude map; the policy is the rule "always step toward higher ground."
Worked example — tic-tac-toe value lookup:

Suppose the board has three possible successor states after X's move:

  • State A (play centre): value = 0.85
  • State B (play top-left): value = 0.60
  • State C (play bottom-right): value = 0.70

The greedy agent compares: , so it plays centre.

Sense-check: The centre cell in tic-tac-toe is indeed the strongest opening move — it participates in the most winning lines (4 out of 8: two diagonals, middle row, middle column), which aligns with the highest value.
Recap: The agent-environment interface is a loop: agent acts, environment responds with (state, reward). The five core elements are agent, environment, policy, value function, and (optionally) a model. *Good value estimates drive good decisions.* Next we unpack two flavours of the value function — and — and why that distinction matters.

2.2 The Two Value Functions: State-Value and Action-Value

2.2.1 Why Two Flavours of Value

Hook: When you stand at a crossroads, do you ask "how good is it to be here?" or "how good is it to go left?" These are two different questions — and RL formalises both.

There are two types of value function. The *state-value function* tells the agent how desirable it is to *be* in a given state, irrespective of which action it picks next. The *action-value function* tells the agent how desirable it is to *take a specific action* *in* a specific state . The convention is strict: when we write , we mean value of a *state*; when we write , we mean value of a *state-action pair*.

Formal definitions:

The *state-value function* under policy is: This is the expected cumulative discounted reward starting from state and following policy thereafter. Here is the discount factor that trades off immediate vs. future reward.

The *action-value function* under policy is: Same idea, but conditioned on taking a specific action first, then following .

Notation note: In the MAB problem (sections 2.6–2.17), since there is no state, the state argument is dropped: .

2.2.2 Symbol Registry

  • — state-value function — scalar in some bounded range (here for tic-tac-toe, larger for the grid below)
  • — action-value function — scalar denoting expected reward for doing in
  • — current state; — next state
  • — action selected in
  • — discount factor — scalar in — controls how much future rewards matter relative to immediate ones

2.2.3 Worked Example: 4×4 Grid World

Setup: Picture a 4×4 grid. Each cell is a state. One corner is the *gold* (the goal, value 100); a different cell is the *start* state. The agent is a coin that moves one cell at a time trying to reach gold.

We assign each state a number representing its desirability, for example (quick illustrative figures): start = 0, neighbour cells carried values of 1, 6, 7, 8, 9, 10, 20, and so on up to gold at 100. These are teaching numbers, not a learned solution.

Step-by-step greedy decision:

From the start state, the available actions are *up* (leading to a state with value 6) and *right* (leading to a state with value 9):

  1. Look at up → successor value = 6
  2. Look at right → successor value = 9
  3. Compare:
  4. Pick *right*
  5. Land in the value-9 cell, repeat the process with its neighbours.
What alone requires: To decide, the agent must look *one step ahead*: for each candidate action it must inspect the resulting state's value and then compare. That one-step look-ahead is small here, but in many problems it is not cheap. What would provide instead: If we pre-compute and , the agent just reads the higher Q-value and picks immediately — no look-ahead needed.

2.2.4 The Simplification Q Provides

If instead of just we attach a number to every *state-action pair* — say and — then the agent already knows, without any look-ahead, which action is better *from this state*. It can simply read off the Q-values and pick. The action-value function *summarises* the look-ahead into a single number attached to each arrow. In grid problems the saving is small; in problems where the outcome of an action is stochastic and produces several possible next states, the saving is large.

Scope: The convenience of over depends on whether the environment is stochastic. In deterministic environments (like chess, where moving a piece uniquely determines the next board state), with one-step look-ahead is perfectly fine and uses less storage ( values instead of ). In stochastic environments, is strongly preferred because it pre-bakes the expectation.

2.2.5 The Braking-Car Analogy (Why Q Is Preferred)

Analogy: A *really* good example of when becomes clumsy is driving a car. Suppose there is an action called *brake*. Its outcome is not deterministic: with probability 0.9 the car stops cleanly, with probability 0.07 it skids, and with probability 0.03 the brake fails.

If we only had , the agent would brake, observe the resulting state (stop / skid / fail), and only *then* see how valuable that state is. To choose an action intelligently *before* braking, the agent would need to enumerate all three possible next states, look up each resulting , and form an expectation.

If we instead teach the agent directly, the agent already has a single expectation baked into that arrow — a weighted average of "stops (value 10), skids (value 3), fails (value )" with weights . The agent can simply compare the -arrows of all available actions and pick the largest one without any further look-ahead.

Worked computation for the braking-car example:

Suppose we also have:

Then — brake is the best action. No need to enumerate successor states.

Q: In the grid example, if we always take the greedy move, we could end up stuck in a cycle. Are we doing duplicate detection? Are the values fixed? A: The numbers shown are *initial*, not yet learned. The whole point of learning is to *update* those values so that following them leads to the goal. If you only ever look at the current table and navigate greedily, you learn nothing. You must explore — make some random moves — to discover where you actually go. The randomness breaks the cycle. So exploration-versus-exploitation is exactly what addresses your worry. A concrete discussion of that, called *epsilon-greedy*, is coming up later in this lecture.

The student was asked to hold the further question on exploration-exploitation until section 2.11, where epsilon-greedy is introduced.

Q: From the explanation, action-value functions seem to make more sense, because they consider the situation and the action together. What are the practical implications for using state-value functions at all? A: In many real problems the outcome of an action is *deterministic* — for example, in chess, if you move a piece from one square to another, you know the resulting state for certain, so a -function with light look-ahead is perfectly adequate. Whenever an action's outcome is stochastic (like braking) and you must *observe* it to even know the next state, becomes costly and you should use . So the choice is problem-specific.
Q: Is the goal always to reach the goal state with minimum cost? Is cost a factor? A: Problem-dependent. Rewards were not factored into the grid example purely — sometimes rewards are uniform (so the agent naturally wants to reach the goal as quickly as possible); sometimes there are intermediate rewards ("hidden gems") worth collecting, which changes the optimum. The strategy depends on the reward design, which you the problem designer control.

2.2.6 Intuition for V vs Q

Side-by-side contrast:
Tells you "I would *like to be* here" "I would *like to do this* here"
Requires look-ahead? Yes — one step to compare successor values No — value is pre-baked per action
Storage One number per state: One number per (state, action) pair:
Best when Deterministic outcomes Stochastic outcomes
Industry usage Used in some policy-evaluation settings Dominates practical algorithms

Action values compress the one-step look-ahead into a single number per arrow, which is a real win when the look-ahead is wide or stochastic. Exam note: in textbook problems you will often be shown how to compute *both* and ; in industry practice is the one most algorithms actually use. Keep that distinction in mind.

Pitfall: Assuming and are interchangeable. They serve different purposes. is needed for certain theoretical analyses and policy-gradient methods; drives action selection directly. Knowing which one a given algorithm uses is essential.
Recap: asks "how good is it to be here?" while asks "how good is it to do *this* here?" eliminates the one-step look-ahead and is preferred in stochastic environments. Both are central to RL; most practical algorithms (Q-learning, DQN) use . Next we introduce the *model of the environment* — the optional sixth element.

2.3 Model of the Environment

2.3.1 Definition and Explanation

Hook: If you could predict exactly what the world would do next — every state change, every reward — you would never need to "learn" by trial and error. You could plan perfectly on paper. The *model of the environment* is precisely that predictive blueprint.

A *model of the environment* is an abstract summary of the environment's behaviour — what it returns as the next state and reward for every possible (state, action) the agent might choose. If you know, for every state and action , the probability of observing a particular next state with a particular reward , then you have a complete model of the environment. Mathematically this means you can evaluate for any .

Formal definition: The environment model is the joint transition-reward probability distribution:

This is a conditional probability distribution over next states and rewards , given the current state and action . It satisfies:

If the model is known, the environment is *fully characterised* — you can simulate it without ever interacting with it.

Notation note: The textbook (Sutton & Barto) uses this exact form throughout. Some texts decompose it as for transitions and or for rewards; the joint form is more general.

2.3.2 Symbol Registry

  • — environment model — scalar in — probability of landing in with reward given action was taken in state
  • , , , — already defined in 2.1.2
  • — the set of all possible states
  • — the set of actions available in state

2.3.3 Why a Model Is Useful

Analogy: A model is like a GPS navigation app. Without a model, you'd have to drive every road to learn which routes are fastest. With a model (the map + traffic data), the GPS plans the optimal route *before* you start driving. In RL terms: the model lets you *plan* instead of purely *learn by doing*.

With a good model you no longer have to *estimate* values from interaction — you can compute *theoretically optimal* values using an algorithmic procedure (this will later be *dynamic programming*). The agent can plan extensively on paper before executing anything, much like an engineer or manager who exhaustively lists outcomes and probabilities before committing to a decision.

A model is not available for every problem. Real-world environments often defeat attempts to model them explicitly. But when a model exists (or can be learned), it is a powerful asset.

Scope: A model is useful when:
  • The state space is small enough to enumerate (tic-tac-toe, small grids).
  • The transition dynamics are known or can be learned from data.
  • The environment is stationary (the dynamics don't change over time).

A model becomes impractical when:

  • The state space is enormous (Go: board positions).
  • The dynamics are too complex to model accurately (real-world robotics).
  • The environment is non-stationary and the model would need constant updating.

2.3.4 Student Doubt: Is It Still RL If You Have a Model?

Q: If the environment is already modelled, do we still call this reinforcement learning? I know the probabilities that take me from state to goal already. A: Two clarifications. (1) Even in problems where modelling is theoretically possible — tic-tac-toe, chess — the state space is huge and an exhaustive computation of the optimal policy is impractical, so we still interact with the environment to learn a *policy* that is "good enough" in finite time, rather than carry out an exhaustive proof. So yes, RL is not defined by the absence of a model. (2) "Reinforcement learning" is the framing of a problem as a *Markov Decision Process* — state, action, reward, model (or not) — and *any* approach used to solve that MDP counts as a reinforcement-learning approach. It could be an exact algorithm like dynamic programming, or an approximate method like Q-learning. RL is the *problem class*, not one specific algorithm family.

We will discuss this distinction at length later. For now, the takeaway is: a model is a fancy thing useful for toy problems, and even when you have one you may not want to use it because the optimal solution is too expensive to compute.

Pitfall: Assuming "having a model" means "solving the problem is easy." Even with a perfect model, finding the optimal policy in a large state space can be computationally intractable. Chess has a perfect model (the rules), but no computer can enumerate all possible games.
Recap: The model captures the environment's dynamics. Having a model enables planning (computing optimal actions without interaction), but not all problems admit a tractable model. RL is defined as the MDP problem class, not by the absence of a model. Next we split RL into model-based vs. model-free approaches.

2.4 Model-Based vs Model-Free RL

2.4.1 Definition and Explanation

Hook: Some people plan every detail of a trip before leaving (model-based). Others just show up at the airport and figure it out (model-free). Both can work — but in very different ways.

RL algorithms split into two broad categories by how they treat the model. *Model-based algorithms* assume a model of the environment is given, *or* learn a model and then use it. *Model-free algorithms* — such as policy-gradient methods and Q-learning — do not use a model; they learn directly from interaction.

Side-by-side contrast:
Model-Based Model-Free
Uses a model? Yes (given or learned) No
Learns from Planning with the model Direct interaction with environment
Examples Dynamic programming, MCTS Q-learning, SARSA, policy gradient
Strength Sample-efficient (fewer interactions needed) Simpler, no model required
Weakness Model can be wrong or expensive to build Requires many interactions
When to pick which: If a model is available and the state space is manageable, model-based methods can be sample-efficient. If the environment is hard to model or the state space is huge, model-free methods are simpler and more robust.

2.4.2 A Quick Map

  • Model-based: model given (then plan) or model learned (then use it to plan)
  • Model-free: Q-learning, policy-optimisation methods, etc.

This lecture will not develop these in detail because doing so hand-waves too much; we revisit them once the foundations are solid.

2.4.3 Named Reference

The standard RL textbook — Sutton & Barto, *Reinforcement Learning: An Introduction* — was described as *by far the best in RL* and *the textbook for this course*. Even for deep RL, its foundations remain foundational. The rest of the course material comes from research papers.

Recap: Model-based methods use a model to plan; model-free methods learn directly from interaction. The choice depends on whether a model is available and how expensive it is to build or compute with. The course textbook is Sutton & Barto. Next we cover course logistics and preview how RL becomes *deep* RL.

2.5 Course Logistics, Assessment, and Deep RL Preview

2.5.1 Course Structure

The course is conceptual and mathematical, deliberately rooted in foundations rather than rushing to deep RL. About 60% of the course is on conceptual RL; deep RL is layered on top once foundations are in place. Exam note: the journey can feel theory-heavy but the payoff is well worth it according to past student feedback.

Scope: This course intentionally delays deep RL. Do not expect neural networks in the first half. The foundations (value functions, MAB, MDPs, dynamic programming, Monte Carlo, TD learning) are the prerequisite machinery.

2.5.2 Assessment

  • Two quizzes, each worth 5%; the final grade uses the *better* of the two. (Technically two 5% quizzes are conducted; the higher of the two counts.) No make-up exams, so plan around the 5-day live window for each quiz.
  • Two group assignments; combined weight 25%; split roughly 10–12% before midterm and 13–14% after.
  • Webinars delivered by senior teaching assistants give hands-on practical exposure; reach out to them for practical doubts.
Q: Are the assignments individual or in groups? A: Group assignments.
Exam note: No make-up quizzes. Mark the quiz windows in your calendar now.

2.5.3 From RL to Deep RL with a Toy Example

Hook: You already know tabular RL from the tic-tac-toe example — one value per state, stored in a lookup table. What happens when the state space is too large for a table? You replace the table with a neural network. That single swap turns RL into *deep* RL.

To show how a tabular RL solution becomes *deep* RL, take the tic-tac-toe value function from the previous lecture. The value function is a map: . Originally that map is a *table*, with one entry per state. Now *parameterise* the same function with a *neural network*: a network takes a state as input, applies parameters , and returns a value . The goal of learning becomes: adjust so that returns good estimates of the true value of for every state . If you swap the value table for a neural network — and learn the parameters — you have a *deep RL* solution to tic-tac-toe.

Worked example — table vs. network: Tabular (classic RL):
  • Board state = "XO_\_X\_\_O\_" → look up table entry →
  • One entry per possible board configuration.
Neural network (deep RL):
  • Board state encoded as a vector (e.g., ) → feed into network with weights → output
  • Same network generalises across *all* states, even ones never seen in training.
Key difference: The table stores each value independently; the network *shares* parameters across states, so it can generalise to new states from patterns in seen states.

2.5.4 Symbol Registry — Parameterised Value Function

  • — parameters of the value network — vector — learned by gradient descent
  • — parameterised state-value function — scalar
  • — already defined in 2.1.2

More generally, in a classic RL framework, if you bring deep-learning components into one or more of the agent's pieces (value function, policy, or model), the result is a *deep reinforcement learning* solution.

Pitfall: Assuming deep RL is fundamentally different from tabular RL. It is the *same* problem (maximise cumulative reward) with the *same* elements (agent, environment, policy, value function, model) — the only change is that the value function (or policy, or model) is now represented by a parameterised function approximator (a neural network) instead of a table.
Recap: Deep RL = tabular RL + a neural network as function approximator. The parameterised value function generalises across states. This is the bridge the course will build toward. Next: the multi-armed bandit problem, the simplest RL-like setting.

2.6 Multi-Armed Bandit Problem (MAB): Setup and Motivation

2.6.1 The Casino Analogy

Hook: You walk into a casino with K slot machines. You have a limited budget. Which machine do you pull — and how long do you keep pulling it before trying another? That decision problem is the *multi-armed bandit*.

Picture walking into a casino with K slot machines — say four machines, each with one arm (a lever). You pay for coins, choose one machine, insert a coin, and pull the lever. With high probability the machine swallows your coin; occasionally it pays back, sometimes substantially more than what you spent. The *one-armed bandit* is one such machine; a *multi-armed bandit* is the K-armed version where you must decide which arm to pull at each step.

This is why the term is used: the bandit *takes everything* — almost 99% of players leave with nothing; a tiny fraction gets a payout. Hence the name "bandit".

Intuition: The name captures the essence: the machines rob you. Your job is to figure out which one robs you *least* — and then exploit that knowledge for all it's worth.

2.6.2 Symbol Registry

  • — number of arms — positive integer (e.g., 4 or 10)
  • — the action of choosing arm ,
  • — discrete time-step index,
  • — reward obtained at time — scalar
  • or — *true* (unknown) expected reward of arm — scalar
  • — our *estimate* of at time — scalar

2.6.3 Formal Setup

The MAB problem is defined by:

  1. arms; choosing arm is the action .
  2. Each arm has a *reward distribution* — an unknown probability distribution from which its reward is sampled.
  3. Pulling arm at time gives a reward drawn from that arm's distribution.
  4. The reward distribution of each arm is NOT known to the learner. If it were known, the problem would be like sitting an exam with the question paper already released — no learning necessary.
  5. The objective is to maximise the expected total reward over a horizon of pulls:

Equivalently, minimise *regret* — the gap between your cumulative reward and the reward you'd have earned by always pulling the best arm.

Evaluative vs. Instructive Feedback: The bandit setting isolates a defining core difficulty of RL — feedback is evaluative, not instructive. Instructive feedback (like supervised learning targets) tells the agent what action it should have taken. Evaluative feedback (reward ) indicates how good the taken action was, but does not reveal if it was the optimal action or what rewards unselected arms would have yielded.

2.6.4 Strategy and the Two Key Questions

The strategy has two halves: (i) you must *identify* the arm with the highest expected reward (the "best" arm), then (ii) keep *pulling* that lever to maximise your cumulative score. This raises two questions:

  1. How do you *identify* the best arm in the first place without knowing the distributions?
  2. How do you define "best"?
Pitfall: Assuming you can identify the best arm by pulling each arm once. A single pull gives one noisy sample — the arm that paid out once may not be the best on average. You need *multiple* samples per arm to get reliable estimates.

2.6.5 Why This Topic Matters in an RL Course

Domain connection: MAB is studied in this course because it isolates the core RL challenge — exploration vs. exploitation — in its simplest form. Every full RL algorithm (Q-learning, policy gradient, etc.) faces the same trade-off; MAB lets us study it cleanly before adding the complexity of states and transitions. It also appears directly in clinical trials, A/B testing, ad placement, and recommendation systems.

MAB is a *precursor* to a full RL problem. It is a deliberately simple, *stateless* setup that lets us study the same elements — action selection, estimation, exploration vs exploitation, learning from rewards — without the additional machinery of states. Once we are comfortable here, the jump to full RL is much easier.

Recap: The MAB problem has K arms with unknown reward distributions. Your goal: maximise cumulative reward by balancing exploration (trying arms to learn their values) and exploitation (pulling the arm you currently believe is best). Next we clarify the notation exception: in MAB, we write instead of .

2.7 MAB Is "Stateless": Action-Value Without State

2.7.1 The Notation Exception

Hook: In section 2.2 we established that always has *two* arguments — state and action. Now watch me break that rule on purpose.

In a full RL problem, the action-value function is — a function of *both* state and action, paired. The state-value function is . This was a hard rule in the previous lecture.

In the *multi-armed bandit* problem, the standard form drops the state argument: we write simply . This is a *deliberate exception for this lecture only* because the MAB problem has no state.

Q: In an earlier slide Q was an (action, state) function, V was (state). But here you wrote Q of an action without a state — did you make a mistake or does it actually need a state? A: Good catch. The reason is that MAB is a *stepping stone* to full RL — its defining feature is that it has *no state*. So I drop the index *only for this MAB problem*. Every other RL problem we discuss will use .
Notation clarification:
Problem Action-value State-value
Full RL — value of doing in state — value of being in state
MAB only — value of pulling arm Not defined (no state)

The dropping of the state index is a notational convenience, not a mathematical change. It reflects the fact that in MAB, the "state" is always the same (the casino hasn't changed), so conditioning on it is meaningless.

2.7.2 Symbol Registry — MAB Notation

  • — action-value function *in MAB only* — scalar; the estimate is the running average of rewards from arm
  • — state-value function (full RL only) — not used in this lecture
  • — state — not used in this lecture (the exception)

2.7.3 When Could a State Creep In?

Analogy: Imagine the casino was run by a classmate who reconfigures machines depending on mood, promotion, or festive season. Then the same arm could have a different reward distribution depending on *who* runs it — and that "who" or "when" is a *state*. The vanilla MAB assumes no such state: the arm always behaves the same way.

This is the seam that *contextual bandits* (section 2.17) will later widen. In a contextual bandit, the agent observes some context (a "state") before choosing an arm, but the action does not affect future contexts. In full RL, the action *does* affect the next state.

Pitfall: Writing in an MAB problem or using in a bandit setting. Both are undefined because there is no state. Check whether the problem has a state before choosing notation.
Recap: MAB drops the state from to get — a deliberate exception for this stateless problem only. If a "context" exists that changes the reward distribution, you have a contextual bandit, not vanilla MAB. Next: what actually represents and why we must estimate it.

2.8 The True Value of an Action and Why It Is Unknown

2.8.1 Definition of

Hook: Every slot machine in the casino has a *hidden personality* — on average it pays back a certain amount. You can never see that number written on the machine. You can only discover it by pulling the lever many times and watching what happens.

The *true value* (sometimes written or ) of arm is:

That is, the *expected reward* of choosing arm . The wording used in class was "expected reward if that action is chosen". If dollars, it means: sometimes the arm pays 0, sometimes 1, sometimes 5, sometimes 3, sometimes 20, but *on average over many pulls* you receive 10 dollars. The expectation is the steady-state average of the arm's reward distribution.

Formal definition:

where is the (unknown) probability density of rewards for arm . If the rewards are discrete with possible values :

The expectation is taken over the *reward distribution* of arm , which is assumed to be stationary (fixed) unless stated otherwise.

2.8.2 Symbol Registry

  • , — true (unknown) expected reward of arm — scalar
  • — reward observed at time — scalar
  • — action chosen at time — element of
  • — expectation under the arm's reward distribution
  • — reward probability density for arm
Worked example — understanding the expectation:

Suppose arm 3 has the following reward distribution:

  • Payout = 0 with probability 0.6
  • Payout = 5 with probability 0.3
  • Payout = 20 with probability 0.1

Then:

So on average, each pull of arm 3 yields \$3.50. But any single pull might give \$0, \$5, or \$20 — you never observe the \$3.50 directly.

2.8.3 Why Estimation Is Needed

You cannot read off the machine. The casino conceals the reward distribution forever; only by pulling repeatedly and observing rewards can you draw closer to it. Hence our *learning target* is a sequence of estimates that converge to .

Pitfall: Confusing (the true, unknown, fixed value) with (our current estimate, which changes over time). is a property of the environment; is a property of our knowledge.
Recap: is the true expected reward of arm — a fixed but hidden number. We estimate it from samples: is our running guess, which should converge to as we pull the arm more. Next: the simplest estimator — the sample average.

2.9 Sample-Average Estimation

2.9.1 The Idea

Hook: You've pulled arm 3 ten times and got: 2, 0, 5, 1, 3, 0, 4, 2, 1, 6. What's your best guess for what arm 3 will pay next? The simplest answer: the average so far.

The simplest estimator of is the *sample average*: every time you pull arm , record the reward; the running average of the rewards is your current estimate. So if two friends jointly take turns pulling arms and pass the slot machine back and forth, the second friend simply averages the rewards each arm has produced and reports "this is what we expect from each arm" — that average is the estimate.

Formal definition: At current time , the *sample-average* estimate of is:

where:

  • The numerator is the sum of all rewards obtained from pulling arm before time .
  • The denominator is the number of times arm was pulled before time .
  • The *indicator* equals 1 if action was chosen at step , and 0 otherwise. It acts as a filter: only rewards from arm contribute to the sum.

This is the arithmetic mean of the rewards observed for arm .

The Repeated Estimation Cycle (4-Step Loop):

Action-value methods operate in a continuous 4-step loop at every decision point :

  1. Maintain estimates: Keep a current action-value estimate for each of the arms.
  2. Select an action: Choose action using an action-selection rule (e.g., greedy or -greedy).
  3. Observe reward: Receive numerical reward generated by arm 's reward distribution.
  4. Update only the selected action: Revise the estimate using . Unselected arms retain their previous estimates.

2.9.2 Symbol Registry

  • — running estimate of at time — scalar
  • — reward obtained at step — scalar
  • — action chosen at step — element of
  • — indicator function: 1 if condition true, 0 otherwise

2.9.3 Incremental Update Formula

Storing all past rewards wastes memory. The textbook (Sutton & Barto, Eq. 2.3) gives an *incremental* form that updates the estimate with constant memory and computation per step:

where is the number of times this arm has been pulled, is the current estimate, and is the latest reward.

Derivation:

Interpretation: The new estimate is the old estimate plus a correction term: . The correction shrinks as grows, so early pulls have more influence and later pulls fine-tune.

This is an instance of the general form: which recurs throughout RL.

2.9.4 Concrete Numerical Mini-Example

Setup: Four arms pulled over 10 steps:
Arm Pulls Rewards Average
1 3
2 3
3 3
4 1

Total pulls = 3 + 3 + 3 + 1 = 10, so the next decision is at .

The estimated values at :

A *greedy* agent picks .

Sense-check: Arm 1 looks best with the highest average, but it had a lucky +5 in only 3 pulls — we might be misled.
Q: Are we averaging across all arms, or per arm? A: Per arm only. If arm 1 gave rewards 1, 2, 3 then . Other arms get their own estimates computed only from their own observed rewards.
Numerical Illustration of Tied Sample-Average Estimates:

Suppose three candidate actions yield the following observed sequence of rewards:

Action Observed Rewards Sample-Average Estimate

Insight: Here and are tied at an estimated value of . Under a greedy selection rule, ties are broken arbitrarily. Further exploration is necessary to determine which action is truly superior.

2.9.5 Second Numerical Story: The "Secret Truth"

The hidden reality: Suppose the *true* (unknown) expected rewards of the four arms are:

(The true values of and are not specified in the lecture.)

Our estimates at tell a very different story:

  • but over-optimistic by 1.5
  • but over-pessimistic by 1.5

A *greedy* agent would keep pulling (it looks best) and *never* discover that is actually the best arm. The agent has been misled by the limited sample.

Key insight: With only 3 pulls per arm, the sample averages are noisy. Arm 1 happened to get a lucky +5; arm 3 happened to get unlucky draws. A pure greedy strategy locks in these early, unrepresentative impressions.
Pitfall: Assuming the sample average converges instantly. With only a few pulls, the estimate is highly variable. This is why exploration is essential — you need enough samples from each arm to get reliable estimates before committing.
Recap: The sample average is the simplest estimator of . It can be computed incrementally with . Early estimates are noisy — a pure greedy strategy can lock onto a lucky arm. Next: what *is* greedy action selection, and why is it flawed?

2.10 Greedy Action Selection

2.10.1 Definition

Hook: If you've tried four restaurants and one of them gave you the best meal so far, would you ever go back to the others? The greedy agent says: never.

*Greedy action selection* always picks the action with the currently highest estimated value:

This is exploitation without exploration. If all estimates are tied (e.g., all zeros at ), the tie is broken arbitrarily.

Formal rule:

where returns the action that maximises . Ties are broken arbitrarily (e.g., uniformly at random among tied actions).

Worked example: At with the estimates from section 2.9.4:
  • , , ,
  • , so (pull arm 1)
  • At , if arm 1 returns reward 0, the new estimate:
  • Still the highest, so greedy pulls arm 1 again. And again. Forever.
Pitfall: The weakness of pure greedy, established in section 2.9.5, is that once an action's estimate leads the pack (perhaps by luck), greedy keeps pulling it and never tries the others. The agent gets *stuck* — not because it made a bad choice initially, but because it *never revisits* the other options.

In the 10-armed testbed (section 2.14), the greedy method finds the optimal action in only about one-third of problems. In the other two-thirds, its initial samples of the optimal action were disappointing, and it *never returns to it*.

Recap: Greedy = always exploit, never explore. It's simple but dangerous: early lucky or unlucky samples determine the agent's fate forever. Next: ε-greedy, which fixes this by occasionally exploring at random.

2.11 -Greedy Action Selection

2.11.1 Definition and Explanation

Hook: Pure greedy says "never explore." ε-greedy says "explore *just enough*." The single number controls the entire trade-off.

-greedy (read "epsilon-greedy") *behaves greedily most of the time, but with a small probability , chooses an action uniformly at random*. Here is a hyperparameter in : with probability take the greedy action; with probability pick uniformly among *all* arms (including the greedy one). The wording used in class: "behave greedily most of the time, but once in a while, with a small probability, choose actions randomly independent of their estimated value so far".

Formal definition:

Key properties:

  • Every arm has a nonzero probability of being selected at every step.
  • As , every arm is sampled infinitely often, so all converge to .
  • The probability of selecting the optimal action converges to at least (see section 2.12).

2.11.2 Symbol Registry

  • — exploration rate — scalar in (e.g., 0.4, 0.1, 0.05, 0.01)
  • — current estimate of
  • — the action with the highest estimated value
  • — fraction of steps that exploit (greedy)

2.11.3 Interpretation of Common Values

What different values mean in practice (100 steps):
Exploit steps (approx.) Explore steps (approx.) Behaviour
0 100 0 Pure greedy — no exploration
0.01 99 1 Minimal exploration — very slow learning
0.1 90 10 Moderate exploration — good balance
0.4 60 40 Heavy exploration — lots of random actions

itself can be tuned — start larger and decay to smaller over time.

Intuition: ε-greedy is popular because it is *dead simple*: one number controls the entire exploration-exploitation trade-off. No complex optimality calculations, no prior knowledge required. Just set and go.

-greedy is one of the most popular ways to balance exploration and exploitation. The single number controls all the trade-off you need. Keep that idea in mind.

Pitfall: Setting too high (e.g., 0.9) wastes most steps on random actions. Setting too low (e.g., 0.001) explores so slowly that the agent may never find the best arm in a reasonable horizon. The "right" depends on the problem — but is a common starting point.
Recap: ε-greedy balances exploration and exploitation with one hyperparameter. With probability exploit (pick best arm), with probability explore (pick randomly). Next: worked examples computing the probability of selecting the greedy arm.

2.12 Worked Examples: Probability the Greedy Arm Is Selected

2.12.1 Example 1 — Two Actions,

Setup: Two actions ; assume is the greedy one (has the higher estimated value). . Step-by-step computation:

The ε-greedy rule splits into two branches:

Branch 1 — Greedy (probability ):
  • We always pick the greedy action .
  • Contribution to :
Branch 2 — Explore (probability ):
  • We pick uniformly among both arms, so each gets of the exploration probability.
  • Contribution to :
  • Contribution to :
Total probabilities:

Sense-check: The greedy action gets 75% of the probability — it's favoured but not guaranteed.

2.12.2 Example 2 — Four Actions,

Setup: Four actions ; assume greedy. . Step-by-step: Greedy branch (probability ):
  • Contribution to :
Explore branch (probability ):
  • Pick uniformly among *all four arms* (including ):
  • Each arm gets
Total probabilities:

Sense-check: . ✓
Common student mistake: The lecturer flagged that *despite many discussions, students often make a mistake here*: when exploring, "the greedy arm is also eligible" — that is why the 0.4 must be split *four ways*, not three. The greedy action still receives one share of exploration. Do NOT compute for the greedy arm.

2.12.3 Example 3 — Detailed 4-Armed Bandit with

Setup: A 4-armed bandit () with current action-value estimates: The greedy action is (). We select actions using -greedy with .
Selection Component Probability & Meaning
Random Exploration Probability (Random action chosen 20% of the time)
Direct Greedy Choice Probability ( directly chosen 80% of the time)
Per-Action Exploration Share (Each arm receives 5% prob via exploration)
Total Probability of Greedy Arm (85%)
Total Probability of Each Non-Greedy Arm () (5% each)

Takeaway: The greedy arm can also be picked during the random exploration phase. Thus its overall selection probability is .

2.12.3 Symbol Registry

  • — the candidate actions (arms)
  • — the greedy arm (the arg-max) — single element
  • — exploration rate (already defined in 2.11.2)
  • — selection probability of action — scalar in
  • — number of arms (already defined in 2.6.2)

2.12.4 Probability of Greedy Action — Formal Derivation

Let be the unique greedy action among arms. Using the law of total probability:

For any *non-greedy* action :

Verification with earlier examples:
Example Matches?
Example 1 2 0.5
Example 2 4 0.4
General formula: . This is the *minimum* probability of selecting the greedy arm at any single step.
Recap: The greedy arm is selected with probability ; non-greedy arms each get . The greedy arm is always *more likely* to be chosen, but every arm has a nonzero chance. Next: the formal ε-greedy algorithm as pseudocode.

2.13 Formal ε-Greedy Algorithm (Pseudocode)

2.13.1 Procedure

ε-Greedy Action Selection Algorithm:

Set small (e.g., 0.05). At each time step:

  1. Draw a uniform random number .
  2. If : exploit — select .
  3. If : explore — select uniformly at random from all arms.
function get_action(Q, ε):    u ← random.random()            # uniform in [0, 1)    if u > ε:        A ← argmax_a Q(a)          # exploit    else:        A ← random over all actions # explore    return A
Trace with :
Step ? Action
1 0.82 Yes exploit: pick argmax
2 0.03 No explore: pick random arm
3 0.91 Yes exploit: pick argmax
4 0.67 Yes exploit: pick argmax
5 0.01 No explore: pick random arm

About 5% of steps explore, 95% exploit — matching .

2.13.2 Symbol Registry

  • — sample from — scalar
  • argmax_a Q(a) — action with the maximum current estimate
  • random — uniform distribution over arms
  • — threshold below which we explore (e.g., 0.05 → 5% of the time)

2.13.3 Student Doubt on the Random Function

Q: Since random can return *any* value in , what if it returns the *same* number every step (e.g., always 0.8)? Doesn't that break the 60/40 split we expect? A: No — the expectation of random.random() is *uniform* over . Every real number in that interval has an equal chance of being returned. Hence the *fraction* of draws falling in is exactly , and the fraction in is , *in expectation over many draws*. If your RNG did *not* have this uniform property the algorithm would break, which is why it must be a proper uniform RNG. Of course, in a *single* draw any value can come up; the guarantee is statistical, not deterministic.
Intuition: Think of as a coin flip each step. The coin lands "explore" with probability and "exploit" with probability . Over 1000 steps with , expect about 50 explore flips and 950 exploit flips — but any single flip can go either way.
Pitfall: Confusing the *threshold* with the *probability of exploring*. They are the same thing. The algorithm draws and explores if . Since is uniform, .
Recap: The ε-greedy algorithm is a simple if-else: draw a uniform random number, exploit if it's above , explore otherwise. The threshold directly equals the exploration probability. Next: empirical results comparing greedy, ε=0.1, and ε=0.01 on the 10-armed testbed.

2.14 The 10-Armed Testbed and Empirical Comparison

2.14.1 Setting Up the Testbed

Hook: How do you prove that ε-greedy is better than greedy? You run the same experiment 2000 times and average the results. The *10-armed testbed* is RL's standard laboratory bench.

The 10-armed bandit is a standard testbed for comparing action-selection algorithms. Each arm has its own reward distribution (so its own ). We generate 2000 different *testbeds* (2000 independent 10-armed problems); for each testbed we run the algorithm for 1000 steps; we average the per-step reward across all 2000 testbeds. This gives a clean empirical curve showing how each algorithm performs over a horizon.

How the testbed is built (from Sutton & Barto §2.3):
  1. For each of 2000 independent runs:
  • Draw 10 true action values: for .
  • These are the *hidden* expected rewards of the 10 arms.
  1. At each time step :
  • The algorithm selects arm .
  • The reward is drawn: — the actual reward is noisy, centred on the true value.
  1. After all 2000 runs, average the reward at each time step across runs.

This setup ensures that:

  • Each arm has a different, unknown true value.
  • Rewards are noisy (variance 1), so single pulls are unreliable.
  • Averaging over 2000 runs gives a statistically stable performance curve.

2.14.2 Symbol Registry

  • — fixed number of arms for this testbed
  • — horizon (steps per run)
  • 2000 — number of independent testbeds averaged
  • — initial estimate for every arm
  • — the three settings compared

2.14.3 Initialisation

Each algorithm begins with for all arms. Whichever arm we sample first returns some reward — say or — and that arm's estimate is updated to the running average from then on.

2.14.4 The Three Algorithms Compared

Visual description of the textbook figure (Figure 2.2):

The figure has two panels:

Upper panel — Average reward vs. steps:
Algorithm Colour Behaviour At step 1000
Greedy () Green Rises quickly at first, then plateaus at ~1.0 Low plateau
Red Rises slowly, still climbing at step 1000 ~1.3, still rising
Blue Rises steadily, clear winner at step 1000 ~1.5 (near optimal ~1.55)
Lower panel — % Optimal action vs. steps:
Algorithm At step 1000
Greedy ~33% — found optimal in only 1/3 of problems
~70% and still climbing
~91% — nearly always picking the best arm
Key observation: The greedy method improved slightly faster at the very beginning (no wasted random moves), but then levelled off. The ε=0.1 method overtook it by about step 200 and never looked back.
Exam note: these colours (green/blue/red) and their shapes are how the textbook figure is drawn and were used in the lecture — know the *ordering* of curves (greedy plateaus, ε=0.1 wins at 1000, ε=0.01 still climbing).

2.14.5 Takeaways on Tuning ε

Pitfall: The lecturer emphasised that ε should never reach exactly 0. Even with a near-perfect policy, if you stop exploring altogether and become permanently fixated on what you currently believe is best. In a non-stationary environment, the "best" arm can change — and the agent must keep probing to detect that.

The practical advice from the lecture is:

  1. Start with a larger (more exploration) when you know little.
  2. Decay as your estimates stabilise.
  3. Never bring down to exactly 0. Even with a near-perfect policy, if you stop exploring altogether and become permanently fixated on what you currently believe is best.
  4. In a non-stationary environment where the underlying reward distribution changes with time (your user's tastes change), you must keep at a small positive number *forever* to react to those changes.

If the rewards are truly stationary, you can in principle drive close to zero — but never to zero, because you can rarely say with absolute certainty that you have cracked the distribution.

Four Core Lessons from the 10-Armed Testbed:
  • Early estimates can mislead: A genuinely optimal action may look poor if its initial reward sample happens to be low due to environmental noise.
  • Greedy selection settles prematurely: Once a greedy agent commits to an early leader, it stops testing alternatives and never returns to actions that were initially underestimated.
  • -greedy restores reliability: Periodic random actions ensure that less-tested options get evaluated, allowing the agent to correct early misleading estimates.
  • Exploration has a short-term cost for long-term gain: Random actions may reduce immediate reward in early steps, but they yield significantly higher cumulative reward over long horizons by discovering the optimal arm.
Recap: The 10-armed testbed (2000 runs, 1000 steps, K=10) shows ε=0.1 outperforms greedy at step 1000. Greedy plateaus at ~33% optimal action; ε=0.1 reaches ~91%. The rule: never set ε=0, especially under non-stationarity. Next: what *is* stationarity, and why does it matter?

2.15 Stationary vs Non-Stationary Rewards

2.15.1 Definition and Explanation

Hook: A restaurant that was great five years ago might be terrible today. The recipe didn't change — your taste did. In RL terms: the reward distribution *shifted*.

A *stationary* reward distribution is one that does not change over time; the underlying is fixed. A *non-stationary* reward distribution is one that drifts, even if the agent and the environment are unchanged.

Formal distinction:
Stationary Non-stationary
over time Fixed: Drifting: changes with
Sample average Converges to true value May converge to a *stale* value
Exploration needed? Eventually is OK forever
Example Fair die (always 1/6 per face) User preferences (shift with life stage)

2.15.2 Intuition: Same User, Different Tastes

Analogy: Suppose an e-commerce account has been used by the same user for fifteen years. While they lived in Campus A they bought certain items; after moving they bought other items; after marriage, after having a child — each life-stage shifted their purchase pattern. The *person is the same* but the reward distribution the merchant must learn has shifted. Amazon could not "crack" the user once and for all at year one; the distribution itself evolves.

This is the proper definition of non-stationarity — even in a single-user model:

  • Stationary: assume reward distribution is fixed; once you learn it you are done (mostly).
  • Non-stationary: rewards drift over time, so to keep current you must *continue to explore at a small rate forever*.
Scope — when sample averages fail under non-stationarity:

The sample average gives equal weight to all past rewards. In a non-stationary environment, old rewards become stale — a reward from 3 years ago may be irrelevant to today's distribution. The fix is to use a *constant step size* instead of :

This gives exponentially decaying weight to old rewards: recent observations dominate. With , a reward from 10 steps ago contributes only as much as the most recent reward.

Pitfall: Setting in a non-stationary environment. If the best arm changes and the agent has stopped exploring, it will never notice. The lecturer's rule: ε must stay positive forever in non-stationary settings.
Recap: Stationary = fixed reward distributions; non-stationary = drifting distributions. Under non-stationarity, use constant step size instead of sample averages, and keep forever. Most real-world problems are non-stationary. Next: real-world applications of MAB.

2.16 Real-World Applications of MAB

2.16.1 Online Advertising and Product Recommendation

Hook: Every time Amazon shows you a product banner, it's pulling an arm of a multi-armed bandit. Your click is the reward. The bandit is learning what you like — one impression at a time.

A simplified "naive Amazon" recommendation banner shows 10 products at a time from a catalogue of millions. A click is one reward; a purchase is a higher reward. Each candidate item is an *arm*; its reward distribution depends on the user and is unknown to the platform. The platform iteratively tries items, updates each item's average click/reward rate, and survives by pushing items with higher observed rates. Items never clicked get pruned; new items keep entering. The platform *doesn't know* what *I* will click on next — my reward distribution is unknown and is being learned from interaction.

Mapping MAB to ad/recommendation:
MAB Concept Ad/Recommendation Analogue
Arm A candidate product or ad
Pull Showing the product to the user
Reward Click (small reward) or purchase (large reward)
True click-through rate of product
Exploration Trying new or rarely-shown items
Exploitation Showing the product with the highest observed CTR

2.16.2 Cloud Configuration and Resource Allocation

A cloud platform regularly selects server, cache, or database configurations for microservices. Candidate configurations represent arms (), and the numerical reward is measured as throughput, negative latency, or cost-adjusted performance score. The system learns which configuration yields the best average performance without shutting down services for exhaustive benchmark testing.

Worked Example — Cloud Cache Configuration Selection:

A platform tests three cache configurations with observed performance scores:

  • :
  • :
  • :

A greedy selection rule picks (score 75.0). Continuous -greedy exploration ensures configuration is re-tested periodically in case workload patterns shift.

The Missing Counterfactual Information Principle: In online ads, web layout tests, clinical trials, and cloud tuning alike, the learner only observes reward feedback for the action actually taken. The unselected alternatives yield no counterfactual observations. This missing information is the fundamental reason why active exploration is mandatory in reinforcement learning.

2.16.3 Detecting a Biased Coin

A student proposed a "biased coin" as a 1-armed bandit: toss the same coin repeatedly, label heads as 1 and tails as 0, and average. If the long-run average is exactly 0.5 the coin is unbiased; if it stays above 0.5 it is biased toward heads and below 0.5 toward tails. The lecturer noted this is *technically* a K-armed bandit with (a "one-armed bandit"). Strictly speaking it is trivial, because there is only one action and hence no choice — proper MABs need at least two arms.

Worked example — biased coin estimation:

Flip a coin 10 times: H, H, T, H, T, H, H, T, H, H → 7 heads, 3 tails. Running average after flips: .

Is the coin biased? With only 10 samples we can't be sure. After 1000 flips with 700 heads, we'd be much more confident that .

Connection to MAB: This is a single-arm estimation problem — there's no choice to make, just estimation. It illustrates the *estimation* component of MAB without the *selection* component.

2.16.3 Clinical Trials

Suppose you have several candidate drugs/treatments to try, a limited number of patients, and you do not yet know which treatment is best. Each regimen is an *arm*; patient response is the *reward*. You keep trying until you accumulate enough evidence to push the bulk of trials to the treatment with the highest response — but you *still* must keep exploring to refine estimates.

Domain connection: Clinical trials are one of the most impactful applications of MAB. The "reward" is patient health — a wrong choice has serious consequences. This is why exploration in MAB is not just about efficiency; in medicine, it can be about saving lives. Adaptive trial designs using MAB principles have been used in cancer treatment studies and COVID-19 vaccine trials.

2.16.4 Simple Portfolio Management

A simplified portfolio of 10 stocks where you have actions *buy / sell / hold* producing rewards. Each action is an arm and we learn its expected reward. Without context this is rather toy; full portfolio management is a more complex agent with state.

Q: In stock/portfolio problems, isn't there a notion of time? Doesn't that make it stateful? A: Time can be a context — so in *some* framings the problem becomes stateful; in a deliberate toy framing where action selection is independent of context you can still pose it as an MAB.

2.16.5 Why Amazon Can Sometimes Surprise Us

Amazon might model my *account*, but my account is used by me, my spouse, my child, my parents; my purchase patterns shift as life stages change. Exam note: the lecturer emphasised these illustrate *why exploration is forever*, not a one-time startup phase — even when you think you have "nailed" a user.

2.16.6 When Is MAB Not Enough? Sports, Games, Driving

Q: Could we model board games like chess, football, or driving as multi-armed bandits? A: No — the lecturer explicitly rejected all three. In each case, the action's worth depends on the *current state* (the board configuration, the position of the ball, the road situation). A move that's brilliant in one chess position is terrible in another. The vanilla MAB is appropriate for *stateless* problems where the action's worth does not depend on context. If it does, you have crossed into *contextual bandit* territory (next section) or a *full RL* setup with state.
Recap: MAB applies to stateless problems: ad selection, clinical trials, A/B testing. It does *not* apply when action value depends on state (games, driving). The key diagnostic: does the value of an action change with context? If yes → contextual bandit or full RL.

2.17 Contextual Bandits and the Bridge to Full RL

2.17.1 Definition and Explanation

Hook: Vanilla MAB says "every arm is the same every time." But what if the casino has a mood ring that changes the odds? Now you need to *read the room* before pulling.

A *contextual bandit* extends MAB by adding a *context* — extra information observed before each action — but *still without* the agent's action affecting future contexts. The reward distribution of an arm depends on this context; the agent learns a policy .

Formal definition:

In a contextual bandit, at each step :

  1. The agent observes a *context* (also called "side information" or "features").
  2. The agent selects arm .
  3. The agent receives reward drawn from a distribution that depends on *both* and .
  4. Crucially: the agent's action does *not* affect the next context . Contexts arrive exogenously.

The policy is a mapping: , where is the context.

2.17.2 Why It Differs From MAB and Full RL

Three-way comparison:
Feature Vanilla MAB Contextual Bandit Full RL
State/context? None Yes () Yes ()
Action affects next state? N/A No Yes
Reward depends on Arm only Arm + context Arm + state
Policy (fixed)
Example Slot machine Ad recommendation given user features Chess, driving
Sequential? No No (each step independent) Yes (current action changes future)
Key insight: Contextual bandits sit between MAB and full RL. They add context (like RL) but keep the single-step structure (like MAB). The missing piece — actions influencing future states — is what makes full RL *sequential*.
Q: Couldn't Amazon just use recommendation based on history, location, similar users, etc. (lots of context)? A: Yes — if you bring in that context you are no longer solving a vanilla MAB. You are solving a contextual bandit, which is the bridge to full RL. We will discuss it next class.

2.17.3 Why This Matters

Domain connection: Contextual bandits power many real-world systems:
  • News recommendation: context = user profile + time of day; arms = articles; reward = click.
  • Personalised medicine: context = patient demographics + history; arms = treatments; reward = outcome.
  • Dynamic pricing: context = demand + competitor prices; arms = price points; reward = revenue.

MAB is studied partly to learn the basic RL elements — action-selection, value estimation, exploration vs exploitation, stationary vs non-stationary — in the simplest possible setup, *before* the full MDP machinery. Once you can handle MAB confidently, full RL with states becomes much easier to reason about.

Recap: Contextual bandits add context to MAB but keep the single-step structure (actions don't affect future contexts). They bridge vanilla MAB (no state) and full RL (sequential state transitions). The course will revisit them after building MDP foundations. The progression: MAB → contextual bandits → full RL.

2.18 Self-Assessment & Numerical Practice Questions

Test your understanding of multi-armed bandits, sample-average updates, and -greedy action selection with these end-of-topic review problems adapted from Sutton & Barto and course material.

Question 1: Multi-Armed Bandit Setup & One-Situation Rationale

Problem: Define the -armed bandit problem. State the learner’s objective and explain why the problem is described as a "one-situation" decision problem.

Solution / Answer:

  • Definition: A -armed bandit problem is a simplified evaluative-feedback decision problem where a learner repeatedly chooses one action from a set of available actions (arms) over discrete time steps . Each action yields a numerical reward drawn from an unknown reward probability distribution.
  • Objective: To maximize expected total cumulative reward (or minimize total expected regret) over the decision horizon.
  • Why "One-Situation": It is stateless. The environment stays in a single static situation across all time steps. The choice of action at time has no influence on future situations, states, or future reward distributions.
Question 2: Evaluative vs. Instructive Feedback

Problem: Explain why the feedback in a bandit problem is evaluative rather than instructive. Why does the received reward not directly reveal the best action?

Solution / Answer:

  • Evaluative Feedback: Indicates how good the action taken was, but does not indicate whether it was the best action available or what rewards unselected actions would have produced.
  • Instructive Feedback: Directly specifies the correct/optimal action regardless of the action taken (as in supervised target labels).
  • Why reward doesn't reveal the best action: Rewards are stochastic samples. A single reward is drawn from a distribution with noise. An optimal action might yield a low reward by chance on a single pull, while a suboptimal action might yield a high reward. Without counterfactual feedback for unselected arms, repeated sampling is required to estimate expected values .
Question 3: True Value vs. Estimated Value

Problem: Explain the difference between the true action value and the estimate . What kind of experience is needed for to become reliable?

Solution / Answer:

  • is the true, fixed, unknown expected reward of action . It is a property of the environment's reward distribution.
  • is the learner's estimate of at time step , calculated from past observed rewards. It is a property of the learner's current knowledge.
  • Reliability Requirement: By the Law of Large Numbers, becomes a reliable estimate of only when action has been selected and sampled a large number of times ().
Question 4: Sample-Average Computation & Greedy Identification

Problem: A bandit has three actions. The observed rewards are: Compute the sample-average estimate for each action and identify the greedy action.

Solution / Answer:

Greedy Action: Actions and are tied with the highest estimated value of . A greedy action selection rule will break ties arbitrarily between and .

Question 5: 5-Armed Bandit Selection Probabilities

Problem: In a 5-armed bandit (), suppose and there is a single unique greedy action. What is the probability of random exploration? What is the total probability that the greedy action is selected?

Solution / Answer:

  • Probability of random exploration: (20%).
  • Probability of selecting greedy action :
  • Each non-greedy action gets probability (4%).
Question 6: 2-Armed Bandit Selection Probability

Problem: In -greedy action selection with two actions () and , what is the total probability that the greedy action is selected? Show the calculation.

Solution / Answer:

  • Exploitation branch probability:
  • Exploration branch share per arm:
  • Total probability for greedy action:
Question 7: Sequence Exploration Trace Problem

Problem: A 4-armed bandit uses -greedy action selection and sample-average estimates with initial values for all actions. Ties are broken by choosing the smallest action index. The first observations are: Identify the time steps on which random exploration definitely occurred, and time steps on which it could have occurred.

Solution / Answer:

Let's trace estimates step-by-step:

  • Step 1 (): Initial estimates . All arms tied at 0. Greedy choice with smallest index is arm 1. Action taken: . Update: .
    Exploration status: could be greedy (tie-break) or random exploration.
  • Step 2 (): Current estimates . Greedy action is any of (tied at 0). Action taken: . Update: .
    Exploration status: Arm 2 was tied-highest, so could be greedy or exploration.
  • Step 3 (): Current estimates . Unique greedy action is arm 2 (). Action taken: .
    Exploration status: Selected greedy arm 2. Could be exploitation or exploration. Result: , so . Update: .
  • Step 4 (): Current estimates . Greedy actions are arms 3 and 4 (tied at 0). Action taken: .
    Exploration status: DEFINITE EXPLORATION! Arm 2 had estimate , while arms 3 and 4 had higher estimate . Choosing arm 2 at could only happen via random exploration! Result: , new . Update: .
  • Step 5 (): Current estimates . Unique greedy action is arm 2 (). Action taken: .
    Exploration status: DEFINITE EXPLORATION! Arm 3 had estimate , which is lower than greedy arm 2 (). Selecting arm 3 at step 5 was a non-greedy choice, so it definitely occurred via random exploration.

Summary:

  • Definitely explored: Steps and .
  • Could have explored (or exploited): Steps .

Question 8: Website Banner Formulation & Unobserved Counterfactuals

Problem: A website can show one of four banners to a visitor. A click gives reward 1 and no click gives reward 0. Identify the arms and rewards in this bandit formulation. What is not observed after a banner is selected?

Solution / Answer:

  • Arms (): The 4 banner variants available to display.
  • Reward (): Binary indicator — if visitor clicks, if visitor leaves without clicking.
  • Unobserved Counterfactuals: The rewards (click or no click) that would have occurred if any of the other 3 banners had been displayed to this specific visitor are completely unobserved.
Question 9: Cloud Cache Configuration Action Values

Problem: A cloud platform tests three cache configurations. The observed performance scores are: Compute the current action-value estimate for each configuration and identify the greedy configuration.

Solution / Answer:

Greedy Configuration: Configuration has the highest current estimate (), so it is the greedy choice.

Question 10: Early Fast Improvement vs. Long-Run Plateau

Problem: Based on the 10-armed testbed performance curves, explain why the greedy method can improve quickly at first but still perform poorly in the long run.

Solution / Answer:

  • Early fast improvement: Greedy immediately exploits whichever arm gives a positive early reward, avoiding exploratory steps on arms that yield low initial rewards.
  • Long-run plateau: Because greedy never explores, if the true optimal arm initially receives an unluckily low reward sample, greedy locks onto a suboptimal leader and never samples the optimal arm again. In the 10-armed testbed, greedy gets stuck on suboptimal arms in roughly 2/3 of all problems, leading to a low long-run average reward plateau (~1.0 vs ~1.55 optimal).
Question 11: Comparing vs.

Problem: Compare and in the 10-armed testbed. Which one explores more often, and how does that affect early discovery of the optimal action vs. long-term performance?

Solution / Answer:

  • explores 10% of the time, while explores only 1% of the time.
  • Early discovery: finds the optimal action much faster early on because it samples alternative arms 10 times more frequently.
  • Long-term performance: levels off at choosing the optimal action ~91% of the time (because 10% of the time it still chooses randomly). improves more slowly, but over very long horizons () it will eventually reach ~99% optimal action selection because its asymptotic penalty for random exploration is much smaller (1% vs 10%).

Exam Guidance Summary

Course structure and assessment:
  • Lecture structure: ~60% of the course is conceptual RL foundations; deep RL comes later. The course journey may feel theoretical but is well worth it.
  • Quizzes: Two quizzes, each 5%, best of two counted. No make-ups — plan around the 5-day live window for each quiz.
  • Assignments: Two group assignments, 25% total split as ~10–12% pre-midterm and ~13–14% post-midterm.
Exam-ready topics from this lecture:
  • The vs. distinction: asks "how good is this state?", asks "how good is this action in this state?"
  • The notation exception: MAB uses instead of because there is no state.
  • Sample-average estimation formula and its incremental form .
  • The -greedy probability calculation: .
  • Formal ε-greedy pseudocode: draw , exploit if , explore otherwise.
  • The 10-armed testbed comparison: greedy plateaus (~33% optimal), wins at 1000 steps (~91% optimal), still climbing.
  • should never reach 0, especially under non-stationary rewards.
  • Classification of scenarios as MAB / contextual bandit / full RL.
Question patterns to expect:
  • Numerical worked problems on ε-greedy selection probabilities (given and , compute ).
  • Short derivations (sample-average formula, incremental update).
  • Conceptual questions on stationary vs. non-stationary rewards and why must stay positive.
  • Application-oriented classification: given a scenario, identify whether it's MAB, contextual bandit, or full RL — and justify.

Key Industry Applications

Domain connection: MAB is not just a textbook curiosity — it drives billions of dollars of decisions in industry. Here are the major application areas.
  • Recommendation and ad platforms (Amazon-style): viewing each candidate product/ad as an arm and the click or purchase as a stochastic reward. The platform maintains running estimates of each item's click-through rate and shifts traffic toward higher-performing items.
  • Clinical trial design: experimental arms compared with limited patient budget; balance exploration (treating new candidates) vs exploitation (using the currently best estimate). Adaptive MAB-based trials have been used in oncology and vaccine development.
  • Simple portfolio management (toy framing): buy/sell/hold as actions with stochastic returns. A simplified MAB abstraction; real portfolio management requires state (market conditions, time, holdings).
  • A/B testing / web layout optimisation: different layouts or treatments as arms; MAB generalises A/B testing by continually shifting traffic toward better variants rather than committing fixed 50/50 splits. This is sometimes called "adaptive experimentation."
  • Detecting a biased coin: a one-armed verification benchmark requiring many samples to estimate a Bernoulli parameter from a running average. Useful as a teaching tool and as a component of more complex systems.
  • Production system monitoring under non-stationarity: adaptive agents maintaining a small but positive exploration rate permanently so they react to drifts. Cloud systems use MAB-based approaches for load balancing, feature flagging, and canary deployments.
Named references:
  • The standard RL textbook — Sutton & Barto, *Reinforcement Learning: An Introduction* — is described as the *best book in RL* and is the course textbook; even deep RL rests on what it covers.
  • Course research papers (cited across remaining lectures) were mentioned but not specifically named this session.

DRL Lecture 2 Notes · Elements of RL and Multi-Armed Bandits

Deep Reinforcement Learning· postgraduate· 2026-07-20

Sections Breakdown

12.1 Recap of the Previous Class and the Agent-Environment Interface

2.1 Recap of the Previous Class and the Agent-Environment Interface

22.2 The Two Value Functions: State-Value \(V(s)\) and Action-Value \(Q(s,a)\)

2.2 The Two Value Functions: State-Value \(V(s)\) and Action-Value \(Q(s,a)\)

32.3 Model of the Environment

2.3 Model of the Environment

42.4 Model-Based vs Model-Free RL

2.4 Model-Based vs Model-Free RL

52.5 Course Logistics, Assessment, and Deep RL Preview

2.5 Course Logistics, Assessment, and Deep RL Preview

62.6 Multi-Armed Bandit Problem (MAB): Setup and Motivation

2.6 Multi-Armed Bandit Problem (MAB): Setup and Motivation

72.7 MAB Is "Stateless": Action-Value Without State

2.7 MAB Is "Stateless": Action-Value Without State

82.8 The True Value of an Action and Why It Is Unknown

2.8 The True Value of an Action and Why It Is Unknown

92.9 Sample-Average Estimation

2.9 Sample-Average Estimation

102.10 Greedy Action Selection

2.10 Greedy Action Selection

112.11 \(\varepsilon\)-Greedy Action Selection

2.11 \(\varepsilon\)-Greedy Action Selection

122.12 Worked Examples: Probability the Greedy Arm Is Selected

2.12 Worked Examples: Probability the Greedy Arm Is Selected

132.13 Formal ε-Greedy Algorithm (Pseudocode)

2.13 Formal ε-Greedy Algorithm (Pseudocode)

142.14 The 10-Armed Testbed and Empirical Comparison

2.14 The 10-Armed Testbed and Empirical Comparison

152.15 Stationary vs Non-Stationary Rewards

2.15 Stationary vs Non-Stationary Rewards

162.16 Real-World Applications of MAB

2.16 Real-World Applications of MAB

172.17 Contextual Bandits and the Bridge to Full RL

2.17 Contextual Bandits and the Bridge to Full RL

182.18 Self-Assessment and Numerical Practice Problems

2.18 Self-Assessment and Numerical Practice Problems

19Exam Guidance Summary

Exam Guidance Summary

20Key Industry Applications

Key Industry Applications

Postgraduate students in Deep Reinforcement Learning

Exam Revision Notes

Below is the distilled, exam-ready core. Every entry comes from the full explanation above. Use this section for rapid review; return to the main notes when a point needs more context.

Recap of the Previous Class and the Agent-Environment Interface

Must-know: The agent-environment interface loop: agent sends action, environment returns (state, reward). The five core elements. Good value estimates are the most important job of an RL learner.

⚠️ Top pitfall: Confusing immediate reward r with long-term value V(s). A state can have low immediate reward but high long-term value.

Self-check: Name the five core elements of RL.

Connects to: 2.2, 2.3

The Two Value Functions: State-Value \(V(s))​{} and Action-Value \(Q(s,a))​{}

Must-know: V(s) vs Q(s,a): V requires one-step look-ahead, Q does not. Q is preferred in stochastic environments. In practice, Q dominates industry algorithms.

⚠️ Top pitfall: Confusing V and Q. V(s) asks 'how good is this state?', Q(s,a) asks 'how good is this action in this state?'. They are not interchangeable.

Self-check: In the braking-car example, compute Q(s, brake) given P(stop)=0.9 (value 10), P(skid)=0.07 (value 3), P(fail)=0.03 (value -10).

Connects to: 2.7, 2.8, 2.9

Model of the Environment

Must-know: The model p(s',r|s,a) is the joint transition-reward distribution. RL is the MDP problem class; having a model does not mean the problem is solved — planning can still be intractable.

⚠️ Top pitfall: Assuming 'having a model' means 'solving the problem is easy'. Even with a perfect model (e.g., chess rules), optimal policy can be intractable.

Self-check: What is the environment model, and what does it allow you to do?

Connects to: 2.4, 2.1

Model-Based vs Model-Free RL

Must-know: Model-based vs model-free: model-based uses a model (given or learned) to plan; model-free learns directly from interaction. Examples: DP (model-based), Q-learning (model-free).

⚠️ Top pitfall: Assuming model-free means 'no planning at all' — some model-free methods still perform limited planning through learned value functions.

Self-check: Is Q-learning model-based or model-free? Explain.

Connects to: 2.3, 2.5

Course Logistics, Assessment, and Deep RL Preview

Must-know: Course structure: two quizzes (5% each, best of two, no make-ups), two group assignments (25% total). Deep RL = tabular RL + neural network function approximator.

⚠️ Top pitfall: Assuming deep RL is fundamentally different from tabular RL. Same problem, same elements — just a different representation.

Self-check: What is the single change that turns tabular RL into deep RL?

Connects to: 2.6, 2.1

Multi-Armed Bandit Problem (MAB): Setup and Motivation

Must-know: MAB: K arms, unknown reward distributions, maximise cumulative reward. Core challenge: exploration vs exploitation.

⚠️ Top pitfall: Thinking one pull per arm is enough to identify the best arm. Noisy samples require multiple pulls.

Self-check: What is the objective in the MAB problem?

Connects to: 2.7, 2.8, 2.9

MAB Is "Stateless": Action-Value Without State

Must-know: MAB uses Q(a) instead of Q(s,a) because there is no state. This notation exception applies only to MAB.

⚠️ Top pitfall: Writing Q(s,a) or V(s) in an MAB problem — both are undefined without a state.

Self-check: Why does MAB write Q(a) instead of Q(s,a)?

Connects to: 2.8, 2.17

The True Value of an Action and Why It Is Unknown

Must-know: q*(a) = E[R_t | A_t = a] is the true expected reward. It is fixed but unknown; Q_t(a) is our running estimate that should converge to it.

⚠️ Top pitfall: Confusing q*(a) (true, fixed, unknown) with Q_t(a) (estimate, changes over time).

Self-check: What is the difference between q*(a) and Q_t(a)?

Connects to: 2.9, 2.6

Sample-Average Estimation

Must-know: Sample-average formula with indicator notation. Incremental update: Q_{n+1} = Q_n + (1/n)[R_n - Q_n]. Per-arm averaging. Early estimates are noisy and can mislead greedy selection.

⚠️ Top pitfall: Averaging across all arms instead of per arm. Assuming a few pulls give reliable estimates.

Self-check: Given rewards for arm 2: 0.5, 0.5, -1.5, what is Q(2)?

Connects to: 2.10, 2.11, 2.8

Greedy Action Selection

Must-know: Greedy: A_t = argmax Q_t(a). No exploration — once an arm leads, it's pulled forever.

⚠️ Top pitfall: Pure greedy gets stuck on early lucky estimates. Only finds optimal action in ~1/3 of problems in the 10-armed testbed.

Self-check: Why does pure greedy fail to find the best arm in most problems?

Connects to: 2.11, 2.12

\(\varepsilon)​{}-Greedy Action Selection

Must-know: ε-greedy: with prob 1-ε pick greedy action, with prob ε pick uniformly at random. All arms have nonzero selection probability. ε=0 is pure greedy.

⚠️ Top pitfall: Setting ε too high wastes steps; too low means insufficient exploration. ε=0.1 is a common starting point.

Self-check: What happens when ε=0? When ε=0.5?

Connects to: 2.12, 2.13, 2.14

Worked Examples: Probability the Greedy Arm Is Selected

Must-know: P(greedy) = 1 - ε + ε/K. P(non-greedy) = ε/K. The greedy arm is always eligible during exploration — split ε/K among all K arms, not K-1.

⚠️ Top pitfall: Splitting exploration probability among K-1 arms instead of K. The greedy arm is eligible during exploration too.

Self-check: For K=10, ε=0.1, what is P(greedy arm)?

Connects to: 2.13, 2.14

Formal ε-Greedy Algorithm (Pseudocode)

Must-know: ε-greedy pseudocode: draw u~U(0,1), if u>ε exploit (argmax), else explore (random).

⚠️ Top pitfall: Confusing the threshold ε with something other than the exploration probability — they are identical.

Self-check: Trace the ε-greedy algorithm for 3 steps with ε=0.1 and u values 0.5, 0.08, 0.95.

Connects to: 2.14

The 10-Armed Testbed and Empirical Comparison

Must-know: 10-armed testbed: 2000 runs, 1000 steps. ε=0.1 is winner at 1000 steps (~91% optimal, ~1.5 avg reward). Greedy ~33% optimal. ε=0.01 still climbing. Never set ε=0.

⚠️ Top pitfall: Thinking greedy is 'good enough'. It finds the optimal action only ~1/3 of the time in the 10-armed testbed.

Self-check: In the 10-armed testbed, which ε value performs best at step 1000? Why does ε=0.01 not win?

Connects to: 2.15, 2.11

Stationary vs Non-Stationary Rewards

Must-know: Stationary = fixed distributions. Non-stationary = drifting. Under non-stationarity: constant step size α, ε>0 forever. Sample averages give equal weight to stale data.

⚠️ Top pitfall: Setting ε=0 in non-stationary environments. Using sample averages when rewards drift.

Self-check: Why can't you set ε=0 in a non-stationary environment?

Connects to: 2.16, 2.14

Real-World Applications of MAB

Must-know: Applications: ads, clinical trials, A/B testing. MAB is for stateless problems. Board games, driving, sports require state → contextual bandit or full RL.

⚠️ Top pitfall: Applying MAB to stateful problems (chess, driving). If action value depends on context, MAB is insufficient.

Self-check: Why is chess not a suitable MAB problem?

Connects to: 2.17, 2.15

Contextual Bandits and the Bridge to Full RL

Must-know: MAB: no context. Contextual bandit: context exists, action doesn't affect future context. Full RL: action affects future state. Contextual bandits bridge MAB and full RL.

⚠️ Top pitfall: Confusing contextual bandits with full RL. In contextual bandits, the next context is independent of the action taken.

Self-check: What is the key difference between a contextual bandit and full RL?

Connects to: 2.7, 2.6

Exam Guidance Summary

Must-know: V vs Q, sample-average formula, ε-greedy probability P(A*)=1-ε+ε/K, ε never reaches 0, MAB vs contextual bandit vs full RL classification.

⚠️ Top pitfall: Splitting ε among K-1 arms instead of K. Setting ε=0.

Self-check: For K=5, ε=0.2, what is P(greedy arm)?

Connects to: 2.12, 2.14, 2.15

Key Industry Applications

Must-know: Applications: ads, clinical trials, A/B testing, production monitoring. Key reference: Sutton & Barto.

⚠️ Top pitfall: Confusing toy MAB applications (portfolio) with the real thing (which requires state).

Self-check: Name two real-world applications of MAB and explain why each is a stateless problem.

Connects to: 2.16, 2.17

Was this lecture useful?

Loading comments…
🤖

BitsNotes AI Assistant

Subject Notes Assistant

Configure AI Chat

Choose how to access the chatbot
Have your own API key?

Switch to "Bring Your Own Key" tab above for unlimited access with any OpenAI-compatible provider.

🔑 Enter API key above to fetch live models from provider, or enter model name manually.
OpenAI-Compatible API Support

Choose any provider preset (Gemini, DeepSeek, Kimi, GLM, MiniMax, Qwen, OpenAI, Groq, Ollama, etc.) or enter a custom endpoint URL.

Security & Privacy First

Your API key is sent directly from your browser to your specified provider. BitsNotes servers never store or see your key.