From d176764f9c54dc1e36c0650c6b341e306a41b339 Mon Sep 17 00:00:00 2001 From: julien Lengrand-Lambert Date: Sun, 3 Jan 2016 12:26:28 +0100 Subject: [PATCH] Finishes Week 9 assignment --- machine-learning-ex8/ex8/cofiCostFunc.m | 8 +++++++- machine-learning-ex8/ex8/ex8_cofi.m | 4 ++-- machine-learning-ex8/ex8/token.mat | Bin 262 -> 262 bytes 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/machine-learning-ex8/ex8/cofiCostFunc.m b/machine-learning-ex8/ex8/cofiCostFunc.m index 70896b5..97e7fde 100644 --- a/machine-learning-ex8/ex8/cofiCostFunc.m +++ b/machine-learning-ex8/ex8/cofiCostFunc.m @@ -46,7 +46,7 @@ t3 = t2(R==1); % only when movie has been rated. temp = sum(t3(:)); J = (1/2) * (temp); -% adding regularization +% adding regularization to cost x_temp = X.^2; theta_temp = Theta.^2; reg_x = (lambda / 2) * sum(x_temp(:)); @@ -58,6 +58,12 @@ temp1 = ((Theta*X')' - Y); temp1(find(R==0)) = 0; % only when movie has been rated. X_grad = temp1 * Theta; Theta_grad = temp1' * X; + +% adding regularization to gradients +X_temp2 = X.*lambda; +Theta_temp2 = Theta.*lambda; +X_grad = X_grad + X_temp2; +Theta_grad = Theta_grad + Theta_temp2; % ============================================================= grad = [X_grad(:); Theta_grad(:)]; diff --git a/machine-learning-ex8/ex8/ex8_cofi.m b/machine-learning-ex8/ex8/ex8_cofi.m index 57baa20..d8f224f 100644 --- a/machine-learning-ex8/ex8/ex8_cofi.m +++ b/machine-learning-ex8/ex8/ex8_cofi.m @@ -40,7 +40,7 @@ ylabel('Movies'); xlabel('Users'); fprintf('\nProgram paused. Press enter to continue.\n'); -% pause; +pause; %% ============ Part 2: Collaborative Filtering Cost Function =========== % You will now implement the cost function for collaborative filtering. @@ -66,7 +66,7 @@ fprintf(['Cost at loaded parameters: %f '... '\n(this value should be about 22.22)\n'], J); fprintf('\nProgram paused. Press enter to continue.\n'); -% pause; +pause; %% ============== Part 3: Collaborative Filtering Gradient ============== diff --git a/machine-learning-ex8/ex8/token.mat b/machine-learning-ex8/ex8/token.mat index aa3c5d91bbd815bedad72400d5733bdc998afee4..9ba66e8b7a4ca11db0a8e7ab726625117572285c 100644 GIT binary patch delta 25 gcmZo;YGaz<%xPj}Y_4ErU}!cmP%@{t096$SKmY&$ delta 25 gcmZo;YGaz<%xPq0XsBRhU}!cmP%@{t091DeHUIzs