Logistic Regression: Implementing the gradient.