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 % =============================================================