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.

Deep Q-Networks: Target Networks, Replay and Online Data

The previous chapter ended with fitted Q-iteration on a fixed log of transitions: an outer loop that computes Bellman targets and an inner loop that fits a function to them, run to completion. This chapter opens the inner loop. Writing out the gradient steps of a neural fit and merging them with the outer loop turns fitted Q-iteration into DQN, with its target network and its online network, and letting the buffer evolve during learning gives DQN proper, Double DQN, and, at the limit of one transition per update, Q-learning. A synthesis section lays out the design space that these choices span, and the chapter closes with losses that model the noise of Bellman targets better than squared error.

How do the buffer, the Bellman target, the function approximator and the optimization budget combine when only one observed successor is available for each stored transition?

From Nested Loops to Target Networks

Fitted Q-iteration has a nested structure: the outer loop computes Bellman targets, and the inner loop fits the function approximator to them. For a tree ensemble the inner loop is one call that builds the trees, and the nesting is the only possible presentation. For a neural network the inner loop is a sequence of gradient steps,

θn(k+1)=θn(k)−α∇θL(θn(k);Dnfit),k=0,…,K−1,\boldsymbol{\theta}_n^{(k+1)} = \boldsymbol{\theta}_n^{(k)} - \alpha \nabla_{\boldsymbol{\theta}} \mathcal{L}\big(\boldsymbol{\theta}_n^{(k)}; \mathcal{D}_n^{\text{fit}}\big), \qquad k = 0, \ldots, K-1,

starting from θn(0)=θn\boldsymbol{\theta}_n^{(0)} = \boldsymbol{\theta}_n and ending with θn+1=θn(K)\boldsymbol{\theta}_{n+1} = \boldsymbol{\theta}_n^{(K)}, where Dnfit\mathcal{D}_n^{\text{fit}} is the regression data set of the nn-th outer iteration. Two loops of counted steps can be written as one, and the rewriting shows where the target network of DQN comes from.

Making the Nested Structure of Batch FQI Explicit

Starting from Algorithm 4, replacing the fit call by KK explicit gradient steps gives the following.

The targets of outer iteration nn are computed with θn\boldsymbol{\theta}_n, the parameters at the end of the previous outer iteration, and they stay fixed for all KK inner steps. The inner iterates θn(k)\boldsymbol{\theta}_n^{(k)} for k>0k > 0 never enter a target. The fit is warm-started from θn\boldsymbol{\theta}_n, the very parameters that computed the targets, and it stops after KK steps rather than at convergence: these are the two departures from supervised learning that neural fitted Q-iteration introduced, and they are kept by everything that follows.

Flattening into a Single Loop

Replace the pair of counters (n,k)(n, k) by a single step counter t=nK+kt = nK + k. The parameters that compute the targets, θn\boldsymbol{\theta}_n, are held in a separate copy that changes only when tt crosses a multiple of KK, the boundary between two outer iterations. That copy is the target network θtarget\boldsymbol{\theta}_{\text{target}}. The parameters that the gradient steps update, θt\boldsymbol{\theta}_t, correspond to the inner iterates θn(k)\boldsymbol{\theta}_n^{(k)}, and are called the online network, online in the sense of being continually updated, not in the sense of how the data were collected. Nothing else changes.

At step tt, the outer iteration is n=⌊t/K⌋n = \lfloor t/K \rfloor and the inner step is k=t mod Kk = t \bmod K. The target network equals θn\boldsymbol{\theta}_n for tt from nKnK to (n+1)K−1(n+1)K - 1 and becomes θn+1\boldsymbol{\theta}_{n+1} at t=(n+1)Kt = (n+1)K, and θt\boldsymbol{\theta}_t is θn(k)\boldsymbol{\theta}_n^{(k)}. With K=10K = 10, the inner step k=7k = 7 of outer iteration n=3n = 3 is the global step t=37t = 37. The data set is still the fixed D\mathcal{D}; only the indexing has changed. A target network, in this reading, is the boundary of an outer iteration of fitted Q-iteration, kept in memory. When DQN is presented with a target network updated every KK steps, it is this flattened fitted Q-iteration with an evolving buffer, which the next section adds.

Smooth Target Updates by Exponential Moving Average

The periodic copy can be replaced by a target network that tracks the online network a little at every step,

θtarget←τ θt+1+(1−τ) θtarget,\boldsymbol{\theta}_{\text{target}} \leftarrow \tau\,\boldsymbol{\theta}_{t+1} + (1-\tau)\,\boldsymbol{\theta}_{\text{target}},

an exponential moving average (also called Polyak averaging) with rate τ∈(0,1)\tau \in (0, 1). For small τ\tau, typically between 0.001 and 0.01, the target lags the online network by roughly 1/τ1/\tau steps, and the targets drift continuously instead of jumping every KK steps. The scheme became standard with DDPG Lillicrap et al. (2015) and is used by TD3 Fujimoto et al. (2018) and SAC Haarnoja et al. (2018).

DQN: Fitted Q-Iteration on a Replay Buffer

The flattened algorithm sampled from a fixed data set. Let the data set change instead: a replay buffer Bt\mathcal{B}_t of fixed capacity BB receives one new transition at every step of interaction and drops the oldest when full, so that Bt={τt−B+1,…,τt}\mathcal{B}_t = \{\tau_{t-B+1}, \ldots, \tau_t\} and its empirical distribution P^Bt\hat{P}_{\mathcal{B}_t} slides forward in time. Each gradient step uses a mini-batch of bb transitions drawn uniformly from the current buffer. The online network acquires a second role: besides being the parameters under training, it is the policy that collects the new transitions, through ε\varepsilon-greedy action selection. “Online” now has both meanings at once, continually updated parameters and data collected during learning.

Deep Q-Network (DQN) Mnih et al. (2013) is this algorithm with a convolutional network and moderate settings: a buffer of about 106 transitions, mini-batches of about 32, and a target network copied every K≈104K \approx 10^4 steps. It is flattened fitted Q-iteration with an evolving buffer, and each of its components has a place in the nested view: the target network marks the outer iterations, the mini-batch gradient step is the inner loop, and the buffer is the data set, now changing slowly under the policy that the online network defines.

The deadly triad of the previous chapter is all here: a neural network, bootstrapped targets, and a buffer whose transitions were collected by earlier policies. The design choices are what keep it in check. Targets are held fixed for KK steps by the target network, each fit is warm-started, and the large buffer averages the data over many policies, so that the distribution of the data used by each fit changes slowly even though the policy changes at every step.

Recent analyses read these choices in the language of projected equations. Zhang et al. (2021) show that a target network, combined with a ridge penalty on the parameters, gives a linear off-policy Q-learning method that provably converges, and Fellows et al. (2023) treat the target network as a partially fitted iteration and identify conditions on the Jacobian of the TD update under which it restores stability. Gallici et al. (2025) show that layer normalization in the value network makes TD stable without a target network, even off-policy.

Double DQN

The target of DQN, max⁡a′q(s′,a′;θtarget)\max_{a'} q(s', a'; \boldsymbol{\theta}_{\text{target}}), uses the target network twice, to select the best next action and to value it, and the previous chapter showed that such a maximum is biased upward by the reuse of the winning noise. Double DQN Van Hasselt et al. (2016) separates the two roles between the two networks that DQN already maintains: the online network selects, ai∗=arg⁡max⁡a′q(si′,a′;θt)a^*_i = \arg\max_{a'} q(s'_i, a'; \boldsymbol{\theta}_t), and the target network evaluates, yi=ri+γ q(si′,ai∗;θtarget)y_i = r_i + \gamma\, q(s'_i, a^*_i; \boldsymbol{\theta}_{\text{target}}). The buffer and the fit are unchanged; only the target function differs.

The two networks are not independent estimates in the sense of the Monte Carlo chapter’s argument, since the target network is a delayed copy of the online one. Their errors are nonetheless less correlated than the errors of one network used twice, because they were fitted to different targets at different times, and the reduction in overestimation that this buys is substantial in practice.

Q-Learning as the Limit of One Transition per Update

DQN uses a buffer of about 106 transitions, a target network updated every 104 steps and mini-batches of 32. At the opposite extreme, with a buffer of one transition, a target network updated at every step and a mini-batch of one, the algorithm is Q-learning Watkins (1989). Each transition is used once and discarded, P^Bt\hat{P}_{\mathcal{B}_t} is a point mass at the current transition, and the parameters that compute the target are the ones just updated.

Q-learning is a stochastic approximation method. The Robbins–Monro procedure solves an equation F(θ)=0F(\boldsymbol{\theta}) = 0 in which F(θ)=E[f(θ;Z)]F(\boldsymbol{\theta}) = \mathbb{E}[f(\boldsymbol{\theta}; Z)] is an expectation that is never computed, by the update θt+1=θt−αtf(θt;Zt)\boldsymbol{\theta}_{t+1} = \boldsymbol{\theta}_t - \alpha_t f(\boldsymbol{\theta}_t; Z_t) on one noisy draw ZtZ_t at a time; under step sizes with αt→0\alpha_t \to 0 and ∑tαt=∞\sum_t \alpha_t = \infty the iterates converge to a solution. For Q-learning the equation is the Bellman equation in residual form, Lq−q=0\Bellman q - q = 0, and the draw is a transition. The residual at a transition (s,a,r,s′)(s,a,r,s') is the TD error

R(s,a,r,s′;θ)=r+γmax⁡a′q(s′,a′;θ)−q(s,a;θ),R(s,a,r,s'; \boldsymbol{\theta}) = r + \gamma \max_{a'} q(s',a'; \boldsymbol{\theta}) - q(s,a; \boldsymbol{\theta}),

whose expectation over transitions is the Bellman residual at (s,a)(s,a), averaged over the distribution of the behavior policy. Each transition is one noisy sample of it, and the update takes a gradient step on the squared TD error with the target held fixed, the semi-gradient of the approximate Bellman chapter.

The gradient in line 5 depends on the function class. With one-hot features ϕ(s,a)=e(s,a)\boldsymbol{\phi}(s,a) = \boldsymbol{e}_{(s,a)} the update is the tabular rule Q(s,a)←Q(s,a)+α(r+γmax⁡a′Q(s′,a′)−Q(s,a))Q(s,a) \leftarrow Q(s,a) + \alpha(r + \gamma \max_{a'} Q(s',a') - Q(s,a)), which converges under the stochastic-approximation conditions. With linear features q(s,a;θ)=θ⊤ϕ(s,a)q(s,a;\boldsymbol\theta) = \boldsymbol{\theta}^\top \boldsymbol{\phi}(s,a) the gradient is ϕ(s,a)\boldsymbol{\phi}(s,a), and convergence is not guaranteed: least squares is not an averager, and the max operator keeps the on-policy argument from applying. With a neural network the gradient comes from backpropagation and there are no guarantees at all.

Convergence Analysis by the ODE Method

Tabular Q-learning converges under diminishing step sizes and sufficient exploration Watkins & Dayan (1992)Jaakkola et al. (1994)Tsitsiklis (1994). The standard proof technique is the ordinary differential equation (ODE) method Kushner & Yin (2003)Borkar & Meyn (2000), which studies a stochastic approximation through an associated deterministic dynamical system. The argument has two steps. As the step sizes shrink, the stochastic recursion θt+1=θt+αth(θt,Zt)\boldsymbol{\theta}_{t+1} = \boldsymbol{\theta}_t + \alpha_t h(\boldsymbol{\theta}_t, Z_t) tracks the ODE θ˙=hˉ(θ)\dot{\boldsymbol{\theta}} = \bar{h}(\boldsymbol{\theta}), where hˉ(θ)=E[h(θ,Z)]\bar{h}(\boldsymbol{\theta}) = \mathbb{E}[h(\boldsymbol{\theta}, Z)] is the expected update direction. Then the ODE is shown to converge, with a Lyapunov function, and the stochastic algorithm converges to the same point.

For tabular Q-learning, the update at the visited pair (s,a)(s,a) is Qt+1(s,a)=Qt(s,a)+αt[r+γmax⁡a′Qt(s′,a′)−Qt(s,a)]Q_{t+1}(s,a) = Q_t(s,a) + \alpha_t [r + \gamma \max_{a'} Q_t(s',a') - Q_t(s,a)], and its expectation over the transition, given that (s,a)(s,a) is visited, is the Bellman residual at (s,a)(s,a). The ODE is

dQ(s,a)dt=∑s′p(s′∣s,a)[r(s,a,s′)+γmax⁡a′Q(s′,a′)]−Q(s,a),\frac{dQ(s,a)}{dt} = \sum_{s'} p(s'|s,a) \big[r(s,a,s') + \gamma \max_{a'} Q(s',a') \big] - Q(s,a),

whose equilibria are the solutions of the Bellman optimality equation, that is, Q∗Q^* alone. The distance ∥Q−Q∗∥∞\|Q - Q^*\|_\infty decreases along its trajectories because the Bellman operator is a contraction, which is the Lyapunov function. Exploration enters through the requirement that every pair be visited infinitely often; under ergodicity the frequency with which each (s,a)(s,a) is updated converges to the stationary distribution of the behavior policy, which the ODE absorbs as a per-coordinate time scale. With linear features the ODE no longer has the Bellman residual as its drift at every coordinate, the projection enters, and the approximate Bellman chapter showed what can go wrong then.

The Design Space of Fitted Q-Iteration

Every algorithm above has the same two-level structure, with three ingredients at any time tt:

  1. A buffer Bt\mathcal{B}_t of transitions, with its empirical distribution P^Bt\hat{P}_{\mathcal{B}_t}. It is a fixed data set D\mathcal{D} in the batch algorithms, a circular buffer of capacity BB in DQN, and the single current transition in Q-learning.

  2. A target function g(s,a,r,s′;θ)g(s,a,r,s'; \boldsymbol{\theta}) that computes a regression target from one transition and the parameters of the current Q-function: r+γmax⁡a′q(s′,a′;θ)r + \gamma \max_{a'} q(s',a';\boldsymbol\theta) for the hard maximum, the log-sum-exp of the regularized chapter for the smooth one, and the decoupled selection and evaluation of Double DQN. Unlike the Bellman operator, which acts on functions, gg acts on tuples.

  3. A fit: a loss ℓ\ell, an initialization θinit\boldsymbol{\theta}_{\text{init}}, and an optimization budget KK.

Pushing the buffer through the target function turns the distribution over transitions into a distribution over regression pairs, P^tfit=(id,g(⋅;θt))#P^Bt\hat{P}_t^{\text{fit}} = (\mathrm{id}, g(\cdot;\boldsymbol\theta_t))_\#\hat{P}_{\mathcal{B}_t}, and the fit minimizes the empirical risk E((s,a),y)∼P^tfit[ℓ(q(s,a;θ),y)]\mathbb{E}_{((s,a),y) \sim \hat{P}_t^{\text{fit}}}[\ell(q(s,a;\boldsymbol\theta), y)]. The buffer distribution changes only when data are collected; the regression distribution changes every time the targets are recomputed. In the abstract, the whole family is

repeat n=0,1,2,…Sample transitions from P^Bn and construct targets via g(⋅;θn)θn+1←fit(P^nfit,θinit,K)until convergence.\begin{aligned} &\textbf{repeat } n = 0, 1, 2, \ldots \\ &\quad \text{Sample transitions from } \hat{P}_{\mathcal{B}_n} \text{ and construct targets via } g(\cdot; \boldsymbol{\theta}_n) \\ &\quad \boldsymbol{\theta}_{n+1} \leftarrow \texttt{fit}(\hat{P}_n^{\text{fit}}, \boldsymbol{\theta}_{\text{init}}, K) \\ &\textbf{until } \text{convergence.} \end{aligned}

How often the data are reused is measured by the replay ratio, the number of optimization steps per transition collected:

Replay ratio={K⋅Nepochs⋅N/bbatch (batch size b from N transitions)bDQN (one step per transition, batch size b)1Q-learning.\text{Replay ratio} = \begin{cases} K \cdot N_{\text{epochs}} \cdot N / b & \text{batch (batch size } b \text{ from } N \text{ transitions)} \\ b & \text{DQN (one step per transition, batch size } b \text{)} \\ 1 & \text{Q-learning.} \end{cases}

A large replay ratio reuses the same empirical distribution many times, which is sample-average approximation; a replay ratio of one uses each transition once, which is stochastic approximation. More reuse lowers the variance of the estimates under P^Bt\hat{P}_{\mathcal{B}_t} and raises the risk of fitting the idiosyncrasies of a buffer that reflects old policies or narrow coverage.

Remark 1 (Two notions of bootstrap)

Two different “bootstraps” meet in fitted Q-iteration. Sampling with replacement from P^Bt\hat{P}_{\mathcal{B}_t} approximates expectations under the unknown PP by expectations under the empirical distribution, which is the bootstrap of statistics; mini-batch training is this resampling, and the replay ratio is the number of bootstrap samples per transition. Computing y=r+γmax⁡a′q(s′,a′;θ)y = r + \gamma \max_{a'} q(s',a';\boldsymbol{\theta}) replaces the unknown continuation value by the current estimate, which is the bootstrap of temporal-difference learning and the source of the maximization bias of the previous chapter. The buffer encodes the first, the target function the second, and the bias corrections (double estimation, learned corrections, Gumbel losses) act on the second alone.

The table places the algorithms of this chapter, and of the next, in this space.

AlgorithmApproximatorTargetFit budgetInitializationDataBias fix
FQI Ernst et al. (2005)Extra treesHard maxFullColdFixed batchNone
NFQI Riedmiller (2005)Neural netHard maxFullWarmFixed batchNone
Q-learning Watkins (1989)AnyHard maxK=1K=1WarmOne transitionNone
DQN Mnih et al. (2013)Deep netHard maxK=1K=1WarmReplay bufferNone
Double DQN Van Hasselt et al. (2016)Deep netDecoupled maxK=1K=1WarmReplay bufferDouble estimation
Soft Q Haarnoja et al. (2017)Neural netLog-sum-expKK stepsWarmReplay bufferNone

The continuous-action methods NFQCA, DDPG and SAC add one more axis, the actor that replaces the maximum in the target, and belong to the next chapter.

Regression Losses and Noise Models

At a fixed time tt, the fit is a statistical estimation problem: given samples from P^tfit\hat{P}_t^{\text{fit}}, choose θ\boldsymbol{\theta} to minimize E((s,a),y)∼P^tfit[ℓ(q(s,a;θ),y)]\mathbb{E}_{((s,a),y)\sim \hat{P}_t^{\text{fit}}}[\ell(q(s,a;\boldsymbol{\theta}), y)]. The loss ℓ\ell is a noise model for the targets. Squared error is the likelihood of Gaussian noise, absolute error of Laplace noise, Gumbel regression of extreme-value noise, and a classification loss over value bins makes no parametric assumption. Bellman targets are noisy, biased by the maximum, and bootstrapped, so the choice is not neutral, and two alternatives to squared error have done well in practice.

Gumbel Regression

Extreme value theory says that the maximum of several Gaussian errors has Gumbel-distributed tails. Garg et al. (2023) took the distribution seriously in Extreme Q-Learning (XQL): instead of modeling the error of a target as Gaussian,

yi=q∗(si,ai)+εi,εi∼N(0,σ2),y_i = q^*(s_i, a_i) + \varepsilon_i, \quad \varepsilon_i \sim \mathcal{N}(0, \sigma^2),

they model it as Gumbel,

yi=q∗(si,ai)+εi,εi∼Gumbel(0,β),y_i = q^*(s_i, a_i) + \varepsilon_i, \quad \varepsilon_i \sim \text{Gumbel}(0, \beta),

a distribution skewed to the right, because a target built from a maximum occasionally lands far above the value it estimates. With ui=q(si,ai;θ)−yiu_i = q(s_i, a_i; \boldsymbol\theta) - y_i, the negative log-likelihood is, up to constants, the Gumbel regression loss

LGumbel(θ)=∑i[exp⁡(uiβ)−uiβ−1],\mathcal{L}_{\text{Gumbel}}(\boldsymbol{\theta}) = \sum_i \left[\exp\left(\frac{u_i}{\beta}\right) - \frac{u_i}{\beta} - 1\right],

with a temperature β\beta that sets the heaviness of the tail. The loss is zero at ui=0u_i = 0 and convex, and its gradient with respect to qq is

∂LGumbel∂q=1β[exp⁡(q−yβ)−1].\frac{\partial \mathcal{L}_{\text{Gumbel}}}{\partial q} = \frac{1}{\beta}\left[\exp\left(\frac{q - y}{\beta}\right) - 1\right].

When q<yq < y the exponential is small and the gradient tends to −1/β-1/\beta, so a target far above the prediction pulls it up only linearly; when q>yq > y the gradient grows exponentially with the error. The loss penalizes overestimation much more than underestimation, which pushes the fit toward conservative values when the targets are biased upward by the maximum. Squared error is the right likelihood for averages, by the central limit theorem; Gumbel regression is the right likelihood for maxima of light-tailed noise, by extreme value theory.

Source
import sys
from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np

code_directory = Path.cwd() / "code"
if str(code_directory) not in sys.path:
    sys.path.insert(0, str(code_directory))
from book_figure_theme import INK, MUTED, PALETTE, figure_style, show

error = np.linspace(-3, 3, 500)                       # q - y
betas = {0.5: PALETTE["vermilion"], 1.0: PALETTE["orange"], 2.0: PALETTE["blue"]}

with figure_style():
    fig, (ax, bx) = plt.subplots(1, 2, figsize=(7.0, 2.5))
    for beta, color in betas.items():
        ax.plot(error, np.exp(error / beta) - error / beta - 1, color=color)
        bx.plot(error, (np.exp(error / beta) - 1) / beta, color=color)
    ax.plot(error, error ** 2, color=MUTED, lw=1, ls="--")
    bx.plot(error, 2 * error, color=MUTED, lw=1, ls="--")
    for axis in (ax, bx):
        axis.axvline(0, color=MUTED, lw=.6)
        axis.set_xlabel("error $q - y$")
        axis.set_xlim(-3, 3)
    ax.set_ylim(0, 10)
    bx.set_ylim(-5, 10)
    ax.text(1.0, 9.2, r"$\beta = 0.5$", color=betas[0.5], fontsize=8.5, ha="right")
    ax.text(1.75, 8.0, r"$\beta = 1$", color=betas[1.0], fontsize=8.5, ha="right")
    ax.text(2.95, 3.2, r"$\beta = 2$", color=betas[2.0], fontsize=8.5, ha="right")
    ax.text(-2.0, 7.4, "squared\nerror", color=MUTED, fontsize=8.5)
    bx.text(-2.9, -3.8, "squared\nerror", color=MUTED, fontsize=8.5)
    ax.set_ylabel("loss")
    bx.set_ylabel(r"derivative with respect to $q$")
    ax.set_title("(a) Gumbel loss")
    bx.set_title("(b) Its gradient")
    fig.tight_layout(w_pad=2)
show(fig)

Figure 1:Gumbel regression against squared error, as functions of the error q−yq - y of a prediction. (a) The loss exp⁡(u/β)−u/β−1\exp(u/\beta) - u/\beta - 1 grows exponentially for overestimates (q>yq > y) and linearly for underestimates; a smaller temperature β\beta makes the asymmetry sharper. (b) Its derivative with respect to qq, which sets how hard the fit pushes back: steep for overestimates, flat near −1/β-1/\beta for underestimates, while the derivative of squared error (dashed) is symmetric.

Loading...

Figure 1 draws the loss and its gradient for three temperatures. The loss handles the asymmetry of the noise on its own, with no variance to estimate and no weights to compute, and XQL has improved both value-based and actor-critic methods, in particular in offline reinforcement learning, where the bias of the maximum compounds across iterations without new data to correct it.

Remark 2 (XQL and soft Q-learning: target function against loss)

XQL and soft Q-learning both involve the Gumbel distribution, at different places in the design space. Soft Q-learning changes the target function, using the smooth Bellman operator of the regularized chapter,

gsoft(s,a,r,s′;θ)=r+γ1βlog⁡∑a′exp⁡(βq(s′,a′;θ)),g^{\text{soft}}(s,a,r,s'; \boldsymbol{\theta}) = r + \gamma \frac{1}{\beta}\log\sum_{a'} \exp(\beta q(s',a'; \boldsymbol{\theta})),

with the squared loss unchanged; the Gumbel distribution enters through the Gumbel-max construction of the log-sum-exp, which is about making the optimal policy stochastic, not about the noise of the targets. XQL keeps the hard maximum in the target and changes the loss to ℓGumbel(q,y)=exp⁡((q−y)/β)−(q−y)/β−1\ell_{\text{Gumbel}}(q,y) = \exp((q-y)/\beta) - (q-y)/\beta - 1, where the Gumbel distribution models the noise of the TD errors. The log-sum-exp reduces maximization bias by averaging over actions, a property of the target; the Gumbel loss penalizes overestimation, a property of the loss. The two can be combined.

Classification-Based Q-Learning

Nothing changes upstream: transitions are sampled from P^Bt\hat{P}_{\mathcal{B}_t} and pushed through the same target function. What changes is the representation of the value and the loss. Choose a grid z1<z2<⋯<zKz_1 < z_2 < \cdots < z_K that spans the plausible returns. The network outputs logits ℓθ(s,a)∈RK\ell_{\boldsymbol{\theta}}(s,a) \in \mathbb{R}^K, converted to probabilities and to a scalar value by

pθ(k∣s,a)=exp⁡(ℓθ(s,a)k)∑j=1Kexp⁡(ℓθ(s,a)j),q(s,a;θ)=∑k=1Kzk pθ(k∣s,a).p_{\boldsymbol{\theta}}(k \mid s,a) = \frac{\exp(\ell_{\boldsymbol{\theta}}(s,a)_k)}{\sum_{j=1}^K \exp(\ell_{\boldsymbol{\theta}}(s,a)_j)}, \quad q(s,a; \boldsymbol{\theta}) = \sum_{k=1}^K z_k \, p_{\boldsymbol{\theta}}(k \mid s,a).

Each scalar target yiy_i becomes a distribution over the bins by the two-hot encoding. If yiy_i falls between zjz_j and zj+1z_{j+1},

qj(yi)=zj+1−yizj+1−zj,qj+1(yi)=yi−zjzj+1−zj,qk(yi)=0 for k∉{j,j+1}.q_j(y_i) = \frac{z_{j+1} - y_i}{z_{j+1} - z_j}, \quad q_{j+1}(y_i) = \frac{y_i - z_j}{z_{j+1} - z_j}, \quad q_k(y_i) = 0 \text{ for } k \notin \{j, j+1\}.

These are barycentric coordinates, and ∑kzkqk(yi)=yi\sum_k z_k q_k(y_i) = y_i recovers the scalar exactly: the encoding is the linear interpolation of the finite-horizon chapter (Algorithm 2) applied to the value axis.

Source
def two_hot(y, bins):
    """Weights q_k(y): linear interpolation of y between the two bins around it."""
    q = np.zeros(len(bins))
    y = np.clip(y, bins[0], bins[-1])
    j = min(np.searchsorted(bins, y, side="right") - 1, len(bins) - 2)
    t = (y - bins[j]) / (bins[j + 1] - bins[j])
    q[j], q[j + 1] = 1 - t, t
    return q

bins = np.linspace(-5, 5, 11)
with figure_style():
    fig, (ax, bx) = plt.subplots(1, 2, figsize=(7.0, 2.3), sharey=True)
    q = two_hot(0.7, bins)
    ax.bar(bins, q, width=.55, color=PALETTE["blue"])
    ax.axvline(0.7, ymax=.88, color=PALETTE["vermilion"], lw=1.2, ls="--")
    ax.text(0.7, 1.0, "$y = 0.7$", color=PALETTE["vermilion"], fontsize=8.5, ha="center")
    for k in np.flatnonzero(q):
        side = 1 if bins[k] > 0.7 else -1
        ax.text(bins[k] + .35 * side, q[k] - .03, f"{q[k]:.1f}", ha="left" if side > 0 else "right",
                va="top", fontsize=8.5, color=INK)
    ax.text(-4.8, .55, rf"$\Sigma_k\, z_k\, q_k(y) = {bins @ q:.1f}$", fontsize=8.5, color=INK)
    ax.set_title("(a) One target")
    for y, color, shift in ((-2.3, PALETTE["green"], -.18), (0.7, PALETTE["blue"], 0), (3.8, PALETTE["purple"], .18)):
        bx.bar(bins + shift, two_hot(y, bins), width=.18, color=color)
        bx.text(y, 1.0, f"$y = {y}$", color=color, fontsize=8.5, ha="center")
    bx.set_title("(b) Three targets")
    for axis in (ax, bx):
        axis.set_xticks(bins, [f"${b:.0f}$" for b in bins])
        axis.set_xlabel("bin value $z_k$")
    ax.set_ylabel("weight $q_k(y)$")
    ax.set_ylim(0, 1.12)
    fig.tight_layout(w_pad=2)
show(fig)

Figure 2:Two-hot encoding on 11 bins spanning [−5,5][-5, 5]. (a) The target y=0.7y = 0.7 puts weight 0.7 on the bin at 1 and 0.3 on the bin at 0, the barycentric coordinates of 0.7 between them, so that the weighted average of the bins is 0.7 again. (b) Three targets, each spread over the two bins around it.

Loading...

In Figure 2, each target puts its mass on the two bins around it, with a weight that decreases with the distance to each bin. The loss is the cross-entropy

LCE(θ)=−E((s,a),y)∼P^tfit[∑k=1Kqk(y)log⁡pθ(k∣s,a)],\mathcal{L}_{\text{CE}}(\boldsymbol{\theta}) = -\mathbb{E}_{((s,a),y) \sim \hat{P}_t^{\text{fit}}}\left[ \sum_{k=1}^K q_k(y) \log p_{\boldsymbol{\theta}}(k \mid s, a) \right],

which projects the target distribution onto the predicted one in the geometry of the simplex rather than of the real line. Its gradient with respect to the logits is pθ−qp_{\boldsymbol\theta} - q, bounded whatever the size of the target. This is where its robustness comes from. Each sample contributes a bounded gradient per bin, where squared error contributes a gradient proportional to the error; the finite grid clips extreme targets to its end bins, so that an outlier cannot set the scale of the regression; and the two-hot encoding spreads each target over two bins, a label smoothing that averages noisy targets at the same (s,a)(s,a). The encoding is an averager in the sense of Definition 1, a convex combination that preserves order and bounds, paired with a network that is not, so that classification-based Q-learning is a hybrid of a monotone target structure and a flexible fit. Farebrother et al. (2024) found that DQN and CQL with squared error degrade when the Q-network is scaled to a large ResNet, while the classification loss (HL-Gauss, which smooths the target with a Gaussian instead of the two-hot encoding) keeps its performance.

Exercises

The first exercises are short checks. The others follow the chapter: the loops and targets of DQN, then the design space.

Solution to Exercise 1

The outer loop freezes the current Q-function and constructs Bellman targets. The inner loop fits a new function approximator to those targets.

Solution to Exercise 2

It slows the movement of regression targets. Without it, each parameter update simultaneously changes the predictions and the targets being fitted, creating a rapidly moving objective.

Solution to Exercise 3
  1. n=⌊12,345/500⌋=24n = \lfloor 12{,}345/500 \rfloor = 24 and k=12,345−24×500=345k = 12{,}345 - 24 \times 500 = 345.

  2. θ24\boldsymbol{\theta}_{24}, the parameters at the end of outer iteration 23, held in the target network since step 12,00012{,}000.

  3. (1−τ)/τ=(K−1)/2(1-\tau)/\tau = (K-1)/2 gives τ=2/(K+1)≈2×10−4\tau = 2/(K+1) \approx 2 \times 10^{-4}. The typical values τ∈[10−3,10−2]\tau \in [10^{-3}, 10^{-2}] of DDPG and TD3 correspond to copies every 200 to 2,000 steps.

Solution to Exercise 4
  1. DQN: 0.5+0.9×max⁡(1.2,1.0,1.1)=1.580.5 + 0.9 \times \max(1.2, 1.0, 1.1) = 1.58. Double DQN: the online network selects the second action, which the target network values at 1.0, so 0.5+0.9×1.0=1.400.5 + 0.9 \times 1.0 = 1.40.

  2. DQN: the target network both selects the first action and values it.

  3. The true target is 0.5+0.9=1.400.5 + 0.9 = 1.40. Double DQN hits it, and DQN overestimates by 0.18 because it values the action that the noise of its own estimate made look best, the evaluation bias.

Solution to Exercise 5
  1. Bootstrapping and off-policy data, but the fit is an averager once the partitions are frozen, so Theorem 1 applies to the empirical Bellman operator.

  2. All three. No guarantee; warm starts and fits run to convergence on fixed targets limit the damage.

  3. All three, with a buffer that moves. No guarantee; the target network, the warm start and the large buffer are the mitigations.

  4. Bootstrapping and off-policy data, but a table is an averager in the trivial sense. Convergence follows from the ODE method under decreasing step sizes and visits to every pair.

  5. Linear features and bootstrapping, but on-policy data, so the projected operator contracts in the ξ\xi-norm (Function Iteration Can Diverge).

Solution to Exercise 6
  1. With Gaussian ε\varepsilon, the negative log-likelihood of yy is (q−y)2/2σ2(q - y)^2/2\sigma^2 plus a constant. With Gumbel ε=y−q\varepsilon = y - q, it is ε/β+e−ε/β\varepsilon/\beta + e^{-\varepsilon/\beta} plus a constant; writing u=q−y=−εu = q - y = -\varepsilon gives eu/β−u/βe^{u/\beta} - u/\beta, the Gumbel loss up to the constant -1.

  2. It is an averager (Definition 1) applied on the value axis, and it reuses the linear interpolation with nonnegative weights of Algorithm 2.

  3. Fitting the ratio y/(C 10ρ)y/(C\,10^{\rho}) assumes that errors are proportional to the predicted cost rather than additive, a multiplicative noise model, so one large cost no longer dominates the squared error of its leaf. A classification loss would have clipped the 2,070 target to the top bin, which bounds its influence too, but loses the information of how large the cost was.

Solution to Exercise 7

This exercise is open-ended. The chapter’s two buffers bound the answer: the broad one covers everything and still loses 5% of the return near the switching curve, where the action values differ by at most 1.24. A good design concentrates data on the states next to that curve, where the action gap is small and errors in the ranking are likely, and spends little on states far from it, where any reasonable fit ranks the actions correctly.

Summary

Writing out the gradient steps of a neural fit and merging them with the outer loop produces the online and target networks of DQN: the target network is the outer iteration’s parameters kept in memory, and the online network is the inner iterate, which also collects the data once the buffer is allowed to evolve. Double DQN changes only the target function, to decouple selection from evaluation, and Q-learning is the limit of one transition per update, a stochastic approximation whose convergence the ODE method establishes for tables. All of them occupy one design space, with a buffer, a target function and a fit as its coordinates, and the loss of the fit is a noise model for the targets, which Gumbel regression and classification losses match better than squared error.

Fitted Q-iteration can now learn action values from fixed or evolving buffers, but every target still requires max⁡aq(s,a)\max_a q(s,a). What happens when that action search is itself a nonlinear program? Amortized action optimization learns an actor to replace the repeated search while retaining the fitted-Q critic.

References
  1. Lillicrap, T. P., Hunt, J. J., Pritzel, A., Heess, N., Erez, T., Tassa, Y., Silver, D., & Wierstra, D. (2015). Continuous Control with Deep Reinforcement Learning. arXiv Preprint arXiv:1509.02971.
  2. Fujimoto, S., Hoof, H., & Meger, D. (2018). Addressing Function Approximation Error in Actor-Critic Methods. International Conference on Machine Learning (ICML), 1587–1596.
  3. Haarnoja, T., Zhou, A., Abbeel, P., & Levine, S. (2018). Soft actor-critic: Off-policy maximum entropy deep reinforcement learning with a stochastic actor. Proceedings of the 35th International Conference on Machine Learning (ICML), 1861–1870.
  4. Mnih, V., Kavukcuoglu, K., Silver, D., Rusu, A. A., Veness, J., Bellemare, M. G., Graves, A., Riedmiller, M., Fidjeland, A. K., Ostrovski, G., & others. (2013). Playing Atari with Deep Reinforcement Learning. NIPS Deep Learning Workshop.
  5. Zhang, S., Yao, H., & Whiteson, S. (2021). Breaking the Deadly Triad with a Target Network. Proceedings of the 38th International Conference on Machine Learning.
  6. Fellows, M., Smith, M. J. A., & Whiteson, S. (2023). Why Target Networks Stabilise Temporal Difference Methods. Proceedings of the 40th International Conference on Machine Learning.
  7. Gallici, M., Fellows, M., Ellis, B., Pou, B., Masmitja, I., Foerster, J., & Martin, M. (2025). Simplifying Deep Temporal Difference Learning. International Conference on Learning Representations.
  8. Van Hasselt, H., Guez, A., & Silver, D. (2016). Deep Reinforcement Learning with Double Q-learning. Proceedings of the AAAI Conference on Artificial Intelligence, 30(1).
  9. Watkins, C. J. C. H. (1989). Learning from Delayed Rewards [Phdthesis]. University of Cambridge.
  10. Watkins, C. J. C. H., & Dayan, P. (1992). Q-learning. Machine Learning, 8(3–4), 279–292.
  11. Jaakkola, T., Jordan, M. I., & Singh, S. P. (1994). Convergence of Stochastic Iterative Dynamic Programming Algorithms. Neural Computation, 6(6), 1185–1201.
  12. Tsitsiklis, J. N. (1994). Asynchronous Stochastic Approximation and Q-Learning. Machine Learning, 16(3), 185–202.
  13. Kushner, H. J., & Yin, G. G. (2003). Stochastic Approximation and Recursive Algorithms and Applications (2nd ed., Vol. 35). Springer.
  14. Borkar, V. S., & Meyn, S. P. (2000). ODE Methods for Temporal Difference Learning. SIAM Journal on Control and Optimization, 38(2), 447–465.
  15. Ernst, D., Geurts, P., & Wehenkel, L. (2005). Tree-Based Batch Mode Reinforcement Learning. Journal of Machine Learning Research, 6, 503–556.