Quant Memo
Advanced

Function Approximation in Reinforcement Learning

When a reinforcement learning problem has too many states to store a table of values for each one, function approximation replaces the table with a parametric model that generalizes across similar states, at the cost of introducing new ways for learning to go wrong.

Prerequisites: The Multilayer Perceptron, The Bias-Variance Decomposition

Basic reinforcement learning keeps a table: for every possible state, store a number saying how good that state is. That works fine for a board game with a few thousand positions, but a trading environment's state might include current price, recent returns, order-book depth, inventory, and time of day — a combination with effectively infinite distinct values. You cannot build a table with a row for every possible price; you'd never visit the same exact state twice, and a table with no entry for the state you're currently in is useless.

Function approximation replaces the table with a model — often a neural network — that takes a state as input and outputs its estimated value, the same way a real estate appraiser doesn't keep a lookup table of every house ever sold; they learn a function of features (square footage, location, condition) that generalizes to a house they've never specifically seen before, because it resembles houses they have. The appraiser doesn't need to have valued this exact house previously; they need to have learned a pattern that transfers.

The mechanics, one symbol at a time

Instead of a table entry V(s)V(s) for each state ss, function approximation learns a parametric function V^(s;w)\hat{V}(s; w) — for instance, a neural network with weights ww that takes a state's features and outputs an estimated value. Training adjusts ww to make V^(s;w)\hat{V}(s;w) match a target value yy (typically built from an observed reward plus a bootstrap estimate of the next state's value) using gradient descent on the squared error:

ww+α(yV^(s;w))wV^(s;w)w \leftarrow w + \alpha \big(y - \hat{V}(s; w)\big) \nabla_w \hat{V}(s; w)

In words: compute the gap between the target yy (what the value "should" be, based on new experience) and the model's current estimate V^(s;w)\hat{V}(s;w), and nudge the weights ww in the direction that would have reduced that gap, scaled by learning rate α\alpha — the same weight-update rule as any neural network trained by gradient descent. The crucial difference from ordinary supervised learning is where yy comes from: it's often built partly from the model's own current estimate of a later state's value (this is called bootstrapping), which means the target the network is chasing keeps shifting as the network itself changes — a moving target the network is partly responsible for creating.

Worked example 1: one value update by hand

A simple linear function approximator, V^(s;w)=w1momentum+w2inventory\hat{V}(s;w) = w_1 \cdot \text{momentum} + w_2 \cdot \text{inventory}, currently w=(0.4,0.2)w = (0.4, -0.2). Current state: momentum =1.5=1.5, inventory =2.0=2.0.

V^(s;w)=0.4(1.5)+(0.2)(2.0)=0.60.4=0.2\hat{V}(s;w) = 0.4(1.5) + (-0.2)(2.0) = 0.6 - 0.4 = 0.2

Suppose the observed reward this step was 0.50.5 and the estimated value of the next state is 0.60.6, with discount factor γ=0.9\gamma=0.9: target y=0.5+0.9(0.6)=0.5+0.54=1.04y = 0.5 + 0.9(0.6) = 0.5+0.54=1.04.

Error: yV^(s;w)=1.040.2=0.84y - \hat{V}(s;w) = 1.04 - 0.2 = 0.84. With learning rate α=0.1\alpha=0.1 and gradient wV^=(momentum,inventory)=(1.5,2.0)\nabla_w \hat{V} = (\text{momentum}, \text{inventory}) = (1.5, 2.0) for this linear model:

w10.4+0.1(0.84)(1.5)=0.4+0.126=0.526,w20.2+0.1(0.84)(2.0)=0.2+0.168=0.032w_1 \leftarrow 0.4 + 0.1(0.84)(1.5) = 0.4 + 0.126 = 0.526, \quad w_2 \leftarrow -0.2 + 0.1(0.84)(2.0) = -0.2+0.168=-0.032

Both weights shift toward valuing momentum and inventory more highly this step, because the target suggested the current state is worth more than the model thought. The key point: this exact same weight update also silently changes the value estimate for every other state with similar momentum and inventory — that's generalization, and it's both the entire benefit and the entire risk of function approximation.

Worked example 2: generalization spilling over, for better and worse

Continue from above: the updated weights (0.526,0.032)(0.526, -0.032) now change the estimated value of a different state never directly visited this step, say momentum =1.4=1.4, inventory =1.8=1.8: V^=0.526(1.4)0.032(1.8)=0.679\hat{V} = 0.526(1.4) - 0.032(1.8) = 0.679, versus 0.200.20 before the update — more than tripled, purely as a side effect of an update triggered by a different state.

That's useful when nearby states genuinely have similar values — the agent doesn't need to visit every state individually to learn a good policy. But it's dangerous when the approximator's assumed shape doesn't match reality: if the true value function has a sharp discontinuity around inventory level 2.0 (say, a risk-limit breach), a linear model cannot represent that break and will systematically misvalue states on one side of it, no matter how much data it sees.

Gradient descent
parameter →
position -0.623loss -0.141gradient -0.930converging

The explorer above shows crawling, converging, and overshooting on a fixed loss surface. Function approximation in RL is harder than that picture: because the target yy is built partly from the model's own shifting estimates, the "surface" itself can move as training proceeds, which is part of why RL training is often less stable than ordinary supervised training on a fixed dataset.

table: one entry per visited state function: covers unvisited states too
A table only knows what it has been told directly; a function approximator assigns a value to every state, including ones the agent has never actually visited, by generalizing from similar ones.

What this means in practice

Function approximation is what makes reinforcement learning applicable to realistic financial environments — execution algorithms, market making, portfolio allocation — where state spaces are continuous or effectively infinite. It's also the source of most of the field's notorious instability: bootstrapping (target built from the model's own output), off-policy learning (training on data from a different policy than the one being evaluated), and function approximation together are sometimes called the "deadly triad" — each is manageable alone, but the combination can make value estimates diverge rather than converge, even in simple toy problems. Techniques like target networks (freezing a slowly-updated copy of the model to compute targets, rather than chasing the live model's shifting output) and experience replay exist to blunt this instability.

Function approximation replaces a lookup table of state values with a parametric model that generalizes across similar states, making RL usable on realistic, continuous state spaces — but because the training target is itself built partly from the model's own shifting estimates, this generalization can amplify errors instead of just smoothing them out.

The classic confusion: assuming a neural network's success in supervised learning transfers automatically to being a stable value-function approximator in RL. In supervised learning the target labels are fixed; in RL, bootstrapped targets move as the network itself updates, and combined with off-policy data this can cause value estimates to diverge rather than settle — RL training needs its own stabilizing tricks (target networks, careful learning rates, replay buffers) that a standard supervised training loop simply doesn't need.

Related concepts

Practice in interviews

Further reading

  • Sutton & Barto, Reinforcement Learning: An Introduction, ch. 9-11
  • Mnih et al., Human-Level Control through Deep Reinforcement Learning
ShareTwitterLinkedIn