From 2d4ad882adfd97a6efff58ab8655190ca0641472 Mon Sep 17 00:00:00 2001 From: Merouane Atig Date: Mon, 12 Dec 2011 09:05:10 +0100 Subject: [PATCH] Gradient with regularization --- mlclass-ex8/cofiCostFunc.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mlclass-ex8/cofiCostFunc.m b/mlclass-ex8/cofiCostFunc.m index 3dcc3f2..5ca85fd 100644 --- a/mlclass-ex8/cofiCostFunc.m +++ b/mlclass-ex8/cofiCostFunc.m @@ -46,14 +46,14 @@ idx = find(R(i, :) == 1); Theta_temp = Theta(idx, :); Y_temp = Y(i, idx); - X_grad(i, :) = (X(i, :) * Theta_temp' - Y_temp) * Theta_temp; + X_grad(i, :) = (X(i, :) * Theta_temp' - Y_temp) * Theta_temp + lambda * X(i, :); end for i=1:num_users idx = find(R(:, i) == 1); X_temp = X(idx, :); Y_temp = Y(idx, i); - Theta_grad(i, :) = (X_temp * Theta(i, :)' - Y_temp)' * X_temp; + Theta_grad(i, :) = (X_temp * Theta(i, :)' - Y_temp)' * X_temp + lambda * Theta(i, :); end % =============================================================