Compute gradient of discretized energy function

29 Views Asked by At

Given the following discretized energy problem, I'd like to compute the gradient with respect to $u[i]$:

$$ \min _{u} \sum_{i=1}^{N-1}|u[i+1]-u[i]|+\frac{\lambda}{2} \sum_{i=1}^{N}(u[i]-f[i])^{2} $$

I have the following solution but I can't come up with it myself.

$$\nabla E[i]=\operatorname{sign}(u[i]-u[i-1])-\operatorname{sign}(u[i+1]-u[i])+\lambda(u[i]-f[i]) \quad \forall 1<i \leq N-1$$

I understand that the derivative of the $|x|$ function is $sign(x)$ but I don't see why there are two $sign$ terms. Basically, my calculation is:

$$\frac{d}{d\;u[i]}|u[i+1]-u[i]| \\= \operatorname{sign}(u[i+1]-u[i])*\frac{d}{d u[i]}(u[i+1] - u[i]) \\= \operatorname{sign}(u[i]-u[i-1])*\frac{d}{d u[i-1]}(u[i] - u[i-1]) \\ = \operatorname{sign}(u[i]-u[i-1])*(\frac{d}{d\;u[i-1]}u[i] - 1)$$

This is where I get stuck and can't come up with the provided solution. Thanks for your help

1

There are 1 best solutions below

2
On

Not sure I understand the meaning of "min u" there. But if I can lay that aside, look at some $u$ in particular, $u[3]$, say. It shows up not once in the calculation, but twice, in two terms $|u[3]-u[2]|$ and $|u[4]-u[3]|$. You have to account for both of them. If you understand where the "sign"s come from, you can take it from there.