public static double deriv(double pred,double y,double c){
  double x=pred - y;
  if (Math.abs(x) <= c)   return x;
 else   return c * Math.signum(x);
}

public static double deriv ( double pred , double y , double c ) { double x = pred - y ; if ( Math . abs ( x ) <= c ) return x ; else return c * Math . signum ( x ) ; }
computes the first derivative of the huberloss loss
