I ran into a seemingly simple matrix calculus question that I can't seem to find the solution to.
Suppose I have the following matrices: $X_{(t \times n)}, V_{(n \times m)}$, and $\Phi_{(t\times m)} = f(XV)$ for some differentiable function $f$, which is applied element-wise to the argument $XV$.
I would like to calculate $\frac{\partial}{\partial V} \|1^T\Phi\|_2^2$, which I expanded to the outer product (hopefully correctly) as $\frac{\partial}{\partial V} 1^T \Phi\Phi^T 1 = \frac{\partial}{\partial V} 1^T f(XV) f(XV)^T 1^T$.
The Matrix Cookbook states that $\frac{d}{dx} \|x\|_2^2 = \frac{d}{dx} \|x^Tx\|_2 = 2x$. However, I'm not 100% certain I can use this in my case.
So far I have that $\frac{\partial}{\partial V} 1^T f(XV) f(XV)^T 1 = 2X^T[f(XV) \circ f^\prime(XV)]$ but my gradient checker (gradest in Matlab) is saying this is incorrect. I've been stuck on this all day, can anyone help?
I'm trying to figure out a vectorized solution (not involving for loop summations) since this piece of code will be called iteratively for optimization.
Edit: I've confirmed that $\frac{d}{d\Phi} \|1^T \Phi \|_2^2 = 2 \cdot 1 1^T \Phi$.
I finally figured out (and verified with gradest) the correct solution in vectorized form: $$ \frac{d}{dV} \|1^T f(XV)\|_2^2 = 2 X^T \left[(1 1^T \Phi) \circ f^\prime(XV)\right], $$ where $\circ$ denotes the Hadamard product.