Commits

Dhananjay Nene  committed df298e8

Solved part 6 of exercise 8 (gradient with regularisation)

  • Participants
  • Parent commits 88b3cdf

Comments (0)

Files changed (1)

File exercise-8/octave/cofiCostFunc.m

 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;
+  X_grad(i,:) = (X(i,:) * Theta_t' - Y(i,idx)) * Theta_t + lambda * X(i,:);
 end
 for i = 1:size(Theta,1)
   idx = find(R(:,i)==1);
-  Theta_grad(i,:) = (X(idx,:)' * (X(idx,:) * Theta(i,:)' - Y(idx,i)))';
+  Theta_grad(i,:) = (X(idx,:)' * (X(idx,:) * Theta(i,:)' - Y(idx,i)))' + lambda * Theta(i,:);
 end