Unit 11 of 13 · about 4 hours · implement
Terminal versus truncated bootstrapping and reward, action, next-state and discount alignment
One wrong zero at a time limit corrupts every value upstream. Termination and truncation look identical in a done flag but demand opposite bootstraps.
You'll be able to
- Implement terminal versus truncated bootstrapping: zero beyond termination, keep on truncation.
- Align reward, action, next state and discount indices on fixed trajectories.
- Detect autoreset and done-flag bugs that store fake transitions.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Terminated versus truncated step APIGymnasium Core API
Env
stepreturning separateterminatedandtruncatedflags withinfo, andresetwithseed, including the version 0.26 done-flag split (Gymnasium 1.4.0; page read 2026-10-14) - Terminal values in the control boxesReinforcement Learning: An Introduction (2nd ed.) - Chapters 2, 5, 6 and 7
The Sarsa and Q-learning boxes with and episodes ending at terminal states (printed pp. 129 to 132)
Read for the terminal convention only; control targets live in earlier units.
- Vector autoreset modeGymnasium Core API
Next-step autoreset: the step that ends an episode returns the true final observation, and the next step returns the reset observation (page read 2026-10-14)
Run the installed release to confirm the mode, then never store the autoreset step as a transition.
Focus on
- Termination ends the MDP: the target is with no bootstrap. Truncation ends the data: the target keeps with the final observation from the truncating step, never the reset observation from the autoreset step.
- Index rule: and belong to . The discount multiplies the next state's value, never the reward.
- Vector next-step autoreset returns the true final observation with flags set, then ignores the next action and returns the reset observation with zero reward. That autoreset step is not a transition and must not be stored.
Common mistakes · 3
- Collapsing both flags into one done. A time-limit done with zero bootstrap undervalues every state near the limit.
- Bootstrapping from the autoreset observation with the ignored action's reward. The reset step carries reward 0 and no flags; storing it trains on a fake transition.
- Off-by-one discount exponents. The first reward after is undiscounted; starts applying at the next state's value.
Try it yourself
Closed-book, before checking anything
CliffWalking-v1 with reset(seed=0) and confirm step returns separate terminated and truncated flags.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Time limit hits with value ahead. What is the target?Answer
Keep bootstrapping: . The limit is truncation, not termination.
2.Goal reached with final reward 1. What is the target?Answer
Exactly 1. Termination zeroes everything beyond.
3.A buffer stores the autoreset step as one transition. Why is it fake?Answer
Its action was ignored and its observation is a fresh reset. It is not a transition from .
4.Reward indices shift by one in the buffer. Which updates break first?Answer
All n-step and TD targets: every pairs with the wrong state.
You're done when
You write both targets from memory, your buffer test rejects autoreset steps, and a shifted-index defect fails loudly.
Only when you can do this without notes.
Leads to
Notes
Resources · 2 for this unit, 5 more in the section
- Reinforcement Learning: An Introduction (2nd ed.) - Chapters 2, 5, 6 and 7Richard Sutton and Andrew Barto · primary
The authors post the full second edition free at incompleteideas.net; cite the printed page numbers. Study Sections 2.4 and 2.5 (incremental and constant step-size estimates), Chapter 5 without the starred sections (Monte Carlo prediction and control, ordinary and weighted importance sampling), Chapter 6 Sections 6.1 to 6.7 (TD(0), Sarsa, Q-learning, Expected Sarsa, maximization bias) and Chapter 7 Sections 7.1 to 7.3 (n-step methods). Reproduce Example 5.4 (off-policy blackjack), Example 6.2 (random walk) and Example 6.6 (cliff walking), and implement each update from fixed hand-calculated trajectories before training an agent.
- Gymnasium Core APIFarama Foundation · reference
Use the reset, step, seeding and wrapper documentation as the behavior authority for the installed environment version:
reset(seed=...)seeds once,stepreturnsterminatedandtruncated, and vector environments autoreset on the next step by default. Test observation, reward, terminated, truncated and info fields at the boundary.
Also in this section
- Stanford CS234 Winter 2026 - Policy Evaluation and Q-LearningStanford University · required
Study Lecture 3 (tabular policy evaluation) and Lecture 4 (Q-learning) slides and the relevant independent Assignment 1 and 2 written questions. Use the course treatment to state model-access, convergence, coverage and function-approximation assumptions for each update.
- Hands-on Modern RL - Dynamic Programming, Monte Carlo and TDWalking Labs · support
Use the DP, MC and TD page and the bandit script as a code companion. Rebuild the algorithms in the shared track schema, and keep the bandit comparison as a seed-sensitivity case: which method wins changes with the seed. Pin commit 9231bab of walkinglabs/hands-on-modern-rl; its
code/chapterNNfolders do not follow the site chapter numbers. - Deep-ML - Tabular Prediction and Control ProblemsDeep-ML · support
Use named problems as closed-book checks after your own implementation passes: 272 (first-visit Monte Carlo), 257 (TD error), 273 (n-step TD), 175 (SARSA), 476 (Expected SARSA), 133 (Q-learning) and 518 (cliff walking, SARSA versus Q-learning). Read each problem's tests before trusting its statement.
- Reinforcement Learning Control Laboratory - Tabular ControlRoadmap-Final · required
Complete the MC, SARSA and Q-learning requirements with exact trajectory updates, stochastic and exploration-sensitive environments, visitation logs, matched interaction budgets and seeded alignment and bootstrap defects.
- Reinforcement Learning: An Introduction (2nd ed.) - Starred Sections 5.8 and 5.9 and Chapter 10 Sections 10.3 to 10.5Richard Sutton and Andrew Barto · support
Study starred Section 5.9 on per-decision importance sampling only for the per-decision estimator, and Chapter 10 Sections 10.3 to 10.5 on average reward and differential values only for the continuing-task unit. Cite printed pages; the authors post the full text free at incompleteideas.net.