changeset 19340:314b4de4bb6d

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.
author Pooja Rao <poojarao12@gmail.com>
date Fri, 14 Mar 2014 02:04:09 -0400
parents e433efa383e4
children 0f70468a56cd
files doc/interpreter/contributors.in scripts/linear-algebra/subspace.m scripts/statistics/tests/t_test.m scripts/statistics/tests/z_test.m
diffstat 4 files changed, 77 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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);
+
--- 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);
+
--- 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);
+