Chapter 8 Value Function Methods
Chapter 8 Value Function Methods
In this chapter we move from previous tabular representation for state/action value to function representation. That is to say, we use a function to fit the true expression of the state/action value function. Such a function can be predifined, e.g., a linear function, or a neural network.
The reason why we move from tabular-based representation to function-based are:
- storage, compared with tabular, we only need to store a few parameters describing the function.
- generalization, action and state may be infinite (or continuous), we cannot store all the state/action value. We need to find a unified representation.


As shown in the figure, we update parameters to update the value.
Tabular TD updates an individual value entry. With function approximation, TD updates shared parameters, so an update can change predictions for many states. The usual update is a semi-gradient update: it differentiates the current prediction while treating the bootstrapped target as fixed. It should not be identified with ordinary gradient descent on the full Bellman residual.
Function-based Value representation
A simple linear function approximation:
here
- is the parameter vector
- is the feature vector of
- is linear in
We can also fit the points using a second-order curve:
In this case,The dimensions of and increase, but the values may be fitted more accurately. Although is nonlinear in , it is linear in . The nonlinearity is contained in .
we can use even higher-order polynomial curves or other complex curves to fit the dots, which we can better approximate true value function but needs more parameter.
TD learning of state values based on function approximation
objective
As we are trying to fit the value function, our optimization objective is:
here we invovle the random variable , if the state is in uniform, we have:
however, we can write it into a more general form:
here is called the the stationary distribution of the Markov process under policy . That is, the probability for the agent visiting after a long period of time is . By definition, .
It is notable that the value of is nontrivial to obtain because it requires knowing the state transition probability matrix . Fortunately, we do not need to calculate the specific value of to minimize this objective function as shown in the next subsection. If the state space is continuous, we can replace the summations with integrals in the above equation.
Stationary distribution
Once a policy is given, the MDP becomes a Markov process, and its dynamics are governed by the probability transition matrix .
Let be a vector representing the probability distribution of the states at the initial time step. The probability distribution vector after exactly steps, denoted as , can be formulated in matrix-vector form as:
here, represents the probability matrix of the agent transitioning from state to after exactly steps under policy .
For a finite irreducible and aperiodic Markov chain, there is a unique stationary distribution and converges as approaches infinity:
Here, , which means is a constant matrix where all of its rows are equal to . Substituting this limit back into the state evolution equation yields:
Under these assumptions, the initial probabilities sum to one (), so the limiting distribution is independent of . Without such assumptions, a stationary distribution may not be unique or the time-indexed distribution may not converge to it. Stationarity should not be assumed for every trajectory from its first sample.
The analytical value of can be calculated by leveraging the recursive nature of the transition process. By taking the limit of both sides of the iterative equation , we obtain:
Since both distributions converge as , this directly resolves to the stationary equation:
In linear algebra, the left eigenvector and its corresponding eigenvalue of a matrix satisfy the definition .
Comparing this to the steady-state equation , it is clear that is precisely the left eigenvector of the probability transition matrix corresponding to the eigenvalue . when transforming the formula to , we find the corresponding eigenvector with an eigenvalue of 1 by solving this homogeneous linear system of equations.
Optimization
We can adopt the gradient descent method to optimaize the objective:
where
Therefore, the gradient descent algorithm is
where the coefficient before can be merged into without loss of generality. The algorithm requires calculating the expectation. In the spirit of stochastic gradient descent (SGD), we can replace the true gradient with a stochastic gradient. Then, we have
where is a sample of at time . It requires the true state value , which is unknown and must be estimated. We can replace with an approximation to make the algorithm implementable.
The following two methods can be used to do so.
- Monte Carlo method: Suppose that we have an episode . Let be the discounted return starting from . Then, can be used as an approximation of . The algorithm in (8.12) becomes:
This is the algorithm of Monte Carlo learning with function approximation.
- Temporal-difference method: In the spirit of TD learning, can be used as an approximation of . The algorithm becomes
This is semi-gradient TD. During the update, is treated as a constant target: gradients flow through , not through the target's dependence on . In code, the target is detached or calculated without recording gradients. At a true terminal transition, omit the bootstrap term. Replacing with this target does not make the update an unbiased gradient of the original mean-squared value error for an arbitrary approximate critic.
We can use the function introduce in Function-based Value representation to represent which function is we use to approximate the true value function. If we use linear approximation function, the gradient is . We can also use neural network.
Theoretical analysis
For the convergence, see at book.
The true state-value function strictly satisfies the Bellman equation: . When we introduce a function approximator (e.g., a linear function or neural network with parameters ), we hope that the estimated value also satisfies this equation as much as possible. Therefore, the difference between the two sides of the equation is the Bellman error:
The Bellman error often cannot be optimized to 0 because the function approximators we use (such as low-dimensional linear features) have limited approximation ability, the result mapped by the Bellman operator often "runs out" of the space that our function approximator can represent.
For linear function approximation, the TD fixed point can instead be characterized using a projection back into the feature space. The mean-squared projected Bellman error is:
Here, and is the orthogonal projection onto the linear feature space in the D-weighted norm. Under standard discounted, on-policy linear-TD assumptions, including suitable feature rank, state coverage, and step sizes, TD converges to the projected Bellman fixed point. At this point the projected error is zero. This conclusion requires those assumptions; merely projecting into the feature space does not establish it for arbitrary settings.
Ordinary semi-gradient TD is not generally gradient descent on itself. The linear on-policy result must not be extended into a blanket convergence claim for neural networks or off-policy TD. Function approximation, bootstrapping, and off-policy sampling can together lead to instability or divergence.
TD learning of action values based on function approximation
Here we use function to approximate action values.
The Sarsa algorithm with function approximation can be readily obtained by replacing the state values with action values in TD learning of state values based on function approximation section. In particular, suppose that is approximated by . Replacing by gives:

Tabular Q-learning can also be extended to the case of function approximation. The update rule is
Deep Q-learning
To connect DQN with Q-learning, first consider the mean-squared sampled TD error:
Here denotes a sampled transition. The Bellman optimality equation requires the conditional mean TD error to be zero at ; it does not require every sampled TD error, or its mean square, to be zero. Writing gives:
Thus, mean-squared sampled TD error includes target variance in addition to the squared Bellman residual. For episodic tasks, all DQN targets below use , where d indicates true termination; the displayed formulas omit d for brevity.
DQN treats the target as fixed during each gradient update rather than differentiating both occurrences of w in the expression above. It additionally uses a target network that changes more slowly to reduce instability from rapidly moving bootstrap targets. Stopping target gradients and maintaining a lagged target network are distinct choices. The two networks are:
- Main Network: represent , namely the approximation of action value.
- Target network: a lagged copy of the main network used to construct bootstrap targets. It is also an approximation and does not already know the optimal action values.
The objective function in this case becomes:
where is the target network's parameter. When is fixed, the gradient of is
where some constant coefficients are omitted without loss of generality.
The main network is updated in every iteration. By contrast, the target network is set to be the same as the main network every certain number of iterations to satisfy the assumption that is fixed when calculating the gradient.
DQN commonly uses experience replay to reuse transitions and reduce the temporal correlation within training batches. We store transitions, including terminal information, in a replay buffer and sample minibatches to update the main network. This supports data reuse; using a neural network does not by itself make replay mandatory.
Uniformly sampling buffer entries is a simple choice, but it does not make the state-action distribution uniform. If 90% of stored transitions visit one state, approximately 90% of uniformly sampled entries will still visit that state. Replay neither guarantees state coverage nor requires uniform sampling. Prioritized experience replay uses nonuniform probabilities, with importance weights to address the resulting sampling bias relative to its intended replay objective. The buffer composition and sampling rule determine how states and actions are weighted in the training loss.

The earlier algorithms were presented as sequential updates for clarity, not because linear models forbid replay or guarantee convergence in all cases. Suitable on-policy linear TD evaluation admits convergence analysis under Markov sampling; this does not imply convergence of arbitrary linear Q-learning or that samples collected while a policy changes already follow a single stationary distribution.
Deep on-policy methods can learn from recent rollouts without a long-term replay buffer; A2C and PPO are examples. For ordinary on-policy Sarsa, reusing a stored next action from an old policy as though it were sampled from the current policy creates a mismatch in the target . Reusing such data requires an appropriate off-policy treatment rather than an assumption that all deep methods should share DQN's replay procedure.
