Tabular Q-learning stores one number for every state-action pair:
Q:S×A→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).
Changing θ 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∣)].
The greedy action only requires one forward pass:
πθ(s)=argamaxQθ(s,a).
Value learning as regression
Suppose an oracle supplied the true label y=Qπ(s,a). We could minimize
The true value is unavailable, so value-based methods differ mainly in how they construct the target y.
Monte Carlo and temporal-difference targets
After a complete trajectory, Monte Carlo learning uses the sampled return
Gt=k=0∑T−t−1γkrt+k.
The update is
θ←θ+α(Gt−Qθ(st,at))∇θQθ(st,at).
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).
For off-policy Q-learning,
ytQ=rt+γa′maxQθ(st+1,a′).
The Q-learning update is therefore
θ←θ+αδt∇θQθ(st,at),
where
δt=rt+γa′maxQθ(st+1,a′)−Qθ(st,at)
is the temporal-difference error.
For state-value policy evaluation, the same idea gives
w←w+α[rt+γVw(st+1)−Vw(st)]∇wVw(st).
If Vw(s)=w⊤x(s), then ∇wVw(s)=x(s) and
w←w+αδtx(st).
Why this is a semi-gradient
The Q-learning label contains the network being trained:
yθ=r+γa′maxQθ(s′,a′).
Standard Q-learning deliberately treats yθ as fixed during the current update. It differentiates the prediction but not the target. This is a semi-gradient update.
›See derivation
Let
a∗=arga′maxQθ(s′,a′)
and define
δθ=r+γQθ(s′,a∗)−Qθ(s,a).
Ignoring nondifferentiability at action ties, the full gradient of the squared Bellman error is
The Bellman target is detached from the gradient graph.
This is not ordinary regression to permanent labels. Updating θ 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)[a′maxQ(s′,a′)].
The optimal action-value function is its fixed point:
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.
Suppose we have a transition dataset
D={(si,ai,ri,si′,di)}i=1N,
where di=1 indicates a true terminal transition. At outer iteration k, freeze the previous Q-function and construct
yi(k)=ri+γ(1−di)a′maxQθk(si′,a′).
We then solve the supervised regression problem
θk+1=argθmin2N1i=1∑N[Qθ(si,ai)−yi(k)]2.
Fitted Q-IterationCollect a transition dataset D.Initialize Qθ0.For k=0,1,…,K−1:yi(k)←ri+γ(1−di)a′maxQθk(si′,a′)∀i,θk+1←argθmin2N1i∑[Qθ(si,ai)−yi(k)]2.Return QθK.
For fixed θ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
amax[r(s,a)+γEs′V(s′)]
for every candidate action. A sampled transition reveals only the outcome of the action that was taken. Learning 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 μ be the behavior policy. Its transition distribution factors as
pμ(s,a,r,s′)=dμ(s)μ(a∣s)p(r,s′∣s,a).
Conditioned on (s,a), the outcome distribution p(r,s′∣s,a) does not depend on μ. The target also uses a greedy next action rather than an action from μ:
r+γa′maxQ(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:
Method
Data
Target refresh
Regression per refresh
Online Q-learning
Latest transition
Every update
One step
DQN
Replay buffer
Slowly through a target network
A few minibatch steps
Fitted Q-iteration
Fixed batch
After an inner fitting phase
Many steps
The Deadly Triad
Approximate value learning becomes especially unstable when it combines:
function approximation, which shares parameters across predictions;
bootstrapping, which uses learned values inside targets;
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.
The exact Bellman operator is a contraction in the sup norm:
∥TQ−TU∥∞≤γ∥Q−U∥∞.
But regression usually defines Π through a replay-weighted squared loss:
Πf=argQ∈ΩminE(s,a)∼dD[(Q(s,a)−f(s,a))2].
This projection is controlled in a distribution-weighted L2 geometry, not necessarily in L∞. 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.
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.
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)
in a finite replay buffer D. Training samples random minibatches
{(si,ai,ri,si′,di)}i=1B∼D.
Replay converts an environment stream into an empirical dataset:
It helps in two ways. First, random batches reduce the short-range temporal correlation in
st→st+1→st+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:
dD(s,a)=∣D∣1i=1∑∣D∣1[(si,ai)=(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+γa′maxQθ(s′,a′).
Every update changes both sides of the regression problem. A target network separates them:
yi=ri+γ(1−di)a′maxQθˉ(si′,a′),
where θ is optimized and θˉ changes slowly.
For fixed θˉ, the loss
L(θ;θˉ)=2B1i=1∑B[Qθ(si,ai)−yi]2
is ordinary regression to stationary minibatch labels.
Hard target updates
Every C environment or gradient steps, copy the online parameters:
θˉ←θ.
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.
Some sources instead write
θˉ←τθ+(1−τ)θˉ,τ≪1.
These are the same update with τ=1−ρ. Unrolling it shows that the target is an exponentially weighted average of historical online networks:
θˉt=ρtθˉ0+(1−ρ)j=0∑t−1ρjθ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θˉ.
Deep Q-Networks
A Deep Q-Network combines:
a neural Q-function Qθ;
an ϵ-greedy behavior policy;
an experience-replay buffer;
a slowly updated target network Qθˉ.
For a sampled transition, the DQN target is
yiDQN=ri+γ(1−di)a′maxQθˉ(si′,a′).
The terminal mask matters. If di=1, then yi=ri 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(θ)=2B1i=1∑B[Qθ(si,ai)−yi]2.
Large TD errors produce large gradients. The Huber loss is quadratic near zero and linear for extreme residuals:
ℓκ(δ)={21δ2,κ(∣δ∣−21κ),∣δ∣≤κ,∣δ∣>κ.
Its derivative is capped at magnitude κ, making individual outliers less destructive.
The behavior policy chooses
at={a uniformly random action,argmaxaQθ(st,a),with probability ϵt,with probability 1−ϵt.
We usually start with high exploration and decay ϵt. Decaying too quickly leaves replay concentrated around a poor early policy; decaying too slowly wastes interaction after useful values have emerged.
Deep Q-NetworkInitialize 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)a′maxQθˉ(si′,a′),θ←argθminB1i∑ℓ(yi−Qθ(si,ai)),update θˉ with a hard copy or Polyak averaging.
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.
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)j∈{1,2}minQθˉ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:
how quickly transitions enter replay;
how quickly θ fits the current targets;
how quickly θˉ changes those targets.
The update-to-data ratio is
UTD=new environment transitionsgradient updates.
With batch size B, the replay-sample ratio is approximately
B×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 n-step target moves it across several transitions:
The bootstrap term is removed if the episode terminates inside the window.
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,c∥g∥2g,∥g∥2≤c,∥g∥2>c.
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∈Rm, both the target
y=r+γa′maxQ(s′,a′)
and greedy behavior
π(s)=argamaxQ(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))].
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) and approximates
amaxQ(s,a)≈i=1,…,NmaxQ(s,ai).
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), it samples actions, keeps an elite set Ej, and refits
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)≈argamaxQϕ(s,a).
The actor maximizes
J(ψ)=Es∼D[Qϕ(s,μψ(s))].
By the chain rule,
∇ψJ(ψ)=Es∼D[∇aQϕ(s,a)∣a=μψ(s)∇ψμψ(s)].
The actor amortizes continuous optimization into one forward pass. DDPG uses target actors and critics to construct
yi=ri+γ(1−di)Qϕˉ(si′,μψˉ(si′)).
The critic minimizes
LQ(ϕ)=2B1i∑[Qϕ(si,ai)−yi]2,
while the actor ascends Qϕ(s,μψ(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 γ-contraction in the sup norm:
The maximum cannot enlarge the largest pointwise difference.
Taking the maximum over s proves the result. The same argument applies to the Q-Bellman operator.
Because Q∗=TQ∗, exact value iteration satisfies
∥Qk+1−Q∗∥∞=∥TQk−TQ∗∥∞≤γ∥Qk−Q∗∥∞.
Therefore,
∥Qk−Q∗∥∞≤γk∥Q0−Q∗∥∞.
This guarantee assumes an exact Bellman backup and a representation that stores every value exactly. Approximate value iteration instead applies ΠT, and the projection Π need not preserve the contraction.
Sampling and Approximation Error
An empirical Bellman operator 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
∥Qk+1−TQk∥∞≤approximation and optimization∥Qk+1−TQk∥∞+sampling∥TQk−TQk∥∞.
Sampling error decreases at the familiar rate
O(N1),
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.
Thus 1/(1−γ) acts like an effective horizon that amplifies persistent backup errors. This is one reason value learning becomes harder as γ 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
Symptom
Likely cause
Useful response
Q-values grow while returns stay flat
Overestimation or bootstrapping feedback
Use Double DQN, slower targets, or a lower learning rate
Sudden loss spikes or NaNs
Extreme TD errors or gradients
Check rewards, use Huber loss, and clip gradients
Learning changes sharply at synchronization
Target updates are too abrupt
Increase the hard-update interval carefully or use Polyak updates
Low replay loss but poor behavior
Distribution mismatch or weak coverage
Improve exploration and inspect replay support
Reward propagates too slowly
One-step targets or low UTD
Try n-step returns or modestly increase UTD
Strong seed sensitivity
Unstable approximation and exploration
Simplify, tune conservatively, and evaluate multiple seeds
Continuous-action maximization is slow
Inner optimization is expensive
Learn 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′),
then fit a critic
L(θ)=ED[ℓ(y−Qθ(s,a))]
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.