Learning values from experience
Value iteration needs the full table of transition probabilities. Usually nobody has that table: the agent can only act and watch what happens. Prediction is the first problem this raises. Given a fixed way of acting, a policy , how much reward will it collect from each state? Its true value is the expected return, the sum of rewards from to the end of the episode, (here , since every episode ends).
This page uses Gymnasium's CliffWalking: a 4 × 12 grid, −1 for every step, and a cliff along the bottom between start and goal that costs −100 and sends the agent back to the start. The policy is fixed: walk the shortest route, along the row next to the cliff, but take a random action 10 % of the time. Its true values are solved exactly from the environment's table (the start is worth −51.8), so the page can show how far each learner is from the truth.
Two targets for the same update
Both methods keep a table of estimates , start it at zero, and nudge it towards a target after each experience, by a step size :
Monte Carlo (MC) waits for the episode to end and uses the actual return as the target. Temporal-difference learning, TD(0), updates right after each step and uses : the one reward it has seen plus its own current estimate of everything after. Using an estimate inside the target is called bootstrapping.
The One episode's two targets panel follows a recorded episode that falls off the cliff twice. Step through it and compare the two targets at each step. The MC target carries both −100s back to every earlier state, so the return from the start is −235. The TD target sees a −100 only at the step where the fall happened; elsewhere it is −1 plus whatever the estimate of the next cell is.
Bias against variance
The MC return is an unbiased sample of : averaged over many episodes, it is exactly right. But a single return depends on every random action until the end, so it varies a lot. In the Every target run 0 used here chart, the returns at the start state form bands about 100 apart: no fall, one fall, two falls. From episode 100 on they average −51.7 with a standard deviation of 69.7.
The TD target depends on one random step, so it varies much less (a standard deviation of 11.9 at the start state over the same episodes). But it is only as right as the estimate it leans on. While is still wrong, the target is biased, and the error spreads backwards one state per visit. The Estimates chart shows both effects across 100 independent runs: MC's runs scatter widely around the truth, while TD's runs agree with each other but drift towards the truth only gradually.
Which one learns faster
Neither wins everywhere. The Step size chart tries six values of for each method, on the same episodes, and plots the error averaged over training (RMS over states, weighted by how often the policy visits them). TD does best at and MC at : MC's noisy targets need a small step. At those settings the two error curves end up close. The start state is 14 steps from the goal and , so TD needs many visits to carry the value of the goal back to it. On short chains or with a discount, TD's lower variance usually gives it the edge, as in Sutton's random-walk experiments. The trade-off between the two is what TD() and GAE (see the PPO tab) tune continuously.
Control: SARSA against Q-learning
To learn to act, the same idea is applied to action values , and the agent acts ε-greedily on them: usually the best action, sometimes a random one. SARSA uses the action it will actually take next, . Q-learning uses the best next action, , whatever it then does.
That one difference decides the route. Q-learning learns the values of the greedy policy, so its greedy route is the shortest, 13 steps along the cliff edge, in all 50 runs. But it keeps exploring along that edge, falls 0.35 times per episode, and while learning collects about −52 per episode. SARSA learns the values of the ε-greedy policy it really follows, random slips included, so cells next to the cliff look bad and it walks one or two rows higher: 0.05 falls and about −26 per episode. The Sum of rewards per episode chart reproduces the classic cliff-walking figure of Sutton and Barto's textbook (Example 6.6) from 50 runs. With a constant , SARSA's table stays noisy, and in 9 of the 50 runs its final greedy walk loops instead of reaching the goal.
Where these come from
Sutton named and analysed TD learning in 1988; Watkins introduced Q-learning in his 1989 thesis, with a convergence proof published with Dayan in 1992; SARSA was proposed by Rummery and Niranjan in 1994 as modified connectionist Q-learning. Q-learning with a neural network instead of a table is the subject of the DQN tab, and PPO's advantages (the PPO tab) are a weighted mix of TD and MC targets.
Papers
- Learning to predict by the methods of temporal differences Introduces TD learning, compares it with Monte Carlo prediction, and runs the random-walk experiments where TD wins.
- Q-learning Q-learning's update and its proof that the table converges to the optimal action values.
- Convergence Results for Single-Step On-Policy Reinforcement-Learning Algorithms Proves that SARSA converges when exploration decays, and why it learns the value of the policy it follows.
- An analysis of temporal-difference learning with function approximation Proves where TD converges when values come from a parametrised function, and what bias bootstrapping leaves.
- A theoretical and empirical analysis of Expected Sarsa Averages over the next action instead of sampling it, which removes part of SARSA's variance; studied on the cliff walk.