Skip to content
Ahmed Haroon
← Reinforcement Learning

Value-Based Reinforcement Learning

From Tables to Function Approximation

Tabular Q-learning stores one number for every state-action pair:

Q:S×A→R.Q:\mathcal S\times\mathcal A\to\mathbb R.

This works for small finite problems, but not when states are images, state variables are continuous, or most state-action pairs are never observed. A table also treats every pair as unrelated.

We instead learn a parameterized function

Qθ(s,a)≈Q(s,a).Q_\theta(s,a)\approx Q(s,a).

Changing θ\theta for one example can then change predictions for similar examples. For a discrete action space, a neural network commonly receives a state and emits every action value at once:

fθ(s)=[Qθ(s,a1)⋯Qθ(s,a∣A∣)].f_\theta(s) = \begin{bmatrix} Q_\theta(s,a_1)&\cdots&Q_\theta(s,a_{|\mathcal A|}) \end{bmatrix}.

The greedy action only requires one forward pass:

πθ(s)=arg⁡max⁡aQθ(s,a).\pi_\theta(s)=\arg\max_a Q_\theta(s,a).

Value learning as regression

Suppose an oracle supplied the true label y=Qπ(s,a)y=Q^\pi(s,a). We could minimize

ℓ(θ)=12(y−Qθ(s,a))2.\ell(\theta) =\frac12\left(y-Q_\theta(s,a)\right)^2.

The resulting gradient update is

θ←θ+α(y−Qθ(s,a))∇θQθ(s,a).\boxed{ \theta \leftarrow \theta+ \alpha\left(y-Q_\theta(s,a)\right) \nabla_\theta Q_\theta(s,a) }.
See derivation

Because the target yy is fixed,

∇θℓ(θ)=12⋅2(y−Qθ(s,a))∇θ(y−Qθ(s,a))=−(y−Qθ(s,a))∇θQθ(s,a).\begin{aligned} \nabla_\theta\ell(\theta) &=\frac12\cdot2\left(y-Q_\theta(s,a)\right) \nabla_\theta\left(y-Q_\theta(s,a)\right)\\ &=-\left(y-Q_\theta(s,a)\right) \nabla_\theta Q_\theta(s,a). \end{aligned}

Therefore gradient descent gives

θ←θ−α∇θℓ(θ)=θ+α(y−Qθ(s,a))∇θQθ(s,a).\begin{aligned} \theta &\leftarrow\theta-\alpha\nabla_\theta\ell(\theta)\\ &=\theta+ \alpha\left(y-Q_\theta(s,a)\right) \nabla_\theta Q_\theta(s,a). \end{aligned}

The true value is unavailable, so value-based methods differ mainly in how they construct the target yy.

Monte Carlo and temporal-difference targets

After a complete trajectory, Monte Carlo learning uses the sampled return

Gt=∑k=0T−t−1γkrt+k.G_t=\sum_{k=0}^{T-t-1}\gamma^k r_{t+k}.

The update is

θ←θ+α(Gt−Qθ(st,at))∇θQθ(st,at).\theta\leftarrow\theta+ \alpha\left(G_t-Q_\theta(s_t,a_t)\right) \nabla_\theta Q_\theta(s_t,a_t).

This target is noisy, but it does not depend on another learned value estimate.

For on-policy SARSA,

ytSARSA=rt+γQθ(st+1,at+1),at+1∼π(⋅∣st+1).y_t^{\mathrm{SARSA}} =r_t+\gamma Q_\theta(s_{t+1},a_{t+1}), \qquad a_{t+1}\sim\pi(\cdot\mid s_{t+1}).

For off-policy Q-learning,

ytQ=rt+γmax⁡a′Qθ(st+1,a′).\boxed{ y_t^Q =r_t+\gamma\max_{a'}Q_\theta(s_{t+1},a') }.

The Q-learning update is therefore

θ←θ+αδt∇θQθ(st,at),\boxed{ \theta\leftarrow\theta+ \alpha\delta_t\nabla_\theta Q_\theta(s_t,a_t) },

where

δt=rt+γmax⁡a′Qθ(st+1,a′)−Qθ(st,at)\delta_t =r_t+\gamma\max_{a'}Q_\theta(s_{t+1},a') -Q_\theta(s_t,a_t)

is the temporal-difference error.

For state-value policy evaluation, the same idea gives

w←w+α[rt+γVw(st+1)−Vw(st)]∇wVw(st).w\leftarrow w+ \alpha\left[r_t+\gamma V_w(s_{t+1})-V_w(s_t)\right] \nabla_wV_w(s_t).

If Vw(s)=w⊤x(s)V_w(s)=w^\top x(s), then ∇wVw(s)=x(s)\nabla_wV_w(s)=x(s) and

w←w+αδtx(st).w\leftarrow w+\alpha\delta_t x(s_t).

Why this is a semi-gradient

The Q-learning label contains the network being trained:

yθ=r+γmax⁡a′Qθ(s′,a′).y_\theta=r+\gamma\max_{a'}Q_\theta(s',a').

Standard Q-learning deliberately treats yθy_\theta as fixed during the current update. It differentiates the prediction but not the target. This is a semi-gradient update.

See derivation

Let

a∗=arg⁡max⁡a′Qθ(s′,a′)a^*=\arg\max_{a'}Q_\theta(s',a')

and define

δθ=r+γQθ(s′,a∗)−Qθ(s,a).\delta_\theta =r+\gamma Q_\theta(s',a^*)-Q_\theta(s,a).

Ignoring nondifferentiability at action ties, the full gradient of the squared Bellman error is

∇θ12δθ2=δθ∇θδθ=δθ[γ∇θQθ(s′,a∗)−∇θQθ(s,a)].\begin{aligned} \nabla_\theta\frac12\delta_\theta^2 &=\delta_\theta\nabla_\theta\delta_\theta\\ &=\delta_\theta \left[ \gamma\nabla_\theta Q_\theta(s',a^*) -\nabla_\theta Q_\theta(s,a) \right]. \end{aligned}

True gradient descent would use

θ←θ+αδθ[∇θQθ(s,a)−γ∇θQθ(s′,a∗)].\theta\leftarrow\theta+ \alpha\delta_\theta \left[ \nabla_\theta Q_\theta(s,a) -\gamma\nabla_\theta Q_\theta(s',a^*) \right].

The semi-gradient update omits the second term:

θ←θ+αδθ∇θQθ(s,a).\theta\leftarrow\theta+ \alpha\delta_\theta\nabla_\theta Q_\theta(s,a).

This is not ordinary regression to permanent labels. Updating θ\theta changes both current predictions and future targets, so learning becomes a moving fixed-point problem.

Fitted Q-Iteration

Exact value iteration repeatedly applies the optimal Bellman operator:

(TQ)(s,a)=r(s,a)+γEs′∼P(⋅∣s,a)[max⁡a′Q(s′,a′)].(TQ)(s,a) =r(s,a)+\gamma \mathbb E_{s'\sim P(\cdot\mid s,a)} \left[\max_{a'}Q(s',a')\right].

The optimal action-value function is its fixed point:

Q∗=TQ∗.Q^*=TQ^*.

With function approximation, the backed-up function may not belong to the representable class. We therefore apply a Bellman backup and regress back into that class:

Qk+1≈ΠTQk.Q_{k+1}\approx\Pi TQ_k.

Suppose we have a transition dataset

D={(si,ai,ri,si′,di)}i=1N,\mathcal D =\{(s_i,a_i,r_i,s_i',d_i)\}_{i=1}^{N},

where di=1d_i=1 indicates a true terminal transition. At outer iteration kk, freeze the previous Q-function and construct

yi(k)=ri+γ(1−di)max⁡a′Qθk(si′,a′).\boxed{ y_i^{(k)} =r_i+\gamma(1-d_i) \max_{a'}Q_{\theta_k}(s_i',a') }.

We then solve the supervised regression problem

θk+1=arg⁡min⁡θ12N∑i=1N[Qθ(si,ai)−yi(k)]2.\boxed{ \theta_{k+1} =\arg\min_\theta \frac{1}{2N}\sum_{i=1}^{N} \left[Q_\theta(s_i,a_i)-y_i^{(k)}\right]^2 }.
Fitted Q-Iteration\textbf{Fitted Q-Iteration}Collect a transition dataset D.Initialize Qθ0.For k=0,1,…,K−1:yi(k)←ri+γ(1−di)max⁡a′Qθk(si′,a′)∀i,θk+1←arg⁡min⁡θ12N∑i[Qθ(si,ai)−yi(k)]2.Return QθK.\begin{aligned} &\text{Collect a transition dataset }\mathcal D.\\[0.25em] &\text{Initialize }Q_{\theta_0}.\\[0.25em] &\text{For }k=0,1,\ldots,K-1:\\[0.25em] &\qquad y_i^{(k)}\leftarrow r_i+\gamma(1-d_i)\max_{a'}Q_{\theta_k}(s_i',a') \quad\forall i,\\[0.25em] &\qquad \theta_{k+1}\leftarrow \arg\min_\theta\frac1{2N}\sum_i \left[Q_\theta(s_i,a_i)-y_i^{(k)}\right]^2.\\[0.25em] &\text{Return }Q_{\theta_K}. \end{aligned}

For fixed θk\theta_k, the inner loop has stationary labels. This separates target construction from regression and makes the moving-target problem easier to control.

Fitted value iteration would require

max⁡a[r(s,a)+γEs′V(s′)]\max_a\left[r(s,a)+\gamma \mathbb E_{s'}V(s')\right]

for every candidate action. A sampled transition reveals only the outcome of the action that was taken. Learning Q(s,a)Q(s,a) avoids this problem: every transition provides a one-sample target for its observed action, while the next action is evaluated through the learned Q-function.

Let μ\mu be the behavior policy. Its transition distribution factors as

pμ(s,a,r,s′)=dμ(s)μ(a∣s)p(r,s′∣s,a).p_\mu(s,a,r,s') =d_\mu(s)\mu(a\mid s)p(r,s'\mid s,a).

Conditioned on (s,a)(s,a), the outcome distribution p(r,s′∣s,a)p(r,s'\mid s,a) does not depend on μ\mu. The target also uses a greedy next action rather than an action from μ\mu:

r+γmax⁡a′Q(s′,a′).r+\gamma\max_{a'}Q(s',a').

Transitions collected by one policy can therefore train values for a different, greedy policy. However, off-policy learning still requires coverage. No algorithm can infer reliable values for important regions that are absent from the dataset.

Fitted Q-iteration, online Q-learning, and DQN mainly differ in their schedules:

MethodDataTarget refreshRegression per refresh
Online Q-learningLatest transitionEvery updateOne step
DQNReplay bufferSlowly through a target networkA few minibatch steps
Fitted Q-iterationFixed batchAfter an inner fitting phaseMany steps

The Deadly Triad

Approximate value learning becomes especially unstable when it combines:

  1. function approximation, which shares parameters across predictions;
  2. bootstrapping, which uses learned values inside targets;
  3. off-policy learning, which trains under a distribution different from the target policy's distribution.

Each ingredient is valuable. Together, they can produce oscillation or divergence.

The idealized fitted update is

Qk+1=ΠTQk.Q_{k+1}=\Pi TQ_k.

The exact Bellman operator is a contraction in the sup norm:

∥TQ−TU∥∞≤γ∥Q−U∥∞.\|TQ-TU\|_\infty \leq\gamma\|Q-U\|_\infty.

But regression usually defines Π\Pi through a replay-weighted squared loss:

Πf=arg⁡min⁡Q∈ΩE(s,a)∼dD[(Q(s,a)−f(s,a))2].\Pi f =\arg\min_{Q\in\Omega} \mathbb E_{(s,a)\sim d_\mathcal D} \left[(Q(s,a)-f(s,a))^2\right].

This projection is controlled in a distribution-weighted L2L_2 geometry, not necessarily in L∞L_\infty. The regression step can therefore undo the contraction created by the Bellman backup.

Bootstrapping then creates a feedback loop:

value error⟶incorrect target⟶shared parameter update⟶new value errors.\text{value error} \longrightarrow \text{incorrect target} \longrightarrow \text{shared parameter update} \longrightarrow \text{new value errors}.

Off-policy data aggravates the problem. The greedy max may select an action that has weak replay support and a large approximation error:

distribution mismatch→poorly constrained value→max⁡ selects the error→bootstrapping spreads it.\text{distribution mismatch} \to \text{poorly constrained value} \to \max\text{ selects the error} \to \text{bootstrapping spreads it}.

Typical symptoms include exploding Q-values, NaNs, oscillating returns, sensitivity to random seeds, and falling Bellman loss without improving policy performance.

Experience Replay

During interaction, we store transitions

(st,at,rt,st+1,dt)(s_t,a_t,r_t,s_{t+1},d_t)

in a finite replay buffer D\mathcal D. Training samples random minibatches

{(si,ai,ri,si′,di)}i=1B∼D.\{(s_i,a_i,r_i,s_i',d_i)\}_{i=1}^{B} \sim\mathcal D.

Replay converts an environment stream into an empirical dataset:

interaction⟶stored transitions⟶random minibatch regression.\text{interaction} \longrightarrow \text{stored transitions} \longrightarrow \text{random minibatch regression}.

It helps in two ways. First, random batches reduce the short-range temporal correlation in

st→st+1→st+2.s_t\to s_{t+1}\to s_{t+2}.

Second, transitions can be reused for many updates. This improves sample efficiency and lets newly learned values propagate backward through older experiences.

Replay does not make data truly independent. It also creates a new training distribution:

d^D(s,a)=1∣D∣∑i=1∣D∣1[(si,ai)=(s,a)].\widehat d_\mathcal D(s,a) =\frac1{|\mathcal D|} \sum_{i=1}^{|\mathcal D|} \mathbb 1[(s_i,a_i)=(s,a)].

This is a mixture of many historical behavior policies. Large buffers improve diversity but retain stale experience. Small buffers adapt quickly but forget rare transitions and contain more correlated samples. Uniform sampling can also let common transitions dominate rare failures or rewards.

Most importantly, replay only constrains observed state-action pairs. A greedy policy may exploit high values in unsupported regions, especially in continuous or offline problems.

Target Networks

Naive deep Q-learning uses the same parameters for the prediction and target:

yθ=r+γmax⁡a′Qθ(s′,a′).y_\theta=r+\gamma\max_{a'}Q_\theta(s',a').

Every update changes both sides of the regression problem. A target network separates them:

yi=ri+γ(1−di)max⁡a′Qθˉ(si′,a′),\boxed{ y_i =r_i+\gamma(1-d_i) \max_{a'}Q_{\bar\theta}(s_i',a') },

where θ\theta is optimized and θˉ\bar\theta changes slowly.

For fixed θˉ\bar\theta, the loss

L(θ;θˉ)=12B∑i=1B[Qθ(si,ai)−yi]2L(\theta;\bar\theta) =\frac1{2B}\sum_{i=1}^{B} \left[Q_\theta(s_i,a_i)-y_i\right]^2

is ordinary regression to stationary minibatch labels.

Hard target updates

Every CC environment or gradient steps, copy the online parameters:

θˉ←θ.\boxed{\bar\theta\leftarrow\theta}.

Longer intervals make targets more stable but more stale. Each synchronization also produces an abrupt change in the labels.

Soft target updates

Polyak averaging moves the target gradually:

θˉ←ρθˉ+(1−ρ)θ,ρ≈1.\boxed{ \bar\theta \leftarrow \rho\bar\theta+(1-\rho)\theta, \qquad \rho\approx1 }.

Some sources instead write

θˉ←τθ+(1−τ)θˉ,τ≪1.\bar\theta \leftarrow \tau\theta+(1-\tau)\bar\theta, \qquad \tau\ll1.

These are the same update with τ=1−ρ\tau=1-\rho. Unrolling it shows that the target is an exponentially weighted average of historical online networks:

θˉt=ρtθˉ0+(1−ρ)∑j=0t−1ρjθt−j.\bar\theta_t =\rho^t\bar\theta_0 +(1-\rho)\sum_{j=0}^{t-1}\rho^j\theta_{t-j}.

Target networks slow target movement; they do not eliminate it. The Bellman target must also be detached so that gradients do not flow through QθˉQ_{\bar\theta}.

Deep Q-Networks

A Deep Q-Network combines:

  • a neural Q-function QθQ_\theta;
  • an ϵ\epsilon-greedy behavior policy;
  • an experience-replay buffer;
  • a slowly updated target network QθˉQ_{\bar\theta}.

For a sampled transition, the DQN target is

yiDQN=ri+γ(1−di)max⁡a′Qθˉ(si′,a′).\boxed{ y_i^{\mathrm{DQN}} =r_i+\gamma(1-d_i) \max_{a'}Q_{\bar\theta}(s_i',a') }.

The terminal mask matters. If di=1d_i=1, then yi=riy_i=r_i because no future return exists. Time-limit truncations should not automatically be treated as true terminal states when the environment distinguishes them.

The squared Bellman loss is

LMSE(θ)=12B∑i=1B[Qθ(si,ai)−yi]2.L_{\mathrm{MSE}}(\theta) =\frac1{2B}\sum_{i=1}^{B} \left[Q_\theta(s_i,a_i)-y_i\right]^2.

Large TD errors produce large gradients. The Huber loss is quadratic near zero and linear for extreme residuals:

ℓκ(δ)={12δ2,∣δ∣≤κ,κ(∣δ∣−12κ),∣δ∣>κ.\ell_\kappa(\delta) = \begin{cases} \frac12\delta^2,&|\delta|\leq\kappa,\\[4pt] \kappa\left(|\delta|-\frac12\kappa\right),&|\delta|>\kappa. \end{cases}

Its derivative is capped at magnitude κ\kappa, making individual outliers less destructive.

The behavior policy chooses

at={a uniformly random action,with probability ϵt,arg⁡max⁡aQθ(st,a),with probability 1−ϵt.a_t= \begin{cases} \text{a uniformly random action},&\text{with probability }\epsilon_t,\\[3pt] \arg\max_aQ_\theta(s_t,a),&\text{with probability }1-\epsilon_t. \end{cases}

We usually start with high exploration and decay ϵt\epsilon_t. Decaying too quickly leaves replay concentrated around a poor early policy; decaying too slowly wastes interaction after useful values have emerged.

Deep Q-Network\textbf{Deep Q-Network}Initialize replay buffer D and online parameters θ.θˉ←θ.For each environment step t:at←ϵt-greedy action from Qθ(st,⋅),execute at and observe (rt,st+1,dt),D←D∪{(st,at,rt,st+1,dt)},{(si,ai,ri,si′,di)}i=1B∼D,yi←ri+γ(1−di)max⁡a′Qθˉ(si′,a′),θ←arg⁡min⁡θ1B∑iℓ(yi−Qθ(si,ai)),update θˉ with a hard copy or Polyak averaging.\begin{aligned} &\text{Initialize replay buffer }\mathcal D\text{ and online parameters }\theta.\\[0.25em] &\bar\theta\leftarrow\theta.\\[0.25em] &\text{For each environment step }t:\\[0.25em] &\qquad a_t\leftarrow\epsilon_t\text{-greedy action from }Q_\theta(s_t,\cdot),\\[0.25em] &\qquad \text{execute }a_t\text{ and observe }(r_t,s_{t+1},d_t),\\[0.25em] &\qquad \mathcal D\leftarrow\mathcal D\cup \{(s_t,a_t,r_t,s_{t+1},d_t)\},\\[0.25em] &\qquad \{(s_i,a_i,r_i,s_i',d_i)\}_{i=1}^{B}\sim\mathcal D,\\[0.25em] &\qquad y_i\leftarrow r_i+\gamma(1-d_i) \max_{a'}Q_{\bar\theta}(s_i',a'),\\[0.25em] &\qquad \theta\leftarrow\arg\min_\theta \frac1B\sum_i\ell\left(y_i-Q_\theta(s_i,a_i)\right),\\[0.25em] &\qquad \text{update }\bar\theta\text{ with a hard copy or Polyak averaging.} \end{aligned}

In practice, we usually delay learning until replay contains enough diverse transitions. We monitor both realized returns and predicted Q-values because training loss alone can be misleading.

Overestimation and Double DQN

Suppose action-value estimates contain zero-mean noise:

Q^(s′,a)=Q(s′,a)+εa,E[εa]=0.\widehat Q(s',a)=Q(s',a)+\varepsilon_a, \qquad \mathbb E[\varepsilon_a]=0.

Even when each action estimate is unbiased,

E[max⁡aQ^(s′,a)]≥max⁡aE[Q^(s′,a)].\boxed{ \mathbb E\left[\max_a\widehat Q(s',a)\right] \geq \max_a\mathbb E\left[\widehat Q(s',a)\right] }.

The maximum preferentially selects positive errors. If two actions both have true value qq, then

max⁡(Q^1,Q^2)=q+max⁡(ε1,ε2),\max(\widehat Q_1,\widehat Q_2) =q+\max(\varepsilon_1,\varepsilon_2),

whose expectation is larger than qq for non-degenerate symmetric noise.

Standard DQN uses the target network both to select and evaluate the action:

max⁡a′Qθˉ(s′,a′)=Qθˉ(s′,arg⁡max⁡a′Qθˉ(s′,a′)).\max_{a'}Q_{\bar\theta}(s',a') =Q_{\bar\theta} \left(s',\arg\max_{a'}Q_{\bar\theta}(s',a')\right).

Double DQN decouples these roles. The online network selects the action, while the target network evaluates it:

ai∗=arg⁡max⁡a′Qθ(si′,a′),yiDDQN=ri+γ(1−di)Qθˉ(si′,ai∗).\boxed{ \begin{aligned} a_i^*&=\arg\max_{a'}Q_\theta(s_i',a'),\\ y_i^{\mathrm{DDQN}} &=r_i+\gamma(1-d_i)Q_{\bar\theta}(s_i',a_i^*). \end{aligned} }

Because the estimators' errors are not identical, positive selection noise is less likely to remain positive during evaluation. This small modification often improves value accuracy.

With two independent critics, clipped double-Q uses

y=r+γ(1−d)min⁡j∈{1,2}Qθˉj(s′,a′).y=r+\gamma(1-d) \min_{j\in\{1,2\}}Q_{\bar\theta_j}(s',a').

The minimum deliberately adds pessimism to counter optimistic feedback. It can also underestimate value, so the goal is stable policy improvement rather than pointwise unbiasedness.

Faster Value Propagation

Deep Q-learning couples three rates:

  1. how quickly transitions enter replay;
  2. how quickly θ\theta fits the current targets;
  3. how quickly θˉ\bar\theta changes those targets.

The update-to-data ratio is

UTD=gradient updatesnew environment transitions.\mathrm{UTD} =\frac{\text{gradient updates}}{\text{new environment transitions}}.

With batch size BB, the replay-sample ratio is approximately

B×UTD.B\times\mathrm{UTD}.

A higher UTD extracts more learning from expensive interaction and propagates value faster. But repeatedly fitting a finite buffer can overfit stale data and amplify bootstrapping errors before new experience corrects them.

One-step backups move a delayed reward backward one transition at a time. An nn-step target moves it across several transitions:

yt(n)=∑k=0n−1γkrt+k+γn(1−dt:t+n)max⁡aQθˉ(st+n,a).\boxed{ y_t^{(n)} =\sum_{k=0}^{n-1}\gamma^k r_{t+k} +\gamma^n(1-d_{t:t+n}) \max_aQ_{\bar\theta}(s_{t+n},a) }.
See derivation

Starting from

Gt=rt+γGt+1,G_t=r_t+\gamma G_{t+1},

we recursively expand

Gt=rt+γrt+1+γ2Gt+2=⋯=∑k=0n−1γkrt+k+γnGt+n.\begin{aligned} G_t &=r_t+\gamma r_{t+1}+\gamma^2G_{t+2}\\ &=\cdots\\ &=\sum_{k=0}^{n-1}\gamma^k r_{t+k}+\gamma^nG_{t+n}. \end{aligned}

We then bootstrap the remaining return:

Gt+n≈max⁡aQθˉ(st+n,a).G_{t+n}\approx\max_aQ_{\bar\theta}(s_{t+n},a).

Multi-step targets reduce dependence on one-step value estimates and learn faster from delayed reward. They also have higher variance and greater off-policy mismatch because their intermediate rewards were generated by the behavior policy.

Huber loss limits extreme residuals. Gradient clipping separately limits the final parameter gradient:

g←{g,∥g∥2≤c,cg∥g∥2,∥g∥2>c.g\leftarrow \begin{cases} g,&\|g\|_2\leq c,\\[3pt] c\dfrac{g}{\|g\|_2},&\|g\|_2>c. \end{cases}

The first operates on TD errors; the second operates after all chain-rule factors have been combined.

Continuous Actions

DQN can enumerate a finite action set. For a∈Rma\in\mathbb R^m, both the target

y=r+γmax⁡a′Q(s′,a′)y=r+\gamma\max_{a'}Q(s',a')

and greedy behavior

π(s)=arg⁡max⁡aQ(s,a)\pi(s)=\arg\max_aQ(s,a)

require a continuous optimization problem.

One option is iterative gradient ascent in action space:

a(j+1)=ΠA[a(j)+η∇aQθ(s,a(j))].a^{(j+1)} =\Pi_\mathcal A \left[a^{(j)}+\eta\nabla_aQ_\theta(s,a^{(j)})\right].

This adds an expensive, initialization-sensitive inner loop to every target and action selection.

Sampling actions

Random shooting samples candidates a1,…,aN∼q(a∣s)a_1,\ldots,a_N\sim q(a\mid s) and approximates

max⁡aQ(s,a)≈max⁡i=1,…,NQ(s,ai).\max_aQ(s,a) \approx \max_{i=1,\ldots,N}Q(s,a_i).

It is simple and parallelizable, but its sample requirement grows quickly with action dimension.

The cross-entropy method improves the proposal iteratively. Starting with q0(a)=N(μ0,Σ0)q_0(a)=\mathcal N(\mu_0,\Sigma_0), it samples actions, keeps an elite set Ej\mathcal E_j, and refits

μj+1=1∣Ej∣∑i∈Ejai,\mu_{j+1}=\frac1{|\mathcal E_j|} \sum_{i\in\mathcal E_j}a_i, Σj+1=1∣Ej∣∑i∈Ej(ai−μj+1)(ai−μj+1)⊤.\Sigma_{j+1} =\frac1{|\mathcal E_j|} \sum_{i\in\mathcal E_j} (a_i-\mu_{j+1})(a_i-\mu_{j+1})^\top.

Each iteration concentrates samples around actions with larger predicted value.

Learning the argmax

Instead of solving a new optimization problem for every state, we can learn an actor

μψ(s)≈arg⁡max⁡aQϕ(s,a).\mu_\psi(s)\approx\arg\max_aQ_\phi(s,a).

The actor maximizes

J(ψ)=Es∼D[Qϕ(s,μψ(s))].J(\psi) =\mathbb E_{s\sim\mathcal D} \left[Q_\phi(s,\mu_\psi(s))\right].

By the chain rule,

∇ψJ(ψ)=Es∼D[∇aQϕ(s,a)∣a=μψ(s)∇ψμψ(s)].\boxed{ \nabla_\psi J(\psi) =\mathbb E_{s\sim\mathcal D} \left[ \left.\nabla_aQ_\phi(s,a)\right|_{a=\mu_\psi(s)} \nabla_\psi\mu_\psi(s) \right] }.

The actor amortizes continuous optimization into one forward pass. DDPG uses target actors and critics to construct

yi=ri+γ(1−di)Qϕˉ(si′,μψˉ(si′)).\boxed{ y_i =r_i+\gamma(1-d_i) Q_{\bar\phi}(s_i',\mu_{\bar\psi}(s_i')) }.

The critic minimizes

LQ(ϕ)=12B∑i[Qϕ(si,ai)−yi]2,L_Q(\phi) =\frac1{2B}\sum_i \left[Q_\phi(s_i,a_i)-y_i\right]^2,

while the actor ascends Qϕ(s,μψ(s))Q_\phi(s,\mu_\psi(s)). From this view, deterministic actor-critic is approximate Q-learning in which the actor learns to perform the continuous-action maximization.

Modern methods often use stochastic actors, entropy regularization, and twin critics. These extensions belong to actor-critic methods, but they retain the same value-based core: fit a critic to a slowly moving Bellman target, then improve the policy using that critic.

Why Exact Value Iteration Converges

The optimal Bellman operator is a γ\gamma-contraction in the sup norm:

∥TQ−TU∥∞≤γ∥Q−U∥∞.\boxed{ \|TQ-TU\|_\infty \leq\gamma\|Q-U\|_\infty }.
See derivation

For state values,

(TV)(s)=max⁡a[r(s,a)+γ∑s′P(s′∣s,a)V(s′)].(TV)(s) =\max_a\left[ r(s,a)+\gamma\sum_{s'}P(s'\mid s,a)V(s') \right].

Then

∣(TV)(s)−(TU)(s)∣≤max⁡a∣γ∑s′P(s′∣s,a)[V(s′)−U(s′)]∣≤γmax⁡a∑s′P(s′∣s,a)∣V(s′)−U(s′)∣≤γ∥V−U∥∞max⁡a∑s′P(s′∣s,a)=γ∥V−U∥∞.\begin{aligned} |(TV)(s)-(TU)(s)| &\leq\max_a \left| \gamma\sum_{s'}P(s'\mid s,a) [V(s')-U(s')] \right|\\ &\leq\gamma\max_a \sum_{s'}P(s'\mid s,a)|V(s')-U(s')|\\ &\leq\gamma\|V-U\|_\infty \max_a\sum_{s'}P(s'\mid s,a)\\ &=\gamma\|V-U\|_\infty. \end{aligned}
∣max⁡xf(x)−max⁡xg(x)∣≤max⁡x∣f(x)−g(x)∣.\left|\max_x f(x)-\max_x g(x)\right| \leq\max_x|f(x)-g(x)|.

Taking the maximum over ss proves the result. The same argument applies to the Q-Bellman operator.

Because Q∗=TQ∗Q^*=TQ^*, exact value iteration satisfies

∥Qk+1−Q∗∥∞=∥TQk−TQ∗∥∞≤γ∥Qk−Q∗∥∞.\begin{aligned} \|Q_{k+1}-Q^*\|_\infty &=\|TQ_k-TQ^*\|_\infty\\ &\leq\gamma\|Q_k-Q^*\|_\infty. \end{aligned}

Therefore,

∥Qk−Q∗∥∞≤γk∥Q0−Q∗∥∞.\boxed{ \|Q_k-Q^*\|_\infty \leq\gamma^k\|Q_0-Q^*\|_\infty }.

This guarantee assumes an exact Bellman backup and a representation that stores every value exactly. Approximate value iteration instead applies ΠT\Pi T, and the projection Π\Pi need not preserve the contraction.

Sampling and Approximation Error

An empirical Bellman operator T^\widehat T replaces rewards and transitions with finite-sample estimates. A fitted update also incurs regression and optimization error. We can separate the one-step error as

∥Q^k+1−TQ^k∥∞≤∥Q^k+1−T^Q^k∥∞⏟approximation and optimization+∥T^Q^k−TQ^k∥∞⏟sampling.\begin{aligned} \|\widehat Q_{k+1}-T\widehat Q_k\|_\infty &\leq \underbrace{ \|\widehat Q_{k+1}-\widehat T\widehat Q_k\|_\infty }_{\text{approximation and optimization}}\\ &\quad+ \underbrace{ \|\widehat T\widehat Q_k-T\widehat Q_k\|_\infty }_{\text{sampling}}. \end{aligned}

Sampling error decreases at the familiar rate

O(1N),O\left(\frac1{\sqrt N}\right),

up to reward, horizon, coverage, cardinality, and confidence factors. Approximation error remains when the function class cannot represent the backed-up value or optimization does not find the best fit.

Suppose each approximate backup has bounded error

∥Q^k+1−TQ^k∥∞≤εk.\|\widehat Q_{k+1}-T\widehat Q_k\|_\infty \leq\varepsilon_k.

Then

∥Q^k−Q∗∥∞≤∑i=0k−1γiεk−i−1+γk∥Q^0−Q∗∥∞.\boxed{ \|\widehat Q_k-Q^*\|_\infty \leq \sum_{i=0}^{k-1}\gamma^i\varepsilon_{k-i-1} +\gamma^k\|\widehat Q_0-Q^*\|_\infty }.
See derivation

Since Q∗=TQ∗Q^*=TQ^*,

∥Q^k+1−Q∗∥∞=∥Q^k+1−TQ^k+TQ^k−TQ∗∥∞≤∥Q^k+1−TQ^k∥∞+∥TQ^k−TQ∗∥∞≤εk+γ∥Q^k−Q∗∥∞.\begin{aligned} \|\widehat Q_{k+1}-Q^*\|_\infty &=\|\widehat Q_{k+1}-T\widehat Q_k +T\widehat Q_k-TQ^*\|_\infty\\ &\leq\|\widehat Q_{k+1}-T\widehat Q_k\|_\infty +\|T\widehat Q_k-TQ^*\|_\infty\\ &\leq\varepsilon_k +\gamma\|\widehat Q_k-Q^*\|_\infty. \end{aligned}

Applying the recurrence repeatedly gives

∥Q^k−Q∗∥∞≤εk−1+γεk−2+⋯+γk−1ε0+γk∥Q^0−Q∗∥∞.\begin{aligned} \|\widehat Q_k-Q^*\|_\infty &\leq\varepsilon_{k-1} +\gamma\varepsilon_{k-2} +\cdots +\gamma^{k-1}\varepsilon_0\\ &\quad+\gamma^k\|\widehat Q_0-Q^*\|_\infty. \end{aligned}

If εk≤ε\varepsilon_k\leq\varepsilon, the limiting error is bounded by

lim sup⁡k→∞∥Q^k−Q∗∥∞≤ε1−γ.\limsup_{k\to\infty} \|\widehat Q_k-Q^*\|_\infty \leq \boxed{\frac{\varepsilon}{1-\gamma}}.

Thus 1/(1−γ)1/(1-\gamma) acts like an effective horizon that amplifies persistent backup errors. This is one reason value learning becomes harder as γ\gamma approaches one.

A small empirical Bellman loss only shows that the network fits its current sampled targets on the replay distribution. It does not prove that the targets match the true Bellman operator, unseen actions have accurate values, the projected iteration converges, or the greedy policy achieves high return.

Practical Diagnosis

SymptomLikely causeUseful response
Q-values grow while returns stay flatOverestimation or bootstrapping feedbackUse Double DQN, slower targets, or a lower learning rate
Sudden loss spikes or NaNsExtreme TD errors or gradientsCheck rewards, use Huber loss, and clip gradients
Learning changes sharply at synchronizationTarget updates are too abruptIncrease the hard-update interval carefully or use Polyak updates
Low replay loss but poor behaviorDistribution mismatch or weak coverageImprove exploration and inspect replay support
Reward propagates too slowlyOne-step targets or low UTDTry n-step returns or modestly increase UTD
Strong seed sensitivityUnstable approximation and explorationSimplify, tune conservatively, and evaluate multiple seeds
Continuous-action maximization is slowInner optimization is expensiveLearn an actor or use a sampling optimizer

The central value-based recipe is always the same. First construct a bootstrapped target

y=r+γ(1−d)V(s′),y=r+\gamma(1-d)\mathcal V(s'),

then fit a critic

L(θ)=ED[ℓ(y−Qθ(s,a))]L(\theta) =\mathbb E_\mathcal D \left[\ell\left(y-Q_\theta(s,a)\right)\right]

without differentiating through the target. Finally, update the target estimator slowly.

The hard part is not writing this loss. It is keeping sampling error, approximation error, distribution shift, maximization bias, and target movement from reinforcing one another.