Least-Squares TD
Semi-gradient TD spends one cheap step per example and needs many examples; this lesson makes the opposite tradeoff. Least-Squares TD (LSTD) accumulates the matrices and and solves the TD fixed point directly, using the Sherman-Morrison identity to maintain the inverse in — the most data-efficient linear TD method, at a quadratic cost.
╌╌╌╌
The previous lessons settled on semi-gradient TD(0) as the default linear learner: one gradient step per transition, memory and compute per step for weights. That frugality is also a weakness. Each example moves the weights only a little, and the example is then discarded, so the method needs a great many transitions to converge. This lesson makes the opposite tradeoff: spend more compute per step to extract more from each example.
Least-Squares TD stays parametric and linear but stops iterating: it accumulates the same matrices and that defined the TD fixed point and solves for in closed form, the most data-efficient linear TD method there is. The complementary route to sample efficiency — abandoning the parametric form and storing the examples themselves — follows in the next lesson.
Least-Squares TD
Every method in the previous lesson spent compute per step proportional to the number of parameters. Recall the endpoint that linear semi-gradient TD(0) converges to. Under the on-policy distribution it settles at the TD fixed point, the weight vector where the expected update vanishes:1
writing for the feature vector at time . TD(0) reaches only in the limit, by taking many small steps that gradually average toward the expectations defining and . This is wasteful of data. If the fixed point is a solved linear system, why iterate at all? Estimate and from the data directly, then solve. Least-Squares TD (LSTD) takes this route. It forms the running sums
where is the identity and , for a small , guarantees the sum is always invertible. These look like they ought to be divided by to be estimates of and ; as written they estimate and . But the extra cancels in the ratio, so LSTD estimates the fixed point as
A worked LSTD solve
For example, take a chain with three states carrying one-hot features , , and , discount , and two transitions in the data: with reward , and with reward . Take for a clean solve.
Each transition contributes the rank-one term to and to . For the first transition, , so
For the second transition , so
Summing gives and . Its inverse is , and the fixed point is
So (its return is the single reward ) and — the reward plus the discounted value of , exactly the Bellman-consistent values. Semi-gradient TD(0) would have reached the same only after many passes; LSTD read it off the two transitions directly.
The Sherman-Morrison incremental inverse
Written naively, LSTD looks like it grows more expensive as grows, and forming from scratch is — the cost of inverting a general matrix. An incremental update resolves both problems. The accumulator is a running sum of outer products (each term is a column vector times a row vector, a rank-one matrix). A matrix of that special form — a previous matrix plus a rank-one update — has an inverse that can be updated directly, without ever inverting anything, by the Sherman-Morrison formula:1
for , initialized with . The formula is simpler than it looks: the numerator is an outer product of two -vectors, and the denominator is a scalar. Every operation is a matrix-vector or vector-vector product — , never . So LSTD stores the inverse matrix (itself memory), maintains it with one Sherman-Morrison update per step, and reads off — all in time and memory per step.
The full procedure keeps and and updates both every step:
- 1input: feature map with , small
- 2a matrix
- 3a -vector
- 4for each episode do
- 5initialize
- 6
- 7repeat
- 8choose , take it, observe ,
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16until is terminal
What the quadratic cost buys, and what it costs
LSTD is the most data-efficient linear TD(0) method — it extracts the fixed point from the data as fast as the data can define it — but is still substantially more than the of semi-gradient TD. Whether the greater data efficiency is worth the expense depends on how large is, how costly data is relative to compute, and the cost of the rest of the system. With in the thousands, can be prohibitive, and semi-gradient TD with a good step size wins on wall-clock; with small and data expensive to gather, LSTD's sample efficiency justifies the cost.
LSTD also has no step-size parameter, which is sometimes cited as an advantage but is overstated. It does still require : set too small, the sequence of inverses can vary wildly; set too large, learning is slowed. More consequentially, lacking a step size means LSTD never forgets. That is fine for a fixed policy , but in control — where generalized policy iteration keeps changing the target policy — an approximation that weights all past data equally is a liability. The data from an abandoned policy should fade, and LSTD has no mechanism to fade it. In control applications LSTD must be combined with some means of inducing forgetting, which moots the supposed advantage of needing no step size.1
| Semi-gradient TD(0) | LSTD | |
|---|---|---|
| Update | one small SGD step per example | recompute exact fixed point of data so far |
| Compute / step | ||
| Memory | (holds ) | |
| Data efficiency | needs many examples | most efficient linear TD method |
| Step size | needs (must be tuned) | none, but needs |
| Forgetting | built in (step size) | none — bad for changing |
Least-squares control
LSTD as presented evaluates a fixed policy. The natural next question — how to do control with the same data efficiency — was answered by least-squares policy iteration (Lagoudakis and Parr 2003, JMLR), which Sutton and Barto cite as the extension of least-squares methods to control. LSPI runs policy iteration on a batch of transitions: an inner routine, LSTDQ, solves the LSTD fixed point for the action-value function of the current policy directly from the stored data, then the policy is made greedy with respect to that , and the two steps repeat over the same fixed batch. Because every iteration reuses all the data and never touches the environment again, LSPI is fully off-line and among the most sample-efficient linear control methods — the control counterpart of LSTD's prediction efficiency, at the same cost.2
Footnotes
- Sutton & Barto, Reinforcement Learning: An Introduction (2nd ed.), §9.8 — Least-Squares TD: the TD fixed point with and ; the LSTD estimates (9.20)–(9.21) with the regularizer; the Sherman-Morrison incremental inverse (9.22); the LSTD algorithm box; and the discussion of the versus tradeoff, the parameter, and the lack of forgetting in control. LSTD is due to Bradtke and Barto (1996); the incremental inverse to Sherman and Morrison (1949). ↩ ↩2 ↩3
- Lagoudakis and Parr (2003),
Least-Squares Policy Iteration
, Journal of Machine Learning Research 4: extends least-squares TD to control by running policy iteration over a fixed batch of transitions, with an inner LSTDQ step that solves the LSTD fixed point for the action-value function of the current policy. Cited by Sutton & Barto (§9.8, Bibliographical Remarks) as the extension of least-squares methods to control. ↩
╌╌ END ╌╌