From f9243ef5934fa171006f090e51b0ea2ec671bf7a Mon Sep 17 00:00:00 2001 From: neingeist Date: Thu, 16 Oct 2014 01:03:58 +0200 Subject: [PATCH] Simplify regularization term --- ex2/costFunctionReg.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ex2/costFunctionReg.m b/ex2/costFunctionReg.m index 572bebf..02f3db3 100644 --- a/ex2/costFunctionReg.m +++ b/ex2/costFunctionReg.m @@ -20,8 +20,7 @@ grad = zeros(size(theta)); J = 1/m * (-y'*log(sigmoid(X*theta)) - (1-y)'*log(1-sigmoid(X*theta))) ... + lambda/(2*m) * theta(2:end)' * theta(2:end); -regularization_term = ... - lambda/m * (theta .* prepad(ones(length(theta)-1, 1), length(theta), 0)); +regularization_term = lambda/m * vertcat([0], theta(2:end)); grad = 1/m * X' * (sigmoid(X*theta) - y) + regularization_term; % =============================================================