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 |
parents |
a4c4da8f4ac0 |
children |
|
files |
costFunction.m costFunctionReg.m |
diffstat |
2 files changed, 2 insertions(+), 2 deletions(-)
[+]
|
line diff
--- a/costFunction.m
+++ b/costFunction.m
@@ -9,7 +9,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;
grad = X'*(ht - y)/m;
endfunction
--- 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 ;