AI Wiki中文/EN

Dueling DQN: split a value prediction into shared and relative parts

Dueling DQN

Derive mean-centered advantages, inspect the remaining shift freedom, and train a tiny shared encoder.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

When every action shares most of its value

Imagine a corridor where moving left or right changes little until an obstacle appears. Much of the predicted return can be common to all actions, while a smaller part describes which action is preferable. A dueling network represents those two parts with a shared encoder and two output branches: one scalar value and a vector of raw advantages. It combines them into ordinary Q values. The original paper uses a corridor experiment to examine this architecture. Architecture and corridor

“Dueling” names the two branches, not a game between agents. Unlike Double DQN, it does not specify which network selects a bootstrap action. A dueling architecture can be used with different target rules; Rainbow’s methods separate the architecture from double estimation. Component distinction

You need DQN and backpropagation for this chapter. We will first check what the branches mean, then train a tiny network against nine fixed answers. That isolates a representation question before adding exploration and changing targets.

Mean aggregation separates a common value from centered advantages. The matrix shows fitted Q values for nine fixed supervised targets; raw common shifts still cancel.
Mean aggregation separates a common value from centered advantages. The matrix shows fitted Q values for nine fixed supervised targets; raw common shifts still cancel.

Center the relative part before adding it

In policy evaluation, a conventional advantage subtracts the policy’s state value from its action value:

Vπ(s)=∑aπ(a∣s)Qπ(s,a),Aπ(s,a)=Qπ(s,a)−Vπ(s),∑aπ(a∣s)Aπ(s,a)=0.V^\pi(s)=\sum_a\pi(a\mid s)Q^\pi(s,a),\qquad A^\pi(s,a)=Q^\pi(s,a)-V^\pi(s),\qquad \sum_a\pi(a\mid s)A^\pi(s,a)=0.

This weighted-zero property depends on the policy. A neural output called “value” need not automatically have this meaning. In particular, simply adding a scalar V to a raw action vector A does not determine their split:

Qa=V+Aa=(V+c)+(Aa−c).Q_a=V+A_a=(V+c)+(A_a-c).

Any common shift c leaves the sum unchanged. The dueling paper compares ways to constrain the combination and uses mean subtraction in its final aggregation rule. For m discrete actions, write the raw branch as A-tilde:

Aˉ=1m∑b=1mA~b,Qa=V+A~a−Aˉ,1m∑aQa=V.\bar A=\frac1m\sum_{b=1}^{m}\widetilde A_b,\qquad Q_a=V+\widetilde A_a-\bar A,\qquad \frac1m\sum_a Q_a=V.

For V=2 and raw advantages [1,2,3], subtract their mean 2 to obtain [−1,0,1], then add V: Q=[1,2,3]. The scalar branch is the arithmetic mean of these action predictions, not their maximum 3. It is also not automatically the value of an arbitrary policy. The paper explicitly notes the changed semantics of the branches under mean aggregation. Mean aggregation, equation 9

Given Q, the scalar V and centered advantages are now determined. The raw advantages are not: adding the same constant to every raw entry still cancels when subtracting their mean. This distinction prevents an overclaim that centering uniquely identifies every network output or parameter.

For one selected action a, let e=Q_a−y and loss be one-half e squared. Differentiating through the mean gives:

∂L∂V=e,∂L∂A~b=e(1[b=a]−1m),∑b∂L∂A~b=0.\frac{\partial L}{\partial V}=e,\qquad \frac{\partial L}{\partial\widetilde A_b} =e\left(\mathbf1[b=a]-\frac1m\right),\qquad \sum_b\frac{\partial L}{\partial\widetilde A_b}=0.

One observed action therefore sends a gradient to every raw-advantage output. That coupling follows from centering; it is not evidence that we observed all actions’ rewards. With only one action, the centered advantage and its gradient are zero, and Q reduces to V.

For the teaching network, use column-vector notation h=tanh(Wx+b), V=v-transpose h+b_v, and raw A=Uh+b_A. Let g_A be the raw-advantage derivative above. The shared encoder receives both branches:

gh=ve+U⊤gA,gz=gh⊙(1−h⊙h),∇WL=gzx⊤,∇UL=gAh⊤,∇vL=eh.g_h=ve+U^\top g_A,\qquad g_z=g_h\odot(1-h\odot h),\qquad \nabla_W L=g_zx^\top,\quad \nabla_U L=g_Ah^\top,\quad \nabla_v L=eh.

The program stores batches as rows, so its matrix products use the transposed storage convention. For B observations it averages their gradients and uses:

L=12B∑i(Q(si,ai)−yi)2,θ←θ−η∇θL.L=\frac{1}{2B}\sum_i(Q(s_i,a_i)-y_i)^2, \qquad \theta\leftarrow\theta-\eta\nabla_\theta L.

These are loss gradients with the prediction-minus-target sign. A target-minus-prediction expression can instead describe an update direction; mixing that sign with gradient descent would reverse learning.

Learn three different patterns of action value

Run this complete Python/NumPy program with the repository’s pinned example dependencies. It uses a 2→6 tanh encoder and scalar/vector heads for three actions, totaling 46 parameters. The three input states are [−1,0], [0,1], [1,0]. Their fixed target vectors are respectively [2,2,2], [1,3,1], [0,0,4]. Each of the nine state-action pairs contributes to the training loss.

The first row has no action preference, the second favors the middle action, and the third strongly favors the last action. These targets are supplied answers, not rewards collected from an environment. Use seed 0, 1,200 full-batch updates and learning rate 0.05.

"""Original two-head nonlinear value representation; supervised architecture probe."""
import numpy as np


def network(seed=0, actions=3):
    if isinstance(actions, bool) or not isinstance(actions, int) or actions < 1:
        raise ValueError('Positive integer action count required')
    rng = np.random.default_rng(seed)
    return dict(w=rng.normal(0, .3, (2, 6)), b=np.zeros(6),
                wv=rng.normal(0, .3, (6, 1)), bv=np.zeros(1),
                wa=rng.normal(0, .3, (6, actions)), ba=np.zeros(actions))


def forward(p, x):
    x = np.asarray(x, dtype=float)
    if x.ndim != 2 or x.shape[1] != 2 or not np.isfinite(x).all():
        raise ValueError('Finite (batch,2) inputs required')
    h = np.tanh(x @ p['w'] + p['b'])
    v, raw = h @ p['wv'] + p['bv'], h @ p['wa'] + p['ba']
    centered = raw - raw.mean(axis=1, keepdims=True)
    return v + centered, (x, h, v, raw, centered)


def loss_gradient(p, x, actions, targets):
    q, (x, h, v, raw, centered) = forward(p, x)
    a, y = np.asarray(actions), np.asarray(targets, dtype=float)
    n = len(x)
    if not n or a.shape != (n,) or a.dtype.kind not in 'iu' or np.any((a < 0) | (a >= q.shape[1])):
        raise ValueError('Valid integer action per row required')
    if y.shape != (n,) or not np.isfinite(y).all():
        raise ValueError('Finite fixed target per row required')
    error = q[np.arange(n), a] - y
    dq = np.zeros_like(q)
    dq[np.arange(n), a] = error / n
    dv = dq.sum(axis=1, keepdims=True)
    da = dq - dq.mean(axis=1, keepdims=True)
    dh = (dv @ p['wv'].T + da @ p['wa'].T) * (1 - h * h)
    g = dict(w=x.T @ dh, b=dh.sum(0), wv=h.T @ dv, bv=dv.sum(0), wa=h.T @ da, ba=da.sum(0))
    return float(.5 * np.mean(error * error)), g


def demo():
    p = network(0)
    states = np.array([[-1., 0.], [0., 1.], [1., 0.]])
    expected = np.array([[2., 2., 2.], [1., 3., 1.], [0., 0., 4.]])
    x, a, y = np.repeat(states, 3, axis=0), np.tile(np.arange(3), 3), expected.ravel()
    initial = loss_gradient(p, x, a, y)[0]
    for _ in range(1200):
        _, g = loss_gradient(p, x, a, y)
        for k in p:
            p[k] -= .05 * g[k]
    q, (_, _, v, raw, centered) = forward(p, states)
    shifted = {k: value.copy() for k, value in p.items()}
    shifted['ba'] += 7.
    shifted_q = forward(shifted, states)[0]
    return dict(states=states.tolist(), fixed_targets=expected.tolist(), predictions=q.tolist(),
                value_head=v.ravel().tolist(), raw_advantage=raw.tolist(), centered_advantage=centered.tolist(),
                mean_q=q.mean(1).tolist(), final_loss=loss_gradient(p, x, a, y)[0], initial_loss=initial,
                raw_shift=7., max_prediction_change_after_shift=float(np.abs(q - shifted_q).max()),
                parameter_count=sum(value.size for value in p.values()), training_steps=1200,
                scope='Fit nine fixed supervised targets to isolate the architecture; no environment interaction or claim of faster RL learning.')


if __name__ == '__main__':
    import json
    print(json.dumps(demo(), indent=2, allow_nan=False))

The half mean-squared loss drops from about 2.2378053 to 8.0272×10⁻⁹. The value head approaches [2,5/3,4/3], the arithmetic means of the target vectors. The largest prediction error is about 0.000222. Adding 7 to every raw-advantage bias changes the computed Q values by only about 9.99×10⁻¹⁶, numerical roundoff in an algebraically invariant operation.

The checks differentiate all 46 parameters numerically, verify both branches reach the encoder, and test the one-action case and shift invariance. Centering costs O(m) per state; for hidden width h and input dimension d, this dense architecture needs O(dh+hm) parameters and per-state work. Batching multiplies the main forward/backward work by B; intermediate activations require O(B(h+m)) storage besides inputs and parameters. These expressions describe this dense teaching network, not the convolutional architecture in the paper.

Architecture does not replace the learning problem

Mean aggregation ties the action outputs together and lets the scalar head carry common value. It does not prove that every task benefits, nor does our supervised fit measure reinforcement-learning speed. A comparison needs matched data, targets, update budgets and evaluation procedures; changing several components at once obscures which change helped.

The arithmetic mean includes every output action. If an environment has invalid actions, masking only the final argmax is not a complete specification of the aggregation: one must also decide which actions enter the mean and its gradient. Our example has three valid actions at every state and does not implement a mask. Continuous action spaces require a different construction from this finite vector of outputs.

The word “advantage” also requires care. The centered branch is relative to the arithmetic action mean, while a policy advantage is relative to a policy-weighted mean. Their equality needs additional conditions, such as a uniform policy over those actions and Q predictions equal to its action values. Branch semantics

Inspect the split, not just the final prediction

  1. V=2 and raw A=[1,2,3]. Add 7 to every raw entry while leaving V fixed. What happens to Q?

Answer: The new raw vector is [8,9,10], with mean 9. Its centered vector remains [−1,0,1], so Q stays [1,2,3]. The raw common-shift freedom remains after mean aggregation.

  1. With three actions, the selected action is index 1 and its error is e=3. What derivatives reach V and the raw advantages for this one observation?

Answer: The value derivative is 3. Raw-advantage derivatives are [−1,2,−1], summing to zero. In a mean batch loss, divide each observation’s contribution by the batch size before summing.

  1. A state has Q=[0,0,4]. Is the scalar head 4? What is its centered advantage vector?

Answer: The head is 4/3, the arithmetic mean, and centered advantages are [−4/3,−4/3,8/3]. A greedy policy’s value based on this Q would be 4; it is not the mean-aggregation head.

  1. Does the successful nine-target fit establish that dueling learns an environment faster than an ordinary Q network?

Answer: No. It checks the architecture, gradient and ability to fit these supplied targets. A learning-speed comparison needs actual environment interaction and a baseline under a matched protocol. Keep this fit as a mechanism check rather than labeling it a benchmark result.

Two branches, one Q function

The ICML 2016 paper appears in PMLR volume 48, pages 1995–2003. This chapter uses its PDF pages 2–5 for the architecture, aggregation and corridor context; it does not reproduce the later score tables or audit the saliency method. Its equation 9 motivates our mean aggregator, while the small dense network and supervised targets here are original teaching choices. Dueling paper

The methods of Rainbow v1, dated October 6, 2017, give a useful map of how this representation can accompany other changes. This scoped reading does not establish the final combined system’s benchmark performance. Continue with Double DQN for target selection or return distributions for richer predictions than a scalar mean. Rainbow methods

Make a prediction, then check

With V=2 and raw advantages[1,2,3], what are the mean-aggregated Q values?

Choose one answer

Learning objectives

  • Derive mean aggregation and distinguish its value head from the maximum action value.
  • Backpropagate through both heads and recognize the raw advantage shift that leaves Q unchanged.

Prerequisites & connections

Explore related knowledge →

References

  1. Dueling Network Architectures for Deep Reinforcement Learning — scoped architecture reading
    Ziyu Wang; Tom Schaul; Matteo Hessel; Hado van Hasselt; Marc Lanctot; Nando de Freitas · 2016
  2. Rainbow: Combining Improvements in Deep Reinforcement Learning — arXiv v1 methods
    Matteo Hessel; Joseph Modayil; Hado van Hasselt; Tom Schaul; Georg Ostrovski; Will Dabney; Dan Horgan; Bilal Piot; Mohammad Azar; David Silver · 2017

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-23 · Single AI author. Scoped reading: ICML2016, PMLR48:1995–2003. Read PDF2–4 and opening5500 characters of5; viewed full5. Mean aggregation Eq9, changed value semantics and remaining raw-advantage shift freedom. No later score-table or saliency-method audit, no speedup replication. Selected2017-10-06v1, then under review for AAAI2018; not verified final2018 bytes. Read PDF2–3 methods: Double Q, PER, dueling mean, categorical softmax and integrated targets. Distributional Rainbow uses KL priority. No later full architecture, benchmark or ablation audit. 6 paired equations and four explained exercises. Checked policy-weighted advantage versus arithmetic centering, value=head mean Q not max Q, remaining raw common-shift freedom, both-head shared backpropagation, all46-parameter finite differences and one-action degeneracy. Nine supplied supervised targets and1200 updates test a representation, not faster environment learning; activation storage and valid-action scope explicit.

  • Checked policy-weighted advantage versus arithmetic centering, value=head mean Q not max Q, remaining raw common-shift freedom, both-head shared backpropagation, all46-parameter finite differences and one-action degeneracy. Nine supplied supervised targets and1200 updates test a representation, not faster environment learning; activation storage and valid-action scope explicit.
  • Four computed SVG variants per topic;14 numeric/geometry tests and24 current responsive cases passed. All eight selected current captures directly viewed. Two unchanged groups retain initial captures, two revised groups use new captures; actual assets and manuscripts are SHA bound. Full article acceptance recorded separately.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.