Commits

Dhananjay Nene  committed 0c8ca97

Solved part 4 of exercise 8 (gradient computation)

  • Participants
  • Parent commits 39bbd64

Comments (0)

Files changed (1)

File exercise-8/octave/cofiCostFunc.m

 %                     partial derivatives w.r.t. to each element of Theta
 %
 
-J = sum(sum(((X * Theta' - Y) .^2) .* R /2))
+J = sum(sum(((X * Theta' - Y) .^2) .* R /2));
+for i=1:size(X,1)
+  idx = find(R(i,:)==1);
+  Theta_t = Theta(idx,:);
+  X_grad(i,:) = (X(i,:) * Theta_t' - Y(i,idx)) * Theta_t;
+end
+for i = 1:size(Theta,1)
+  idx = find(R(:,i)==1);
+  Theta_grad(i,:) = (X(idx,:)' * (X(idx,:) * Theta(i,:)' - Y(idx,i)))';
+end
+
+