implemented cost function J and computed gradient for logistic regression