Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Semi-gradient methods and linear function approximation

Semi-gradient methods update value-function parameters using the gradient of the estimate but with bootstrap targets; with a linear function approximator this leads to a linear system A w = b and (under standard ergodic and step-size assumptions) convergence to the projected Bellman fixed point.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Semi-gradient methods are used when we approximate value functions with parameterized functions (common in control algorithms like actor–critic). They let engineers scale reinforcement learning to large or continuous state spaces while using cheap linear models or neural networks for value estimation.

Key ideas

Start with a fixed policy π and a Markov decision process (MDP) with states S, rewards R and discount factor γ (0 ≤ γ < 1). We need to evaluate the policy (policy evaluation) using function approximation.

  • Function approximation: A method that maps states to approximate values using a parameter vector. For a linear approximator we define the feature vector and the approximated value:

    • Feature vector φ(s) ∈ R^n: a column vector of n features for state s.
    • Linear function approximator v̂(s, w) = φ(s)^T w, where w ∈ R^n is the parameter vector. (This is linear in parameters.)
  • Value function vπ(s): the true (expected) return when following policy π from state s. We try to make v̂(·, w) approximate vπ(·).

  • Mean-squared value error (MSVE): With a fixed state distribution μ (often the stationary distribution under π), define the squared error we would like small:

    • MSVE(w) = E_{s~μ}[(vπ(s) - v̂(s,w))^2].
  • Bootstrapping: Temporal-difference (TD) methods update estimates using other value estimates (bootstrapped target). Using a one-step target gives the TD(0) error.

  • Semi-gradient: An update that uses the gradient of the approximated value v̂(s,w) with respect to w but treats the bootstrapped target as a constant (so we do not take derivative through the target). This is why TD updates are called semi-gradient updates — they use a partial/incorrect gradient when the target depends on parameters.

  • TD(0) sample update (stochastic semi-gradient): on transition (S_t, A_t, R_{t+1}, S_{t+1}) under policy π, define the TD error and update:

    • δ_t = R_{t+1} + γ v̂(S_{t+1}, w_t) - v̂(S_t, w_t)
    • w_{t+1} = w_t + α δ_t ∇_w v̂(S_t, w_t) For linear v̂, ∇w v̂(S_t, w_t) = φ(S_t), so the update becomes w{t+1} = w_t + α δ_t φ(S_t).
  • For the linear case, the expected update (under the stationary distribution and transitions) yields a linear system for the fixed point. Define expectations over the stationary (ergodic) trajectory under π:

    • A = E[φ_t (φ_t - γ φ_{t+1})^T]
    • b = E[R_{t+1} φ_t] The algorithm's expected TD(0) update points to the root of A w = b. Under standard assumptions (policy fixed, Markov chain ergodic, feature vectors bounded, A nonsingular—e.g., Φ has full column rank under μ, and step-sizes satisfying Robbins–Monro conditions) the weights converge to the unique solution w* of A w* = b. This w* is the parameter vector whose approximated value v̂(·, w*) is the solution of the projected Bellman equation:
    • Π Tπ v̂ = v̂ (where Π is the projection onto the space spanned by features under μ-weighted norm and Tπ is the Bellman operator for policy π).
  • Projection operator Π: For any value function v, Π v is the (μ-weighted) orthogonal projection of v into the linear subspace spanned by {φ_i}. It minimizes the μ-weighted norm ||v - v̂||_μ.

  • Why semi-gradient, not true gradient: The TD target contains v̂(S_{t+1}, w) which depends on w. A true gradient of the mean-squared TD error would differentiate through that dependency; semi-gradient treats the target as constant and differentiates only through v̂(S_t, w). This mismatch prevents TD(0) from being a true gradient descent on MSVE, but for linear v̂ the expected update still defines a linear fixed point A w = b and converges under assumptions.

  • Diagram to draw for exams: Draw a 2D plane representing the space of value functions. Mark the true Bellman target Tπ v̂ (a function not in the feature space) and the linear subspace spanned by features as a straight line. Draw the orthogonal projection Π(Tπ v̂) onto the line, and show that v̂* is where Π(Tπ v̂) intersects the line. Label axes as “value for state 1” and “value for state 2”.

Formulas

v̂(s, w) = φ(s)^T w — v̂ is approximated value; φ(s) is feature vector (unitless), w is parameter vector (unitless). Applies for linear approximation.

δ_t = R_{t+1} + γ v̂(S_{t+1}, w_t) - v̂(S_t, w_t) — TD error; R in reward units (e.g., joules if reward measures energy) or unitless; γ dimensionless; applies at each transition.

w_{t+1} = w_t + α δ_t ∇_w v̂(S_t, w_t) — semi-gradient update; α is learning rate (unitless); applies for stochastic online updates.

for linear v̂: w_{t+1} = w_t + α δ_t φ(S_t) — since ∇_w v̂ = φ.

z_t = γ λ z_{t-1} + ∇_w v̂(S_t, w_t) — eligibility trace with z_{-1} = 0 (TD(λ)) w_{t+1} = w_t + α δ_t z_t — semi-gradient TD(λ) update for linear v̂: z_t = γ λ z_{t-1} + φ(S_t)

A = E[φ_t (φ_t - γ φ_{t+1})^T] — matrix A (n×n), unitless; expectation over stationary distribution and transition dynamics.

b = E[R_{t+1} φ_t] — vector b (n×1), units = reward × feature units (usually reward units since features are unitless).

A w* = b — linear system giving the TD fixed point w* (unitless), holds under the expectation operator and stationarity. In matrix form (feature matrix Φ, transition matrix P_π, reward vector r_π, and D_μ = diag(μ)): A = Φ^T D_μ (I - γ P_π) Φ and b = Φ^T D_μ r_π.

Π Tπ v̂ = v̂ — projected Bellman equation: Π is μ-weighted orthogonal projection, Tπ is Bellman operator for policy π. In matrix form (feature matrix Φ and D_μ = diag(μ)): Π = Φ (Φ^T D_μ Φ)^{-1} Φ^T D_μ.

Worked examples

Example 1 — one TD(0) update (numerical): Consider an MDP with two states S = {1,2}, fixed policy π, discount γ = 0.9. Use two features φ(1) = [1, 0]^T, φ(2) = [0, 1]^T (so value estimates are independent). Initial weights w = [0.5, 1.0]^T. At time t we are in S_t = 1, we take action (according to π), receive R_{t+1} = 2.0 (unitless), and next state S_{t+1} = 2. Compute one semi-gradient TD update with α = 0.1. Steps:

  1. Compute v̂(S_t, w) = φ(1)^T w = [1,0]·[0.5,1.0]^T = 0.5 (unitless).
  2. Compute v̂(S_{t+1}, w) = φ(2)^T w = 1.0 (unitless).
  3. TD error: δ_t = 2.0 + 0.9·1.0 - 0.5 = 2.0 + 0.9 - 0.5 = 2.4 (unitless).
  4. Update: w_{t+1} = w + 0.1·2.4·φ(1) = [0.5,1.0]^T + 0.24·[1,0]^T = [0.74, 1.0]^T. Final answer: w_{t+1} = [0.74, 1.0]^T (unitless).

Example 2 — solve A w = b (small linear algebra): Same two-state MDP; suppose we are given the following expectations (for illustration): E[φ_t φ_t^T] = diag(0.6, 0.4) (probability of visiting state 1 is 0.6, state 2 is 0.4), E[φ_t φ_{t+1}^T] = [[0.3, 0.3],[0.2,0.2]] (numbers chosen for example), and expected rewards E[R_{t+1} φ_t] = [1.2, 0.8]^T. With γ = 0.9 compute A and b then w*. Steps:

  1. Compute A = E[φ_t φ_t^T] - γ E[φ_t φ_{t+1}^T]. Plug values: E[φ_t φ_t^T] = [[0.6,0],[0,0.4]] γ E[φ_t φ_{t+1}^T] = 0.9 * [[0.3,0.3],[0.2,0.2]] = [[0.27,0.27],[0.18,0.18]] A = [[0.6-0.27, 0-0.27],[0-0.18, 0.4-0.18]] = [[0.33, -0.27],[-0.18, 0.22]]
  2. b is given = [1.2, 0.8]^T.
  3. Solve A w* = b. Solving (e.g., via matrix inverse) gives w* = [20, 20]^T. Final answer: w* = [20, 20]^T (unitless).

Example 3 — model answer question (short derivation): Show that the expected TD(0) update is -α (A w - b). Model answer: Start from expected update: E[Δw] = α E[δ_t φ_t] = α E[(R_{t+1} + γ φ_{t+1}^T w - φ_t^T w) φ_t] = α (E[R_{t+1} φ_t] + γ E[φ_t φ_{t+1}^T] w - E[φ_t φ_t^T] w). Rearranging terms gives E[Δw] = α (b - (E[φ_t φ_t^T] - γ E[φ_t φ_{t+1}^T]) w) = -α (A w - b). Thus fixed point satisfies A w = b.

Common mistakes

  • Mixing up φ_{t+1} and φ_t in expectations (order matters in A).
  • Assuming convergence for arbitrary step-size α; need Robbins–Monro conditions (diminishing step-size) or sufficiently small constant α and additional assumptions.
  • Using non-stationary distribution μ without adjusting projection operator Π or sampling corrections.
  • Assuming off-policy TD(0) with linear function approximation will converge; it can diverge (e.g., Baird's counterexample). Use importance sampling or gradient TD methods (GTD/TDC) for stability.

For your exam

Typical question types

  • Definitions: define semi-gradient, linear function approximator, projection Π, A and b.
  • Derivations: derive A and b and show expected TD(0) update leads to A w = b.
  • Proof sketches: conditions for convergence (reference Tsitsiklis & Van Roy 1997 sketch) — state assumptions and main idea.
  • Numericals: compute one TD update given φ, w, R, γ, α; or solve A w = b for small n.
  • Diagrams: draw function-space, Bellman target, and projection as described above. What full-marks answers include
  • Clear definitions with bolded terms.
  • Correct formulas for δ_t, A and b and the projected Bellman equation.
  • All assumptions listed (fixed policy, ergodic Markov chain, bounded features, appropriate step-size).
  • Correct algebra in derivations and neat matrix work for numericals.

Quick check

  1. What is a semi-gradient step?
  2. For linear v̂, what is ∇_w v̂(s, w)?
  3. Write the matrix A used in linear TD(0). Answers: 1) An update that differentiates only the estimate term and treats the bootstrapped target as constant. 2) φ(s). 3) A = E[φ_t (φ_t - γ φ_{t+1})^T].

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?