public inbox for gsl-discuss@sourceware.org
 help / color / mirror / Atom feed
From: "Jonathan \"Duke\" Leto" <jaleto@gmail.com>
To: gsl-discuss@sourceware.org
Subject: Rstat improvements
Date: Mon, 03 Oct 2016 05:57:00 -0000	[thread overview]
Message-ID: <CABQG1aSMQz5XJKwnZRGzG+493cB3F3hXA=hPu_kswWv6+2C-zQ@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 331 bytes --]

Howdy,

I have made some improvements to the rstat example, tests and docs.
Documentation for gsl_rstat_sd_mean has been added and now all rstat
functions are tested, including gsl_rstat_n and gsl_rstat_reset.

I have attached the patch and the diff is also viewable here:

https://github.com/leto/gsl/compare/rstat

Thanks,

Duke

[-- Attachment #2: 0001-Improve-tests-examples-and-docs-for-rstat-module.patch --]
[-- Type: application/octet-stream, Size: 5864 bytes --]

From a068128f2a61aec255c5ae8ab3141a032a955e7a Mon Sep 17 00:00:00 2001
From: "Jonathan \"Duke\" Leto" <jonathan@leto.net>
Date: Sun, 2 Oct 2016 22:22:35 -0700
Subject: [PATCH] Improve tests, examples and docs for rstat module

---
 doc/examples/rstat.c   | 23 +++++++++++++++++++++--
 doc/examples/rstat.txt |  8 ++++++++
 doc/rstat.texi         | 18 ++++++++++++++++++
 rstat/test.c           | 26 +++++++++++++++++++-------
 4 files changed, 66 insertions(+), 9 deletions(-)

diff --git a/doc/examples/rstat.c b/doc/examples/rstat.c
index 7152be6..645507d 100644
--- a/doc/examples/rstat.c
+++ b/doc/examples/rstat.c
@@ -5,9 +5,10 @@ int
 main(void)
 {
   double data[5] = {17.2, 18.1, 16.5, 18.3, 12.6};
-  double mean, variance, largest, smallest;
+  double mean, variance, largest, smallest, sd,
+         rms, sd_mean, median, skew, kurtosis;
   gsl_rstat_workspace *rstat_p = gsl_rstat_alloc();
-  size_t i;
+  size_t i, n;
 
   /* add data to rstat accumulator */
   for (i = 0; i < 5; ++i)
@@ -17,6 +18,13 @@ main(void)
   variance = gsl_rstat_variance(rstat_p);
   largest  = gsl_rstat_max(rstat_p);
   smallest = gsl_rstat_min(rstat_p);
+  median   = gsl_rstat_median(rstat_p);
+  sd       = gsl_rstat_sd(rstat_p);
+  sd_mean  = gsl_rstat_sd_mean(rstat_p);
+  skew     = gsl_rstat_skew(rstat_p);
+  rms      = gsl_rstat_rms(rstat_p);
+  kurtosis = gsl_rstat_kurtosis(rstat_p);
+  n        = gsl_rstat_n(rstat_p);
 
   printf ("The dataset is %g, %g, %g, %g, %g\n",
          data[0], data[1], data[2], data[3], data[4]);
@@ -25,6 +33,17 @@ main(void)
   printf ("The estimated variance is %g\n", variance);
   printf ("The largest value is %g\n", largest);
   printf ("The smallest value is %g\n", smallest);
+  printf( "The median is %g\n", median);
+  printf( "The standard deviation is %g\n", sd);
+  printf( "The root mean square is %g\n", rms);
+  printf( "The standard devation of the mean is %g\n", sd_mean);
+  printf( "The skew is %g\n", skew);
+  printf( "The kurtosis %g\n", kurtosis);
+  printf( "There are %zu items in the accumulator\n", n);
+
+  gsl_rstat_reset(rstat_p);
+  n = gsl_rstat_n(rstat_p);
+  printf( "There are %zu items in the accumulator\n", n);
 
   gsl_rstat_free(rstat_p);
 
diff --git a/doc/examples/rstat.txt b/doc/examples/rstat.txt
index a1d53bc..8c3bcf7 100644
--- a/doc/examples/rstat.txt
+++ b/doc/examples/rstat.txt
@@ -3,3 +3,11 @@ The sample mean is 16.54
 The estimated variance is 5.373
 The largest value is 18.3
 The smallest value is 12.6
+The median is 16.5
+The standard deviation is 2.31797
+The root mean square is 16.6694
+The standard devation of the mean is 1.03663
+The skew is -0.829058
+The kurtosis -1.2217
+There are 5 items in the accumulator
+There are 0 items in the accumulator
diff --git a/doc/rstat.texi b/doc/rstat.texi
index dcd173b..e4272af 100644
--- a/doc/rstat.texi
+++ b/doc/rstat.texi
@@ -110,6 +110,24 @@ This function returns the standard deviation of all data added to the
 accumulator, defined as the square root of the variance given above.
 @end deftypefun
 
+@deftypefun double gsl_rstat_sd_mean (gsl_rstat_workspace * @var{w})
+This function returns the standard deviation of the mean, defined as
+@tex
+\beforedisplay
+$$
+sd_mean = {\Hat\sigma} \over \sqrt{N}
+$$
+\afterdisplay
+@end tex
+@ifinfo
+
+@example
+sd_mean = \Hat\sigma / \sqrt (N)
+@end example
+
+@end ifinfo
+@end deftypefun
+
 @deftypefun double gsl_rstat_rms (gsl_rstat_workspace * @var{w})
 This function returns the root mean square of all data added to the
 accumulator, defined as
diff --git a/rstat/test.c b/rstat/test.c
index d226ab5..1359564 100644
--- a/rstat/test.c
+++ b/rstat/test.c
@@ -49,11 +49,13 @@ test_basic(const size_t n, const double data[], const double tol)
   const double expected_mean = gsl_stats_mean(data, 1, n);
   const double expected_var = gsl_stats_variance(data, 1, n);
   const double expected_sd = gsl_stats_sd(data, 1, n);
+  const double expected_sd_mean = expected_sd / sqrt(n);
   const double expected_skew = gsl_stats_skew(data, 1, n);
   const double expected_kurtosis = gsl_stats_kurtosis(data, 1, n);
   double expected_rms = 0.0;
-  double mean, var, sd, rms, skew, kurtosis;
-  size_t i;
+  double mean, var, sd, sd_mean, rms, skew, kurtosis;
+  size_t i, num;
+  int status;
 
   /* compute expected rms */
   for (i = 0; i < n; ++i)
@@ -65,20 +67,30 @@ test_basic(const size_t n, const double data[], const double tol)
   for (i = 0; i < n; ++i)
     gsl_rstat_add(data[i], rstat_workspace_p);
 
-  mean = gsl_rstat_mean(rstat_workspace_p);
-  var = gsl_rstat_variance(rstat_workspace_p);
-  sd = gsl_rstat_sd(rstat_workspace_p);
-  rms = gsl_rstat_rms(rstat_workspace_p);
-  skew = gsl_rstat_skew(rstat_workspace_p);
+  mean     = gsl_rstat_mean(rstat_workspace_p);
+  var      = gsl_rstat_variance(rstat_workspace_p);
+  sd       = gsl_rstat_sd(rstat_workspace_p);
+  sd_mean  = gsl_rstat_sd_mean(rstat_workspace_p);
+  rms      = gsl_rstat_rms(rstat_workspace_p);
+  skew     = gsl_rstat_skew(rstat_workspace_p);
   kurtosis = gsl_rstat_kurtosis(rstat_workspace_p);
+  num      = gsl_rstat_n(rstat_workspace_p);
 
+  gsl_test_int(num, n, "n=%zu" , num);
   gsl_test_rel(mean, expected_mean, tol, "mean n=%zu", n);
   gsl_test_rel(var, expected_var, tol, "variance n=%zu", n);
   gsl_test_rel(sd, expected_sd, tol, "stddev n=%zu", n);
+  gsl_test_rel(sd_mean, expected_sd_mean, tol, "stddev_mean n=%zu", n);
   gsl_test_rel(rms, expected_rms, tol, "rms n=%zu", n);
   gsl_test_rel(skew, expected_skew, tol, "skew n=%zu", n);
   gsl_test_rel(kurtosis, expected_kurtosis, tol, "kurtosis n=%zu", n);
 
+  status = gsl_rstat_reset(rstat_workspace_p);
+  gsl_test_int(status, GSL_SUCCESS, "rstat returned success");
+  num    = gsl_rstat_n(rstat_workspace_p);
+
+  gsl_test_int(num, 0, "n=%zu" , num);
+
   gsl_rstat_free(rstat_workspace_p);
 }
 
-- 
2.5.0


             reply	other threads:[~2016-10-03  5:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-03  5:57 Jonathan "Duke" Leto [this message]
2016-10-03  9:24 ` Patrick Alken

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABQG1aSMQz5XJKwnZRGzG+493cB3F3hXA=hPu_kswWv6+2C-zQ@mail.gmail.com' \
    --to=jaleto@gmail.com \
    --cc=gsl-discuss@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).