derivative of cost function for logistic regression