Chapter 9 · Sutton & Barto

Prediction with function approximation

A table with one entry per state stops working when there are millions of states, or when states are continuous and never repeat. Part II replaces the table with a parameterised function: a small weight vector w that determines the value of every state. Learning now means adjusting w, and each update generalises from the state visited to many others.

01From tables to functions

We approximate vπ(s) by v̂(s, w), where w has d components and d is much smaller than the number of states. v̂ might be a linear function of features of the state, a neural network, or a decision tree. Every method from Part I fits in: each update says “move the value at St toward target Ut”, and we now treat that pair as a training example for a supervised-learning method.

Two things change. First, an update changes the value of many states at once. That generalisation is what makes learning feasible in large spaces, but it also means improving one state can worsen another. Second, since states compete for the function's limited capacity, we must say which states matter most. We weight the error by the on-policy distribution μ(s), the fraction of time spent in s:

Mean squared value errorVE(w) = Σs μ(s) [ vπ(s) − v̂(s, w) ]2

02Stochastic gradient and semi-gradient methods

Stochastic gradient descent moves w a little in the direction that most reduces the error on the current example. If Ut is the target for St:

General gradient-descent updatewt+1 = wt + α [ Ut − v̂(St, wt) ] ∇v̂(St, wt)

With the Monte Carlo target Ut = Gt, the target is an unbiased estimate of vπ(St), so gradient Monte Carlo is true SGD and converges to a local optimum of VE under the usual step-size conditions.

With a bootstrapping target, such as Ut = Rt+1 + γv̂(St+1, w), the target itself depends on w, but the update ignores that dependence. These are semi-gradient methods. They are not true gradient descent and lack its guarantees, but in the linear on-policy case they converge reliably, usually faster, and they work online and on continuing tasks.

Semi-gradient TD(0)w ← w + α [ R + γ v̂(S′, w) − v̂(S, w) ] ∇v̂(S, w)

03Linear methods

The most important special case is linear: each state is described by a feature vector x(s) = (x1(s), …, xd(s)), and v̂(s, w) = wᵀx(s). The gradient is then just the feature vector, ∇v̂(s, w) = x(s), so the update adds α × error × x(s): only the weights of active features change.

Linear semi-gradient TD(0) converges to the TD fixed point wTD, not to the minimum of VE. Its error is bounded: VE(wTD) ≤ (1/(1−γ)) minw VE(w). With γ close to 1 that bound is loose, which is the price of bootstrapping, but TD usually gets near its fixed point much faster than Monte Carlo gets near the minimum.

04Worked example: the 1000-state random walk

States are numbered 1 to 1000 and every episode starts at 500. Each step jumps to a state between 1 and 100 places to the left or right, all 200 jumps equally likely. A jump past state 1 ends the episode with reward −1; past state 1000, with +1. All other rewards are 0 and γ = 1. The true values, computed here by dynamic programming, rise from about −0.92 to +0.92. Choose a feature representation and an algorithm, then run episodes.

Approximating vπ on 1000 states

episodes 0 · weights d = – · √VE –
10
2.0e-4
Changing features, algorithm or α resets the weights.

True value vπ(s) and approximation v̂(s, w)

True value vπApproximation v̂Shading: on-policy distribution μ(s)

√VE over episodes (this run)

What to try

05Constructing features

Linear methods are only as good as their features. Features are where domain knowledge enters, and they determine how the function generalises.

06Setting the step size

A useful rule of thumb for linear methods: to learn from about τ experiences with roughly the same feature vector, use α = (τ 𝔼[xᵀx])−1. For tile coding with n tilings, xᵀx = n for every state, so α = 1/(τn). For example, with 10 tilings, α = 0.01 averages over roughly the last 10 visits to similar states.

07Beyond linear

Artificial neural networks learn their own features in hidden layers. Trained by backpropagation with semi-gradient targets, deep networks are behind most large-scale successes, at the cost of losing convergence guarantees. Least-squares TD (LSTD) computes the linear TD fixed point directly from the data seen so far, w = Â−1b̂. It is very data-efficient but costs O(d2) per step and has no step size to forget old data. Memory-based and kernel methods store examples and compute values by comparing the query state with nearby stored states, adapting their resolution to wherever data actually falls.

Finally, interest and emphasis: VE weights states by how often they are visited, but sometimes some states matter more, such as the start state. Assigning each state an interest It and scaling updates by an emphasis Mt = It + γnMt−n lets the approximation spend its capacity where it is needed.