Skip to content

Commit

Permalink
added test_costFunctionReg & included it in the test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
etjones-erisyon committed Mar 29, 2014
1 parent 3a50775 commit a9747f6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
32 changes: 32 additions & 0 deletions ex2/test_costFunctionReg.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function test_costFunctionReg ()
tolerance = 1e-3;
% Test 1, w/ lambda = 3
% From TA Colin Beckingham, at https://class.coursera.org/ml-005/forum/thread?thread_id=943#post-4593
theta = [2; 1; -9];
X = magic(3);
y = [1; -0.2; 3];
lambda = 3;

J_exp = 50.971;
grad_exp = [-6.1081 -7.1932 -12.3540];

[J, grad] = costFunctionReg(theta, X, y, lambda);

assert(J, J_exp, tolerance );
assert(grad, grad_exp, tolerance);

% Test 2, w/ lambda = 0.1
% From TA Colin Beckingham, at https://class.coursera.org/ml-005/forum/thread?thread_id=943#post-4666
theta = [2; 1; -9];
X = magic(3);
y = [1; -0.2; 3];
lambda = 0.1;
J_exp_2 = 11.338;
grad_exp_2 = [-6.1081 -8.1598 -3.6540];

[J, grad] = costFunctionReg(theta, X, y, lambda);

assert(J, J_exp_2, tolerance );
assert(grad, grad_exp_2, tolerance);

endfunction
4 changes: 3 additions & 1 deletion ex2/test_ex2.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@

%!test test_costfunction_nontrivial()

%!test test_predict()
%!test test_predict()

%!test test_costFunctionReg()

0 comments on commit a9747f6

Please sign in to comment.