Implements gradientDescent.

End of the mandatory assignment.
This commit is contained in:
julien Lengrand-Lambert
2015-11-12 19:03:57 +01:00
parent 84705edfc1
commit beb5981609
2 changed files with 10 additions and 6 deletions

View File

@@ -16,12 +16,16 @@ for iter = 1:num_iters
% Hint: While debugging, it can be useful to print out the values
% of the cost function (computeCost) and gradient here.
%
tmat = repmat( theta, 1, size(X, 1) );
h_theta = tmat' .* X;
to_sum = (sum(h_theta,2) - y);
to_sum_1 = to_sum .* X(:, 1);
to_sum_2 = to_sum .* X(:, 2);
theta(1) = theta(1) - (alpha * (1/m) * sum(to_sum_1));
theta(2) = theta(2) - (alpha * (1/m) * sum(to_sum_2));
% ============================================================

Binary file not shown.