Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 20, 2012
@scottwb Cleanup HW4 computeCost function to use the vector operations instead of
rolling the loop out by hand, now that I have time to figure out the
syntax.
35a3267
@scottwb Cleaned up H4 gradient descent using matrix math now that I had time …
…to figure out the syntax.
d49b941
Showing with 2 additions and 28 deletions.
  1. +1 −8 prog-05/ex1/computeCost.m
  2. +1 −20 prog-05/ex1/gradientDescent.m
View
9 prog-05/ex1/computeCost.m
@@ -13,14 +13,7 @@
% Instructions: Compute the cost of a particular choice of theta
% You should set J to the cost.
-% REVISIT: For some reason I keep breaking on the vectorization version
-% with some obscure syntax error. Busting this out iteratively
-% for now since I am super-crunched for time.
-for i=1:m
- J = J + (((theta(1) + (theta(2) * X(i,2))) - y(i)) ^ 2);
-end
-J = J / (2 * m);
-
+J = sum((X*theta - y) .^ 2) / (2*m);
% =========================================================================
View
21 prog-05/ex1/gradientDescent.m
@@ -17,26 +17,7 @@
% of the cost function (computeCost) and gradient here.
%
-
- % REVISIT: Again, troubles with the syntax of octave vector stuff and
- % making the formulas from class work. Busting out the quick
- % manually iterative version like I did in python for the robotics
- % class, just to get this in by the deadline...which I only
- % made by 3 minutes.
-
- s1 = 0;
- s2 = 0;
- for i=1:m
- h = (theta(1) + (theta(2) * X(i,2)));
- s1 = s1 + ((h - y(i)));
- s2 = s2 + ((h - y(i)) * X(i,2));
- end
- s1 = (alpha/m) * s1;
- s2 = (alpha/m) * s2;
-
- theta(1) = theta(1) - s1;
- theta(2) = theta(2) - s2;
-
+ theta = theta - ((X*theta - y)' * X)' .* (alpha/m);
% ============================================================

No commit comments for this range

Something went wrong with that request. Please try again.