function [J, grad] = costFunction(theta, X, y)
%COSTFUNCTION Compute cost and gradient for logistic regression
%   [J, grad] = COSTFUNCTION(theta, X, y) computes the cost of using theta as the
%   parameter for logistic regression and the gradient of the cost
%   w.r.t. to the parameters.
%
%	Code source: ml-class.org

m = length(y); % number of training examples

J = (1/m)*(-y'*log(logsig(X*theta)) - (1-y)'*log(1-logsig(X*theta)));
grad = ((1/m)*(logsig(X*theta) - y)'*X)';
end
