Computes cost function, after a difficult couple of hours figuring
things out.
This commit is contained in:
julien Lengrand-Lambert
2015-11-22 16:15:08 +01:00
parent fce4426cab
commit 8370f8b6a5
2 changed files with 10 additions and 4 deletions

View File

@@ -20,12 +20,18 @@ grad = zeros(size(theta));
% Note: grad should have the same dimensions as theta
%
% Calculating J
theta_t_x = X*theta;
h_theta = sigmoid(theta_t_x);
part_1 = -y'*log(h_theta);
part_2 = (1 - y)' * log(1 - h_theta);
J = 1 / m * sum(part_1 - part_2);
% Calculating g
temp_1 = sigmoid(X*theta) - y;
temp_2 = repmat(temp_1, 1, size(X, 2));
g = 1/m * sum(X .* temp_2);
% =============================================================