Skip to content

Commit

Permalink
Merge pull request #2 from vasnake/ex1
Browse files Browse the repository at this point in the history
Ex1
  • Loading branch information
cod3monk3y committed Apr 1, 2014
2 parents f1ce1a4 + da61458 commit b5d394d
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ex1/test_computeCost.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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);

x = computeCost( [1 2; 1 3; 1 4; 1 5], [7;6;5;4], [0.1;0.2] );
a = 11.9450;
assert(x, a, epsilon);

endfunction
8 changes: 8 additions & 0 deletions ex1/test_computeCostMulti.m
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
15 changes: 15 additions & 0 deletions ex1/test_ex1.m
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
24 changes: 24 additions & 0 deletions ex1/test_featureNormalize.m
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
12 changes: 12 additions & 0 deletions ex1/test_gradientDescent.m
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
12 changes: 12 additions & 0 deletions ex1/test_gradientDescentMulti.m
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
10 changes: 10 additions & 0 deletions ex1/test_normalEqn.m
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
4 changes: 4 additions & 0 deletions ex1/test_sanity.m
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
5 changes: 5 additions & 0 deletions ex1/test_warmup.m
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

0 comments on commit b5d394d

Please sign in to comment.