Gradient for logistic classifier