Linear Function Approximation
Imagine an agent learning to evaluate chess positions, or a thermostat learning to predict room temperature from sensor readings. In both cases the state space is effectively infinite or astronomically large. So a lookup table mapping each state to a value is impossible to store. It is also impossible to learn from sparse experience. The agent must instead generalize. It needs to guess the value of states it has never visited. It does this based on similarity to states it has seen. Linear function approximation is the oldest, simplest, and still most analyzable tool for this generalization problem. It remains the backbone against which every neural-network-based Deep Q-Networks method is implicitly compared. The core move is to describe each state (or state-action pair) by a fixed vector of numerical features. The value function is then represented as a weighted sum of those features. Learning then means adjusting a small vector of weights, rather than filling in an enormous table. This single change transforms reinforcement learning from a bookkeeping problem into a genuine statistical estimation problem. It is the reason Temporal-Difference Learning: TD(0) can scale from toy gridworlds to problems with continuous or combinatorially large state spaces. The big picture is that linear approximation buys generalization and memory efficiency. The cost is representational power and some theoretical guarantees. With a table, TD learning provably converges to the true value function under standard conditions. With function approximation, convergence is only guaranteed under specific structural assumptions. Combining function approximation, bootstrapping, and off-policy learning can actually diverge. This phenomenon is known as the deadly triad. Understanding linear approximation precisely is essential preparation for more general methods. This includes knowing where its guarantees come from and where they break. It prepares readers for semi-gradient methods and deep RL architectures built on top of it. This article develops the linear architecture from first principles. It derives the gradient and semi-gradient TD update. It proves a convergence guarantee for on-policy linear TD(0). It walks through a worked numerical trace. Finally, it surveys the classic failure modes that motivate later, more robust methods.
- Linear function approximation represents , a dot product of learned weights and hand- or learned-designed features.
- It replaces a table of entries with a weight vector of size , enabling generalization to unseen states.
- The semi-gradient TD(0) update adjusts weights using the TD error times the feature vector, ignoring the dependence of the bootstrap target on the weights.
- On-policy linear TD(0) provably converges to a well-characterized fixed point, with error bounded relative to the best possible linear approximation.
- Feature design (tile coding, radial basis functions, polynomials, Fourier bases) determines what generalization is even possible — the algorithm cannot fix a bad representation.
- Off-policy training, bootstrapping, and function approximation together can cause divergence — the deadly triad — motivating later corrections like gradient-TD methods.
Representing values as turns learning into adjusting a handful of weights, letting experience at one state update predictions at every state that shares its features.
The idea
In tabular reinforcement learning, the value function is stored as one independent number per state. Function approximation instead posits a parametric family of functions , indexed by a weight vector , and asks the learning algorithm to find good weights rather than good table entries. Linear function approximation is the special case where the approximation is linear in the weights:
where is a feature vector representing state . The features are fixed, hand-designed (or otherwise pre-computed) functions of the raw state; only the weights are learned. This is distinct from nonlinear approximators such as neural networks, where the mapping from state to features is itself learned jointly with the output weights. The appeal of linearity is twofold. First, the approximation's gradient with respect to the weights is simply the feature vector itself,
independent of . This makes gradient-based updates trivial to write down and analyze. Second, because the objective (mean squared value error, weighted by the on-policy state distribution) is a quadratic function of when the target is fixed, the associated optimization landscape has a single global optimum with no spurious local minima — a property that is lost the moment the features themselves are learned nonlinearly. Feature construction is where domain knowledge enters. Classic choices include polynomial features (products of state coordinates up to some degree), tile coding (a form of coarse coding using multiple overlapping binned grids, each grid shifted slightly from the others), radial basis functions (Gaussian bumps centered at prototype states), and the Fourier basis (cosine features at increasing frequencies). Each induces a different notion of "similarity" between states — two states with similar feature vectors will necessarily be assigned similar values, whether or not that similarity is appropriate for the task. This is the central tradeoff of linear approximation: it is exactly as good as the features fed into it, and no amount of clever weight-tuning can compensate for a representation that cannot express the true value function.
How it works
The learning target for prediction under a fixed policy is to find minimizing the Mean Squared Value Error,
where is the fraction of time spent in state under the behavior policy (the on-policy distribution when learning on-policy). Since is unknown, we cannot compute this loss directly; instead we use sampled transitions and bootstrap estimates, exactly as in tabular TD(0), but now update a shared weight vector using stochastic gradient descent.
Monte Carlo with linear approximation. If we had the true return as an unbiased target, the update is ordinary stochastic gradient descent on squared error:
This is a true gradient step because does not depend on .
TD(0) with linear approximation. TD(0) instead bootstraps, using as the target. Crucially, this target does depend on , but the standard algorithm ignores that dependency and treats the target as fixed when differentiating — hence the name semi-gradient TD(0):
This is not gradient descent on any fixed objective (it is a semi-gradient), yet under on-policy sampling and diminishing step sizes it converges — to a specific, well-understood fixed point derived below, not to the minimizer of itself. ``` Algorithm: Semi-Gradient TD(0) for Policy Evaluation with Linear Function Approximation Input: policy π to evaluate feature function x : S → R^d step size α ∈ (0, 1], discount factor γ ∈ [0, 1] Initialize weight vector w ∈ R^d arbitrarily (e.g., all zeros) for each episode: initialize S (first state of episode) while S is not terminal: A ← action given by π(·|S) take action A, observe reward R and next state S' if S' is terminal: target ← R # no bootstrap term else: target ← R + γ dot(w, x(S')) δ ← target − dot(w, x(S)) # TD error w ← w + α δ x(S) # semi-gradient update S ← S' return w ``` The pseudocode is deliberately close to tabular TD(0): the table lookup `V[S]` is replaced by `dot(w, x(S))`, and the tabular update — which changes exactly one table entry — is replaced by an update that nudges every* weight touched by the nonzero components of . If features are sparse (e.g., tile coding, where a fixed small number of tiles are active per state), this update touches only weights per step, where is the number of active features, regardless of . Extending to control (estimating or an optimal policy) replaces with and follows the same semi-gradient recipe for SARSA or Q-learning, using an -greedy policy derived from for action selection. The weight update becomes with built from either the SARSA target (on-policy) or the max-Q target (off-policy, and hence more fragile under function approximation).
Complexity & correctness
Time and space complexity. Storing the weight vector requires space, versus for a table — decisive when is combinatorially large or continuous, since is chosen by the designer independent of state-space size. Each TD(0) step computes , , two dot products, and an update — all in the dense case. With sparse binary features such as tile coding, where exactly features are active per state (a small constant, e.g. tiles), the dot products and updates cost per step, independent of , because only the active components need be touched. This is why tile coding scales to in the millions in practice: memory is dominated by the weight array, but per-step compute stays bounded by .
Correctness for on-policy linear TD(0). Unlike the tabular case, linear TD(0) does not converge to the true value function in general, because may not lie in the span of the chosen features. Instead, on-policy linear TD(0) with diminishing step sizes converges (with probability 1, under standard stochastic-approximation conditions on the step-size sequence and an irreducible, aperiodic Markov chain induced by ) to the unique fixed point satisfying
where
A key structural fact — proved by Tsitsiklis and Van Roy (1997) — is that under the on-policy distribution , the matrix is positive definite (in the relevant subspace), which guarantees this linear system has a unique solution and that the associated ODE (the expected direction of the stochastic update) is globally stable. The proof sketch: where has rows , , and is the policy's transition matrix; a classical result shows is positive definite whenever is the stationary distribution of , and this property is inherited by for any full-rank feature matrix . Positive definiteness is precisely what fails when the sampling distribution is off-policy, which is the root cause of divergence examples in the deadly triad.
Error bound. The fixed point is not the projection minimizer of , but it is provably close to it:
That is, TD's fixed-point error is at most a factor worse than the best possible linear approximation of under the chosen features — a guarantee unavailable to naive bootstrapping schemes without this structural analysis. As this bound loosens considerably, reflecting the well-known difficulty of long-horizon credit assignment with bootstrapping.
Honest tradeoffs. These guarantees hinge on three things simultaneously: (1) on-policy sampling, (2) linear architecture, (3) the specific semi-gradient TD update. Change any one — e.g., train off-policy, or use a nonlinear network, or use a different bootstrapping scheme — and the clean positive-definiteness argument no longer applies; convergence must be re-established (or may provably fail), which is exactly the subject of the deadly triad and of corrective algorithms like gradient-TD (GTD2, TDC).
Worked example
Consider a tiny 5-state random walk: states in a line, terminal states at both ends (reward on the left exit, reward on the right exit), and equiprobable left/right moves — the classic tabular TD(0) benchmark, now equipped with linear features. Use a simple aggregation feature scheme: group the five states into two feature "bins" for illustration —
This deliberately imperfect feature set cannot represent the true values exactly (true values under random walk dynamics are ), which lets us see the semi-gradient update converge to a biased but bounded solution rather than the exact answer. Initialize , , . Trace one episode :
| Step | update | |||||||
|---|---|---|---|---|---|---|---|---|
| 1 | 0 | no change: | ||||||
| 2 | 0 | no change: | ||||||
| 3 | terminal | 1 | (n/a, terminal) |
After this single episode . Note that step 3's update changed only, because has a zero first component — exactly the sparse-update behavior predicted by the complexity analysis. On the next episode, suppose the walk visits :
| Step | new | |||||||
|---|---|---|---|---|---|---|---|---|
| 1 | 0 | |||||||
| 2 | 0 | |||||||
| 3 | terminal | 0 | n/a |
Over many more episodes, converges toward the fixed point solving for this feature map and Markov chain — a pair of values that best fit each aggregated bin, biased slightly by the bootstrapping and averaging inherent to TD, but with error provably within the factor of the best two-parameter linear fit to the true random-walk values. This demonstrates concretely how coarse features force nearby states to share value estimates ( and are forced identical, likewise and ), trading exactness for a drastically smaller parameter count — 2 weights instead of 5 table entries — and this ratio only becomes more favorable as state spaces grow.
Common pitfalls & traps
| Pitfall | Why it happens | Fix |
|---|---|---|
| Forgetting the bias/constant feature | Without an always-on feature ( for all ), the approximator is forced through the origin, limiting expressiveness | Always include a constant feature unless features already span an affine family |
| Treating semi-gradient as true gradient | The bootstrap target depends on ; differentiating it fully gives a different (and empirically worse-behaved) "residual gradient" algorithm | Understand that ignoring the target's -dependence is intentional and is what makes TD's fixed point meaningful |
| Using highly correlated or redundant features | Makes near-singular, causing slow, unstable, or oscillating convergence even though it's theoretically still positive semi-definite | Use tile coding / RBFs with good coverage, check conditioning, consider regularization |
| Applying linear TD(0) off-policy without correction | Off-policy sampling breaks the positive-definiteness of , and the deadly triad (function approximation + bootstrapping + off-policy) can make weights diverge to infinity | Use importance sampling with gradient-TD methods (GTD2, TDC), or switch to on-policy training |
| Step size too large relative to feature scale | Because the update is , large or unnormalized feature magnitudes amplify effective step size, causing divergence | Normalize features, tune relative to (e.g., set for tile coding) |
| Assuming convergence to | Linear TD(0) converges to the TD fixed point, not the true value function, whenever is not representable by the chosen features | Report/expect the -bounded fixed point error, not exact recovery |
Pioneers & history
Origins · 1 minRichard S. Sutton and how this was discovered
Sutton's early work formalized TD learning and, together with collaborators including Doina Precup and Satinder Singh, drove the theoretical analysis of function approximation in RL, including convergence proofs and the identification of divergence risks that motivated gradient-TD methods.
Where this matters
Linear function approximation underlies decades of applied reinforcement learning before the deep learning era, and remains the workhorse whenever interpretability, sample efficiency, or provable convergence matter more than raw representational capacity. Classic large-scale successes include Tesauro's TD-Gammon-style value learning (originally with neural nets, but linear variants with hand-designed backgammon features perform competitively), robotic control with tile-coded state spaces (as in early Sarsa and Q-learning applications to mountain-car and acrobot benchmarks), and industrial process control where engineers can hand-design physically meaningful features (position, velocity, error terms) and need auditable, stable weight updates. Linear methods with sparse coarse-coded features (tile coding, radial basis functions) remain standard baselines in continuous-control benchmarking because they train in milliseconds and their convergence properties are mathematically characterized, unlike black-box deep networks. The positive-definiteness argument developed here for on-policy linear TD(0) is also the conceptual seed for gradient-TD methods and later analyses of semi-gradient methods with function approximation more broadly, and the divergence risks identified in the linear, off-policy setting directly foreshadow the deadly triad, the central cautionary framework used to explain instability in deep reinforcement learning systems such as DQN (which needed target networks and experience replay specifically to blunt these effects).
Ask the tutor: How does the positive-definiteness of matrix A break down specifically under off-policy sampling, and how do gradient-TD methods like TDC restore convergence?
Why use linear function approximation instead of a full lookup table?
Lookup tables require one independent parameter per state, which is infeasible when the state space is very large or continuous, and they cannot generalize — visiting one state teaches you nothing about neighboring states. Linear function approximation represents the value as a dot product of weights and features, so the parameter count is chosen by the designer (independent of state-space size) and updating the weights after visiting one state automatically shifts predictions for every other state sharing similar features. This enables learning from far less experience than tabular methods require, at the cost of only being as accurate as the chosen feature representation allows.
Does linear TD(0) converge to the true value function v_π?
Not in general. It converges (under on-policy sampling with diminishing step sizes) to a specific fixed point solving , which equals the true value function only if happens to lie exactly in the span of the chosen features. Tsitsiklis and Van Roy proved that this fixed point's mean squared value error is at most times the error of the best possible linear approximation to — a strong but not perfect guarantee. The gap between and the true is entirely attributable to representational limits of the feature set, not to a flaw in the learning rule itself.
What is the difference between semi-gradient TD(0) and "true gradient" TD(0)?
The TD(0) target depends on the current weights through the bootstrapped next-state value. A fully correct gradient of the squared TD error would differentiate through this dependence as well, producing an extra term. Semi-gradient TD(0) deliberately omits that term, treating the target as a constant when computing the gradient. Empirically and theoretically, this "incorrect" simplification behaves better in the on-policy case (it is what has the clean fixed-point theory), whereas the theoretically "correct" full gradient method (sometimes called the residual-gradient method) tends to converge more slowly in practice despite stronger convergence guarantees.
How should I choose features for linear function approximation?
Feature choice should encode which states you believe should have similar values. Tile coding (overlapping grids of binary indicator features) gives fast, sparse, easily tunable generalization and is popular in continuous control. Radial basis functions place smooth Gaussian bumps at prototype states, giving smoother generalization at higher computational cost per feature. The Fourier basis represents states as combinations of cosine waves and works well when value functions are smooth over the state space. There is no universally best choice — the guarantee that linear TD(0) is within a factor of the best linear fit only helps if that best linear fit is itself good, so feature engineering is where most of the real design effort belongs.
What is the deadly triad, and why does it matter for linear methods?
The deadly triad refers to the simultaneous combination of function approximation, bootstrapping (as in TD methods), and off-policy training. Individually each is fine and widely used; combined, they can cause the weight vector to diverge to infinity, as shown by counterexamples such as Baird's star problem, even in the simple linear setting. The root cause is that off-policy sampling can make the key matrix indefinite rather than positive definite, destroying the stability argument that guarantees on-policy convergence. This risk directly motivated the development of gradient-TD algorithms (GTD2, TDC) that restore convergence guarantees even under off-policy sampling with linear function approximation.
Can linear function approximation be used for control, not just prediction?
Yes. Replacing with an action-value approximator allows semi-gradient SARSA or semi-gradient Q-learning to be run with the same update rule, using -greedy action selection derived from the current estimates. On-policy control (semi-gradient SARSA) inherits similar convergence intuitions to on-policy prediction, though the moving target policy complicates a clean fixed-point analysis. Off-policy control (semi-gradient Q-learning) is more fragile and sits squarely in deadly-triad territory, which is one reason deep Q-learning systems require additional stabilizers like target networks and experience replay.
How does linear function approximation relate to deep reinforcement learning?
Deep RL architectures such as DQN can be viewed as linear function approximation applied to the last layer, stacked on top of a nonlinear feature extractor (the earlier network layers) that is trained jointly rather than fixed. This means all the intuitions from linear analysis — the semi-gradient update, the risk of the deadly triad, the sensitivity to feature (representation) quality — still apply, but the convergence guarantees available for fixed linear features generally do not transfer, because the features themselves now shift during training. Studying linear function approximation rigorously is therefore the cleanest way to understand both the promise and the instability risks inherited by its nonlinear, deep-network descendants.