-
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.
added: ex1 unit tests from https://class.coursera.org/ml-005/forum/th…
- Loading branch information
Showing
9 changed files
with
98 additions
and
0 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,8 @@ | ||
function test_computeCost () | ||
epsilon = 1e-4; | ||
|
||
x = computeCost([1 2 3; 1 3 4; 1 4 5; 1 5 6], [7;6;5;4], [0.1;0.2;0.3]); | ||
a = 7.0175; | ||
assert(x, a, epsilon); | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function test_computeCostMulti () | ||
epsilon = 1e-4; | ||
|
||
x = computeCostMulti( [ 2 1 3; 7 1 9; 1 8 1; 3 7 4 ], [ 2; 5; 5; 6 ], [ 0.3816; 0.7655; 0.7952 ] ); | ||
a = 6.7273; | ||
assert(x, a, epsilon); | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
%!test test_sanity() | ||
|
||
%!test test_warmup() | ||
|
||
%!test test_computeCost() | ||
|
||
%!test test_gradientDescent | ||
|
||
%!test test_featureNormalize | ||
|
||
%!test test_computeCostMulti | ||
|
||
%!test test_gradientDescentMulti | ||
|
||
%!test test_normalEqn |
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,24 @@ | ||
function test_featureNormalize () | ||
epsilon = 1e-4; | ||
|
||
x = featureNormalize([1 2 3]'); | ||
a = [-1; 0; 1]; | ||
assert(x, a, epsilon); | ||
|
||
x = featureNormalize([1 2 3;6 4 2]'); | ||
a = [-1 1; 0 0; 1 -1]; | ||
assert(x, a, epsilon); | ||
|
||
x = featureNormalize( [ 8 1 6; 3 5 7; 4 9 2 ] ); | ||
a = [1.1339 -1.0000 0.3780; -0.7559 0 0.7559; -0.3780 1.0000 -1.1339]; | ||
assert(x, a, epsilon); | ||
|
||
x = featureNormalize([1 2 3 1;6 4 2 0;11 3 3 9;4 9 8 8]'); | ||
a = [ | ||
-0.78335 1.16190 1.09141 -1.46571; | ||
0.26112 0.38730 -0.84887 0.78923; | ||
1.30558 -0.38730 -0.84887 0.33824; | ||
-0.78335 -1.16190 0.60634 0.33824]; | ||
assert(x, a, epsilon); | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function test_gradientDescent () | ||
epsilon = 1e-4; | ||
|
||
x = gradientDescent([1 5; 1 2; 1 4; 1 5],[1 6 4 2]',[0 0]',0.01,1000); | ||
a = [5.2148; -0.5733]; | ||
assert(x, a, epsilon); | ||
|
||
x = gradientDescent([3 5; 1 2; 9 4; 1 5],[1 6 4 2]',[0 0]',0.01,1000); | ||
a = [0.2588; 0.3999]; | ||
assert(x, a, epsilon); | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function test_gradientDescentMulti () | ||
epsilon = 1e-4; | ||
|
||
x = gradientDescentMulti([3 5 6; 1 2 3; 9 4 2],[1 6 4]',[0 0 0]',0.01,1000); | ||
a = [ | ||
1.2123; | ||
-2.9458; | ||
2.3219]; | ||
|
||
assert(x, a, epsilon); | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function test_normalEqn () | ||
epsilon = 1e-4; | ||
|
||
x = normalEqn([1 0; 0 2],[1 1]'); | ||
a = [ | ||
1.00000; | ||
0.50000]; | ||
assert(x, a, epsilon); | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function test_sanity () | ||
% make sure tests are running correctly | ||
assert(1,1); | ||
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function test_warmup () | ||
X = warmUpExercise(); | ||
A = eye(5); | ||
assert(X, A) | ||
endfunction |