How derivative of matrix leads to its transpose?

I'm deriving backpropagation step of training neural networks using vectorized equations. Following are two forward propagation equations between last hidden layer and output layer.

$$Z^{} = W^{}A^{} + b^{}$$ $$A^{} = \hat{y} = g(Z^{})$$

Where $$g(z)$$ is activation function.

Now in backpropagation, we calculate the change in cost function ($$J$$) w.r.t. all the parameters.

I've successfully calculated $$\partial{J}/\partial{A^{}}$$ and $$\partial{J}/\partial{Z^{}}$$ using chain rule. Now to calculate $$\partial{J}/\partial{W^{}}$$, I've formed following chain

$$\frac{\partial{J}}{\partial{W^{}}} = \frac{\partial{J}}{\partial{A^{}}} \frac{\partial{A^{}}}{\partial{Z^{}}} \frac{\partial{Z^{}}}{\partial{W^{}}}$$

Now to calculate $$\frac{\partial{Z^{}}}{\partial{W^{}}}$$, I used $$Z^{} = W^{}A^{} + b^{}$$ equation which simply gives the derivation $$A^{}$$. But in literature, it's given as $$A^{^{T}}$$, which is transpose of my answer.

By checking dimensions of the answer, I could verify that the answer should be $$A^{^{T}}$$ instead if $$A^{}$$. But is there any general rule for such cases using which I could directly tell whether the derivative will be the transpose of a matrix or not without verifying dimensions?

I've also checked matrix cookbook but couldn't find any related thumb rules.

Unfortunately, there are 2 common convention in matrix calculus: Jacobian (Numerator) and Gradient (Denominator).

For a function $$f:\mathbb R^n \to \mathbb R^m$$, then

1. Jacobian convention: $$\frac{\partial f}{\partial x}$$ is represented by the $$m\times n$$ matrix with entries $$\big(\tfrac{\partial f}{\partial x}\big)_{ij} = \tfrac{\partial f_i}{\partial x_j}$$

2. Gradiant convention: $$\frac{\partial f}{\partial x}$$ is represented by the $$n\times m$$ matrix with entries $$\big(\tfrac{\partial f}{\partial x}\big)_{ij} = \tfrac{\partial f_j}{\partial x_i}$$

If $$f(x) = Ax$$ then one can easily check that

1. Under Jacobian convention $$\frac{\partial f}{\partial x} = A$$

2. Under Gradient convention $$\frac{\partial f}{\partial x} = A^T$$

So it is a matter of which convention you are following.

• Thanks for the answer! So if I don't know which convention is used, I've to verify this using only checking dimensions, right? Can you provide any references for these conventions? Thanks. Jul 8 '19 at 16:07
• Jul 8 '19 at 17:06
• @Kaushal28 Also, I highly recommend matrixcalculus.org which is a new CAS that can do matrix calculus; very useful for checking hand computations. Jul 8 '19 at 17:09
• Got it! A detailed explanation of matrix calculus is given here: explained.ai/matrix-calculus/index.html Jul 9 '19 at 15:59