I have question :
suppose that $x_i , y \in \mathbb{R^n}$:
$C(y) = \sum_{i =1}^{n} || y - x_i|| $
then how I can get $\nabla C = - \sum_{i = 1}^n \frac{x_i - y}{|| y - x_i||}$ .
I have question :
suppose that $x_i , y \in \mathbb{R^n}$:
$C(y) = \sum_{i =1}^{n} || y - x_i|| $
then how I can get $\nabla C = - \sum_{i = 1}^n \frac{x_i - y}{|| y - x_i||}$ .
Copyright © 2021 JogjaFile Inc.
Writing $x_i\in \mathbb{R}^{\mathbb{n}}$ as $(x_{i,1},\ldots,x_{i,\mathbb{n}})$, we have that $$ y-x_i=(y_1-x_{i,1},\ldots,y_\mathbb{n}-x_{i,\mathbb{n}}), $$ whence $$ \|y-x_i\|=\sqrt{(y_1-x_{i,1})^2+\ldots+(y_\mathbb{n}-x_{i,\mathbb{n}})^2}. $$ Now compute $$ \frac{\partial }{\partial y_j} \|y-x_i\| = \frac{y_j-x_{i,j}}{\|y-x_i\|}, $$ or $$ \frac{\partial }{\partial y_j} \sum_{i=1}^n\|y-x_i\|=\sum_{i=1}^n\frac{y_j-x_{i,j}}{\|y-x_i\|}. $$ Thus $$ \nabla C=\left(\sum_{i=1}^n\frac{y_1-x_{i,1}}{\|y-x_i\|},\ldots,\sum_{i=1}^n\frac{y_\mathbb{n}-x_{i,\mathbb{n}}}{\|y-x_i\|}\right)=\sum_{i=1}^n\frac{y-x_{i}}{\|y-x_i\|}=-\sum_{i=1}^n\frac{x_{i}-y}{\|y-x_i\|}. $$