Gradient of a nonlinear function?

217 Views Asked by At

I would like to take the gradient of the following function with respect to $x_{ki}$

$$D = (\frac{13}{12})^N - \frac{2}{n}\sum_{k=1}^n\prod_{i=1}^N(1 + \frac{1}{2}|x_{ki}-0.5| - \frac{1}{2}|x_{ki}-0.5|^2) \\ + \frac{1}{n^2}\sum_{k=1}^n\sum_{l=1}^n\prod_{i=1}^N[1+\frac{1}{2}|x_{ki}-0.5| + \frac{1}{2}|x_{li}-0.5|-\frac{1}{2}|x_{ki}-x_{li}|] $$

Now I know that when $f(x) = |u(x)| = \sqrt{(u^2(x))}$ then $\frac{df}{dx} = \frac{u(x)}{\sqrt{(u^2(x))}}$

So, if we let $N=2$ then I can begin computing $\frac{\partial D}{\partial x_{k1}}$ by looking at the first term:

Attempted solution

1st term partial derivative: $$\frac{\partial D}{\partial x_{k1}} = \frac{2}{n}(1 + \frac{1}{2}|x_{k2}-0.5| - \frac{1}{2}|x_{k2}-0.5|^2)*(\frac{1}{2}\frac{x_{k1}-0.5}{\sqrt{(x_{k1}-0.5)^2}}-\frac{1}{2}\frac{2(x_{k1}-0.5)}{\sqrt{(x_{k1}-0.5)^2}}) \\ = \frac{2}{n}(1 + \frac{1}{2}|x_{k2}-0.5| - \frac{1}{2}|x_{k2}-0.5|^2)*(-\frac{1}{2}\frac{x_{k1}-0.5}{\sqrt{(x_{k1}-0.5)^2}})$$

2nd term partial derivative: $$\frac{\partial D}{\partial x_{k1}} = \frac{1}{n^2}\sum_{l=1}[1+\frac{1}{2}|x_{k2}-0.5| + \frac{1}{2}|x_{l2}-0.5|-\frac{1}{2}|x_{k2}-x_{l2}|]*(\frac{1}{2}\frac{x_{k1}-0.5}{\sqrt{(x_{k1}-0.5)^2}} - \frac{1}{2}\frac{x_{k1}-x_{l1}}{\sqrt{(x_{k1}-x_{l1})^2}})$$

and you would combine the terms for the full derivative

Questions:

  1. is this the correct approach?
  2. for $\frac{\partial D}{\partial x_{k2}}$ would you simply switch the $x_{k1}$ and $x_{k2}$ terms?
  1. What if N was an arbitrary dimension? Would the product contain identical constants of the different indices (ie: $\prod_{i=1\not\in LHS}^N\frac{2}{n}(1 + \frac{1}{2}|x_{ki}-0.5| - \frac{1}{2}|x_{ki}-0.5|^2)$ multiplied by the derivative term?
  2. Can this easily be extended for the Hessian? My goal is to utilize the gradient and hessian matrices in an optimization routine

Thanks!

1

There are 1 best solutions below

0
On

If $D$ is the objective function of your optimization problem, I would recommend you reformulate your problem into a smooth problem: replace any $|y_i|$ with $p_i + n_i$, subject to the constraints $y_i = p_i - n_i$ and $p_i, n_i \ge 0$.