What is the derivative of the following matrix expression with respect to $W$?
$J(W)=\log(\det(\operatorname{diag}(WRW^T)))$ where $W$ is a square matrix and $R$ is a symmetric matrix
Where the $\operatorname{diag}$ operator sets all the off-diagonal elements to zero, for example: $$ \operatorname{diag} \begin{bmatrix} 1 & 1 & 5 \\ 1 & 2 & 6 \\ 1 & 0 & 7 \\ \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 7 \\ \end{bmatrix} $$
Let's replace the diagonalization function by a Hadamard $(\odot)$ product with the identity matrix, which is easier to type. For further convenience, let's define the (symmetric) matrix variable $$X = I\odot(WRW^T)$$ Write the function in terms of this new variable. Then find its differential and gradient $$\eqalign{ J &= \log(\det(X)) \cr\cr dJ &= d\log(\det(X)) \cr &= d\,{\rm tr}(\log(X)) \cr &= X^{-1}:dX \cr &= X^{-1}:I\odot(dW\,RW^T+WR\,dW^T) \cr &= I\odot X^{-1}:2\,{\rm sym}(dW\,RW^T) \cr &= 2X^{-1}:(dW\,RW^T) \cr &= 2X^{-1}WR:dW \cr\cr \frac{\partial J}{\partial W} &= 2X^{-1}WR \cr &= 2\Big(I\odot(WRW^T)\Big)^{-1}WR \cr }$$ In some of the steps above, a colon was used to denote the trace/Frobenius product $$A:B = {\rm tr}(A^TB)$$ and ${\rm sym}$ refers to the symmetrization function $${\rm sym}(A)=\frac{1}{2}(A+A^T)$$