diff costFunctionReg.m @ 6:141d81a2acf5 default tip

Remove usage of sum function in cost function (thanks Jeroen Willems)
author Jordi GutiƩrrez Hermoso <jordigh@octave.org>
date Tue, 08 Nov 2011 03:30:56 -0500 (2011-11-08)
parents 4fb05328d3cf
children
line wrap: on
line diff
--- a/costFunctionReg.m
+++ b/costFunctionReg.m
@@ -11,7 +11,7 @@
   ## h_theta(x)
   ht = sigmoid (X*theta); 
 
-  J = -sum (y.*log (ht) + (1 - y).*log (1 - ht))/m \
+  J = -(y'*log (ht) + (1 - y)'*log (1 - ht))/m \
       + lambda*sum (theta(2:end).^2)/(2*m);
 
   grad = (X'*(ht - y) + [0; lambda*theta(2:end)])/m ;