Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Parametric Value Functions

The dynamic programming chapters solved Bellman equations by storing one number per state, or per grid state. That works for the reservoir, the antibiotic regimen and a river of eight reaches, and it fails soon after. This part of the book replaces the table by a function with a fixed number of parameters, and it builds up to the algorithms used in practice: fitted Q-iteration with trees or neural networks, its online form DQN, and its continuous-action form NFQCA. This chapter starts with why the replacement is needed and what it must provide. It then asks the first question that the replacement raises. A function with finitely many parameters cannot satisfy the Bellman equation at every state, so which equations should determine its parameters? Numerical analysis answers this question for operator equations in general with the method of weighted residuals, a template of five steps. We present the template directly on the Bellman equation. One problem, a fishery near a tipping point, motivates it and then follows it through every step, in boxes that the method does not depend on.

Limits of Tabular Dynamic Programming

The tables of the previous chapters cannot simply be made larger, for three reasons, each already visible in an example we have solved.

The first is that the number of states grows exponentially with the number of state variables. The tamarisk river of Example: Controlling an Invasive Plant in a River Network has one site per reach and three conditions per site, so a river of DD reaches has 3D3^D states. Value iteration needed about 150 sweeps whatever the size of the river, but each sweep touches every state, and a dense transition table for a seven-reach river without the treatment budget would take 84 GB. The rivers that land managers face have hundreds of reaches. Continuous states hit the same wall through the grid. The reservoir of the finite-horizon chapter stored its value on 181 storage levels; five reservoirs in one valley, managed jointly on the same grid, would need 1815≈2×1011181^5 \approx 2 \times 10^{11} grid states, each with its own one-step optimization at every stage. A grid with NN nodes per axis in DD dimensions has NDN^D nodes. This is the curse of dimensionality that Bellman named, and it belongs to the representation rather than to the problem: the value function of a large system often has structure, such as smoothness or a dependence on a few aggregate quantities, that a grid cannot exploit and a more flexible representation can.

The second is that successors fall between the stored states. Even in one dimension, the finite-horizon chapter had to decide which value to use for a successor that lands between two grid states. Its answer, a family of cardinal functions, turned the table into a function defined everywhere, and its analysis of how the reconstruction error propagates through the recursion was a first instance of what this part of the book studies in general.

The third is that learning from data visits only some states. In the chapters ahead the model is replaced by a simulator or by recorded transitions (s,a,r,s′)(s, a, r, s'). A batch of transitions covers a vanishing fraction of a large state space, and each Bellman target r+γv(s′)r + \gamma v(s') needs a value at a successor s′s' that may never have been visited. A table has nothing to say there. A function fitted to the visited states does: it generalizes from them, and how well it generalizes decides how well the method works.

The replacement for the table is therefore a function v(s;θ)v(s; \theta) with a parameter vector θ\theta of fixed size. It must be cheap to evaluate at any state. It must be possible to fit it to a finite set of pairs (state, target value), which is a supervised learning problem. And it must extrapolate sensibly between and beyond those states. Grid interpolation is cheap and easy to fit, but it extrapolates only to the cells of its grid and its size grows as NDN^D. A polynomial or another fixed basis is linear in θ\theta, which gives closed-form fits and a complete theory, but its features must be chosen in advance. Tree ensembles and neural networks choose their features from the data. The fitted Q-iteration methods used in practice, from the tree-based FQI of Ernst et al. (2005) to NFQ Riedmiller (2005) and NFQCA Hafner & Riedmiller (2011), use these.

Replacing vv by v(⋅;θ)v(\cdot;\theta) raises two questions. The Bellman equation v=Lvv = \Bellman v imposes one condition per state, infinitely many when the state space is continuous, while θ\theta has finitely many components. Which finite set of conditions should determine θ\theta? This chapter answers it with the weighted-residual template of numerical analysis Chakraverty et al. (2019)Atkinson & Potra (1987), using linear bases, for which the conditions can be written out and solved in closed form. Once the conditions are fixed, which algorithm finds θ\theta, and does the contraction that made value iteration converge survive the approximation? The next chapter answers the second question, and the chapter on fitted value methods extends the iteration to any regressor, neural networks included, and to sampled data.

A Motivating Example: Harvesting a Fishery Near a Tipping Point

This example shows what goes wrong when a value function on a continuum is stored in a few numbers, and how the choice of representation changes the decisions that the stored function produces. A regulator sets the annual quota for a fish stock. Before the season, a survey gives the stock ss, measured as a fraction of the carrying capacity of the habitat. The regulator chooses the escapement a∈[0,s]a \in [0, s], the part of the stock left in the water to spawn. The escapement is the action, which is why we write it aa. The rest, s−as - a, is caught and sold at a unit price. Over the following year the escaped stock grows to

s′=z f(a),f(a)=aexp⁡ ⁣(r(1−aK)a−CK),s' = z\, f(a), \qquad f(a) = a \exp\!\Big(r \Big(1 - \frac{a}{K}\Big) \frac{a - C}{K}\Big),

where zz is a log-normal shock with mean one that stands for the environment: how many young fish survive varies a lot from year to year. This growth law, which Boettiger et al. (2015) use to study tipping points in fisheries, has an Allee effect. Below the threshold CC, the fish are too sparse to replace themselves, and the stock shrinks even when nobody fishes it (panel (a) of Figure 1). We take r=2r = 2, K=1K = 1, C=0.3C = 0.3, a shock whose logarithm has standard deviation 0.15, and γ=0.95\gamma = 0.95. These are teaching values, not the assessment of a real stock. The Bellman optimality equation is

v⋆(s)=max⁡0≤a≤s{s−a+γ Ez[v⋆(zf(a))]},s∈[0,1.6].v^\star(s) = \max_{0 \le a \le s} \Big\{ s - a + \gamma\, \mathbb{E}_z\big[ v^\star\big(z f(a)\big) \big] \Big\}, \qquad s \in [0, 1.6].

Three things separate it from the finite MDPs of the earlier chapters. The state is a real number, so v⋆v^\star is a function on an interval and no table holds it. The action is a real number too, so the maximization runs over an interval. And the expectation is an integral over zz, which we compute with 21-point Gauss–Hermite quadrature. The successor stock zf(a)z f(a) almost never falls on a point where a value was stored, which is the difficulty that interpolation handled in the finite-horizon chapter.

This problem has one state variable, so we can still afford a reference solution: value iteration on 4,001 grid points, with linear interpolation between them and escapements restricted to the grid. Because the harvest value s−as - a is linear in aa, the maximization over a≤sa \le s reduces to a running maximum along the grid, and one backup costs a single pass. Halving the number of grid points changes the solution by less than 0.001.

The fishery. (a) Expected stock next year against the escapement, with the
band that holds 80% of the years. Below the tipping point C the curve lies
under the diagonal: the stock shrinks even without fishing. (b) The optimal
value v^\star, computed on a fine grid. (c) The optimal escapement. The
shading marks the three regions of the policy.

Figure 1:The fishery. (a) Expected stock next year against the escapement, with the band that holds 80% of the years. Below the tipping point CC the curve lies under the diagonal: the stock shrinks even without fishing. (b) The optimal value v⋆v^\star, computed on a fine grid. (c) The optimal escapement. The shading marks the three regions of the policy.

The optimal policy has three regions. Above S⋆=0.712S^\star = 0.712, the regulator harvests down to the constant escapement S⋆S^\star, the policy that Reed (1979) proved optimal for this class of models. Reed’s optimality condition, γf′(S⋆)=1\gamma f'(S^\star) = 1, gives S⋆=0.710S^\star = 0.710. The small gap comes from bad years, which leave the stock below S⋆S^\star, where a fish left to spawn is worth more than its price. Between s^=0.23\hat s = 0.23 and S⋆S^\star, the fishery is closed and the stock rebuilds. Below s^\hat s, the policy fishes the stock out: a stock this far below the tipping point will most likely decline anyway, and its catch today is worth more than its small chance of recovery. Clark (1973) showed that maximizing the value of the harvest can make extinction optimal in this way. Fisheries law adds conservation limits for that reason, and this model leaves them out. For the methods of this chapter, what matters is the shape of v⋆v^\star. It is linear on [0,s^][0, \hat s], has a kink at s^\hat s, rises more than tenfold across the tipping point, and is smooth elsewhere.

Now suppose we may store only nn numbers. Two choices are natural.

Neither can satisfy the Bellman equation at every stock. Write vθ=v(⋅;θ)v_\theta = v(\cdot;\theta) for the whole function. The residual

R(s;θ)=(Lvθ)(s)−v(s;θ)R(s; \theta) = (\Bellman v_\theta)(s) - v(s; \theta)

measures by how much it fails at ss. Both terms depend on θ\theta: the operator is applied to the function vθv_\theta, and the result is evaluated at ss. Collocation picks nn points s1,…,sns_1, \ldots, s_n and asks the residual to vanish at them:

R(si;θ)=0,i=1,…,n.R(s_i; \theta) = 0, \qquad i = 1, \ldots, n.

We use the Chebyshev nodes for the polynomial and the interpolation nodes for the hat functions, and we solve the nn nonlinear equations by function iteration. Each iteration computes the Bellman backup at the nodes with the current vθv_\theta, then chooses the θ\theta that reproduces those targets at the nodes. Figure 2 shows both approximations with n=12n = 12.

Collocation with n = 12 coefficients. (a) The two approximations against
the exact value, with their collocation nodes. (b) The Bellman residual
R(s;\theta), which vanishes at the nodes. (c) The escapement chosen by the
greedy policy of each approximation, against the optimal escapement.

Figure 2:Collocation with n=12n = 12 coefficients. (a) The two approximations against the exact value, with their collocation nodes. (b) The Bellman residual R(s;θ)R(s;\theta), which vanishes at the nodes. (c) The escapement chosen by the greedy policy of each approximation, against the optimal escapement.

The residuals in panel (b) vanish at the nodes, as collocation requires, and both peak at about 0.2 between them. The approximations themselves differ much more. A polynomial of degree 11 cannot bend sharply enough to follow the cliff, so it oscillates around it. Near the left end, its value at an empty stock is 1.6 instead of zero. The greedy policy inherits these oscillations (panel (c)). It fishes out every stock below 0.31, past the tipping point, where the optimal policy closes the fishery and lets the stock rebuild. A stock at 0.31 is worth 1.49 under the optimal policy and 0.31, its immediate catch, under this one. Between 0.53 and 0.67 the policy also harvests stocks that should be left to grow. The piecewise-linear approximation is coarse between its nodes, but it follows the cliff, and its greedy policy loses at most 0.064 anywhere. That worst case is near s=0.21s = 0.21, where the policy closes the fishery a little too early.

The example leaves three questions open, and the rest of the chapter takes them in order. Collocation asked for a zero residual at twelve points; where else could the residual be made small, and what does that choice decide? The twelve coefficients were found by repeating a backup and a fit; when does that repetition converge, and what else could find them? And the polynomial had the smaller residual of the two approximations and a policy loss eighteen times larger; which quantity should judge an approximation?

From One Equation per State to nn Equations

The Bellman optimality equation v=Lvv = \Bellman v holds at every state. For the fishery, that is one equation for every stock in [0,1.6][0, 1.6], and the unknown is the whole function v⋆v^\star. Replacing vv by v(⋅;θ)v(\cdot;\theta) leaves nn unknowns, so only nn conditions can be imposed, and the choice of those conditions is the method.

The earlier chapters made the same move for trajectories. A continuous-time trajectory cannot be chosen one instant at a time, so direct collocation represented the state and the control by polynomial pieces with finitely many coefficients, enforced the differential equation at selected points of each interval, and replaced the integrals of the cost by quadrature. The value function is treated in the same way: a basis for the unknown function, finitely many conditions in place of the equation, and quadrature for the expectations. The method of weighted residuals Chakraverty et al. (2019)Atkinson & Potra (1987) organizes these choices into five steps. Each step below is stated for a general Bellman equation and names the alternatives at that fork. The fishery took one path through the steps, and a box after each step picks the example up where it went through that step; the steps themselves need nothing from the boxes.

Step 1: Choose a Parametric Value Function

The unknown value function is replaced by a family v(s;θ)v(s;\theta) indexed by a parameter vector θ∈Rn\theta \in \mathbb{R}^n. Nothing in the five steps requires θ\theta to enter linearly: a neural network v(s;θ)v(s;\theta) with nn weights is such a family, and every condition below applies to it. Linearity matters for solving. When the family is a linear combination of nn basis functions,

v(s;θ)=∑j=1nθjϕj(s),v(s;\theta) = \sum_{j=1}^n \theta_j \phi_j(s),

each condition reduces to linear algebra and can be written out, so this chapter uses linear families to make the steps explicit. The chapter on fitted value methods shows that the solver that carries over to neural networks needs nothing from the representation beyond the ability to fit it to data.

Two kinds of basis are in common use. A global basis, such as Chebyshev polynomials or Fourier modes, gives every coefficient influence over the whole state space, and its error decreases exponentially in nn when the function is smooth. A local basis, such as the hat functions of piecewise-linear interpolation, splines with small support, or radial basis functions, lets each coefficient act near one node, and its error decreases at a rate set by the node spacing, whatever the smoothness of the function. Tile coding, the linear representation that Sutton (1996) and much of early reinforcement learning relied on, is a local basis of this kind: several overlapping grids partition the state space, each cell is a binary feature, and v(s;θ)v(s;\theta) is the sum of the weights of the cells that contain ss. Linear representations were the norm in reinforcement learning until neural networks took over in the 2010s, and they remain the setting where the theory is complete. To match a deep network, though, a linear model may need a very large number of features.

Step 2: Define the Bellman Residual

Substituting the approximation into the Bellman equation leaves a function of the state,

R(s;θ)=(Lvθ)(s)−v(s;θ),R(s;\theta) = (\Bellman v_\theta)(s) - v(s;\theta),

the Bellman residual, where vθv_\theta abbreviates v(⋅;θ)v(\cdot;\theta). It measures by how much the approximation fails the equation at ss, and it is the zero function if and only if vθv_\theta is a fixed point of L\Bellman. The Newton–Kantorovich section of the infinite-horizon chapter wrote the Bellman equation as the root-finding problem B(v)=0\mathrm{B}(v) = 0 with B(v)=Lv−v\mathrm{B}(v) = \Bellman v - v. The residual is that operator applied to vθv_\theta and then evaluated at the state ss, R(s;θ)=(B(vθ))(s)R(s;\theta) = \big(\mathrm{B}(v_\theta)\big)(s). What changes is the argument: B\mathrm{B} takes any function, while RR takes only the nn coefficients that describe vθv_\theta. Read Lvθ\Bellman v_\theta in the same way, as the operator applied to the function vθv_\theta, which returns a new function; it is not a product of a matrix and a vector. One evaluation of it costs one evaluation of the Bellman operator, a maximization over the actions and an expectation over the successor, with the current coefficients inside both. The coefficients enter RR twice, directly through v(s;θ)v(s;\theta) and again through the expectation inside the maximum, and the maximum makes RR nonlinear in θ\theta even though vθv_\theta is linear in it.

Step 3: Impose nn Conditions on the Residual

The residual is a function of the state, and θ\theta has only nn components. The equation R(⋅;θ)=0R(\cdot;\theta) = 0 asks for one condition at every state, so it has to be replaced by nn scalar conditions. To choose them, we first ask how one checks that an object is zero, starting with a vector.

Take r=(r1,r2,r3)∈R3\mathbf{r} = (r_1, r_2, r_3) \in \mathbb{R}^3. The inner product with the coordinate vector ei\mathbf{e}_i reads off one coordinate, ⟨r,ei⟩=ri\langle \mathbf{r}, \mathbf{e}_i \rangle = r_i, so the three tests against e1,e2,e3\mathbf{e}_1, \mathbf{e}_2, \mathbf{e}_3 all return zero only when r=0\mathbf{r} = 0. Other test vectors work as well, as long as together they reach every direction. In general, r\mathbf{r} is zero if and only if ⟨r,y⟩=0\langle \mathbf{r}, \mathbf{y} \rangle = 0 for every y\mathbf{y}, and the single test y=r\mathbf{y} = \mathbf{r} settles the question, because it returns ∥r∥2\|\mathbf{r}\|^2. Now keep only the two tests e1\mathbf{e}_1 and e2\mathbf{e}_2. The vector r=(0,0,5)\mathbf{r} = (0, 0, 5) passes both of them and is not zero. Two tests check r\mathbf{r} in two directions, those of the plane spanned by e1\mathbf{e}_1 and e2\mathbf{e}_2, and they say nothing about the component of r\mathbf{r} orthogonal to that plane. Passing both tests means that the component of r\mathbf{r} in the plane is zero.

Each test is therefore a direction. For a unit vector p\mathbf{p}, the inner product ⟨r,p⟩=∥r∥cos⁡∠(r,p)\langle \mathbf{r}, \mathbf{p} \rangle = \|\mathbf{r}\| \cos\angle(\mathbf{r}, \mathbf{p}) is the signed length of the shadow that r\mathbf{r} casts on the line of p\mathbf{p}: it is large when r\mathbf{r} is aligned with p\mathbf{p} and zero when the two are perpendicular. A set of tests passes if and only if r\mathbf{r} is perpendicular to every test direction, which is the same as being perpendicular to the subspace that they span. The tests need not be orthogonal to each other or of unit length; only that subspace matters. The first tab of Figure 3 draws this picture in R3\mathbb{R}^3 for one, two or three test directions, including two oblique ones.

A function of the state behaves like a vector with one coordinate for each state, and the sum in the inner product becomes an integral. With a weight w>0w > 0 over the states, the weighted inner product of two functions is

⟨R,p⟩w=∫SR(s) p(s) w(s) ds.\langle R, p \rangle_w = \int_{\mathcal{S}} R(s)\, p(s)\, w(s)\, ds .

The argument for vectors carries over: RR is the zero function if and only if ⟨R,p⟩w=0\langle R, p \rangle_w = 0 for every test function pp, and the test p=Rp = R returns ∥R∥w2\|R\|_w^2. Each test function is a direction in the space of functions, and ⟨R,p⟩w\langle R, p \rangle_w measures how far RR reaches along it. The coordinate vectors have a counterpart as well. A point mass at a state ss reads off the value R(s)R(s), as ei\mathbf{e}_i reads off rir_i. A function has infinitely many directions, and no finite set of tests can check them all. Testing against nn chosen test functions p1,…,pnp_1, \ldots, p_n gives exactly the nn equations that this step needs,

⟨R(⋅;θ),pi⟩w=0,i=1,…,n,\langle R(\cdot;\theta), p_i \rangle_w = 0, \qquad i = 1, \ldots, n,

and the price is the one paid with two tests in R3\mathbb{R}^3. The equations make the residual vanish in the nn directions of the tests and leave it free in every other direction. The residual of the solution is in general not the zero function. It is a function in which the nn tests detect nothing.

The second tab of Figure 3 runs these tests on functions. There, each bar is the inner product of a residual with one test function, and selecting a bar shades the product R piR\,p_i, whose area is the value of that bar. The button that hides the residual from the tests subtracts a function that returns the same test values as the residual: the orthogonal projection onto the span of the tests for hat functions and polynomials, and the piecewise-linear interpolant through the nodes for point masses. After it is pressed, every bar is zero and the residual is still visibly nonzero, like (0,0,5)(0, 0, 5) against e1\mathbf{e}_1 and e2\mathbf{e}_2. With polynomial tests, hide the residual and predict which bars change when nn increases by one.

Figure 3:Testing a residual with inner products. First tab: a vector r\mathbf{r} in R3\mathbb{R}^3 and one, two or three test directions; each bar is the length of the shadow of r\mathbf{r} on one direction, and the tests detect only the component of r\mathbf{r} in the span of their directions. Second tab: a residual RR, taken from the presets or drawn with the pointer, is tested against nn point masses, hat functions or polynomials. Each bar is one test, and the shaded area under the product R piR\,p_i equals the selected bar. Third tab: one policy-evaluation equation is solved by collocation, Galerkin and least squares with the same basis. Each solution makes its own nn tests return zero, and the tests of the other two methods do not.

Since the nn equations control the residual only in the directions of the tests, the approximation that they produce depends on the choice of test functions, and a method is defined by that choice. Three choices cover almost every method in use.

MethodTest functions pip_iConditions (nn equations)
CollocationPoint masses at chosen states s1,…,sns_1, \ldots, s_nR(si;θ)=0R(s_i; \theta) = 0
GalerkinThe basis functions ϕi\phi_i⟨R(⋅;θ),ϕi⟩w=0\langle R(\cdot;\theta), \phi_i \rangle_w = 0
Least squaresThe derivatives ∂R/∂θi\partial R / \partial \theta_i of the residual⟨R(⋅;θ),∂R/∂θi⟩w=0\langle R(\cdot;\theta), \partial R/\partial\theta_i \rangle_w = 0

Collocation: a Zero Residual at Chosen States

Collocation is the method of the continuous-time collocation chapter, applied to a different equation. There, each piece of a trajectory was stored by its values at nodes, in a Lagrange basis whose cardinal functions equal one at their own node and zero at the others, and the differential equation was imposed only at the collocation points: at each one, the slope of the interpolating polynomial had to match the slope f\mathbf f prescribed by the dynamics. Between the points, nothing was imposed. Here the unknown is the value function instead of a trajectory, and the equation is the Bellman equation instead of x˙=f\dot{\mathbf x} = \mathbf f. Collocation picks nn states s1,…,sns_1, \ldots, s_n and asks the residual to vanish there,

R(si;θ)=0,i=1,…,n.R(s_i;\theta) = 0, \qquad i = 1, \ldots, n .

With a nodal basis, Lagrange polynomials through the collocation points or the hat functions of piecewise-linear interpolation, the coefficient θi\theta_i is the value at sis_i, and the condition reads θi=(Lvθ)(si)\theta_i = (\Bellman v_\theta)(s_i). The value stored at each node must equal the Bellman backup computed from the interpolated function, as the slope stored at each node had to equal the slope given by the dynamics. The interpolated backward recursion (16) of the finite-horizon chapter imposed the same condition, one stage at a time.

In the language of test functions, a point mass at sis_i picks out the value R(si)R(s_i), so collocation is (9) with point masses as test functions, as the dual-pairing formulation of Legrand & Junca (2025) makes precise. No integral over states appears, so each condition costs one evaluation of the Bellman operator. The conditions make the residual vanish at the nodes and leave it unconstrained between them, as the residual of the differential equation is unconstrained between the collocation points of a trajectory. The name of the method describes this. To collocate, from the Latin collocare, is to place together, and in the definition of Frazer et al. (1937) that the collocation chapter recalled, it is “the act of assigning the error at given points or stations”. The approximation and the exact equation are placed together at a finite set of points: times for a trajectory, states for a value function.

Where to collocate is a choice of its own. For a polynomial of degree n−1n - 1, the standard choice is the zeros of the nn-th Chebyshev polynomial, the Chebyshev nodes, and the combination is called orthogonal collocation. The same nodes serve as the nodes of Gauss–Chebyshev quadrature, the interpolation matrix Φij=ϕj(si)\Phi_{ij} = \phi_j(s_i) built on them is well conditioned, and the polynomial through them is within a small factor of the best polynomial approximation of a smooth function, so a residual that vanishes at them stays small between them. Equally spaced nodes have none of these properties once the degree is high. For a nodal basis the collocation points are the nodes of the basis itself, where one cardinal function equals one and the others vanish, so that the interpolation matrix is the identity and the coefficients are the values at the nodes.

The collocation conditions can be rewritten as a fixed-point equation for the function vθv_\theta, and the derivation takes three steps. Write ϕ(s)=(ϕ1(s),…,ϕn(s))⊤\boldsymbol\phi(s) = (\phi_1(s), \ldots, \phi_n(s))^\top for the vector of basis functions at ss, so that v(s;θ)=ϕ(s)⊤θv(s;\theta) = \boldsymbol\phi(s)^\top\theta, and for any function gg of the state write g(s)=(g(s1),…,g(sn))⊤g(\mathbf{s}) = (g(s_1), \ldots, g(s_n))^\top for the vector of its values at the collocation points. The rows of the interpolation matrix Φ\boldsymbol\Phi are the vectors ϕ(si)⊤\boldsymbol\phi(s_i)^\top, so the values of the approximation at the nodes are vθ(s)=Φθv_\theta(\mathbf{s}) = \boldsymbol\Phi\theta. Assume that Φ\boldsymbol\Phi is invertible, which holds for a polynomial basis with distinct nodes and for hat functions collocated at their own nodes.

The first step writes the nn conditions as one vector equation. The condition at sis_i is (Lvθ)(si)=vθ(si)=ϕ(si)⊤θ(\Bellman v_\theta)(s_i) = v_\theta(s_i) = \boldsymbol\phi(s_i)^\top\theta, and stacking the nn of them gives

Φ θ=(Lvθ)(s),that is,θ=Φ−1(Lvθ)(s).\boldsymbol\Phi\,\theta = (\Bellman v_\theta)(\mathbf{s}), \qquad\text{that is,}\qquad \theta = \boldsymbol\Phi^{-1}(\Bellman v_\theta)(\mathbf{s}) .

This is already a fixed-point equation, in the coefficients: θ\theta appears on the right through vθv_\theta.

The second step gives a name to the map on the right. The interpolant of a function gg through the nodes is the element of the span that has the same values as gg at the nodes. Its coefficients cc solve Φc=g(s)\boldsymbol\Phi c = g(\mathbf{s}), so

(Pg)(s)=ϕ(s)⊤Φ−1g(s).(\Proj g)(s) = \boldsymbol\phi(s)^\top \boldsymbol\Phi^{-1} g(\mathbf{s}) .

Three properties of this map are used below. It is linear in gg, because gg enters only through the vector g(s)g(\mathbf{s}). It reproduces gg at the nodes, since (Pg)(s)=ΦΦ−1g(s)=g(s)(\Proj g)(\mathbf{s}) = \boldsymbol\Phi\boldsymbol\Phi^{-1}g(\mathbf{s}) = g(\mathbf{s}). And it leaves the elements of the span unchanged: if g(s)=ϕ(s)⊤cg(s) = \boldsymbol\phi(s)^\top c, then g(s)=Φcg(\mathbf{s}) = \boldsymbol\Phi c and Pg=g\Proj g = g. Applying P\Proj twice therefore gives the same result as applying it once, P(Pg)=Pg\Proj(\Proj g) = \Proj g. A linear map with this property is a projection: it sends every function into the span and leaves the span fixed.

The third step multiplies (11) on the left by ϕ(s)⊤\boldsymbol\phi(s)^\top. For every state ss,

vθ(s)=ϕ(s)⊤θ=ϕ(s)⊤Φ−1(Lvθ)(s)=(P Lvθ)(s),v_\theta(s) = \boldsymbol\phi(s)^\top\theta = \boldsymbol\phi(s)^\top\boldsymbol\Phi^{-1}(\Bellman v_\theta)(\mathbf{s}) = (\Proj\,\Bellman v_\theta)(s),

where the last equality is (12) with g=Lvθg = \Bellman v_\theta. As an equation between functions,

vθ=P Lvθ.v_\theta = \Proj\, \Bellman v_\theta .

The steps also run backward. If vθ=P Lvθv_\theta = \Proj\,\Bellman v_\theta, then evaluating both sides at the nodes and using that Pg\Proj g reproduces gg there gives vθ(si)=(Lvθ)(si)v_\theta(s_i) = (\Bellman v_\theta)(s_i) for every ii, which are the collocation conditions. The collocation solutions are therefore exactly the fixed points of PL\Proj\Bellman: the Bellman operator followed by a projection, which is the form that Step 4 exploits.

The derivation used two assumptions. The family is linear in θ\theta, so that its values at the nodes are Φθ\boldsymbol\Phi\theta and the interpolant of any function is again a member of the family. And Φ\boldsymbol\Phi is invertible. Nothing was assumed about L\Bellman beyond the fact that it returns a function that can be evaluated at the nodes. The operator may contain a maximum and be nonlinear in vv; the projection P\Proj is linear whatever L\Bellman is, and the nonlinearity stays inside L\Bellman. With a nodal basis, Φ\boldsymbol\Phi is the identity and (12) becomes (Pg)(s)=∑j=1nϕj(s) g(sj)(\Proj g)(s) = \sum_{j=1}^n \phi_j(s)\, g(s_j), a combination of the values at the nodes weighted by the cardinal functions. The next chapter uses this form to decide when PL\Proj\Bellman is a contraction.

Read the right-hand side as a composition of maps on functions, not as a product of matrices. Lvθ\Bellman v_\theta is the operator applied to the function vθv_\theta, which gives a new function, and P Lvθ\Proj\,\Bellman v_\theta is that function passed through the interpolation procedure, which gives an element of the span. With parentheses, P(L(vθ))\Proj\big(\Bellman(v_\theta)\big). In code, P\Proj is a call such as an interpolation routine: it receives the values of Lvθ\Bellman v_\theta at the nodes and returns the coefficients of the interpolant. The composed map PL\Proj\Bellman is a new operator, and (14) is a new Bellman-type equation whose solution is the approximation. Texts on approximate dynamic programming, following Bertsekas & Tsitsiklis (1996), often write the projection Π\Pi; it is not a policy.

Galerkin: a Residual Orthogonal to the Basis

Galerkin takes the basis functions themselves as test functions, ⟨R(⋅;θ),ϕi⟩w=0\langle R(\cdot;\theta), \phi_i \rangle_w = 0 for i=1,…,ni = 1, \ldots, n. By linearity the residual is then orthogonal to every function in the approximation space V=span{ϕ1,…,ϕn}\mathcal{V} = \text{span}\{\phi_1, \ldots, \phi_n\},

⟨R,∑i=1nciϕi⟩w=∑i=1nci⟨R,ϕi⟩w=0for every c∈Rn,\Big\langle R, \sum_{i=1}^n c_i \phi_i \Big\rangle_w = \sum_{i=1}^n c_i \langle R, \phi_i \rangle_w = 0 \quad \text{for every } c \in \mathbb{R}^n,

so that Lvθ−vθ\Bellman v_\theta - v_\theta is orthogonal to V\mathcal{V}. The vector example at the start of this step has the same structure. To approximate a vector of R3\mathbb{R}^3 by a vector in the plane spanned by e1\mathbf{e}_1 and e2\mathbf{e}_2, one keeps (v1,v2,0)(v_1, v_2, 0), and the error (0,0,v3)(0, 0, v_3) is orthogonal to the plane, so the tests e1\mathbf{e}_1 and e2\mathbf{e}_2 detect nothing in it. Keeping (v1,v2,0)(v_1, v_2, 0) is the orthogonal projection onto the plane, and the Galerkin conditions say that vθv_\theta is the orthogonal projection of Lvθ\Bellman v_\theta onto V\mathcal{V}.

The same three steps as for collocation make this precise. Collect the inner products among the basis functions in the mass matrix M\mathbf{M}, with entries Mij=⟨ϕi,ϕj⟩wM_{ij} = \langle \phi_i, \phi_j \rangle_w, and for a function gg write b(g)\mathbf{b}(g) for the vector of its inner products with the basis, bi(g)=⟨g,ϕi⟩wb_i(g) = \langle g, \phi_i \rangle_w. Assume that the basis functions are linearly independent under ww: no combination ϕ⊤c\boldsymbol\phi^\top c with c≠0c \neq 0 has zero ww-norm. Since c⊤Mc=∥ϕ⊤c∥w2c^\top \mathbf{M} c = \|\boldsymbol\phi^\top c\|_w^2, this says that M\mathbf{M} is positive definite, hence invertible.

The first step writes the conditions as one vector equation. Since vθ=∑jθjϕjv_\theta = \sum_j \theta_j \phi_j, the inner product of vθv_\theta with ϕi\phi_i is ∑jMijθj=(Mθ)i\sum_j M_{ij}\theta_j = (\mathbf{M}\theta)_i. Condition ii, ⟨Lvθ−vθ,ϕi⟩w=0\langle \Bellman v_\theta - v_\theta, \phi_i \rangle_w = 0, therefore reads bi(Lvθ)=(Mθ)ib_i(\Bellman v_\theta) = (\mathbf{M}\theta)_i, and stacking the nn conditions gives

M θ=b(Lvθ),that is,θ=M−1b(Lvθ),\mathbf{M}\,\theta = \mathbf{b}(\Bellman v_\theta), \qquad\text{that is,}\qquad \theta = \mathbf{M}^{-1}\mathbf{b}(\Bellman v_\theta),

a fixed-point equation in the coefficients, as for collocation, with M\mathbf{M} in place of Φ\boldsymbol\Phi and inner products in place of values at the nodes.

The second step identifies the map on the right. The ww-orthogonal projection of a function gg onto V\mathcal{V} is the element of V\mathcal{V} closest to gg in the norm ∥⋅∥w\|\cdot\|_w, the function ϕ⊤c\boldsymbol\phi^\top c whose coefficients minimize ∥ϕ⊤c−g∥w2\|\boldsymbol\phi^\top c - g\|_w^2. Expanding the square,

∥ϕ⊤c−g∥w2=c⊤Mc−2 c⊤b(g)+∥g∥w2,\|\boldsymbol\phi^\top c - g\|_w^2 = c^\top \mathbf{M} c - 2\, c^\top \mathbf{b}(g) + \|g\|_w^2 ,

a quadratic function of cc whose Hessian 2M2\mathbf{M} is positive definite. Its unique minimizer is the zero of the gradient 2Mc−2b(g)2\mathbf{M}c - 2\mathbf{b}(g), which is c=M−1b(g)c = \mathbf{M}^{-1}\mathbf{b}(g), so

(Pg)(s)=ϕ(s)⊤M−1b(g).(\Proj g)(s) = \boldsymbol\phi(s)^\top \mathbf{M}^{-1}\mathbf{b}(g) .

This map has the properties of the interpolation operator. It is linear in gg, because b\mathbf{b} is. It leaves the elements of V\mathcal{V} unchanged: if g=ϕ⊤cg = \boldsymbol\phi^\top c, then b(g)=Mc\mathbf{b}(g) = \mathbf{M}c and Pg=g\Proj g = g, so P(Pg)=Pg\Proj(\Proj g) = \Proj g. In place of reproducing gg at the nodes, it leaves an error that is orthogonal to every basis function, ⟨g−Pg,ϕi⟩w=bi(g)−(MM−1b(g))i=0\langle g - \Proj g, \phi_i \rangle_w = b_i(g) - (\mathbf{M}\mathbf{M}^{-1}\mathbf{b}(g))_i = 0. That is the R3\mathbb{R}^3 picture: the part of gg that the projection discards is invisible to the tests.

The third step multiplies (16) on the left by ϕ(s)⊤\boldsymbol\phi(s)^\top:

vθ(s)=ϕ(s)⊤θ=ϕ(s)⊤M−1b(Lvθ)=(P Lvθ)(s)v_\theta(s) = \boldsymbol\phi(s)^\top\theta = \boldsymbol\phi(s)^\top\mathbf{M}^{-1}\mathbf{b}(\Bellman v_\theta) = (\Proj\,\Bellman v_\theta)(s)

for every ss, which is vθ=P Lvθv_\theta = \Proj\,\Bellman v_\theta, the projected Bellman equation (14) with P\Proj now the ww-orthogonal projection onto V\mathcal{V}. Conversely, if vθ=P Lvθv_\theta = \Proj\,\Bellman v_\theta, the residual Lvθ−vθ=Lvθ−P Lvθ\Bellman v_\theta - v_\theta = \Bellman v_\theta - \Proj\,\Bellman v_\theta is orthogonal to every ϕi\phi_i by the last property, which is the set of Galerkin conditions. As for collocation, the derivation needs the family to be linear in θ\theta and M\mathbf{M} to be invertible, and it allows L\Bellman to be nonlinear. Orthogonality here is with respect to the weighted inner product ⟨⋅,⋅⟩w\langle \cdot, \cdot \rangle_w. When ww is not uniform, the same map seen in the unweighted Euclidean geometry is an oblique projection; it is orthogonal only after rescaling each state by w(s)\sqrt{w(s)}. In reinforcement learning ww is the distribution of the states in the data, and the next chapter shows that this choice decides whether the iteration converges.

The conditions are integrals over the state space, so Galerkin needs a quadrature rule for them on top of the quadrature inside L\Bellman. With an orthogonal polynomial basis and its matching weight, the inner products among basis functions are known in closed form and the systems are well conditioned. When the states are instead sampled from ww, the integrals become sample averages and the Galerkin conditions become the normal equations of a least-squares regression: vθv_\theta is the least-squares fit of the basis to the backups (Lvθ)(sm)(\Bellman v_\theta)(s_m) at the sampled states. The targets of that regression depend on its own solution, and Step 4 breaks the circularity.

One Formula for Any Fixed Tests

Collocation and Galerkin are two instances of one construction. For test functions p1,…,pnp_1, \ldots, p_n fixed in advance, form the n×nn \times n matrix A\mathbf{A} with entries Aij=⟨ϕj,pi⟩wA_{ij} = \langle \phi_j, p_i \rangle_w and the vector bp(g)\mathbf{b}_p(g) with entries ⟨g,pi⟩w\langle g, p_i \rangle_w. The conditions (9) read Aθ=bp(Lvθ)\mathbf{A}\theta = \mathbf{b}_p(\Bellman v_\theta), and when A\mathbf{A} is invertible the map (Pg)(s)=ϕ(s)⊤A−1bp(g)(\Proj g)(s) = \boldsymbol\phi(s)^\top\mathbf{A}^{-1}\mathbf{b}_p(g) is a projection onto V\mathcal{V} whose error g−Pgg - \Proj g passes all nn tests. The argument of the two previous subsections goes through unchanged and gives vθ=P Lvθv_\theta = \Proj\,\Bellman v_\theta. Collocation has point masses as tests, so A=Φ\mathbf{A} = \boldsymbol\Phi and bp(g)=g(s)\mathbf{b}_p(g) = g(\mathbf{s}). Galerkin has the basis functions as tests, so A=M\mathbf{A} = \mathbf{M} and bp=b\mathbf{b}_p = \mathbf{b}. When the tests differ from the basis, the error of P\Proj is orthogonal to the tests and not to V\mathcal{V}, and P\Proj is an oblique projection: it moves gg onto V\mathcal{V} along the directions that the tests cannot see. The interpolation operator is of this kind.

On a finite state space with mm states, these maps are matrices. Stack the rows ϕ(s)⊤\boldsymbol\phi(s)^\top for all mm states into an m×nm \times n matrix ΦS\boldsymbol\Phi_{\mathcal{S}}, let W=diag⁡(w)\mathbf{W} = \operatorname{diag}(w), so that ⟨f,g⟩w=f⊤Wg\langle f, g \rangle_w = f^\top \mathbf{W} g, and let E\mathbf{E} be the n×mn \times m matrix whose row ii selects the state sis_i, so that g(s)=Egg(\mathbf{s}) = \mathbf{E}g and Φ=EΦS\boldsymbol\Phi = \mathbf{E}\boldsymbol\Phi_{\mathcal{S}}. Put the values of the nn tests at the mm states in the columns of an m×nm \times n matrix Ψ\boldsymbol\Psi. Then A=Ψ⊤WΦS\mathbf{A} = \boldsymbol\Psi^\top\mathbf{W}\boldsymbol\Phi_{\mathcal{S}}, bp(g)=Ψ⊤Wg\mathbf{b}_p(g) = \boldsymbol\Psi^\top\mathbf{W}g, and the projection is the matrix

P=ΦS (Ψ⊤WΦS)−1 Ψ⊤W.\Proj = \boldsymbol\Phi_{\mathcal{S}}\,(\boldsymbol\Psi^\top\mathbf{W}\boldsymbol\Phi_{\mathcal{S}})^{-1}\,\boldsymbol\Psi^\top\mathbf{W} .

It is idempotent, P2=P\Proj^2 = \Proj, because (Ψ⊤WΦS)−1Ψ⊤WΦS(\boldsymbol\Psi^\top\mathbf{W}\boldsymbol\Phi_{\mathcal{S}})^{-1}\boldsymbol\Psi^\top\mathbf{W}\boldsymbol\Phi_{\mathcal{S}} is the identity. A point mass at sis_i is the test whose weighted inner product with gg returns g(si)g(s_i), so for collocation Ψ⊤W=E\boldsymbol\Psi^\top\mathbf{W} = \mathbf{E}; for Galerkin, Ψ=ΦS\boldsymbol\Psi = \boldsymbol\Phi_{\mathcal{S}}. The two projections are

Pcol=ΦS (EΦS)−1 E,Pgal=ΦS (ΦS⊤WΦS)−1 ΦS⊤W.\Proj_{\text{col}} = \boldsymbol\Phi_{\mathcal{S}}\,(\mathbf{E}\boldsymbol\Phi_{\mathcal{S}})^{-1}\,\mathbf{E}, \qquad \Proj_{\text{gal}} = \boldsymbol\Phi_{\mathcal{S}}\,(\boldsymbol\Phi_{\mathcal{S}}^\top\mathbf{W}\boldsymbol\Phi_{\mathcal{S}})^{-1}\,\boldsymbol\Phi_{\mathcal{S}}^\top\mathbf{W} .

The Galerkin matrix is the one that the next chapter uses, where ΦS\boldsymbol\Phi_{\mathcal{S}} is written Φ\boldsymbol\Phi and W\mathbf{W} is written Ξ\boldsymbol\Xi.

The code below checks the derivations on the policy-evaluation problem of Figure 3, with six hat functions and with six Legendre polynomials collocated at the Chebyshev nodes. It solves the collocation and the Galerkin conditions directly, builds the two projections from (12) and (18), and measures how far each solution is from being a fixed point of each projected operator.

Source
import sys
from pathlib import Path

import numpy as np

sys.path.insert(0, str(Path.cwd() / "code"))
from test_functions_demo import GAMMA, GRID, PROBS, QW, basis, reward, solve, successors

def backup(phi, n, theta, s):
    # (L_pi v_theta)(s) = r(s) + gamma E[v_theta(s')]
    return reward(s) + GAMMA * (phi(successors(s), n) @ theta) @ PROBS

for kind in ("hat", "legendre"):
    n = 6
    phi, nodes = basis(kind, n)
    Phi = phi(nodes, n)                       # interpolation matrix, Phi_ij = phi_j(s_i)
    F = phi(GRID, n)                          # basis on a fine grid
    M = F.T @ (QW[:, None] * F)               # mass matrix, uniform weight

    def P_col(g):                             # coefficients of the interpolant
        return np.linalg.solve(Phi, g(nodes))

    def P_gal(g):                             # coefficients of the w-orthogonal projection
        return np.linalg.solve(M, F.T @ (QW * g(GRID)))

    print(f"{kind} basis, n = {n}: sup over states of |v_theta - P L v_theta|")
    print(f"{'solution':<13}{'P = interpolation':>20}{'P = orthogonal':>17}")
    for method in ("collocation", "galerkin"):
        theta = solve(kind, n, method)
        Lv = lambda s: backup(phi, n, theta, s)
        gaps = [np.max(np.abs(F @ theta - F @ P(Lv))) for P in (P_col, P_gal)]
        print(f"{method:<13}{gaps[0]:>20.1e}{gaps[1]:>17.1e}")

    # P leaves the span fixed, and the Galerkin error is orthogonal to the basis
    c = np.random.default_rng(0).normal(size=n)
    g = lambda s: phi(s, n) @ c
    Lv = lambda s: backup(phi, n, solve(kind, n, "galerkin"), s)
    err = Lv(GRID) - F @ P_gal(Lv)
    print(f"  span fixed: {np.max(np.abs(P_col(g) - c)):.1e} (interpolation), "
          f"{np.max(np.abs(P_gal(g) - c)):.1e} (orthogonal)")
    print(f"  max |<g - P g, phi_i>_w| for the orthogonal projection: "
          f"{np.max(np.abs(F.T @ (QW * err))):.1e}\n")
hat basis, n = 6: sup over states of |v_theta - P L v_theta|
solution        P = interpolation   P = orthogonal
collocation               3.6e-15          4.5e-01
galerkin                  2.9e-01          1.1e-14
  span fixed: 0.0e+00 (interpolation), 4.4e-16 (orthogonal)
  max |<g - P g, phi_i>_w| for the orthogonal projection: 1.1e-15

legendre basis, n = 6: sup over states of |v_theta - P L v_theta|
solution        P = interpolation   P = orthogonal
collocation               3.6e-15          1.5e-01
galerkin                  1.5e-01          1.3e-13
  span fixed: 2.2e-16 (interpolation), 2.0e-15 (orthogonal)
  max |<g - P g, phi_i>_w| for the orthogonal projection: 1.2e-13

Each solution is a fixed point of its own projected operator, to rounding error, and is not a fixed point of the other one. The two methods solve the same kind of equation, vθ=P Lvθv_\theta = \Proj\,\Bellman v_\theta, with two different projections, and that is the only difference between them.

Least Squares: the Smallest Residual

The most direct choice minimizes the weighted norm of the residual,

min⁡θ∫SR(s;θ)2 w(s) ds,\min_\theta \int_{\mathcal{S}} R(s; \theta)^2\, w(s)\, ds,

whose first-order conditions are (9) with test functions pi=∂R/∂θip_i = \partial R / \partial \theta_i. For the Bellman residual this is Bellman residual minimization. Its test functions,

∂R(s;θ)∂θi=∂(Lvθ)(s)∂θi−ϕi(s),\frac{\partial R(s;\theta)}{\partial \theta_i} = \frac{\partial (\Bellman v_\theta)(s)}{\partial \theta_i} - \phi_i(s),

contain the derivative of the Bellman operator with respect to the coefficients, which Galerkin and collocation never need. Computing it means differentiating through the maximum, which Step 4 does with the envelope theorem. The solution also differs from the Galerkin solution, because the residual is made orthogonal to a different set of functions. It is not a projected Bellman equation with a projection fixed in advance: the tests ∂R/∂θi\partial R/\partial\theta_i contain the derivative of L\Bellman, so they change with the operator and, through the maximum, with θ\theta. The chapter on fitted value methods returns to the difference between fitting a backup and minimizing the residual, which separates the algorithms used in practice from this one.

That difference is often blurred. DQN and the other fitted value methods are frequently described as minimizing the Bellman error, and they do not: they fit vθv_\theta to targets computed from the previous iterate and held fixed (a stop-gradient on the target), which is Galerkin or collocation solved by iteration, not least squares on the residual. Bellman residual minimization is the residual-gradient algorithm of Baird (1995), which mainstream reinforcement learning did not adopt, in part because an unbiased gradient of the squared residual needs two independent samples of the successor state from the same state, which a single online trajectory does not provide. The best known method of this kind today is path consistency learning Nachum et al. (2017). It minimizes the squared residual of the smooth Bellman equation of the entropy-regularized chapter, written along a path of several steps, and it assumes deterministic dynamics, which removes the double-sampling problem. The trajectory balance objective used to train generative flow networks is a consistency condition of the same kind Malkin et al. (2022)Tiapkin et al. (2024).

The three methods compute three different approximations from the same basis, because each one makes the residual vanish in different directions. The third tab of Figure 3 shows this on a small policy-evaluation problem on S=[0,1]\mathcal{S} = [0, 1]. The next state is s′=0.8s+0.2us' = 0.8\sqrt{s} + 0.2u, where uu equals 0, 1/21/2 or 1 with probabilities 1/41/4, 1/21/2 and 1/41/4. The reward rises smoothly from 0 to 1 around s=0.7s = 0.7, and γ=0.9\gamma = 0.9. The policy is fixed, so the operator is Lπ\BellmanPi and contains no maximum. The residual is then affine in θ\theta, and each set of conditions is a linear system in θ\theta. The code below solves the three systems with six hat functions and a uniform weight ww, and then tests each solution against all three families of test functions.

Source
import sys
from pathlib import Path

sys.path.insert(0, str(Path.cwd() / "code"))
from test_functions_demo import table

rows = table(kind="hat", n=6)
families = ("collocation", "galerkin", "least squares")
print("Largest |test value| of each solution, against each family of tests")
print(f"{'solution':<15}" + "".join(f"{f:>15}" for f in families) + f"{'sup |v - v_pi|':>16}")
for method, row in rows.items():
    print(f"{method:<15}" + "".join(f"{row[f]:>15.4f}" for f in families) + f"{row['value error (sup)']:>16.3f}")
Largest |test value| of each solution, against each family of tests
solution           collocation       galerkin  least squares  sup |v - v_pi|
collocation             0.0000         0.1202         0.1232           0.668
galerkin                0.2853         0.0000         0.0027           0.351
least squares           0.2871         0.0022         0.0000           0.335

Each row has a zero in its own column, as the conditions of that method require, and no row has a zero anywhere else. The Galerkin and least-squares solutions are close to each other on this problem. Both leave a residual of about 0.29 at one of the collocation points, which is what the collocation conditions rule out. None of the three solutions satisfies the Bellman equation, and none satisfies the conditions of the other two methods. The choice between them is a choice of the directions in which the residual must vanish. In reinforcement learning, the Galerkin conditions with the states weighted by the data are the equations that TD(0) and LSTD solve, as the next chapter shows.

Step 4: Solve the nn Equations

The conditions of Step 3 are nn equations in the nn unknowns, G(θ)=0G(\theta) = 0 with Gi(θ)=⟨R(⋅;θ),pi⟩wG_i(\theta) = \langle R(\cdot;\theta), p_i \rangle_w, or Gi(θ)=R(si;θ)G_i(\theta) = R(s_i;\theta) for collocation. They are nonlinear, because the maximum in the Bellman operator is. The infinite-horizon chapter solved the exact Bellman equation with two general methods for operator equations, successive approximation, which gave value iteration, and the Newton–Kantorovich method, which gave policy iteration. Each has a counterpart for the nn equations.

Function Iteration

For collocation and Galerkin, the conditions have the fixed-point form vθ=P Lvθv_\theta = \Proj\,\Bellman v_\theta of (14), and the natural solver repeats the map,

vk+1=P Lvk,vk=v(⋅;θk),v_{k+1} = \Proj\, \Bellman v_k, \qquad v_k = v(\cdot;\theta_k),

value iteration with a projection after each application of the operator. The functions vkv_k are never stored: each one is the function described by its coefficients θk\theta_k, and what the iteration updates is the coefficient vector, from θk\theta_k to θk+1\theta_{k+1}. One iteration of the collocation version has two steps. The first evaluates the operator at the nodes with the current function, ti=(Lvk)(si)t_i = (\Bellman v_k)(s_i) for i=1,…,ni = 1, \ldots, n. The second chooses the coefficients that reproduce those nn targets, which is the linear system Φθk+1=t\boldsymbol{\Phi}\theta_{k+1} = t with the interpolation matrix Φij=ϕj(si)\Phi_{ij} = \phi_j(s_i). With hat functions collocated at their own nodes the solve is trivial, because Φ\boldsymbol\Phi is the identity. The Galerkin version replaces the second step by the orthogonal projection of the target function, which is the weighted least-squares fit

θk+1=arg⁡min⁡θ∥v(⋅;θ)−Lvk∥w2.\theta_{k+1} = \arg\min_{\theta} \big\| v(\cdot;\theta) - \Bellman v_k \big\|_w^2 .

Its first-order conditions are the linear system Mθk+1=bkM\theta_{k+1} = b_k with the mass matrix Mij=⟨ϕi,ϕj⟩wM_{ij} = \langle \phi_i, \phi_j \rangle_w and bi=⟨Lvk,ϕi⟩wb_i = \langle \Bellman v_k, \phi_i \rangle_w. The system is linear whatever the operator is, because the target Lvk\Bellman v_k is computed from θk\theta_k and held fixed while θk+1\theta_{k+1} is chosen. With sampled states, the fit is an ordinary regression of the backups on the basis. This fit is not the least-squares method of Step 3. Least squares minimizes ∥R(⋅;θ)∥w2\|R(\cdot;\theta)\|_w^2 once, with θ\theta on both sides of the residual. The fit above solves a new minimization at every iteration, with θ\theta only on the side of the approximation; in an implementation by gradient descent, the target is wrapped in a stop-gradient. The circularity of Step 3 is gone: the targets come from the previous iterate. Fitting a parametric function to Bellman backups, then recomputing the backups, is the algorithm that the chapter on fitted value methods calls fitted value iteration and generalizes to any regressor.

Whether the iteration converges is a separate question. Being a contraction is a property of an operator with respect to a norm: an operator that contracts in the sup norm need not contract in a weighted L2L^2 norm, and conversely. The composed operator PL\Proj\Bellman therefore inherits the contraction of L\Bellman when P\Proj is a nonexpansion in the same norm, that is, when

∥Pu−Pw∥≤∥u−w∥for all u,w.\|\Proj u - \Proj w\| \leq \|u - w\| \quad \text{for all } u, w.

The Bellman operator is a γ\gamma-contraction in the sup norm, so value iteration converges from any start (Proposition 2). If P\Proj is a nonexpansion in the sup norm, then ∥PLu−PLw∥∞≤∥Lu−Lw∥∞≤γ∥u−w∥∞\|\Proj\Bellman u - \Proj\Bellman w\|_\infty \leq \|\Bellman u - \Bellman w\|_\infty \leq \gamma\|u - w\|_\infty, so PL\Proj\Bellman is a γ\gamma-contraction, and (25) converges to the unique solution of the projected Bellman equation, with the sup-norm error multiplied by at most γ\gamma per iteration. For a linear P\Proj, being a sup-norm nonexpansion means that its sup-norm operator norm, which for interpolation is the Lebesgue constant Λ\Lambda, is at most one, and this depends on the sign of the weights. An interpolation operator with nonnegative cardinal functions returns a convex combination of the targets, so Λ=1\Lambda = 1, the condition of Proposition 1, and P\Proj is a nonexpansion. Polynomial interpolation through Chebyshev nodes has cardinal functions that dip below zero between the nodes, so Λ>1\Lambda > 1: for some pairs of target vectors, ∥Pu−Pw∥∞>∥u−w∥∞\|\Proj u - \Proj w\|_\infty > \|u - w\|_\infty. The composition need not be a contraction, and the iteration can diverge although every iteration reproduces its targets exactly. The next chapter proves that the first kind of fit always preserves the contraction and shows what happens with the second. Even when it converges, function iteration is slow when γ\gamma is near one: the error bound decreases by a factor γ\gamma per iteration, so reducing it by 10-10 with γ=0.95\gamma = 0.95 takes about 450 iterations.

Newton’s Method

The alternative treats G(θ)=0G(\theta) = 0 as a rootfinding problem and linearizes it,

θk+1=θk−JG(θk)−1G(θk),\theta_{k+1} = \theta_k - J_G(\theta_k)^{-1} G(\theta_k),

where JGJ_G is the Jacobian of GG. For collocation, Gi(θ)=v(si;θ)−(Lvθ)(si)G_i(\theta) = v(s_i;\theta) - (\Bellman v_\theta)(s_i), and the Jacobian entries are

∂Gi∂θj=ϕj(si)−∂(Lvθ)(si)∂θj.\frac{\partial G_i}{\partial \theta_j} = \phi_j(s_i) - \frac{\partial (\Bellman v_\theta)(s_i)}{\partial \theta_j}.

The first term is a basis function at a node. The second is the derivative of the Bellman operator with respect to a coefficient, the quantity that the least-squares conditions of Step 3 also needed, and it contains a maximum. The maximum is not differentiable where two actions tie, but wherever the maximizer is unique its derivative is given by the envelope theorem.

Before reading on, differentiate h(θ)=max⁡ag(a,θ)h(\theta) = \max_a g(a, \theta) with the chain rule, writing a∗(θ)a^*(\theta) for the maximizer. Which term involves ∂a∗/∂θ\partial a^*/\partial\theta, and why does it vanish?

For the Bellman operator, (Lvθ)(s)=max⁡a{r(s,a)+γ E[v(s′;θ)∣s,a]}(\Bellman v_\theta)(s) = \max_a \{ r(s,a) + \gamma\, \mathbb{E}[v(s';\theta) \mid s, a] \}, the objective is linear in θ\theta with coefficients γ E[ϕj(s′)∣s,a]\gamma\,\mathbb{E}[\phi_j(s') \mid s, a], so

∂(Lvθ)(s)∂θj=γ E[ϕj(s′)∣s,a∗(s;θ)],\frac{\partial (\Bellman v_\theta)(s)}{\partial \theta_j} = \gamma\, \mathbb{E}\big[\phi_j(s') \mid s, a^*(s;\theta)\big],

where a∗(s;θ)a^*(s;\theta) is the greedy action at ss for the current coefficients. The derivative is the expected value of the basis function at the successor under the greedy action, and computing it costs one more quadrature per node and basis function. The same formula holds for the discrete-action case, and on a finite set of actions the maximizer is unique except at ties.

Substituting (31) into the Newton step gives it a familiar form. Let πk\pi_k be the greedy policy for vθkv_{\theta_k}, let rπk\mathbf{r}_{\pi_k} collect its rewards at the nodes, and let PπkΦ\mathbf{P}_{\pi_k}\boldsymbol{\Phi} be the matrix with entries E[ϕj(s′)∣si,πk(si)]\mathbb{E}[\phi_j(s') \mid s_i, \pi_k(s_i)]. Then JG=Φ−γPπkΦJ_G = \boldsymbol{\Phi} - \gamma \mathbf{P}_{\pi_k}\boldsymbol{\Phi} and G(θk)=Φθk−rπk−γPπkΦθkG(\theta_k) = \boldsymbol\Phi\theta_k - \mathbf{r}_{\pi_k} - \gamma \mathbf{P}_{\pi_k}\boldsymbol\Phi\theta_k, and the Newton update JGθk+1=JGθk−G(θk)J_G \theta_{k+1} = J_G\theta_k - G(\theta_k) simplifies to

(Φ−γPπkΦ) θk+1=rπk.(\boldsymbol{\Phi} - \gamma \mathbf{P}_{\pi_k}\boldsymbol{\Phi})\, \theta_{k+1} = \mathbf{r}_{\pi_k}.

This is the policy evaluation equation of πk\pi_k, imposed at the collocation nodes and solved within the span of the basis. Newton’s method on the collocation equations alternates a greedy improvement with an approximate evaluation, exactly as Newton’s method on the exact Bellman equation is policy iteration (Newton-Kantorovich and Policy Iteration). With the smooth Bellman operator of the regularized chapter, the maximum is replaced by a log-sum-exp, the operator is differentiable everywhere, and the same step holds with the softmax policy in place of the greedy one (Smooth Policy Iteration Is Newton’s Method).

Newton’s method converges quadratically near the solution, a few iterations instead of the hundreds of function iteration, and it does not need P L\Proj\,\Bellman to be a contraction, since it never iterates that map. It pays for this in two ways. Each iteration forms and solves the Jacobian system, whose entries need the expectations of every basis function at every node. And it depends on the starting point: started far from the solution it can diverge, or converge to a fixed point that the nn equations have and the Bellman equation does not.

MethodConvergencePer-iteration costNeeds
Function iterationLinear, factor γ\gammann backups and one linear solve with a fixed matrixP L\Proj\,\Bellman to be a contraction
Newton’s methodQuadratic near the solutionnn backups, n2n^2 expectations and a fresh linear solveA good starting point

The two solvers complement each other. When the fit is monotone and γ\gamma is moderate, function iteration is simple and robust. When γ\gamma is near one or the basis is a high-order polynomial, a hybrid works well: a few function iterations with a coarse, monotone approximation to reach the basin of attraction, then Newton’s method with the accurate basis. This is how Rust solved his bus-engine model (Rust’s Bus Engines and Inverse Reinforcement Learning), and the next chapter develops the Newton side as approximate policy iteration.

Step 5: Check the Solution

The conditions of Step 3 control the residual only where they were imposed, at the collocation nodes or against the chosen test functions. The first check is therefore to evaluate the residual where it was not controlled: at many states between the nodes, with a finer quadrature inside the operator than the one used in the fit, and against higher-order basis functions in the Galerkin case.

A small residual everywhere does bound the value error. Since vθ−v⋆=(vθ−Lvθ)+(Lvθ−Lv⋆)v_\theta - v^\star = (v_\theta - \Bellman v_\theta) + (\Bellman v_\theta - \Bellman v^\star) and L\Bellman is a γ\gamma-contraction,

∥vθ−v⋆∥∞≤∥R(⋅;θ)∥∞1−γ,\|v_\theta - v^\star\|_\infty \le \frac{\|R(\cdot;\theta)\|_\infty}{1 - \gamma},

where the norm of RR is taken over all states, not over the nodes. The bound is loose in general, and neither the residual nor the value error is what is used. The greedy policy is, and its loss is the difference between the optimal value and the value of acting on the approximation. The three quantities answer different questions. The residual is what the method controls. The value error is what the residual bounds, through 1/(1−γ)1/(1-\gamma). The policy loss is what matters, and it depends on the value error only through the differences between actions, which an approximation can get wrong while its values are accurate and right while they are not. The chapter on fitted value methods bounds the policy loss by the value error and tests both bounds on a problem that a government agency solves every year.

Exercises

The exercises use the notation of the five steps. The first ones are short checks of the definitions; most of the others can be done by hand, and Exercise 7 needs the fishery module that produced the figures.

Solution to Exercise 1

Against the basis functions themselves: ⟨Lvθ−vθ,ϕi⟩w=0\langle \Bellman v_\theta - v_\theta, \phi_i\rangle_w = 0 for every ii. The residual is then orthogonal to the whole span, so the ww-orthogonal projection of Lvθ\Bellman v_\theta onto the span is vθv_\theta itself.

Solution to Exercise 2

Collocation forces the residual to vanish at selected states. Least squares minimizes the weighted squared residual over the state space. Least squares needs the envelope theorem, because its first-order conditions contain the derivative of the Bellman operator with respect to the coefficients; collocation needs it only if the collocation equations are solved by Newton’s method.

Solution to Exercise 3

Collocation controls the residual at the nodes only. The sup norm of the residual over all states bounds the value error through 1/(1−γ)1/(1-\gamma), and the value error bounds the policy loss (next chapter). Both bounds are loose, and the policy depends on differences between the values of actions rather than on the values themselves, so an approximation with a smaller residual can place a decision boundary in the wrong region, as the polynomial does across the tipping point.

Solution to Exercise 4
  1. 43s=s+12⋅43⋅s2=s+13s\tfrac43 s = s + \tfrac12 \cdot \tfrac43 \cdot \tfrac s2 = s + \tfrac13 s.

  2. R(s;θ)=s+12(θ1+θ2s2/4)−θ1−θ2s2=s−12θ1−78θ2s2R(s;\theta) = s + \tfrac12(\theta_1 + \theta_2 s^2/4) - \theta_1 - \theta_2 s^2 = s - \tfrac12\theta_1 - \tfrac78\theta_2 s^2.

  3. R(0)=−12θ1=0R(0) = -\tfrac12\theta_1 = 0 gives θ1=0\theta_1 = 0, and R(1)=1−78θ2=0R(1) = 1 - \tfrac78\theta_2 = 0 gives θ2=87\theta_2 = \tfrac87.

  4. The conditions ∫01R ds=12−12θ1−724θ2=0\int_0^1 R\,ds = \tfrac12 - \tfrac12\theta_1 - \tfrac{7}{24}\theta_2 = 0 and ∫01R s2 ds=14−16θ1−740θ2=0\int_0^1 R\,s^2\,ds = \tfrac14 - \tfrac16\theta_1 - \tfrac{7}{40}\theta_2 = 0 give θ1=38\theta_1 = \tfrac38 and θ2=1514\theta_2 = \tfrac{15}{14}.

  5. Collocation: largest residual 0.25, largest value error 0.389 (near s=0.58s = 0.58). Galerkin: largest residual 0.1875, largest value error 0.375 (at s=0s = 0). Galerkin is slightly better by both measures here. Both are poor, because a parabola cannot follow a line through the origin and the ends: no choice of conditions repairs a basis that cannot represent the solution. Least squares happens to give the Galerkin answer in this problem, because the residual is linear in θ\theta and its derivatives ∂R/∂θi\partial R/\partial\theta_i are −12-\tfrac12 and −78s2-\tfrac78 s^2, which span the same space as the basis.

Solution to Exercise 5
  1. ℓ0(s)=1−s2\ell_0(s) = 1 - s^2 and ℓ1(s)=s2\ell_1(s) = s^2.

  2. Both lie in [0,1][0, 1] on [0,1][0, 1] and sum to one, so Pg\Proj g is a convex combination of g(0)g(0) and g(1)g(1) at every ss and ∥Pf−Pg∥∞≤∥f−g∥∞\|\Proj f - \Proj g\|_\infty \le \|f - g\|_\infty. The composition PL\Proj\Bellman is then a γ\gamma-contraction for any γ\gamma-contraction L\Bellman, and function iteration converges from any start. On this problem it converges to the collocation solution of Exercise 4.

  3. The cardinal functions are 2(s−12)(s−1)2(s - \tfrac12)(s-1), −4s(s−1)-4s(s-1) and 2s(s−12)2s(s-\tfrac12). The first and last are negative on parts of [0,1][0, 1], so Λ=1.25>1\Lambda = 1.25 > 1. The sup-norm operator norm of P\Proj is 1.25, so P\Proj is not a nonexpansion: some pair of target vectors has ∥Pu−Pw∥∞=1.25 ∥u−w∥∞\|\Proj u - \Proj w\|_\infty = 1.25\,\|u - w\|_\infty. The bound 1.25γ1.25\gamma on the modulus of PL\Proj\Bellman then exceeds one for γ>0.8\gamma > 0.8, and the argument fails.

Solution to Exercise 6
  1. Everywhere except θ=12\theta = \tfrac12. The envelope theorem gives the derivative of the active action: 1 for θ>12\theta > \tfrac12 and -1 for θ<12\theta < \tfrac12.

  2. The maximizer is not unique. The one-sided derivatives are -1 and 1, and every slope λ⋅1+(1−λ)(−1)\lambda \cdot 1 + (1-\lambda)(-1) with λ∈[0,1]\lambda \in [0, 1] is a subgradient: it is the derivative of the value of the randomized choice that takes the first action with probability λ\lambda.

  3. A tie means two actions have the same value at that node, so evaluating either one gives a valid Newton step: the step solves the evaluation equation of some greedy policy, and policy iteration converges whichever greedy action it picks. The smooth Bellman operator replaces the maximum by a log-sum-exp, which is differentiable everywhere; its Jacobian uses the softmax policy, which splits the probability between tied actions, and no tie-breaking rule is needed.

Solution to Exercise 7
import numpy as np
from fishery_tipping_point import Bellman, HatBasis, growth, X_MAX

bellman, basis = Bellman(), HatBasis(12)
nodes, gamma = basis.nodes, bellman.gamma

def hats(points):                                   # phi_j(points), one column per node
    return np.stack([np.interp(points, nodes, np.eye(basis.n)[j]) for j in range(basis.n)], axis=-1)

theta = np.zeros(basis.n)
for k in range(30):
    escapement = bellman.greedy(basis.function(theta))
    index = np.clip(np.searchsorted(bellman.x, nodes, side="right") - 1, 0, bellman.x.size - 1)
    a = escapement[index]                           # greedy escapement at each node
    successors = np.clip(np.outer(growth(a), bellman.z), 0, X_MAX)
    P_Phi = np.einsum("q,iqj->ij", bellman.w, hats(successors))
    new = np.linalg.solve(np.eye(basis.n) - gamma * P_Phi, nodes - a)
    step, theta = np.abs(new - theta).max(), new
    if step < 1e-10:
        break
print(k + 1, "Newton iterations")

The steps are 1.6, 2.9, 0.86, 3×10−73 \times 10^{-7} and then zero: five iterations, against about 410 for function iteration, and the coefficients agree with the fixed point of function iteration to 10-14. They must agree, because both methods solve the same collocation equations θ=PLvθ\theta = \Proj\Bellman v_\theta, which have a unique solution here since PL\Proj\Bellman is a contraction; Newton’s method only finds it faster.

Solution to Exercise 8

This exercise is open-ended. A least-squares fit to more nodes than coefficients is no longer an averager, so it carries no guarantee either, although oversampling reduces the size of the weights. Newton’s method does not iterate PL\Proj\Bellman and needs no contraction; started from the piecewise-linear solution, which is close, it is the hybrid strategy of the chapter. Whatever converges, judge it by the policy loss, as in Step 5: a polynomial that converges can still place the decision boundary on the wrong side of the tipping point.

Summary and Outlook

Replacing the value function by v(⋅;θ)v(\cdot;\theta) turns the Bellman equation into a residual R(⋅;θ)=Lvθ−vθR(\cdot;\theta) = \Bellman v_\theta - v_\theta that no choice of θ\theta makes zero everywhere. The method of weighted residuals imposes nn conditions on it instead: collocation makes it vanish at chosen states, Galerkin makes it orthogonal to the basis, and least squares minimizes its norm. The first two are projected Bellman equations vθ=P Lvθv_\theta = \Proj\,\Bellman v_\theta, and their solvers are the two solvers of the exact equation with a projection inserted: function iteration, which is value iteration with a fit after each sweep, and Newton’s method, which is policy iteration with each evaluation done within the span of the basis. The fishery showed that the fit decides both the accuracy of the solution and whether function iteration converges, and that a smaller residual does not mean a better policy.

Nothing in the five steps is specific to the Bellman equation. Any operator equation N(f)=0\Residual(f) = 0 for an unknown function ff is treated the same way, with a basis for ff, a residual N(f^)\Residual(\hat f), test functions, and one of the two solvers, and the collocation chapter did exactly this for differential equations, with polynomial pieces for the trajectory and the equation of motion enforced at the collocation points. What the Bellman equation adds is the maximum, which makes the equations nonlinear and the Jacobian a matter for the envelope theorem, and the contraction, which is what makes function iteration an option at all.

Step 4 left two things open. Function iteration converged for one basis and not the other, and the explanation, that the fit must be a nonexpansion in the sup norm, was asserted and not proved. Newton’s method was shown to be policy iteration in coefficient space for collocation, without saying how accurate each evaluation must be for the policies to improve. The next chapter takes up both. It shows when the fit makes function iteration diverge and which fits cannot, and turns Newton’s method into approximate policy iteration. The chapter after it then lets the fit be any regressor, which turns function iteration into fitted value iteration, a sequence of regression problems with Bellman targets, bounds its error when every fit is accurate, and replaces the exact expectations by samples, which leads to fitted Q-iteration.

References
  1. Ernst, D., Geurts, P., & Wehenkel, L. (2005). Tree-Based Batch Mode Reinforcement Learning. Journal of Machine Learning Research, 6, 503–556.
  2. Riedmiller, M. (2005). Neural Fitted Q Iteration – First Experiences with a Data Efficient Neural Reinforcement Learning Method. Proceedings of the 16th European Conference on Machine Learning (ECML), 317–328.
  3. Hafner, R., & Riedmiller, M. (2011). Reinforcement learning in feedback control: Challenges and benchmarks from technical process control. Machine Learning, 84(1–2), 137–169. 10.1007/s10994-011-5235-x
  4. Chakraverty, S., Mahato, N. R., Karunakar, P., & Rao, T. D. (2019). Weighted Residual Methods. In Advanced Numerical and Semi-Analytical Methods for Differential Equations (pp. 25–44). John Wiley & Sons, Inc. 10.1002/9781119423461.ch3
  5. Atkinson, K. E., & Potra, F. A. (1987). Projection and Iterated Projection Methods for Nonlinear Integral Equations. SIAM Journal on Numerical Analysis, 24(6), 1352–1373. 10.1137/0724087
  6. Boettiger, C., Mangel, M., & Munch, S. (2015). Avoiding tipping points in fisheries management through Gaussian process dynamic programming. Proceedings of the Royal Society B: Biological Sciences, 282(1801), 20141631. 10.1098/rspb.2014.1631
  7. Reed, W. J. (1979). Optimal escapement levels in stochastic and deterministic harvesting models. Journal of Environmental Economics and Management, 6(4), 350–363. 10.1016/0095-0696(79)90014-7
  8. Clark, C. W. (1973). Profit maximization and the extinction of animal species. Journal of Political Economy, 81(4), 950–961. 10.1086/260090
  9. Sutton, R. S. (1996). Generalization in Reinforcement Learning: Successful Examples Using Sparse Coarse Coding. Advances in Neural Information Processing Systems, 8, 1038–1044.
  10. Legrand, M., & Junca, S. (2025). Weighted Residual Solution Methods.
  11. Frazer, R. A., Jones, W. P., & Skan, S. W. (1937). Approximations to Functions and to the Solutions of Differential Equations (Reports and Memoranda No. 1799). Aeronautical Research Committee.
  12. Bertsekas, D. P., & Tsitsiklis, J. N. (1996). Neuro-Dynamic Programming. Athena Scientific.
  13. Baird, L. (1995). Residual algorithms: Reinforcement learning with function approximation. Proceedings of the Twelfth International Conference on Machine Learning, 30–37.
  14. Nachum, O., Norouzi, M., Xu, K., & Schuurmans, D. (2017). Bridging the Gap Between Value and Policy Based Reinforcement Learning. Advances in Neural Information Processing Systems, 30, 2775–2785.
  15. Malkin, N., Jain, M., Bengio, E., Sun, C., & Bengio, Y. (2022). Trajectory Balance: Improved Credit Assignment in GFlowNets. Advances in Neural Information Processing Systems, 35.