Skip to content

Commit

Permalink
Additional sigmoid from Apurva, non-square costFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
cod3monk3y committed Mar 31, 2014
1 parent 3b1db0b commit 9410e10
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
20 changes: 20 additions & 0 deletions ex2/test_costfunction_forums.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function test_costfunction_forums ()
epsilon = 1e-4;

% CTA Colin Beckingham
% https://class.coursera.org/ml-005/forum/thread?thread_id=943#post-4641
[J grad] = costFunction([0 1 0]', magic(3), [1 2 3]');
assert( J, -7.5600, epsilon );
assert( grad, [-4.3907 -7.7678 -4.2202]', epsilon);


% Me - non-square matrix example
% I HAVE NOT VALIDATE THIS BY HAND
% https://class.coursera.org/ml-005/forum/thread?thread_id=943#comment-3379
X = magic(3)(1:2,:)
[J grad] = costFunction([1 2 3]', X, [4 5]');
assert( J, -109.93, 1e-2 );
assert( grad, [-18.000 -11.500 -23.000]', 1e-2);


endfunction
2 changes: 2 additions & 0 deletions ex2/test_ex2.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

%!test test_costfunction_nontrivial()

%!test test_costfunction_forums()

%!test test_predict()

%!test test_costfunction_reg_minimal()
Expand Down
9 changes: 7 additions & 2 deletions ex2/test_sigmoid.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ function test_sigmoid ()
%
% Apurva Dubey
%
assert(sigmoid([1 2 3]), [0.73106 0.88080 0.95257], 1e-4);
assert(sigmoid([4 -2 -3]), [0.98201 0.119203 0.047426], 1e-4);
epsilon = 1e-4;
assert(sigmoid([1 2 3]), [0.73106 0.88080 0.95257], epsilon);
assert(sigmoid([4 -2 -3]), [0.98201 0.119203 0.047426], epsilon);

% https://class.coursera.org/ml-005/forum/thread?thread_id=943#comment-3352
assert( sigmoid([-1.414 2.739 -3.1415 pi sin(pi/2)]),
[0.195604 0.939289 0.041428 0.958576 0.731059 ], epsilon );

endfunction

0 comments on commit 9410e10

Please sign in to comment.