# HG changeset patch # User Pooja Rao # Date 1394777049 14400 # Node ID 314b4de4bb6dffb9840494afaafebf64980e4a94 # Parent e433efa383e4b3cc448ec9cfb40040f389397af7 Add BIST tests for subspace, t_test, z_test. * subspace.m, t_test.m, z_test.m: Add BIST tests. * contributors.in: Add Pooja Rao to list of contributors. diff -r e433efa383e4 -r 314b4de4bb6d doc/interpreter/contributors.in --- a/doc/interpreter/contributors.in Tue Nov 04 20:18:15 2014 -0800 +++ b/doc/interpreter/contributors.in Fri Mar 14 02:04:09 2014 -0400 @@ -245,6 +245,7 @@ Konstantinos Poulios Jarno Rajahalme Eduardo Ramos +Pooja Rao James B. Rawlings Eric S. Raymond Balint Reczey diff -r e433efa383e4 -r 314b4de4bb6d scripts/linear-algebra/subspace.m --- a/scripts/linear-algebra/subspace.m Tue Nov 04 20:18:15 2014 -0800 +++ b/scripts/linear-algebra/subspace.m Fri Mar 14 02:04:09 2014 -0400 @@ -60,3 +60,18 @@ endfunction + +%!test +%! ## For random vectors +%! a = rand (2,1); +%! b = rand (2,1); +%! a1 = norm (a,2); +%! b1 = norm (b,2); +%! theta = acos (dot (a,b)/(a1*b1)); +%! assert (theta, subspace (a, b), 100*eps); + +%!test +%! ## For random matrices +%! M = rand (3, 3); +%! assert (0, subspace (M, M'), 100*eps); + diff -r e433efa383e4 -r 314b4de4bb6d scripts/statistics/tests/t_test.m --- a/scripts/statistics/tests/t_test.m Tue Nov 04 20:18:15 2014 -0800 +++ b/scripts/statistics/tests/t_test.m Fri Mar 14 02:04:09 2014 -0400 @@ -82,3 +82,34 @@ endfunction + +%!test +%! ## Two-sided (also the default option) +%! x = rand (10,1); n = length (x); +%! u0 = 0.5; # true mean +%! xbar = mean (x); +%! pval = t_test (x, u0, "!="); +%! if (xbar >= u0) +%! tval = abs (tinv (0.5*pval, n-1)); +%! else +%! tval = -abs (tinv (0.5*pval, n-1)); +%! endif +%! unew = tval * std(x)/sqrt(n) + u0; +%! assert (xbar, unew, 100*eps); + +%!test +%! x = rand (10,1); n = length (x); +%! u0 = 0.5; +%! pval = t_test (x, u0, ">"); +%! tval = tinv (1-pval, n-1); +%! unew = tval * std(x)/sqrt(n) + u0; +%! assert (mean (x), unew, 100*eps); + +%!test +%! x = rand (10,1); n = length (x); +%! u0 = 0.5; +%! pval = t_test (x, u0, "<"); +%! tval = tinv (pval, n-1); +%! unew = tval * std(x)/sqrt(n) + u0; +%! assert (mean (x), unew, 100*eps); + diff -r e433efa383e4 -r 314b4de4bb6d scripts/statistics/tests/z_test.m --- a/scripts/statistics/tests/z_test.m Tue Nov 04 20:18:15 2014 -0800 +++ b/scripts/statistics/tests/z_test.m Fri Mar 14 02:04:09 2014 -0400 @@ -86,3 +86,33 @@ endfunction + +%!test +%! ## Two-sided (also the default option) +%! x = rand (10,1); n = length (x); +%! u0 = 0.5; v = 1/12; # true mean, var +%! pval = z_test (x, u0, v, "!="); +%! if (mean (x) >= u0) +%! zval = abs (norminv (0.5*pval)); +%! else +%! zval = -abs (norminv (0.5*pval)); +%! endif +%! unew = zval * sqrt (v/n) + u0; +%! assert (mean (x), unew, 100*eps); + +%!test +%! x = rand (10,1); n = length (x); +%! u0 = 0.5; v = 1/12; +%! pval = z_test (x, u0, v, ">"); +%! zval = norminv (1-pval); +%! unew = zval * sqrt (v/n) + u0; +%! assert (mean (x), unew, 100*eps); + +%!test +%! x = rand (10,1); n = length (x); +%! u0 = 0.5; v = 1/12; +%! pval = z_test (x, u0, v, "<"); +%! zval = norminv (pval); +%! unew = zval * sqrt (v/n) + u0; +%! assert (mean (x), unew, 100*eps); +