Chapter 9: On-policy Prediction with Approximation

Overview

This chapter explores how to estimate the state-value function from on-policy data when the state space is too large for tabular representations. We transition from tables to parameterized functional forms with a weight vector , where .

Intuition

In function approximation, an update to one state affects many others through generalization. This makes learning more powerful but also more complex to manage, as we cannot get the values of all states exactly correct.


9.1 Value-function Approximation

All prediction methods are viewed as updates , where is the state and is the target.

  • Monte Carlo:
  • TD(0):
  • n-step TD:

This is essentially a supervised learning task where we provide training examples to a Function Approximation method. However, RL requires methods that can handle:

  1. Online Learning: Learning while interacting with the environment.
  2. Nonstationary Targets: The target changes as the policy improves (control) or because of Bootstrapping (TD/DP).

9.2 The Prediction Objective ()

In the tabular case, we could reach exactly for all . With approximation, we must decide which states to prioritize using a state distribution .

Mean Squared Value Error (VE)

Where is typically the on-policy distribution (fraction of time spent in under policy ).

Under on-policy training, for a continuing task is the stationary distribution. For episodic tasks:


9.3 Stochastic Gradient and Semi-gradient Methods

Stochastic Gradient Descent (SGD) is ideal for online RL. We adjust weights to reduce the error on the current example:

SGD Update Rule

where is the gradient vector of partial derivatives with respect to .

Gradient Monte Carlo

Since is an unbiased estimate of , MC using SGD converges to a local optimum.

# Gradient Monte Carlo Algorithm
Initialize w arbitrarily
Loop for each episode:
    Generate episode S_0, A_0, R_1, ..., S_T using pi
    Loop for each step t = 0, ..., T-1:
        w <- w + alpha * [G_t - v_hat(S_t, w)] * grad_v_hat(S_t, w)

Semi-Gradient Methods

When we use Bootstrapping (TD), the target depends on the weights , meaning the update is not a true gradient. We call these Semi-Gradient Methods.

Semi-gradient TD(0) Update

# Semi-gradient TD(0) Algorithm
Initialize w arbitrarily
Loop for each episode:
    Initialize S
    Loop for each step of episode:
        Choose A ~ pi(.|S)
        Take action A, observe R, S'
        w <- w + alpha * [R + gamma*v_hat(S', w) - v_hat(S, w)] * grad_v_hat(S, w)
        S <- S'
    Until S is terminal

Warning

Semi-gradient methods do not converge as robustly as gradient methods but often learn faster and enable online learning.


9.4 Linear Methods

In Linear Function Approximation, the estimate is the inner product of weights and a feature vector : Here, the gradient is simply the feature vector: .

The TD Fixed Point

Linear semi-gradient TD(0) converges to the TD fixed point: Where:

At this point, the error is bounded: .


9.5 Feature Construction

The choice of features determines how the agent generalizes.

Polynomials and Fourier Basis

  • Polynomials: Features are combinations of state dimensions (e.g., ). They have difficulty with high dimensionality.
  • Fourier Basis: Uses cosine functions of different frequencies: . Often performs better than polynomials in RL.

Coarse Coding

States are represented by overlapping binary features (e.g., circles in a 2D space).

  • Narrow features: Fine discrimination, slow generalization.
  • Broad features: Broad generalization, coarse initial approximation.

Tile Coding

A computationally efficient form of coarse coding using shifted grids (tilings).

  • Each state falls into exactly one tile per tiling.
  • Total number of active features = number of tilings.
  • Hashing can be used to reduce memory requirements.

Tile Coding Illustration

If you have 8 tilings shifted asymmetrically, a single point in state space activates 1 feature in each tiling. Generalization occurs to any state that shares one or more tiles.

Radial Basis Functions (RBFs)

Continuous version of coarse coding. Features have a Gaussian response:


9.7 Neural Network Function Approximation

Neural Network Function Approximation uses multi-layer ANNs to learn non-linear approximations.

  • Hidden layers: Automatically create features.
  • Backpropagation: Computes gradients of the loss with respect to weights.
  • Deep RL: Successes in Go and Atari rely on deep convolutional networks that extract hierarchical spatial features.

9.8 Least-Squares TD (LSTD)

Instead of iterative updates, LSTD estimates and directly.

  • Complexity: per step using the Sherman-Morrison formula for recursive matrix inversion.
  • Data Efficiency: Most efficient linear TD method; no step-size needed (though it needs a regularization parameter ).

9.11 Interest and Emphasis

We can focus approximation on specific “interesting” states using:

  1. Interest : How much we care about the error at time .
  2. Emphasis : A multiplier for the update that maintains stability.

Summary

  • Function Approximation is necessary for large state spaces.
  • SGD provides the theoretical bedrock for updates.
  • Linear Methods with Tile Coding or Fourier Basis are robust and efficient.
  • Deep Learning allows for complex, non-linear feature discovery.
  • There is a trade-off between Local Optimum convergence (Gradient MC) and the faster, biased convergence of Semi-Gradient Methods.