Looking at Dueling DQN:
$Q = V + A - mean(A)$
For simplicity, let's assume we are working with 4 neurons. Recall that Value stream only has 1 neuron $(v_0)$
Re-writing the above equation, we get:
$$ \left[ \begin{array}{c} Q_0\\Q_1\\Q_2\\Q_3 \end{array} \right] = \left[ \begin{array}{c} v_0\\v_0\\v_0\\v_0 \end{array} \right] + \left[ \begin{array}{c} a_0\\a_1\\a_2\\a_3 \end{array} \right] - \left[ \begin{array}{c} \frac{1}{N}(a_0 + a_1 + a_2 + a_3) \\\frac{1}{N}(a_0 + a_1 + a_2 + a_3) \\\frac{1}{N}(a_0 + a_1 + a_2 + a_3) \\\frac{1}{N}(a_0 + a_1 + a_2 + a_3) \end{array} \right] $$
Question:
V (the Value) is a usual Dense Layer which has 1 neuron at the output.
A (the Advantage) is a usual Dense Layer which has N neurons at the output - what is the correct gradient vector to be passed to the neurons of this Advantage stream?
Thoughts:
From this post:
Since Q is a simple sum of functions you have:
$$\nabla_{\theta} Q(s,a) = \nabla_{\theta}V(s) + \nabla{\theta}A(s,a) - \frac{1}{numActions} \sum_{a'}\nabla_{\theta}A(s, a')$$
You get the gradients of the V and A networks as usual by backprop.
To me, the correct gradient vector to be passed to the advantage stream is:
$$gradForA = \frac{dE}{dQ}\frac{dQ}{dA}$$
however, the second fraction of the equation is what makes me puzzled. Is it as simple as:
$$\frac{dQ}{dA} = \left[ \begin{array}{c} 1-\frac{1}{N}\\1-\frac{1}{N}\\1-\frac{1}{N}\\1-\frac{1}{N} \end{array} \right] $$
It's probably not, especially if we look at the "mean" vector, in the example above. We can see that its every entry contains contribution of all advantage neurons - because they are summed.
Am I doomed to perform 2 backpropagations for the advantage dense layer, in parallel? - One for $+A$ and one for $-mean(A)$. I would then add-up (component-wise) the two gradient vectors. Sounds like a clumsy idea..