Skip to content
AI360Xpert
Beta

Linear Methods in RL

Linear methods score a state as a weighted sum of hand picked features, so the error surface is one clean bowl with a single best setting.

Value 2.5 comes from weights 2.0 and 1.0 on features 1.0 and 0.5, then one update moves weights to 2.30 and 1.15 and value to 2.875 on a single bowl
Value 2.5 comes from weights 2.0 and 1.0 on features 1.0 and 0.5, then one update moves weights to 2.30 and 1.15 and value to 2.875 on a single bowl

Why Does This Exist?

Tables fail when states are many or continuous. A robot arm never sees the exact same joint angles twice, so a table entry per state wastes memory and shares nothing between near identical states. You need generalization across states.

Value function approximation replaces the table with a parameterized guess. Deep nets generalize well but bring a rugged loss with local dips, saddle points, and divergence when combined with bootstrapping and off policy data. Linear methods keep the generalization and drop the ruggedness. The value is a dot product, the error is a quadratic bowl, and on policy TD converges to a bounded fixed point. This page covers the dot product form, the gradient identity, and the TD bound. Feature construction covers where good features come from. Semi-gradient TD covers the bootstrapped update in full.

The one idea you need first

A feature vector x(s)x(s) in Rd\mathbb{R}^d is a short numeric summary of state ss, one number per property. The weight vector ww in Rd\mathbb{R}^d holds one tunable number per property. Their dot product wTx(s)w^T x(s) is the sum of pairwise products. That sum is the whole model.

Think of It Like This

A grading rubric

Your final course score is not a mystery model. Homework counts 20 percent, midterm 30, final 40, attendance 10. With scores 0.95, 0.82, 0.88, 1.00 you multiply and add and get the total.

Features are the assignment scores. Weights are the syllabus percentages. The predicted value is the final score. To raise the total you push each weight in proportion to its score, which is exactly the linear update.

Where it stops: a rubric is fixed by a teacher. Here weights start as guesses and move after every transition until error sits at the bottom of the bowl.

How It Actually Works

Map state ss to features x(s)x(s). Call ww the weights. The estimate is:

v^(s,w)=wTx(s)=∑i=1dwixi(s)\hat{v}(s, w) = w^T x(s) = \sum_{i=1}^d w_i x_i(s)

The gradient with respect to ww is just the features:

∇wv^(s,w)=x(s)\nabla_w \hat{v}(s, w) = x(s)

In words: to raise the estimate fastest, push weights along the feature direction. No chain rule, no backward pass.

Why the bowl has one bottom

Mean squared error under state weighting μ(s)\mu(s) is:

VE‾(w)=∑sμ(s)[v(s)−wTx(s)]2=wTAw−2bTw+c\overline{VE}(w) = \sum_s \mu(s)[v(s) - w^T x(s)]^2 = w^T A w - 2b^T w + c

Here A=∑sμ(s)x(s)x(s)TA = \sum_s \mu(s)x(s)x(s)^T is the feature covariance, bb mixes features with true values, cc is constant. Because AA is positive semi definite, the surface is a paraboloid. One bottom, no traps. Monte Carlo SGD with target GtG_t is:

wt+1=wt+α[Gt−wtTx(St)]x(St)w_{t+1} = w_t + \alpha[G_t - w_t^T x(S_t)]x(S_t)

Semi-gradient TD with reward Rt+1R_{t+1} and discount γ\gamma uses the bootstrapped error:

δt=Rt+1+γwtTx(St+1)−wtTx(St)\delta_t = R_{t+1} + \gamma w_t^T x(S_{t+1}) - w_t^T x(S_t)

wt+1=wt+αδtx(St)w_{t+1} = w_t + \alpha \delta_t x(S_t)

On policy this converges to the TD fixed point wTDw_{TD} with error bounded by 1/(1−γ)1/(1-\gamma) times the best linear error.

Worked example

Features x=[1.0,0.5]x = [1.0, 0.5], weights w0=[2.0,1.0]w_0 = [2.0, 1.0], rate α=0.2\alpha = 0.2, target U=4.0U = 4.0.

Prediction:

v^=2.0×1.0+1.0×0.5=2.5\hat{v} = 2.0 \times 1.0 + 1.0 \times 0.5 = 2.5

Error:

δ=4.0−2.5=1.5\delta = 4.0 - 2.5 = 1.5

Update along features:

Δw=0.2×1.5×[1.0,0.5]=[0.30,0.15]\Delta w = 0.2 \times 1.5 \times [1.0, 0.5] = [0.30, 0.15]

w1=[2.30,1.15]w_1 = [2.30, 1.15]

New prediction:

v^new=2.30×1.0+1.15×0.5=2.875\hat{v}_{new} = 2.30 \times 1.0 + 1.15 \times 0.5 = 2.875

Shift is 0.3750.375, which equals αδ∥x∥2=0.2×1.5×1.25\alpha \delta \|x\|^2 = 0.2 \times 1.5 \times 1.25. The diagram draws this exact move from 2.52.5 to 2.8752.875 on the bowl.

Code

This snippet replays the worked numbers and one TD step. It uses only the standard library.

from typing import List

def predict(w: List[float], x: List[float]) -> float:    """Dot product wT x."""    return sum(wi * xi for wi, xi in zip(w, x))

if __name__ == "__main__":    x = [1.0, 0.5]    w = [2.0, 1.0]    v0 = predict(w, x)    print(f"v0 = {v0:.3f}")  # -> v0 = 2.500    delta = 4.0 - v0    alpha = 0.2    w = [wi + alpha * delta * xi for wi, xi in zip(w, x)]    print(f"w1 = {w}")  # -> w1 = [2.3, 1.15]    v1 = predict(w, x)    print(f"v1 = {v1:.3f}")  # -> v1 = 2.875

Watch Out For

Features on wildly different scales

Mixing a velocity in 0 to 100 with a distance in 0 to 0.01 stretches the bowl into a narrow canyon. One global rate either explodes along the large feature or crawls along the small one. Symptom: oscillating loss that never settles even though the model is linear.

Standardize each feature to zero mean and unit variance or to the range minus 1 to 1. If you cannot rescale, give each dimension its own rate scaled by inverse mean square. Tile coding and radial bases help because their norms stay bounded.

Off policy TD without correction

Linear TD carries a convergence proof for on policy sampling. Under off policy sampling with bootstrapping the same update can diverge, the classic deadly triad. Symptom: weights grow slowly then blow up while on policy runs stay calm.

Stay on policy for plain semi-gradient TD, or switch to gradient TD methods that correct the sampling mismatch. Do not fix divergence by shrinking the rate alone. The sampling is the bug.

The Quick Version

  • Linear methods predict value as v^(s,w)=wTx(s)\hat{v}(s,w) = w^T x(s), a weighted sum of features with learnable weights.
  • The gradient equals the features, so each update is w+αδx(s)w + \alpha \delta x(s) with no backprop.
  • Squared error is a quadratic bowl with one global bottom, so there are no local minima.
  • In the worked check features [1.0,0.5][1.0, 0.5] and weights [2.0,1.0][2.0, 1.0] give 2.52.5, then move to [2.30,1.15][2.30, 1.15] and 2.8752.875 after one step toward 4.04.0.
  • On policy semi-gradient TD converges to a fixed point within 1/(1−γ)1/(1-\gamma) of the best linear fit, but off policy use needs correction.