Partial Derivative of Hadamard Root (elements-wise square root)

Given $\mathbf{X} \in \mathbb{R}^{n \times 1}$, $\mathbf{A} \in \mathbb{R}^{n \times n}$, the function is $\mathbf{f}=\sqrt{\mathbf{A} \mathbf{X} \odot \mathbf{A} \mathbf{X}}$, where $\sqrt{(\cdot)}$ is Hadamard root (elements-wise square root), and $(\cdot) \odot (\cdot)$ is the Hadamard Product. How to compute $\frac{\partial \mathbf{f}}{\partial \mathbf{X}}$?


I have tried to follow this similar question and answer to solve my problem, but the function of that question is Frobenius inner product, which is different with mine so can not solve in that way.

Thanks in advance!


Solution 1:

Define $$\eqalign{ b &= Ax \qquad\implies\quad &db = A\,dx \\ B &= {\rm Diag}(b) &F = {\rm Diag}(f) \\ }$$ Then calculate $$\eqalign{ f\odot f &= b\odot b \\ 2f\odot df &= 2b\odot db \\ F\,df &= B\,db = BA\;dx \\ \frac{\partial f}{\partial x} &= F^{-1}BA \\\\ }$$

Solution 2:

As it has been reckoned by Jean-Claude, you can simplify your vector function as $$ \mathbf{f}(\mathbf{x}) = |\mathbf{Ax}| = g(\mathbf{z}) $$ where $\mathbf{z}=\mathbf{Ax}$ and $g(\mathbf{z})=|\mathbf{z}|$. Here the absolute value is applied componentwise (this function is not differentiable at zero).

It follows $$ d\mathbf{f} = g'(\mathbf{z}) \circ d\mathbf{z} = g'(\mathbf{z}) \circ \mathbf{A}d\mathbf{x} $$

The Jacobian is thus $$ \frac{\partial \mathbf{f}}{\partial \mathbf{x}} = \mathrm{diag}[g'(\mathbf{Ax})] \mathbf{A} $$ The diagonal matrix contains -1 or +1 depending on the sign of the vector elements $\mathbf{z}=\mathbf{Ax}$