# Neural network with a custom loss function

I'm trying to implement a simple neural network (in Python) with 1 hidden layer and a loss function based on the GINI coefficient. But I just cannot find a way to minimize it with gradient descent. I'm not sure if this is even possible with this method. A simplified form can be written this way with e, current vector of errors : $$e = y - \hat y$$ $$min\ G(e)=min\sum\limits_i\sum\limits_j \mid e_i-e_j\mid$$

Any idea or a trick to do this ? Thanks

• What exactly are you stuck on? The loss looks (almost everywhere) differentiable to me, so what is the problem? Mar 6 '18 at 21:26
• Im trying to get the derivative but im stuck due to the presence of absolute values. Mar 6 '18 at 21:51
• The derivative of $f(x)=|x|$ is $1$ if $x>0$ and $-1$ if $x<0$ and undefined at $x=0$ (look at a plot of $f$). Use the chain rule. Mar 8 '18 at 7:30
– Sycorax
Jul 5 '18 at 15:02
The derivative of $f(x)=|x|$ is $1$ if $x>0$ and $−1$ if $x<0$ and undefined at $x=0$ (look at a plot of $f$). Use the chain rule.