Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r80451 - sandbox/variadic_templates/sandbox/array_dyn
From: cppljevans_at_[hidden]
Date: 2012-09-08 11:19:30


Author: cppljevans
Date: 2012-09-08 11:19:30 EDT (Sat, 08 Sep 2012)
New Revision: 80451
URL: http://svn.boost.org/trac/boost/changeset/80451

Log:
Add bessel correction to reducer_variance.

Text files modified:
   sandbox/variadic_templates/sandbox/array_dyn/reduce_axis.cpp | 24 ++++++++++++++++++++----
   1 files changed, 20 insertions(+), 4 deletions(-)

Modified: sandbox/variadic_templates/sandbox/array_dyn/reduce_axis.cpp
==============================================================================
--- sandbox/variadic_templates/sandbox/array_dyn/reduce_axis.cpp (original)
+++ sandbox/variadic_templates/sandbox/array_dyn/reduce_axis.cpp 2012-09-08 11:19:30 EDT (Sat, 08 Sep 2012)
@@ -98,6 +98,21 @@
 };
 struct reducer_variance
 {
+ unsigned const
+ my_bessel_correction
+ /**@brief
+ * == 0 or 1, indicating whether to use
+ * Bessel's correction:
+ * http://en.wikipedia.org/wiki/Bessel%27s_correction
+ * if == 0, don't correct.
+ * if == 1, then do correct.
+ */
+ ;
+ reducer_variance
+ ( bool a_bessel_correction=false
+ )
+ : my_bessel_correction(a_bessel_correction?1:0)
+ {}
       template
       < typename Iter
>
@@ -110,6 +125,9 @@
        * return value == variance of data in sample, *beg ... *(end-1).
        */
       {
+ auto
+ sample_size=beg.distance(end);
+ assert(sample_size > my_bessel_correction);
               typedef
             typename Iter::value_type
           val_t
@@ -125,9 +143,7 @@
             , end
             , reduce_add_v
             );
- auto
- d=beg.distance(end);
- mean_v=mean_v/d
+ mean_v=mean_v/sample_size
             //mean_v = mean of data in *beg ... *(end-1)
             ;
             val_t
@@ -140,7 +156,7 @@
             , end
             , reduce_var_v
             );
- var_v=var_v/d
+ var_v=var_v/(sample_size-my_bessel_correction)
             //var_v = variance of data in *beg ... *(end-1)
             ;
           return var_v;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk