From 111a0d1cca533f589b6a3a390357c3cf0d355b70 Mon Sep 17 00:00:00 2001 From: neingeist Date: Thu, 27 Nov 2014 23:47:18 +0100 Subject: [PATCH] Regularized Cost --- ex8/cofiCostFunc.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ex8/cofiCostFunc.m b/ex8/cofiCostFunc.m index 02d14a6..0f171af 100644 --- a/ex8/cofiCostFunc.m +++ b/ex8/cofiCostFunc.m @@ -40,7 +40,9 @@ Theta_grad = zeros(size(Theta)); % partial derivatives w.r.t. to each element of Theta % -J = 0.5 * sum(sum(R.*(X*Theta'-Y).^2)); +J = 0.5 * sum(sum(R.*(X*Theta'-Y).^2)) ... + + 0.5 * lambda * sum(sum(Theta.^2)) ... + + 0.5 * lambda * sum(sum(X.^2)); X_grad = (R.*(X*Theta'-Y))*Theta; % mov X user * uxer X feat = mov X feat Theta_grad = (R.*(X*Theta'-Y))'*X; % user X mov * mov X feat = user X feat