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:
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:
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.
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
True value vπ(s) and approximation v̂(s, w)
√VE over episodes (this run)
What to try
- State aggregation with 10 groups and gradient Monte Carlo: after a few thousand episodes the approximation becomes a staircase, each step close to the μ-weighted average of the true values in its group. Groups near the ends are pulled toward the more frequently visited states inside them.
- Switch to semi-gradient TD(0) with the same features. Its default α is about 20 times larger: early on most TD errors are exactly zero (an estimate compared with an equal estimate), so information spreads slowly from the ends. Its staircase ends slightly further from the truth, especially near the ends, because TD converges to the TD fixed point rather than the VE minimum.
- Tile coding with several tilings gives a much smoother fit than one tiling with the same tile width, at the same cost per update. Each extra tiling adds resolution without making generalisation narrower.
- Compare the polynomial and Fourier bases at the same order with gradient Monte Carlo. The polynomial features are highly correlated (u5 and u6 look alike), so it learns more slowly and is touchier about α. This is one reason Fourier features are generally preferred for online learning.
05Constructing features
Linear methods are only as good as their features. Features are where domain knowledge enters, and they determine how the function generalises.
- State aggregation: partition the states into groups and give each group one weight. The simplest case of the methods below.
- Polynomials: products of powers of the state variables, s1is2j…. They can represent interactions between variables, but the number of features grows fast with dimension and order.
- Fourier basis: cosines of different frequencies, xi(s) = cos(π ciᵀs). They approximate smooth functions well, especially with step sizes scaled down for high frequencies.
- Coarse coding: many overlapping receptive fields (circles, for instance), each a binary feature that is 1 when the state falls inside. The size and shape of the fields set how broadly learning generalises; their density sets how finely it can discriminate.
- Tile coding: coarse coding with several offset grids (tilings). Exactly one tile per tiling is active, so the number of active features is constant, which makes setting α easy, and computing them is cheap. It is a strong default for low-dimensional continuous states and is used for Mountain Car in chapter 10.
- Radial basis functions: smooth, graded versions of coarse coding, with each feature a Gaussian bump around a centre.
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.