Unit 2 of 10 · about 5 hours · derive, implement

Semi-gradient TD, on-policy prediction and value error versus Bellman error

Every deep value update is a semi-gradient step. If you cannot say which term is dropped, target-network and detachment bugs stay invisible.

You'll be able to

  • Derive the semi-gradient TD(0) update and name the gradient term it drops.
  • Explain why a Monte Carlo target gives a true gradient while a bootstrapped target does not.
  • Compute value error and Bellman error on a small example and state which one samples can estimate.

Covers

Semi-gradient TD updatesMean-squared value error and Bellman-error distinctionsOn-policy prediction with function approximation
1

Read

In this order, only the parts listed

0 of 2 done

  1. Stochastic gradients, gradient Monte Carlo and semi-gradient TD(0)Reinforcement Learning: An Introduction (2nd ed.) - Chapters 9 and 11

    Section 9.3, printed pp. 200-203: Eqs. 9.4 to 9.7, the gradient Monte Carlo box, and the semi-gradient TD(0) box with . The key sentence is that these methods account for the effect on the estimate but ignore the effect on the target.

  2. Why the Bellman error is not learnableReinforcement Learning: An Introduction (2nd ed.) - Chapters 9 and 11

    Section 11.6, printed pp. 274-275: the learnability argument and the two-MRP example with identical features but different Bellman error. The double-sampling requirement is in Section 11.5, printed p. 272.

2

Focus on

  • A true gradient needs the target independent of . Bootstrapped targets depend on , so the step from Eq. 9.4 to Eq. 9.5 is invalid and only part of the gradient is used.
  • Gradient Monte Carlo converges to a local value error optimum under standard step-size conditions. Semi-gradient TD(0) converges in the linear on-policy case, but that does not make it true gradient descent.
  • The value error needs the true . The Bellman error squares an expectation, so estimating it needs two independent next-state samples; one sample used twice biases it.
  • On-policy prediction means states arrive under the target policy's . Change the sampling distribution and the fixed point moves.
Common mistakes · 3
  • Calling TD(0) a gradient method on the value error. The target-dependence term is dropped in every update.
  • Reading zero TD error as zero value error. Zero TD error marks the TD fixed point, which generally differs from the value error minimum.
  • Trusting a small single-sample Bellman residual. Without double sampling the estimate is biased, and minimizing it can prefer the wrong function.
3

Try it yourself

Closed-book, before checking anything

Closed-book, compute one linear semi-gradient TD(0) step with features , weights , reward , a terminal next state, and : show and the new . Then state which gradient term was ignored.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Which step of the SGD derivation fails for bootstrapped targets?Answer

    From Eq. 9.4 to Eq. 9.5. Moving the gradient inside the square requires the target to be independent of , but bootstrapped targets depend on .

  2. 2.In Reproduce, what changes if the transition is non-terminal with ?Answer

    . The update adds , giving .

  3. 3.Why does the Bellman error need two independent next-state samples?Answer

    Its square contains an expectation inside the square. Reusing one sample for both factors correlates them and biases the estimate.

  4. 4.Linear on-policy TD(0) converges, yet the book still calls it semi-gradient. Why?Answer

    Convergence in that restricted case does not make it true gradient descent. The term from the target's dependence on is still dropped.

5

Practice

You're done when

Your hand update matches Deep-ML 530 exactly, and for any target you can state whether its gradient is true or semi.

Only when you can do this without notes.

Leads to

Notes

Resources · 1 for this unit, 11 more in the section
  • Reinforcement Learning: An Introduction (2nd ed.) - Chapters 9 and 11Richard Sutton and Andrew Barto · required

    The authors post the full second edition free at incompleteideas.net; cite the printed page numbers. Study Sections 9.1 to 9.4 (value error, semi-gradient TD, linear methods) and Sections 11.1 to 11.3 and 11.6 (off-policy divergence, the deadly triad, why the Bellman error is not learnable). Reproduce Baird's counterexample (Section 11.2, Figure 11.1) and show the weights diverge under off-policy semi-gradient TD.

Also in this section

  • Berkeley CS 185/285 Deep Reinforcement Learning (Spring 2026) - Value-Based RL and Q-Learning in PracticeUC Berkeley · primary

    Slides are public at https://rail.eecs.berkeley.edu/deeprlcourse/static/slides/lec-N.pdf; current videos are not, and the public Fall 2023 playlist numbers lectures differently. Study Lecture 7 (value-based RL) and Lecture 8 (Q-learning in practice: replay, target networks, double Q-learning). Work the DQN part of Homework 3 (src/agents/dqn_agent.py, CartPole then LunarLander with double DQN) on CPU or one small GPU; the Atari run is optional. The homework pins gym==0.25.2, which fails on NumPy 2, so port it to Gymnasium (terminated and truncated) or pin numpy<2 in its own environment, and turn off its forced WandB logging.

  • Stanford CS224R Spring 2026 - Q-Learning and Off-Policy MethodsStanford University · support

    Use Lecture 06 (Q-learning) and the TA Q-learning tutorial (material/CS224R_Tutotial_Max.pdf) as a second derivation of fitted Q-iteration, targets and overestimation. Its homeworks run on cloud GPUs; follow the Stanford honor code for course materials.

  • Playing Atari with Deep Reinforcement LearningDeepMind · required

    Read the algorithm, replay and target-network design plus experimental protocol. Reproduce DQN on a small discrete environment, then ablate replay and target networks rather than attempting an Atari score reproduction.

  • Deep Reinforcement Learning with Double Q-LearningDeepMind · required

    Derive the action-selection and action-evaluation split, construct a noisy maximization example and compare DQN with Double DQN using identical samples and tuning budgets.

  • Dueling Network Architectures for Deep Reinforcement LearningWang et al. (ICML 2016) · support

    Read the dueling architecture and its aggregation equations (the mean-subtracted form). Implement it as an optional head and test that the value and advantage streams are identifiable only up to the stated constraint.

  • CleanRL DQNCleanRL · support

    Read the single-file DQN implementation and documented benchmark details after the blank-file update passes. Trace replay, target, seeding, termination and evaluation semantics. The script expects the final_info and final_observation keys of older Gymnasium releases; on Gymnasium 1.x (next-step autoreset) it logs no episode returns and raises KeyError at truncation, so run it in an environment with gymnasium==0.29.1 or patch those lines and say so.

  • Hands-on Modern RL - From Q-Learning to DQNWalking Labs · support

    Use Sections 5.1 to 5.4, with the masked target on the components page (the formula on the first page omits the terminal mask). code/chapter04_dqn/dqn_cartpole.py trains CartPole on CPU in about two minutes. Treat score claims as hypotheses requiring local seed and version evidence. Pin commit 9231bab of walkinglabs/hands-on-modern-rl; its code/chapterNN folders do not follow the site chapter numbers.

  • Deep-ML - Function Approximation and DQN ProblemsDeep-ML · support

    Use named problems as closed-book checks after your own implementation passes: 530 (semi-gradient TD(0)), 556 (deadly-triad instability), 557 (Baird's counterexample), 537 (experience replay) and 477 (double Q-learning). Read each problem's tests before trusting its statement.

  • Reinforcement Learning Control Laboratory - Deep Value CoreRoadmap-Final · required

    Implement DQN and Double DQN with replay and target state, fixed-batch target tests, checkpoint and resume, overestimation evidence and injected online-target, detach, action-gather and replay defects.

  • Gymnasium - Time Limits and Vector AutoresetFarama Foundation · reference

    Read Termination, Truncation, Importance in learning code and Solution in the time-limits tutorial, plus the vector autoreset note at https://farama.org/Vector-Autoreset-Mode. Next-step autoreset is the default for Gymnasium 1.x vector environments; on Gymnasium 1.4.0 the step after an episode ends returns reward 0 with both flags false and is not a transition.

  • Gymnasium - Env.reset and seedingFarama Foundation · reference

    Read the Env.reset entry for the seeding contract: an integer seed resets the environment PRNG np_random, and a later reset with seed=None continues it, so seed once right after creation.