how to differentiate this equation (contains absolute and norm)

40 Views Asked by At

how can I differentiate the following wrt $\mathbf{d}_i$?

$\frac{|\mathbf{d}_i^T\mathbf{d}_j|}{\|\mathbf{d}_i\|_2\|\mathbf{d}_j\|_2}$

Thanks in advance.

1

There are 1 best solutions below

2
On BEST ANSWER

Hints: For $x,y \in \mathbb{R}^n$, $$\nabla_{x} |x^Ty|= \text{sign}(|x^Ty|)y,\qquad \nabla_{x}\|x\|_2 = \dfrac{ x }{ \|x\|_2 }, $$ So $$\nabla_x \left(\dfrac{|x^Ty|}{\|x\|_2\|y\|_2}\right) = \dfrac{\|x\|_2\nabla_{x}|x^Ty|+|x^Ty|\nabla_{x}\|x\|_2}{\|x\|_2^2\|y\|_2}=\ldots $$