Let $A$ be an $n\times n$ symmetric, positive semi-definite matrix. I also have the following elements
- Function $f(x) = -\frac{1}{2}x^\top A x$.
- Gradient $\nabla f(x) = -Ax$ and Jacobian $J_f(x) = -x^\top A$.
- Hessian $H_f(x) = -A$.
- Define the function $N:\mathbb{R}^n\to\mathbb{R}^{n\times n}$ $$ N(x) = \frac{\nabla f(x) \nabla f(x)^\top}{\nabla f(x)^\top \nabla f(x)} = \frac{Axx^\top A}{x^\top AA x} $$
How can I write the derivative of $N$ with respect to $x$ without using index notation?
The derivative will be a third-order tensor, but fundamentally I would like to be able to write down the result so that I can code it in Python.
$ \newcommand\diff[1]{\left\{#1\right\}} \newcommand\Diff[1]{\Bigl\{#1\Bigr\}} \newcommand\trans[1]{#1^{\mathrm T}} \newcommand\R{\mathbb R} $
I hate the usual $D$ notation for total derivatives; it always creates a mess that's hard to read. Instead I'm going to use the following notation: $$ \diff{f}_x = \diff{f(x)}_x = Df(x), $$$$ \diff{f}^h_x = \diff{f(x)}^h_x = Df(x)(h). $$ We will use the following facts:
These facts let us easily evaluate the desired derivative: $$\begin{aligned} \diff{\frac{Ax\trans xA}{\trans xA^2x}}^h_x &= \frac{A\diff{x\trans x}^h_xA}{\trans xA^2x} + Ax\trans xA\diff{\frac1{\trans xA^2x}}^h_x \\ &= \frac{A(h\trans x + x\trans h)A}{\trans xA^2x} - \frac{Ax\trans xA}{(\trans xA^2x)^2}\diff{\trans xA^2x}^h_x \\ &= \frac{A(h\trans x + x\trans h)A}{\trans xA^2x} - \frac{Ax\trans xA}{(\trans xA^2x)^2}(\trans hA^2x + \trans xA^2h) \\ &= \frac1{\trans xA^2x}A(h\trans x + x\trans h)A - 2\frac{\trans hA^2x}{(\trans xA^2x)^2}Ax\trans xA. \end{aligned}$$ The last line follows since $\trans hA^2x = \trans xA^2 h$ since $A^2$ is symmetric.