-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from etjones/master
Added test_costFunctionReg to ex2 tests
- Loading branch information
Showing
3 changed files
with
43 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,6 @@ | |
|
||
%!test test_costfunction_nontrivial() | ||
|
||
%!test test_predict() | ||
%!test test_predict() | ||
|
||
%!test test_costFunctionReg() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters