|
|
@ -80,23 +80,14 @@ assert(size(J) == [1 1]);
|
|
|
|
% and Theta2_grad from Part 2.
|
|
|
|
% and Theta2_grad from Part 2.
|
|
|
|
%
|
|
|
|
%
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
% Note: Theta1/2 are matrixes here, we want all their rows, but skip their
|
|
|
|
|
|
|
|
% first column (not regularizing the bias term).
|
|
|
|
|
|
|
|
regularization_term = lambda/(2*m) * ...
|
|
|
|
|
|
|
|
(sum(sum(Theta1(:,2:end).^2)) ...
|
|
|
|
|
|
|
|
+ sum(sum(Theta2(:,2:end).^2)));
|
|
|
|
|
|
|
|
assert(size(regularization_term) == [1 1]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
J += regularization_term;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
% -------------------------------------------------------------
|
|
|
|
% -------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|