public static double loss ( double pred , double y ) { final double x = - y * pred ; if ( x >= 30 ) //as x -> inf, L(x) -> x. At 30 exp(x) is O(10^13), getting unstable. L(x)-x at this value is O(10^-14), also avoids exp and log ops return x ; else if ( x <= - 30 ) return 0 ; return log ( 1 + exp ( x ) ) ; }
Computes the logistic loss