Skip to main content
Deep Reinforcement Learning

Temporal Difference Learning, Maximization Bias, and Function Approximation

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

Prerequisite Knowledge

This lecture builds on the following concepts from earlier lectures. If any feel unfamiliar, review the linked notes before proceeding.

Previously Covered in This Subject

  • Temporal Difference Learning (TD(0), SARSA, Q-Learning) — covered in Lecture 10
  • On-Policy vs Off-Policy Control — SARSA learns the value of the behavior policy; Q-learning learns the optimal action values — covered in Lecture 10
  • n-Step TD Prediction — the credit-assignment spectrum between one-step TD and Monte Carlo — covered in Lecture 10

Temporal Difference Learning, Maximization Bias, and Function Approximation

11.1 Revision of Temporal Difference Learning

Symbol registry — TD Learning

  • — state value function — scalar, expected return from state
  • — action value function — scalar, expected return from state taking action
  • — learning rate / step size — scalar in
  • — discount factor — scalar in
  • — reward at time — scalar
  • — state at time
  • — action at time
  • -step return from time — scalar
  • — exploration rate in -greedy — scalar in
  • — TD error at time — scalar,

11.1.1 The TD Learning Framework

How can you learn from experience without waiting for the final result? You are driving home and get stuck in traffic five minutes after leaving. You know your initial 30-minute estimate was too optimistic — do you really need to reach home before updating it? TD learning says no: you can learn right now, using your current guess about the rest of the trip.

Think of TD learning like a weather forecaster who updates predictions throughout the day. At 8 am she predicts 22°C. By 10 am it is already 24°C. She does not wait until midnight to revise — she adjusts right now. The 10 am reading gives her new information (the reward), and she bootstraps: she uses her own forecast for later hours to estimate the final temperature. That is what TD does — it learns a guess from a guess.

The analogy breaks in one way: the forecaster has a model of weather physics. TD is model-free — it learns purely from observed outcomes, no physics required. But the bootstrap idea is the same.

Temporal Difference (TD) learning combines Monte Carlo and dynamic programming. Like Monte Carlo, it is model-free: it learns from raw experience, no environment model needed. Like dynamic programming, it bootstraps: it updates after every step, not after full episodes. And critically, TD(0) for prediction is on-policy — it estimates values for the policy it follows — while TD control methods like Q-learning can be off-policy.

The core TD update:

Every term named:

  • : current estimate of state 's value
  • : step size (learning rate), how much the new information moves the estimate
  • : reward received after taking action from
  • : discount factor, how much future rewards matter (0 = only immediate, 1 = all equally)
  • : current estimate of next state's value — the bootstrap
  • : the TD target — a better estimate than alone
  • : the TD error — surprise, how wrong the old estimate was

The TD error is central. It measures the difference between what you expected () and what you got plus what you now expect for the future (). If is positive, the state was better than expected — increase its value. If negative, worse than expected — decrease it.

From the textbook (Sutton & Barto §6.1), the TD error can be written recursively in terms of the Bellman equation for :

TD replaces the true with the current estimate and the expectation with a single sample — it both samples and bootstraps. Monte Carlo samples but does not bootstrap. DP bootstraps but does not sample. TD does both.

Driving home — TD vs Monte Carlo

You estimate 30 minutes to get home. You reach your car at 6:05 and it starts raining — new estimate 40 minutes total. Here is how each method updates the initial estimate:

Time State Actual time to go Your estimate
6:00 Leave office 43 min 30 min
6:05 Reach car, raining 38 min 40 min (new guess)
6:20 Exit highway 23 min 35 min
6:30 Secondary road 13 min 40 min
6:40 Home street 3 min 43 min
6:43 Arrive home 0 43 min

At 6:05, the TD update for the "leave office" state uses the 6:05 estimate (40) as the bootstrap target:

With : .

Monte Carlo must wait until 6:43 when the actual return (43) is known, then updates: . Both moved upward, but TD did it 38 minutes earlier. That is the power of bootstrapping.

Sense-check: The "leave office" estimate should be around 43 (the actual total time). TD moved it from 30 to 35 immediately; over many days of similar traffic, it would converge near 43.

Scope: When TD applies and when it breaks.

Assumptions: 1. The environment is a Markov Decision Process — the next state and reward depend only on the current state and action, not on history. 2. The step size satisfies the usual stochastic approximation conditions (decreasing but not too fast, e.g., , ) for guaranteed convergence in the tabular case. 3. For off-policy TD (like Q-learning), all state-action pairs must be visited infinitely often.

What breaks when assumptions fail:

  • If the environment is not Markov (partial observability), TD may converge to a wrong value or oscillate — you would need methods that maintain a belief state.
  • If is too large, the estimates oscillate and never settle. If is constant (not decaying), TD still works but fluctuates around the true value — convergence is in expectation, not pointwise.
  • If some state-action pairs are never explored in off-policy control, the learned policy can be arbitrarily poor — this is why exploration (e.g., -greedy) is mandatory.

Visual intuition: Imagine a graph tracking your drive-home estimates over time. The x-axis is time (6:00 to 6:43). The y-axis is predicted total travel time (30 to 43 minutes). Your estimates start at 30, jump to 40 at 6:05, dip to 35 at 6:20, climb back to 40 at 6:30, then to 43 at 6:40. TD updates (with ) are proportional to the vertical gaps between consecutive estimates — the temporal differences. If a prediction changes by minutes, TD says the earlier state should also shift up. The takeaway: TD chases its own changing predictions, learning from how predictions evolve through time.

Pitfalls:

1. Confusing TD target with actual return. The target is a guess, not the truth. It is biased because is itself an estimate. Monte Carlo targets are unbiased but high-variance. Neither is always better — it depends on the problem.

2. Treating TD(0) as off-policy for prediction. TD(0) for state values is on-policy — it learns for the policy that generated the data. If you want to learn about a different policy, you need importance sampling or off-policy methods like Q-learning.

3. Forgetting that the discount factor shapes what is learned. With , TD learns the expected undiscounted return (average total reward). With , it learns a myopic value that increasingly ignores distant rewards. A common mistake: setting without considering that , meaning rewards 100 steps away still carry weight — this might be what you want, or it might not.

4. Ignoring that TD(0) bootstraps on its own estimates. Early in training when is random, the bootstrap target is nearly random. TD learns from bad guesses early on — but they improve together, and convergence is still guaranteed for tabular cases under appropriate conditions.

TD learning bridges Monte Carlo and dynamic programming — it samples like MC but bootstraps like DP. The TD error is the engine: it captures how much expectations shift over time, letting you learn from every step without waiting. Next we see that targets can span multiple steps, trading bias for variance.

Real-world connection: TD learning is behind many practical systems. In finance, TD methods price options by learning value functions from market data without modeling the full stochastic process. In robotics, TD enables robots to learn walking gaits from trial and error — each step gives a reward signal, and the robot updates its value estimates online rather than waiting until it falls over. The DQN agent that learned to play Atari games at superhuman level (Mnih et al., 2015) uses Q-learning, the control variant of TD, as its core learning rule.

11.1.2 Multi-Step Targets (n-Step TD)

The target does not have to be one-step. You can use a two-step target, a three-step target, or any -step target. The general -step return is:

For a two-step target ():

For a three-step target ():

The -step return spans the spectrum between one-step TD (, high bias, low variance — relies heavily on the bootstrap estimate) and Monte Carlo ( episode length, zero bias, high variance — no bootstrap, waits for actual return). The lecture calls this the "depth and breadth" trade-off. Shorter means the target is mostly estimated value (biased but stable). Longer means the target is mostly actual rewards (unbiased but noisy).

The textbook (Sutton & Barto §7.1) proves the error reduction property: the worst-case error of the expected -step return is at most times the worst-case error in :

This guarantees that -step returns are always better targets in expectation than the raw bootstrap — the improvement factor shrinks as grows (when ).

11.1.3 SARSA — On-Policy TD Control

SARSA stands for State-Action-Reward-State-Action. It is an on-policy algorithm: it learns the value of the policy it is currently following. The name describes the transition quintuple: you are in a state , you take an action , you receive a reward , you land in a next state , and you choose a next action .

The update is:

The target uses — the value of the action actually taken next according to the current policy (typically -greedy). This is what makes it on-policy: the update uses the action the policy actually selects. SARSA learns for the behavior policy , and as becomes greedier, SARSA converges to the optimal policy, provided all state-action pairs are visited infinitely often (e.g., with decay).

Exam note: SARSA's on-policy nature means it learns safer policies in risky environments. In the cliff-walking example (Sutton & Barto §6.5), SARSA learns a path farther from the cliff because its updates account for the occasional exploratory step off the cliff. Q-learning learns the optimal (shortest) path but falls off more often during training.

11.1.4 Q-Learning — Off-Policy TD Control

Q-learning is an off-policy algorithm. The update uses the maximum action value from the next state — not the action the policy would actually take:

The target uses — the best possible value from , regardless of what action is actually taken next. The behavior policy (which selects actions in the environment) can be -greedy for exploration, but the update always assumes greedy continuation. The policy being learned (greedy with respect to ) differs from the policy being followed (-greedy) — so it is off-policy.

Q-learning directly approximates the optimal action-value function , independent of the policy being followed. This makes it simpler to analyze — the early convergence proofs for TD control were for Q-learning. The requirement: all state-action pairs must continue to be updated (achieved through exploration).

Student Q&A (deduplicated from multiple questions):

Q: Why is Q-learning off-policy? It still uses the same Q-table for both updates and action selection. A: The Q-values are shared, but the policies differ. The update target assumes the agent will act greedily forever after (). But the behavior policy — what the agent actually does — explores with -greedy. The target says "learn this value assuming optimal future behavior," while the behavior says "but I might explore." This gap is the defining trait of off-policy learning. SARSA, by contrast, uses the actual next action in its target — what the agent will really do — so it learns the value of the current (possibly suboptimal) policy.

Q: Does Q-learning always learn faster than SARSA? A: Not necessarily. Q-learning learns the optimal policy directly, which sounds better. But in risky environments (like the cliff-walking example in Sutton & Barto §6.5), Q-learning's online performance is worse because it occasionally explores off the cliff while SARSA learns a safer, longer path. The key distinction: Q-learning learns optimal values faster in terms of convergence to ; SARSA often achieves better online performance during training.

Real-world: Q-learning and its deep variant (DQN) are the foundation of many practical RL systems — from game-playing AI (Atari, Go) to robotic control. DQN used Q-learning with a convolutional neural network to achieve human-level performance on 49 Atari games from raw pixels (Mnih et al., 2015, Nature).

11.2 Maximization Bias

Symbol registry — Maximization Bias MDP

  • — value of taking right from A — scalar, always 0
  • — value of taking left from A — scalar, overestimated under Q-learning
  • — value of action from B — scalar, drawn from distribution with mean
  • — maximum over action values from next state — scalar, the source of bias
  • — the action that maximizes Q — used for selection in Double Q-learning
  • — normal distribution with mean and variance

11.2.1 The Problem

Imagine a talent show with 50 singers. Each judge scores differently — some singers get lucky with a generous judge, others get unlucky. If you pick the singer with the single highest score across all judges, that score is probably inflated. The singer might genuinely be good, but part of that top score is noise — a lucky break from one judge. Now imagine you use that same judge to both pick the winner and certify the score. The score the winner walks away with will almost certainly overstate their true talent. Q-learning does exactly this with action values.

Q-learning uses as its target. This expression uses the same estimated Q-values to both select the best action (which action has the highest Q?) and evaluate it (how good is that action?). Because the Q-values contain estimation noise — they are not perfect — the action that looks best will tend to be the one where the noise happened to push the estimate upward. The max operator latches onto positive noise, and the resulting target is systematically too high.

This is like the talent show: you pick the singer whose score (truth + noise) is highest, then report that score as their value. The reported value is biased upward — it overstates the truth because it captures noise as well as signal.

Maximization bias is the systematic overestimation of action values that arises when the same noisy estimates are used both to select and to evaluate actions. In Q-learning, the update target is:

The operator picks the action with the highest estimated Q-value. But that estimate is . The max selects the action where noise is largest in the positive direction, so:

The inequality is strict whenever there is any estimation error and more than one action. The textbook (Sutton & Barto §6.7) shows a concrete simulation: if true Q-values are all zero and estimates are drawn from a standard normal, then with 2 actions the expected max is 0.56, with 5 actions it is 1.16, and with 10 actions it climbs to 1.53 — all when the true max is 0.

This bias propagates through bootstrapping: overestimated becomes the target for , pushing those values up too. The error cascades backward through the value function.

11.2.2 Textbook Example: The Small MDP

The classic illustration comes from Sutton & Barto (§6.7, Example 6.7). You always start in state A. From A you have two actions:

  • Right: You get a reward of 0 and reach a terminal state. So always — it is deterministic.
  • Left: You get a reward of 0 and move to state B.

From state B, there are many actions available — all leading to a terminal state. The reward for each action from B is drawn from a normal distribution with true mean and standard deviation . So the long-term average reward for taking left is . But individual samples vary: sometimes you get 0, sometimes 1, sometimes even a larger positive number (with small probability).

Under Q-learning, when you take left from A you receive 0 and land in B. The target for is:

Now suppose one of the actions from B happened to give a reward of at some point in the past. Q-learning stores that as . The max over all actions from B then becomes (or higher if any other action gave more). So:

This pushes to a positive value. At a later time, some other action from B might give . Now the max becomes , and gets pushed even higher.

The result: stays consistently positive — always greater than . Even with -greedy action selection (which picks the greedy action ~90% of the time), the agent will almost always choose left. And every time it does, it actually receives rewards drawn from a distribution with mean — accumulating negative returns while believing left is good. The agent keeps going left, keeps getting negative rewards, and the overestimation persists.

Numerical trace — one possible Q-learning run with :

Start: all Q-values initialized to 0.

  • Episode 1: A → left → B → random action gives reward . Store . Update : target = . Error = . .
  • Episode 2: -greedy picks left (since ). A → left → B → another action gives . . Max still (from ). Target = . .
  • After 100 episodes: max over B actions might be 1.8 (some lucky reward). climbs toward 1.8. Agent picks left ~95% of the time. Average reward per left-action: . Accumulated reward: negative, despite being positive.

Sense-check: The true value of left is (mean of B's reward distribution). Yet settles around 1.8 — a gap of 1.9. This gap is pure maximization bias. Double Q-learning (next section) eliminates it.

Scope: When maximization bias matters.

Assumption: Maximization bias is proportional to the number of actions and the noise in Q-value estimates. It is most severe when:

  • Many actions exist in the next state (more chances for one to be overestimated)
  • Q-values are noisy (early training, high-variance environments, function approximation)
  • The true Q-value differences between actions are small (noise can flip the ranking)

When it matters less:

  • Environments with few actions (2–3) and low noise
  • Late in training when Q-values are near convergence
  • Domains where overestimation uniformly affects all actions (all inflated by same amount, ranking preserved)

The bias is not just an academic curiosity — it degrades policy quality in practice. An agent that overestimates bad actions will waste time exploring them.

Visual intuition: The textbook (Sutton & Barto Figure 6.5) shows a plot with episodes on the x-axis and "% left actions from A" on the y-axis. Standard Q-learning shoots to nearly 100% left actions within ~50 episodes and stays there — the agent is trapped choosing the worse action. Double Q-learning hovers near the optimal 5% (the -greedy minimum). The gap between the two curves is the cost of maximization bias: Q-learning wastes exploration on a provably bad action because its value estimates are inflated by noise.

Pitfalls:

1. Confusing action selection with value estimation. The max in Q-learning's target is for value estimation, not action selection. Even if you use -greedy for behavior, the max still biases the learned values. As the student Q&A below clarifies, this is a subtle but key distinction.

2. Thinking more exploration fixes it. Increasing (more random exploration) does not remove the bias — it just means you explore right more often. But the Q-values for left remain inflated because every visit to B re-triggers the max. The bias is in the update target, not the behavior policy.

3. Assuming it only affects Q-learning. SARSA also involves maximization (through -greedy action selection), and can suffer from a related bias. The bias is inherent to any algorithm that uses a max over estimates as an estimate of the max of true values. Expected SARSA avoids it by using an expectation instead of a max.

4. Overestimation can sometimes help early exploration. Early in training, inflating values of unexplored actions encourages visiting them — this is the "optimism in the face of uncertainty" principle. The problem arises when overestimation persists and becomes non-uniform, causing the agent to persistently prefer truly suboptimal actions.

Student Q&A (deduplicated — two questions merged into one confusion point):

Q: In Q-learning, when the agent goes from state A to B, it chooses the maximum of all available action values for the update. Is it always greedy — does it always choose the maximum? And if we use -greedy, do we not sometimes explore right and discover left is bad?

A: Several students asked variants of this. There are two separate things. For computing the update target, Q-learning always uses the max — that is how values are estimated. The target assumes the best possible continuation. But for selecting which action to take in the environment, you use a policy like -greedy. The problem: if the Q-values themselves are misleading because of the max bias, then even -greedy will mostly pick the misleading action. From A there are only two actions — right gives 0, left always gets a positive Q-value due to the max. So even with , the agent picks left ~95% of the time (90% greedy + half of the 10% random due to tie-breaking). The occasional exploration to right (getting 0) is not frequent enough to overcome the persistent overestimation of left. Every visit to B re-inflates the max, keeping the bias alive.

Maximization bias is not a bug in implementation — it is built into the math of using as an estimate of . The same noisy function selects and evaluates, so the selected action's value is systematically inflated. The next section shows how Double Q-learning eliminates this by splitting selection and evaluation across two separate Q-functions.

Real-world connection: Maximization bias is not just a toy problem — it affects real deep RL systems. The original DQN algorithm (which plays Atari games from pixels) was found to overestimate Q-values substantially, sometimes by 50% or more above true values. This led to the development of Double DQN (van Hasselt et al., 2016), which applies the Double Q-learning idea to deep networks and consistently improves performance across dozens of Atari games. The bias is particularly dangerous in healthcare applications of RL, where overestimating a treatment's value could lead to recommending harmful interventions.

11.2.3 Consequences

With maximization bias, Q-learning can take a very long time — many episodes — to realize that left is actually worse than right. The algorithm essentially needs enough exploratory samples of all B-actions for their Q-values to converge to the true mean of , at which point the max would also approach . Until then, the bias dominates. In complex environments with many actions per state, this problem compounds: the more actions, the larger the expected overestimation, and the longer it takes for all action values to converge.

11.3 Double Q-Learning

Symbol registry — Double Q-Learning

  • — first action-value function — scalar
  • — second action-value function — scalar
  • — the action that maximizes Q — used for selection (one function)
  • — evaluation of the selected action by the other function — scalar

11.3.1 The Key Insight

What if the talent show used two independent judges — one to pick the winner and another to certify the score? The selector could be biased, but the certifier has no reason to inflate that specific singer's score. The certified score would be unbiased on average.

Double Q-learning does exactly this with two Q-functions.

Think of two friends rating restaurants. Alice picks the best pizza place based on her experience. Bob independently rates it. Alice might overrate a place she visited on a good day. But Bob has no such bias toward that particular restaurant — his rating is honest. Over time, each friend both selects and certifies, with roles swapping. Neither one's bias accumulates unchecked.

The analogy breaks in one way: in Double Q-learning, the two functions are not truly independent — they see overlapping data. But the random 0.5 coin flip ensures each function sees a different subset of updates, making their biases sufficiently decorrelated.

Double Q-learning decomposes the Q-learning target into two operations performed by separate functions:

Step 1 — Selection: (e.g., ) finds the action with the highest estimated value:

Step 2 — Evaluation: (e.g., ) provides the value for that action:

Because has its own independent noise, it is unlikely to share 's overestimation for the same action. On average, the evaluation is unbiased:

This is the core insight from van Hasselt (2010): separating selection from evaluation removes the positive bias.

11.3.2 The Double Q-Learning Update

You maintain two action-value functions, and . At each update step, you flip a fair coin (probability 0.5):

With probability 0.5 selects, evaluates:

With probability 0.5 — the roles reverse, selects, evaluates:

The action selection policy (for actually acting in the environment) uses the sum with -greedy. This is the same form as the textbook algorithm (Sutton & Barto §6.7, page 136).

Scope: When Double Q-learning helps versus when it is unnecessary.

Assumptions: 1. There are at least two actions in the next state (otherwise the max has no selection to bias). 2. Q-value estimates contain noise (always true with function approximation or early in training). 3. The two Q-functions are sufficiently decorrelated (the 0.5 random update split achieves this in practice).

When it is most valuable:

  • Large action spaces (many actions → larger expected max overestimation)
  • Noisy environments or function approximation
  • Critical that the agent avoids persistently overestimating bad actions

When it may not help:

  • Trivial environments where Q-values converge quickly and accurately
  • Single-action problems (max over one action has no selection bias)
  • When the two functions happen to have identical biases (rare with random updates)

11.3.3 Algorithm Summary

1. Initialize and arbitrarily (e.g., all zeros or small random values). 2. Initialize step size (small) and exploration rate (small). 3. Start in initial state . 4. Choose action from using policy derived from (e.g., -greedy on the sum). 5. Execute , observe reward and next state . 6. With probability 0.5: update using as the evaluator. 7. With probability 0.5: update using as the evaluator. 8. ; repeat from step 4.

At each step, only one of the two Q-functions is updated — not both. The other one serves as the unbiased evaluator for that step. This doubles the memory (two tables instead of one) but does not increase computation per step.

11.3.4 Why Double Q-Learning Works

In the small MDP example from §11.2, Double Q-learning learns much faster that left is not good. The textbook results (Sutton & Barto, Figure 6.5) show standard Q-learning taking left ~95% of the time even after hundreds of episodes, while Double Q-learning drops to near the optimal 5% (the -greedy minimum).

The reason: even if has an overestimated value for some action at B (because it saw a lucky reward), is unlikely to have the same overestimation for the same action — they have seen different update histories. When selects the action it thinks is best, evaluates it more honestly. The roles swap, so both functions get regularized by the other.

In theory, 10 consecutive coin flips could all update and never , letting 's bias grow. In practice, this is improbable and does not cause issues over many steps. The two functions track similar values but with decorrelated noise — enough to break the selection-evaluation coupling that creates maximization bias.

Numerical trace — Double Q-learning on the small MDP (start from scratch):

Initialize for both A-left and A-right. All B-actions at 0.

  • Episode 1, Step 1: A → left. both 0, so random tie-break picks left. Land in B, action gives reward .
  • Coin flip: heads → update . any (all 0). .
  • . (No overestimation — evaluates honestly!)
  • Episode 1, Step 2: is also updated to . (Both functions store the reward for the B-action.)
  • Episode 2: says left = 0, right = 0. Random tie-break picks right (reward 0, terminal).
  • or records . No change.
  • Episode 3: : left = 0 (from ), right = 0. Random tie-break. Say left again. B-action gives .
  • Coin flip: tails → update . 's max at B might be 0.23 (from the lucky stored in ).
  • But wait — the reward was stored in , not . (never updated). So is any B-action with value 0.
  • (from episode 1). Target = .
  • .

Over many episodes, and values for left stabilize near the true mean , not some inflated positive number. The max operator's bias is broken because whichever function selects, the other evaluates.

Sense-check: The true value of left is . After convergence, for left, 0 for right. The agent correctly prefers right.

Visual intuition: Picture two thermometers measuring the same room. Thermometer A reads slightly high, B slightly low — each has its own noise pattern. If you always take the maximum reading, you will get a biased (too hot) estimate. But if A picks the spot to measure and B takes the actual reading there, the reading is honest. In the textbook plot (Figure 6.5), this translates to a dramatic gap: Q-learning (red line) stays at ~95% left actions; Double Q-learning drops rapidly to ~5%.

11.3.5 Practical Recommendations

In practice, when solving an RL problem, Double Q-learning and Expected SARSA are both good options for avoiding maximization bias. Expected SARSA requires a bit more computation — you need to compute an expectation over all actions from the next state rather than just a max — but it avoids maximization bias in a different way. Double Q-learning maintains the simplicity of the max operator while controlling the bias through the two-function split.

Comparison — Q-learning vs Double Q-learning vs Expected SARSA:

Method Selection Evaluation Bias Computational cost
Q-learning on Same Positive bias
Double Q-learning on Unbiased , double memory
Expected SARSA Expectation Same Unbiased

All three have the same per-step cost (finding the max requires scanning all actions anyway), but Expected SARSA additionally computes a weighted average. Double Q-learning's main overhead is storing two Q-tables (or two networks in the deep case).

11.3.6 Student Q&A

Q: So are we going at the right pace? Are things getting too involved with Q1, Q2, two Q-networks? A: The discussion acknowledged that the material is getting deeper. A buffer/extra class was planned to help students catch up. The key takeaway: Double Q-learning is conceptually one extra step — maintaining two copies and flipping a coin — and the payoff (eliminating a systematic bias) justifies the added complexity.

Exam note: Be ready to write both update equations for Double Q-learning and explain why separating selection from evaluation removes maximization bias. Know the coin-flip mechanism (0.5 probability, only one Q-function updated per step) and why using for behavior is natural. The Double Q-learning algorithm in Sutton & Barto (Chapter 6, page 136) is the canonical reference.

Real-world connection: Double DQN (van Hasselt et al., 2016, AAAI) applies the Double Q-learning idea to deep neural networks, using the online network for action selection and the target network for evaluation. It is now a standard component of deep RL systems. In the Atari benchmark, Double DQN reduces overestimation by 30–50% and improves final performance on most games. The technique also applies to actor-critic methods and policy gradient algorithms — any method that uses a max or argmax over value estimates can benefit from the double estimator trick.

11.4 From Tabular Methods to Function Approximation

Symbol registry — Function Approximation

  • — approximate state-value function with parameters — scalar
  • — approximate action-value function — scalar
  • — weight vector / parameters of the approximator — vector in
  • -th feature of state — scalar
  • — number of features / parameters — integer
  • — number of states — integer, can be huge or infinite

11.4.1 The Tabular Method

So far, all methods discussed — TD learning, SARSA, Q-learning, Double Q-learning — have been tabular methods. A tabular method stores a table of values:

  • For state-value functions: a table with entries
  • For action-value functions: a table with entries for each state

When you update, you change exactly one entry in the table without affecting any other entry. For example, touches only row . This independence means that, given enough experience in each cell, you can drive the table to a global optimum — each entry can move independently toward its true value. Convergence guarantees exist for all tabular methods under standard conditions.

11.4.2 Why Function Approximation?

You cannot keep a filing cabinet with a card for every number between 0 and 1. There are infinitely many. So instead of writing down every number, you remember a compact rule: "multiply by 2 and add 3." A function is a compact rule, and its parameters are the tiny set of numbers you need to store. Function approximation replaces the impossibly large table with a compact rule.

Think of function approximation like Google Maps estimating drive times. Maps does not store a driving time for every possible start and end point on the planet — that table would be impossibly large. Instead, it uses a model (a function) with parameters like road speeds, distances, and traffic patterns. Given a new route, Maps plugs in the features (distance, road type, time of day) and estimates the time. It learns those parameters from observing many actual drives. Function approximation does the same for value functions.

Tabular methods break down when the state space is large or continuous. If there are a million states, maintaining a million-entry table is infeasible. Many real problems have effectively infinite states — every moment while driving a car is slightly unique.

In function approximation, the table is replaced by a function that maps state representations to value estimates. Instead of learning individual table entries, you learn the parameters of this function:

The hat indicates this is an approximation, not the true value. The function takes the state representation as input and returns a scalar value. You no longer need a table: to know the value of any state, you call the function with that state's representation. The key trade-off:

From Sutton & Barto §9.1: "Typically, the number of weights (the dimensionality of ) is much less than the number of states (), and changing one weight changes the estimated value of many states. When a single state is updated, the change generalizes from that state to affect the values of many other states. Such generalization makes the learning potentially more powerful but also potentially more difficult to manage and understand."

11.4.3 Types of Approximating Functions

The function can be simple or complex:

  • Linear function: , where are features of the state — numbers computed from the state description. The parameters are just weights . Each weight says "how much does feature contribute to value?"
  • Nonlinear function (neural network): A deep network takes the state representation (e.g., raw pixels) and outputs an estimated value. The network may have millions or billions of weights. It learns its own internal features through hidden layers — no manual feature design required.

In many real-world problems, the number of parameters is far less than the number of possible states. You are approximating the values of billions of possible states with (say) thousands of parameters. Approximation is inevitable — you cannot represent a billion values exactly with a thousand parameters. The hope is that states that are similar (in feature space) have similar values, so the function can generalize.

11.4.4 The Core Challenge

The generalization trade-off is the central challenge of function approximation in RL.

When you update a single parameter in a function approximator, it affects the value estimates for all states that depend on that parameter. You cannot fix one state's value without disturbing others. This is fundamentally different from tabular methods, where each entry is independent.

Good news: Generalization means learning about one state helps you estimate values for similar states you have never seen. In the Pac-Man example, learning that being near a ghost is bad generalizes to any state where a ghost is nearby.

Bad news: Generalization also means fixing an error at one state can worsen estimates at others. If you update to correct an overestimate at state , you might accidentally create an underestimate at state that shares the same parameters. This coupling makes convergence guarantees weaker — linear methods converge to a global optimum of the VE objective, but nonlinear methods (neural networks) may only reach local optima, and semi-gradient methods may even diverge in some cases.

Your learning objective: keep updating the parameters until the function returns values that are close to the true (or optimal) values for all states — weighted by how often each state occurs.

11.4.5 The Pac-Man Example

Consider the Pac-Man game. A state can be described by features like:

  • Distance to ghost 1
  • Distance to ghost 2
  • Distance to nearest food
  • Pac-Man's location

State 1 (ghost at distance 2, food at distance 5) should have a lower value than State 2 (ghost at distance 10, food at distance 3), because the ghost proximity is more important than food proximity for survival. After seeing many such labeled examples — this state has this value, that state has that value — the function should generalize: given a new state never seen before (e.g., two ghosts at specific distances), it should estimate a reasonable value based on the pattern learned from similar states.

The representation could also be raw pixels — the entire 160×210 game screen fed to a neural network, which extracts features automatically. DQN (Mnih et al., 2015) used exactly this approach: a convolutional neural network that takes 84×84×4 pixel input (four grayscale frames) and outputs Q-values for each possible joystick action.

11.4.6 Student Q&A on Learning from Scratch

Q: How does the analogy of a kid learning from nothing apply here? Does the algorithm start from zero, or do we feed it initial data?

A: When you study an RL algorithm in a course, you understand the algorithm as it is — some algorithms can genuinely learn from nothing (tabula rasa). In real applications, you can be flexible. If you have prior knowledge — a pre-trained supervised network, domain expertise from human experts — you can use it to initialize the agent. The algorithm's ability to start from zero and become competent is an impressive property. But engineering a real solution often benefits from a warm start. The algorithm itself is not rigid about this.

This connects to a broader principle in Sutton & Barto (§9.1): function approximation makes RL applicable to partially observable problems. If the parameterized function cannot depend on certain aspects of the state (because those features are not provided), then it is as if those aspects are unobservable. The function learns to predict values from whatever information is available — limited features, raw pixels, or a pre-trained representation.

Function approximation replaces the table with a parameterized function, trading exact per-state accuracy for generalization across similar states. The core challenge is that updating parameters for one state affects all states — a blessing (generalization) and a curse (interference). Linear functions give convergence guarantees; neural networks give power but weaker guarantees. Next we formalize the objective function that drives learning.

Real-world connection: Function approximation is what makes RL practical. Without it, self-driving cars would need a separate table entry for every possible road configuration — impossible. Deep RL systems (AlphaGo, OpenAI Five, autonomous vehicle control) all rely on neural network function approximators. AlphaGo's value network had millions of parameters but evaluated board positions far better than any tabular approach could — because it generalized patterns (ladders, life-and-death shapes) across board positions that were not identical but structurally similar.

11.5 The Objective Function: Mean Squared Value Error

Symbol registry — Objective Function

  • — Mean Squared Value Error — scalar, the objective to minimize
  • — state importance / visitation weight for state — scalar in ,
  • — true value of state under policy — scalar
  • — state space — set of all states
  • — expected number of visits to state per episode — scalar (from Sutton & Barto §9.2)

11.5.1 Defining the Error

You are trying to draw a smooth curve through a scatter of points. Some points you care about a lot (they appear often), others rarely. You cannot fit every point exactly — there are too many. So you minimize a weighted sum of squared vertical distances, where the weight is how often each point appears. That is — the weighted average of squared errors between true and estimated values.

To learn the parameters , you need an error function to minimize. The natural choice is the squared difference between the true value (under policy ) and the estimated value, weighted by how often each state occurs:

Every term named:

  • : "VE-bar" — the Mean Squared Value Error. The overbar marks it as an objective defined by a distribution, not a sample estimate.
  • : the true value of state under policy — what we want to approximate but cannot observe directly
  • : our function approximator's estimate for state , given parameters
  • : the on-policy state distribution — fraction of time spent in , with

In the textbook (Sutton & Barto, §9.1–9.2), this is denoted and is the canonical objective for on-policy prediction with function approximation. The notation matches — the professor uses to emphasize that the true is not known in practice; you approximate it with returns or bootstrapped targets.

11.5.2 State Importance Weighting

Not all states are equally important. Some states occur very frequently (e.g., the starting region of a game), others almost never. The term captures this: it is the fraction of time spent in state under the policy — a probability distribution over states, with .

States with high are frequent — you cannot afford large errors there, because you visit them often. States with low are rare — errors there matter less. The weighting prevents the optimization from wasting capacity on rarely-visited states at the expense of common ones.

From Sutton & Barto (§9.2): "In continuing tasks, the on-policy distribution is the stationary distribution under . In episodic tasks, let be the probability an episode begins in , and the expected number of time steps spent in per episode. Then:

and ."

In supervised learning terms, this is like weighting each training example by how often it appears. States you visit 100 times per episode get 100× the weight of states you visit once.

11.5.3 Practical Considerations

Scope: What can and cannot do.

What guarantees:

  • For linear function approximators with gradient Monte Carlo: convergence to a global minimum of .
  • For linear function approximators with semi-gradient TD: convergence to a point near the local minimum (the TD fixed point, not exactly the minimum, but close under typical conditions).

What it does not guarantee:

  • Nonlinear function approximators (neural networks): no guarantee of even a local minimum — may diverge.
  • The -optimal value function may not be the best value function for control (finding a good policy). A function that minimizes squared error in values is not necessarily the one that leads to the best greedy policy.

Key practical point from the professor: Global optimality is rarely achievable for real problems with function approximation. The goal is a good local optimum. The specific computation of — how to estimate the state distribution from data — is deferred to later discussion. In practice, is often just the empirical distribution of states encountered during training.

Visual intuition: Imagine a 2D plot with states sorted on the x-axis and value on the y-axis. The true value function is some smooth curve. Your approximator is a simpler curve (maybe a straight line for linear, or a wiggly curve for a network). measures the area between these two curves, weighted by — regions the agent visits often contribute more to the area. The goal of gradient descent is to adjust the parameters so the approximator curve hugs the true curve tightly in the high- regions.

is the objective — the weighted squared error between true and estimated values. The weights reflect state importance: common states matter more. This objective drives the gradient descent updates covered next. Knowing the objective is step one; actually computing the gradient from experience is step two.

Real-world connection: The weighted least-squares formulation appears throughout engineering. In control theory, the Linear Quadratic Regulator (LQR) minimizes a weighted sum of state errors and control effort — exactly the same mathematical structure as . In recommendation systems, collaborative filtering minimizes a weighted squared error between predicted and actual ratings, with weights for user frequency. The formulation connects RL to decades of work in optimization and statistical estimation.

11.6 Gradient Descent for Value Function Approximation

Symbol registry — Gradient Descent

  • — gradient of the value estimate with respect to parameters — vector in
  • — return (sum of discounted rewards) from time — scalar
  • — terminal time step of an episode — integer
  • — generic update target at time — scalar (from Sutton & Barto §9.3)
  • For linear function : — the feature vector itself

11.6.1 The General Update Form

You are hiking in fog on a mountain and want to reach the lowest valley. You cannot see the whole landscape, but at your feet you feel which direction is steepest downhill. You take a small step that way. At the new spot, you feel again and step again. That is gradient descent: at each point, move a small amount in the direction that most reduces error.

Given the objective , the parameters are updated by stochastic gradient descent (SGD). The derivation from Sutton & Barto §9.3:

Every step annotated:

  • Line 1: The loss for a single example is half the squared error. The is a convenience — it cancels with the 2 from the derivative of the square, keeping the gradient clean.
  • Line 2: Take the gradient with respect to . Chain rule: derivative of is . The derivative of with respect to is .
  • Line 3: The negative sign from appears, giving .
  • Line 4: Gradient descent moves opposite the gradient: subtract .
  • Line 5: . The plus sign is correct — when the estimate is too low (positive error), increase weights in the direction of the gradient of the estimate.

This is the general SGD update from Sutton & Barto equation (9.7). The target can be anything — for Monte Carlo, for TD, for n-step.

11.6.2 Monte Carlo Target:

If you generate a full episode — states with rewards — you can compute the actual return for each state:

is an unbiased estimate of . Using in the SGD update yields Gradient Monte Carlo — a true gradient method that converges to a local minimum of under standard SGD conditions.

With a linear function approximator , the gradient is simply the feature vector itself. The update for each weight becomes:

11.6.3 Worked Example: Gradient Monte Carlo

Given:

  • State representation: a 3-dimensional feature vector
  • Current state : features — ghost 1 is 2 steps away, ghost 2 is 2 steps away, food is 1 step away
  • Initial parameters:
  • Learning rate:
  • Actual return from this state in the episode:

Step-by-step:

1. Current estimate:

2. Error:

3. Gradient: For a linear function,

4. Update:

The new parameters are . For a subsequent state with features (one ghost moved farther away), the estimated value is:

Sense-check: means the actual return from the state was 10. The estimate increased from 0 to a value influenced by the error. The update is intuitive: the feature vector says "ghosts are near, food is near" — the sign of each weight will determine whether proximity helps or hurts. With more data, the weights will learn that ghost proximity reduces value and food proximity increases it.

This is called Gradient Monte Carlo because the target requires the full episode to be generated before any update can happen.

11.6.4 The Semi-Gradient Problem

Gradient Monte Carlo is mathematically clean — the target does not depend on , so the gradient is exact. But it forces you to wait until the episode ends. TD methods want to update online, using a target that does depend on . This creates a tension: speed versus mathematical correctness.

In TD learning, you want to update online after every step. So instead of , you use the one-step TD target:

The update becomes:

Now here is the problem: the target depends on through . The true gradient of the squared error would require differentiating through the target as well — by the chain rule:

This is the full gradient — it includes the effect of on the target. The semi-gradient update ignores the term and uses only . It is not a true gradient — so we call it "semi-gradient."

From Sutton & Barto (§9.3): "Bootstrapping methods are not in fact instances of true gradient descent. They take into account the effect of changing the weight vector on the estimate, but ignore its effect on the target. They include only a part of the gradient, and accordingly, we call them semi-gradient methods."

Despite being semi-gradient, these methods work well in practice. The dependence on in the target is through the next state's estimate, and bootstrapping in this way enables online learning. For linear function approximators, semi-gradient TD(0) converges to a well-defined fixed point near the minimum.

11.6.5 Worked Example: Semi-Gradient TD(0)

Given:

  • Current state : features
  • Next state : features
  • Reward:
  • Initial parameters:
  • Learning rate:
  • Discount factor:

Step-by-step:

1. Current estimate:

2. Next state estimate:

3. TD target:

4. TD error:

5. Gradient:

6. Update:

The new parameters are . For a state with features , the estimated value is now .

Contrast with MC: The MC example used a return (requiring the full episode). The TD example used a one-step reward and bootstrap, needing only the transition . Both gave identical updates because both targets happened to be 10 and the initial weights were zero. In general, they differ — MC uses actual future rewards; TD uses a mix of reward and estimated future value.

Sense-check: The target of 10 says "this state is good." The feature vector gets weighted proportionally. Feature 2 (ghost distance 3) gets the most credit because it has the largest feature value — even though logically, being far from a ghost should increase value (positive credit) while the large update here is just because started at zero. Over many updates, the weights will learn the semantically correct signs.

11.6.6 RL vs. Supervised Learning

In supervised learning, examples are assumed to be independent and identically distributed (IID). For classifying cat vs. rat vs. bat, each image-label pair is independent — the first example being a bat does not constrain what the second example must be.

In reinforcement learning, this assumption does not hold. Consecutive states in an episode are strongly dependent — each step's state depends on the previous action and state. The examples come from the agent's own trajectory, which depends on the policy being followed. The same state can have different true values depending on the policy. And you do not know the true value until the episode completes (or ever, in continuing tasks).

Scope: Key differences between RL and supervised learning with function approximation.

Aspect Supervised Learning RL with Function Approximation
Data distribution IID, static dataset Non-IID, sequential, generated by agent
Target values Known, fixed labels Unknown, estimated via returns or bootstrapping
Target stationarity Stationary Nonstationary (targets change as changes)
Feedback delay Immediate (label present) Delayed (rewards may arrive much later)
Active data collection Passive (given dataset) Active (agent chooses what data to collect)

These differences mean that standard supervised learning theory (convergence, generalization bounds) does not directly apply. Semi-gradient methods are one way to adapt SGD to RL's nonstationary, bootstrapped targets. The price: weaker convergence guarantees.

Exam note: Be able to distinguish gradient Monte Carlo (true gradient, uses , must wait for episode end) from semi-gradient TD(0) (approximate gradient, uses TD target, can learn online). The semi-gradient "cheat" — ignoring the target's dependence on — is what makes online TD learning possible. Derive the update explicitly: loss → gradient → update with the sign correction.

Real-world connection: Semi-gradient methods are the backbone of practical RL. The DQN algorithm uses semi-gradient Q-learning with a neural network: the target uses a target network (frozen copy of ) precisely to stabilize the semi-gradient — the target network reduces the coupling between the target and the current parameters. This combination of semi-gradient updates with target networks enabled DQN to achieve human-level Atari performance.

11.7 N-Step Semi-Gradient Methods

Symbol registry — N-Step Semi-Gradient

  • -step return from time — scalar
  • — simplified scalar feature for the worked example (each state represented as 1)
  • — scalar weight for the simplified example — scalar

11.7.1 Extending to Multiple Steps

Just as tabular TD can use -step returns, function approximation methods can too. The general -step semi-gradient update is:

where is the -step return as defined in §11.1.2. For this reduces to the semi-gradient TD(0) update from §11.6.4. For equal to the episode length, it approximates Gradient Monte Carlo (the target still bootstraps slightly through at the horizon unless the episode ends exactly at the horizon).

The textbook (Sutton & Barto §7.1) proves the error reduction property: the expected -step return is always a better estimate than the current by a factor of at least in worst-case error.

11.7.2 Worked Example: 3-Step Semi-Gradient with Simple Features

To make the computation tractable, this example uses the exact setup from the lecture slides (S P Vimal). Every state is represented by a single constant feature . The function approximator has a single weight , so and .

Parameters: (episode length), (3-step window), discount factor , step size , initial weight .

Trajectory & Rewards:

The update rule at step updates state where :

Detailed Step-by-Step Updates ( to — Full Bootstrap Window):

  • Update (State ):

  • Update (State ):

  • Update (State ):

  • Update (State ):

  • Update (State ):

  • Update (State ):

  • Update (State ):

11.7.3 Handling the End of an Episode (Terminal Truncation)

When doing -step updates near the end of an episode, the lookahead window reaches or exceeds the terminal time step (here ). For , because , the indicator . There is no bootstrap term; the return is truncated to sum only the remaining actual rewards before termination.

Detailed Step-by-Step Updates ( to — Truncated Windows):

  • Update (State , 3-step window reaches ):

  • Update (State , 2-step window reaches ):

  • Update (State , 1-step window reaches ):

Final parameter after episode completion: .

11.7.4 Summary Tables: Complete 10-Step Episode Update Trace

The tables below consolidate the complete trajectory trace across all 10 updates for :

Summary Table: First Five Updates ( to )

State () Target () Error ()
0 2.0000 4.2580 2.2580 0.2258 2.2258
1 2.2258 6.0526 3.8268 0.3827 2.6085
2 2.6085 5.4116 2.8031 0.2803 2.8888
3 2.8888 7.6259 4.7371 0.4737 3.3625
4 3.3625 5.2513 1.8888 0.1889 3.5514

Summary Table: Remaining Updates ( to )

State () Target () Error ()
5 3.5514 5.3990 1.8476 0.1848 3.7361
6 3.7361 6.8636 3.1275 0.3128 4.0489
7 4.0489 6.2200 2.1711 0.2171 4.2660
8 4.2660 5.8000 1.5340 0.1534 4.4194
9 4.4194 2.0000 -2.4194 -0.2419 4.1775

11.7.5 Teaching Insights & Key Observations

  • Full Window vs. Truncated Target: Until , the target incorporates three rewards plus a discounted bootstrap estimate . For , the target is truncated because the episode terminates at .
  • Weight Flow & Gradient Simplicity: Because , the gradient is identically 1. Each update directly increments by . The updated weight immediately influences the bootstrap value in subsequent updates.
  • Generalization to Higher Dimensions: In higher-dimensional linear function approximation, is replaced by the full state feature vector , so the error scales each feature independently.

Exam note: Practice computing -step returns and parameter updates for linear function approximators by hand. The pattern is always the same: sum the discounted rewards → add → compute error → multiply by and the feature vector → update. Be ready for numerical examples with small feature vectors (2–4 dimensions) and explicit discount factors.

Real-world connection: In the A3C algorithm (Mnih et al., 2016), -step returns with typically between 5 and 20 are used to train both the policy and value function. The -step horizon provides a practical middle ground: enough actual rewards to reduce bias, but not so many that variance explodes. This technique was key to achieving state-of-the-art performance on Atari games with asynchronous training.

11.8 Algorithm Walkthrough: Semi-Gradient TD(0) for Prediction

Symbol registry — Semi-Gradient TD(0) Algorithm

  • — weight vector (reused from §11.4)
  • — learning rate (reused from §11.1)
  • — discount factor (reused from §11.1)
  • — gradient (reused from §11.6)

11.8.1 The Full Algorithm

You now have all the pieces: a function approximator , an objective , and a semi-gradient update. The algorithm just wires them together in a loop. Every time you take an action and observe the outcome, you nudge in the direction that reduces the TD error for the state you just left.

This algorithm estimates the state-value function for a given policy using a function approximator. It is the textbook algorithm from Sutton & Barto (§9.3):

Inputs:

  • A differentiable value function parameterized by
  • The policy to be evaluated

Output:

  • Parameters such that

Algorithm:

1. Initialize arbitrarily (e.g., all zeros or small random values) 2. For each episode:

  • Initialize state
  • For each step of the episode:
  • Choose action
  • Take action , observe reward and next state
  • Update:
  • Until is terminal

Why semi-gradient: The target contains (through ), making the gradient incomplete. Despite this, the algorithm typically converges to a useful solution for linear function approximators and works well with neural networks in practice.

Visual intuition: Picture a hiker on a value surface. At each step, the hiker looks at the current state's estimated height (), takes a step forward (action ), lands at a new spot (), observes the immediate change in elevation (reward ), and estimates the height ahead (). The TD error is the surprise — "I thought it would be at the end, but now it looks like " — and the hiker adjusts the map () accordingly. The map changes affect all nearby points, not just the current one — that is the function approximation effect.

11.8.2 Contrast with Monte Carlo

Aspect Gradient Monte Carlo Semi-Gradient TD(0)
Target (full return, unbiased) (bootstrapped, biased)
When update happens After episode ends After every step
Gradient type True gradient Semi-gradient (approximate)
Episode requirement Must generate full episode Can learn incrementally
Bias/Variance Zero bias, high variance Some bias, lower variance
Converges to (linear case) Global VE minimum TD fixed point (near VE minimum)
Works on continuing tasks No (needs episode boundary) Yes

The TD(0) algorithm for function approximation is a direct analog of tabular TD(0): same bootstrap target, same incremental nature, but the update changes parameters of a function rather than individual table entries. The generalization means learning from one state helps predict values for others — but also means errors in one state can degrade predictions elsewhere.

Pitfalls:

1. Divergence with nonlinear approximators. Semi-gradient TD can diverge with neural networks — the value estimates can grow without bound. The "deadly triad" (function approximation, bootstrapping, off-policy learning) is a known risk. Target networks (as used in DQN) help stabilize by slowing target updates.

2. Forgetting that is shared. Every update affects all states similarly (in proportion to their feature overlap). If you only visit a subset of states, the approximator will fit those well and ignore the rest — a form of catastrophic forgetting. Experience replay (storing and reusing past transitions) mitigates this.

3. Choosing poorly. Too large: updates oscillate and never settle. Too small: learning is impractically slow. For linear approximators with decaying satisfying , convergence is guaranteed. For constant , values fluctuate around the fixed point.

The semi-gradient TD(0) algorithm is the simplest concrete method for prediction with function approximation. It updates online, requires only one transition per update, and works for both episodic and continuing tasks. The cost: weaker theoretical guarantees and potential instability with nonlinear function approximators. Understanding this algorithm is the gateway to practical deep RL.

Real-world connection: This algorithm is the value-learning component of actor-critic methods like A2C and PPO. In those algorithms, the "critic" uses exactly this semi-gradient TD update to learn a value function, while the "actor" uses the TD error (or advantage) to improve the policy. The TD error computed by this algorithm is precisely the signal used to update the policy — making this simple prediction algorithm the engine of modern policy-gradient methods.

11.9 Feature Engineering for Function Approximation

Symbol registry — Feature Engineering

  • — feature vector for state — vector in
  • — number of features / dimensionality — integer
  • — approximate value function (reused from §11.4)

11.9.1 What Are Features?

Features are the language you use to describe a state to your function approximator. If you describe a chess position only by "number of pieces," you lose key information about piece positions. If you describe it by all 64 squares, you give too much detail that the function must sort through. Feature engineering is choosing the right vocabulary.

Features are the representation of a state — the numbers you feed into or . For the Pac-Man problem, features could include:

  • Pac-Man's (x, y) location
  • Distance to ghost 1
  • Distance to ghost 2
  • Distance to nearest food pellet
  • Whether a power-up is active

In the earlier worked examples, the features were simple scalar distances: ghost-1-distance, ghost-2-distance, food-distance — a 3-dimensional feature vector. Each feature captures one aspect of the state that you believe is relevant to predicting value.

The choice of features determines what the function approximator can learn. If you omit "distance to ghosts," the function cannot learn that being near a ghost is dangerous — that information is simply not in the input.

11.9.2 The Deep Learning Approach

In modern practice, you often skip manual feature engineering entirely. You feed the raw input — the entire game screen as pixels — directly into a neural network. The network learns its own internal feature representations through its hidden layers. Early layers might detect edges, middle layers might detect objects (ghosts, Pac-Man, pellets), and later layers might combine these into value predictions.

This is the deep reinforcement learning paradigm. DQN (Mnih et al., 2015) fed 84×84 grayscale pixel frames into a convolutional neural network and learned to play 49 Atari games at human level or above — with no hand-crafted features at all.

The lecture positions this as the direction the course is heading: starting with linear function approximation as the "humble beginning" and building toward deep neural networks as the function approximator. The key insight: the mathematical framework (VE objective, gradient updates, TD targets) remains the same whether your approximator is linear or a deep network. Only the gradient computation changes — for neural networks, it is backpropagation instead of the simple .

11.9.3 Feature Extraction — Next Class

Classical feature extraction methods — how to design good features by hand — will be covered in the next class. This bridges the gap between the simple linear examples and the deep learning approach. Topics likely include:

  • Tile coding: partitioning the state space into overlapping grids (from Sutton & Barto §9.5)
  • Radial basis functions: using Gaussian-like features centered at chosen points
  • Fourier basis: representing value functions as sums of sinusoids
  • Coarse coding: overlapping receptive fields that capture state similarity

These classical methods are still relevant: they work well for problems with known structure and few dimensions, and they provide theoretical guarantees (convergence, error bounds) that deep networks lack.

Features are the interface between the raw environment and the value function. Manual features give control and guarantees; learned features (neural networks) give power and flexibility. The course is building from manual features toward learned representations — from "humble beginnings" to deep RL.

Real-world connection: Feature engineering was the dominant paradigm in RL until ~2015, when DQN showed that learned features from pixels could outperform hand-crafted features on complex visual tasks. Today, most production RL systems use neural networks for feature extraction. However, in domains with structured state information (robotics joint angles, financial indicators, game theory), hand-crafted features remain competitive and are often combined with learned features in hybrid architectures.

11.10 Summary of the Lecture

Symbol registry — Summary (all symbols reused from prior sections)

  • — return (from §11.1, §11.6)
  • — state visitation weight (from §11.5)
  • — approximate value of next state (from §11.4)
  • — discount factor (from §11.1)

11.10.1 Three Major Topics

The lecture covers three major topics that build on each other:

1. TD Learning Recap and Control: Temporal difference learning blends dynamic programming (bootstrapping) with Monte Carlo (sampling). SARSA is on-policy — it learns the value of the policy it follows, using the actual next action in the target. Q-learning is off-policy — it learns the optimal value directly, using regardless of what the policy does. Multi-step (-step) returns interpolate between one-step TD (high bias, low variance) and Monte Carlo (zero bias, high variance), offering a tunable trade-off.

2. Maximization Bias and Double Q-Learning: Q-learning's max operator inherently overestimates action values because the same noisy function both selects and evaluates actions. In the textbook small MDP (state A → left to B with actions drawn from , right gives 0), Q-learning gets trapped choosing the suboptimal left action. Double Q-learning fixes this by maintaining two separate Q-functions: one selects the best action via argmax, the other evaluates it. A fair coin flip at each step decides which function gets updated, decorrelating the estimation noise and removing the positive bias.

3. Function Approximation and Gradient Methods: When state spaces are large or continuous, tabular methods become infeasible. Function approximation replaces the table with a parameterized function . The objective is the Mean Squared Value Error , weighted by state visitation . Gradient descent updates toward minimizing this error. Gradient Monte Carlo uses the full return as target — a true gradient, but requires full episodes. Semi-gradient TD uses the bootstrapped target — not a true gradient (it ignores the target's dependence on ), but enables online learning. The same machinery extends to -step semi-gradient updates, where an -step window of rewards supplements the bootstrap term.

11.10.2 Looking Ahead

Next class: feature extraction methods (tile coding, radial basis functions, Fourier basis) and the transition toward deep neural network function approximators. This lecture is the "humble beginning" into function approximation — the foundation for modern deep reinforcement learning, where convolutional and transformer networks replace linear functions but the mathematical framework (TD errors, bootstrapping, gradient updates) remains the same.

The arc of the lecture: tabular TD → maximization bias (a fundamental flaw) → Double Q-learning (the fix) → function approximation (the bridge to scale) → VE objective → gradient methods → semi-gradient compromises. Every concept builds on the one before. Know the TD error intimately — it is the engine driving every algorithm in this lecture.

Exam Guidance Summary

  • Maximization bias — Expect questions testing what causes it (using the same Q-function for both selecting and evaluating actions via max), the textbook MDP example (state A with left/right, state B with rewards), and how Double Q-learning fixes it. Be able to explain why stays positive when the true value is , and why -greedy does not solve the problem on its own.
  • Double Q-learning update expressions may appear. Know that two Q-functions () are maintained, updated with 0.5 probability each, and why the split helps — it decorrelates the noise in selection from the noise in evaluation. Be able to write the update equation showing updated with 's evaluation of , and the symmetric swap.
  • Gradient vs. semi-gradient methods — Know the distinction: Gradient Monte Carlo uses (true return, independent of ), giving a true gradient. Semi-gradient TD uses (depends on ), ignoring the target's parameter dependence. Be able to derive the update from the squared error loss and explain where the semi-gradient approximation drops a term.
  • Tabular vs. function approximation — Conceptual: tabular methods update one entry independently; function approximation updates shared parameters, affecting many states at once. Know the trade-off — generalization helps but creates interference. Linear methods converge to a global VE minimum (MC) or TD fixed point (semi-gradient); nonlinear methods (neural networks) have weaker guarantees.
  • Worked numerical examples — Practice computing -step returns () and weight updates for linear function approximators. The 3-step semi-gradient example (scalar weight, , ) shows the mechanics. Be able to trace an update given a trajectory of rewards, initial , , and .
  • The course textbook (Sutton & Barto, Reinforcement Learning: An Introduction, 2nd ed.) is the primary reference. The small MDP example for maximization bias (§6.7), Double Q-learning algorithm (§6.7), and function approximation (§9) are from the textbook.
  • An extra/buffer class session is planned for the upcoming week to help students catch up on the material.

Key Industry Applications

  • Q-learning / DQN: Foundation of DeepMind's Atari-playing agent (Mnih et al., 2015, Nature) — achieved human-level or superhuman performance on 49 Atari 2600 games from raw pixel input. Q-learning with function approximation (convolutional neural networks) is the core learning rule. The same framework extends to Go (AlphaGo used a variant), robotics, and recommendation systems.
  • Double Q-learning / Double DQN: Used in modern deep RL (van Hasselt et al., 2016, AAAI) to reduce the overestimation bias that standard DQN exhibits. Double DQN consistently improves performance across Atari games — reducing Q-value overestimates by 30–50% and yielding better final policies. The idea has been adopted in virtually all modern deep Q-network variants and in actor-critic methods.
  • Function approximation with neural networks: Enables RL to scale to high-dimensional problems that are impossible for tabular methods. Applications span autonomous driving (Waymo, Tesla — learning driving policies from camera and sensor input), robotic manipulation (OpenAI's robot hand solving Rubik's cube), game playing (AlphaStar for StarCraft II, OpenAI Five for Dota 2), and recommendation systems (YouTube, Netflix — learning to rank content from user interaction data).
  • Pac-Man: Classic RL benchmark in the ACI course — illustrates the need for generalization across similar but unseen states. A state with a ghost at distance 3 is similar to one at distance 4, and a function approximator can share value estimates between them, unlike a table. This simple idea scales to every practical RL application: the space of real-world states is effectively infinite, and generalization through function approximation is the only path to competent behavior.

DRL Lecture 11 notes · Temporal Difference Learning, Maximization Bias, and Function Approximation

Deep Reinforcement Learning· postgraduate· 2026-07-18

Sections Breakdown

1Revision of Temporal Difference Learning

TD update, n-step targets, SARSA (on-policy) and Q-learning (off-policy) control.

2Maximization Bias

Why Q-learning's max operator overestimates action values, with the textbook small MDP.

3Double Q-Learning

Separating selection from evaluation with two Q-functions to remove the bias.

4From Tabular Methods to Function Approximation

Why large or continuous state spaces require parameterized value functions.

5The Objective Function: Mean Squared Value Error

The VE-bar objective and state-importance weighting mu(s).

6Gradient Descent for Value Function Approximation

Gradient Monte Carlo and the semi-gradient problem in TD.

7N-Step Semi-Gradient Methods

Extending semi-gradient updates to n-step returns with a worked example.

8Algorithm Walkthrough: Semi-Gradient TD(0) for Prediction

The full semi-gradient TD(0) algorithm and contrast with Monte Carlo.

9Feature Engineering for Function Approximation

Manual features versus learned representations (deep learning).

10Summary of the Lecture

Three major topics and the arc from tabular TD to function approximation.

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.

Temporal Difference Learning

Must-know: TD blends Monte Carlo (sampling) and DP (bootstrapping). The TD error drives every update; it learns from each step without waiting for episode end.

⚠️ Top pitfall: Calling TD(0) off-policy for prediction. TD(0) for state values is on-policy; only control variants like Q-learning are off-policy.

Self-check: Why does TD update before reaching the terminal state, while Monte Carlo must wait until the end?

Connects to: n-Step Targets, SARSA, Q-Learning, Semi-Gradient TD.

Maximization Bias

Must-know: Q-learning uses the same noisy Q-values to both select (argmax) and evaluate (max) the next action, so the max latches onto positive noise and overestimates values. The bias grows with the number of actions.

⚠️ Top pitfall: Thinking -greedy fixes it. Exploration changes which action is tried, but the max in the target still overestimates the chosen action's value.

Self-check: In the small MDP, why does stay positive even though its true value is ?

Connects to: Double Q-Learning, Q-Learning, The Small MDP Example.

Double Q-Learning

Must-know: Maintain two Q-functions. One selects the best action (argmax), the other evaluates it. A fair coin decides which updates each step, decorrelating selection noise from evaluation noise and removing the positive bias.

⚠️ Top pitfall: Forgetting the 0.5 coin flip. Without splitting updates between the two functions, they stay correlated and the bias returns.

Self-check: Why does using two Q-functions (updated on disjoint data) give an unbiased evaluation on average?

Connects to: Maximization Bias, Q-Learning.

Function Approximation

Must-know: When the state space is large or continuous, replace the table with a parameterized function . Updating one weight changes many states at once: generalization helps but creates interference.

⚠️ Top pitfall: Assuming tabular convergence guarantees carry over. Linear methods converge to a VE minimum or TD fixed point; nonlinear (neural net) methods may only reach local optima or diverge.

Self-check: Why can fixing an error at one state accidentally worsen the estimate at a similar state under function approximation?

Connects to: Mean Squared Value Error, Gradient Descent, Feature Engineering.

Mean Squared Value Error (Objective)

Must-know: The objective is the state-weighted squared error between true and estimated values. weights frequent states more; common states dominate the optimization.

⚠️ Top pitfall: Believing the VE-optimal value function is the best for control. Minimizing value error does not guarantee the best greedy policy.

Self-check: What does represent, and why does it matter for where the approximator concentrates its accuracy?

Connects to: Function Approximation, Gradient Descent.

Gradient Descent and Semi-Gradient TD

Must-know: Gradient Monte Carlo uses the full return (true gradient, needs full episodes). Semi-gradient TD uses the bootstrapped target , ignoring the target's dependence on , so it is not a true gradient but enables online learning.

⚠️ Top pitfall: Writing the semi-gradient update as a true gradient. The target depends on through ; the semi-gradient drops that term.

Self-check: Why is Gradient Monte Carlo a true gradient but Semi-Gradient TD is not?

Connects to: Mean Squared Value Error, n-Step Semi-Gradient, Algorithm Walkthrough.

n-Step Semi-Gradient Methods

Must-know: The n-step semi-gradient update uses the n-step return as target. recovers semi-gradient TD(0); larger trades bias for variance and reduces error by a factor of in expectation.

⚠️ Top pitfall: Confusing the n-step return with the one-step target. The n-step return sums rewards before bootstrapping with .

Self-check: As grows toward the episode length, what happens to the bias and variance of the target?

Connects to: Gradient Descent, Temporal Difference Learning.

Semi-Gradient TD(0) Algorithm

Must-know: The prediction algorithm loops over episodes: take action by the policy, observe and , then nudge by the TD error times the gradient. It is the workhorse that wires the objective and the update together.

⚠️ Top pitfall: Mixing up the prediction (V) and control (Q) forms. This algorithm estimates for a fixed policy; control needs the action-value version.

Self-check: How does the semi-gradient TD(0) loop differ from the Gradient Monte Carlo loop in when it updates ?

Connects to: Gradient Descent, n-Step Semi-Gradient.

Feature Engineering

Must-know: Features are the interface between the raw state and the value function. Manual features give control and guarantees; deep networks learn their own features from raw input (e.g., pixels) but need more data and lack guarantees.

⚠️ Top pitfall: Omitting a relevant feature (e.g., distance to ghosts) means the function can never learn that factor matters, no matter how much training.

Self-check: Why might a hand-crafted feature set still beat a neural network on a small, well-understood problem?

Connects to: Function Approximation, Mean Squared Value Error.

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.