Skip to content
This repository has been archived by the owner on Sep 25, 2022. It is now read-only.

Commit

Permalink
ex8
Browse files Browse the repository at this point in the history
  • Loading branch information
ngosangns committed Feb 24, 2019
1 parent 08ca546 commit 58e8a53
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
26 changes: 16 additions & 10 deletions ex/ex8/cofiCostFunc.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,23 @@
% partial derivatives w.r.t. to each element of Theta
%

for i = 1:num_movies
for j = 1:num_users
if(R(i, j)==1)
J = J + (Theta(j, :)*transpose(X(i, :))-Y(i, j)).^2;
end;
end;
% J ---------------------------
% X = m*k
% Theta = j*k
% Y = m*j = R
J = (X*transpose(Theta)-Y).^2;
J = sum(sum(J.*R));
J = (J + lambda*(sum(sum(Theta.^2)) + sum(sum(X.^2))))/2;
% X_grad ----------------------
for k = 1:num_features
X_grad = ((X*transpose(Theta)-Y).*R)*Theta;
X_grad = X_grad + (lambda.*X);
end;
% Theta_grad ------------------
for k = 1:num_features
Theta_grad = transpose((X*transpose(Theta)-Y).*R)*X;
Theta_grad = Theta_grad + (lambda.*Theta);
end;
X = [zeros(num_movies, 1) X(:, 2:end)];
Theta = [zeros(num_movies, 1) Theta(:, 2:end)];
J = J + sum(sum(X.^2)) + sum(sum(Theta.^2));
X(:, 1) = ones(num_movies, 1);

% =============================================================

Expand Down
15 changes: 15 additions & 0 deletions ex/ex8/token.mat
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Created by Octave 4.4.1, Sun Feb 24 12:03:11 2019 GMT <unknown@DESKTOP-MBF20VQ>
# name: email
# type: sq_string
# elements: 1
# length: 21
scotter7902@gmail.com


# name: token
# type: sq_string
# elements: 1
# length: 16
PXFW0JhAbEF8jIoG


0 comments on commit 58e8a53

Please sign in to comment.