00001 #ifndef _theplu_yat_statistics_averager_
00002 #define _theplu_yat_statistics_averager_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "yat/utility/iterator_traits.h"
00029
00030 #include <boost/concept_check.hpp>
00031
00032 #include <cmath>
00033
00034 namespace theplu{
00035 namespace yat{
00036 namespace statistics{
00037
00038 class ostream;
00039
00045 class Averager
00046 {
00047 public:
00048
00052 Averager(void);
00053
00058 Averager(double x, double xx, long n);
00059
00063 Averager(const Averager& a);
00064
00068 void add(double d, long n=1);
00069
00078 double cv(void) const;
00079
00083 double mean(void) const;
00084
00088 long n(void) const;
00089
00095 void rescale(double a);
00096
00101 double standard_error(void) const;
00102
00109 double std(void) const;
00110
00117 double std(double m) const;
00118
00122 double sum_x(void) const;
00123
00127 double sum_xx(void) const;
00128
00132 double sum_xx_centered(void) const;
00133
00142 double variance(double m) const;
00143
00152 double variance(void) const;
00153
00162 double variance_unbiased(void) const;
00163
00167 void reset(void);
00168
00172 const Averager& operator=(const Averager&);
00173
00177 const Averager& operator+=(const Averager&);
00178
00179 private:
00180 long n_;
00181 double x_, xx_;
00182 };
00183
00184
00190 template <typename InputIterator>
00191 void add(Averager& a, InputIterator first, InputIterator last)
00192 {
00193 BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>));
00194 utility::check_iterator_is_unweighted(first);
00195 for ( ; first != last; ++first)
00196 a.add(*first);
00197 }
00198
00199 }}}
00200
00201 #endif