Gradient of Hadamard product on Matrix

54 Views Asked by At

I wasn't able to find another question able to answer my case as all of them seemed be be able to use the Hadamard products relationship with the Frobenius inner product to remove the Hadamard product to figure out the gradient. Let:

$n\in\mathbb{N}$, $m\in\mathbb{N}$

$R\in\mathbb{R}^{n\times m}$

$f:\mathbb{R}^{n\times m}\rightarrow \mathbb{R}$

$g:\mathbb{R}\rightarrow\mathbb{R}$, if its applied to a vector its applied element wise.

$x\in\mathbb{R}^m$

and ${\bf1}$ represents the vertical 1 vector.

I want to find the gradient of: $$f(R \odot (1(g(x)^T)))$$ with respect to the vector x

How would I go about doing this?

1

There are 1 best solutions below

0
On BEST ANSWER

The following variables will be useful $$\eqalign{ \def\o{{\tt1}} \def\qiq{\quad\implies\quad} \def\p{\partial} \def\grad#1#2{\frac{\p #1}{\p #2}} \def\deriv#1#2{\frac{d #1}{d #2}} \def\LR#1{\left(#1\right)} \def\op#1{\operatorname{#1}} \def\diag{\op{diag}} \def\Diag{\op{Diag}} \def\trace#1{\op{Tr}\LR{#1}} \def\frob#1{\left\| #1 \right\|_F} f &= f(Y), &g=g(x) \\ J &= \grad{f}{Y}, &h = \deriv{g}{x} &\qiq dg = h\odot dx \\ G &= \Diag(g), \quad &H = \Diag(h) &\qiq dg = H\;dx \\ g &= \diag(G), \quad &h=\diag(H) &\qiq dG = \Diag(dg) \\ Y &=R\odot\o g^T =&RG &\qiq dY = R\;dG \\ }$$ in calculating the differential and gradient of $f$ $$\eqalign{ df &= J:dY \\ &= J:R\,dG \\ &= R^TJ:\Diag(dg) \\ &= \diag\LR{R^TJ}:dg \\ &= \diag\LR{R^TJ}:H\:dx \\ &= H\,\diag\LR{R^TJ}:dx \\ \grad{f}{x} &= H\,\diag\LR{R^TJ} \\ &= h\odot\diag\LR{R^TJ} \\ \\ }$$


In the above, $(:)$ denotes the Frobenius product $$\eqalign{ A:B &= \sum_{i=1}^m\sum_{j=1}^n A_{ij}B_{ij} \;=\; \trace{A^TB} \\ A:A &= \frob{A}^2 \qquad \{ {\rm Frobenius\;norm} \}\\ A:B &= B:A \;=\; B^T:A^T \\ CA:B &= C:BA^T \;=\; A:C^TB \\ }$$ $\Diag()$ creates a diagonal matrix from its vector argument, and
$\diag()$ returns the main diagonal of its matrix argument as a vector.