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 #include "yat/utility/iterator_traits.h"
00028
00029 #include <cmath>
00030
00031 namespace theplu{
00032 namespace yat{
00033 namespace statistics{
00034
00035 class ostream;
00036
00042 class Averager
00043 {
00044 public:
00045
00049 Averager(void);
00050
00055 Averager(double x, double xx, long n);
00056
00060 Averager(const Averager& a);
00061
00065 void add(double d, long n=1);
00066
00075 double cv(void) const;
00076
00080 double mean(void) const;
00081
00085 long n(void) const;
00086
00093 void rescale(double a);
00094
00099 double standard_error(void) const;
00100
00107 double std(void) const;
00108
00115 double std(double m) const;
00116
00120 double sum_x(void) const;
00121
00125 double sum_xx(void) const;
00126
00130 double sum_xx_centered(void) const;
00131
00140 double variance(double m) const;
00141
00150 double variance(void) const;
00151
00160 double variance_unbiased(void) const;
00161
00165 void reset(void);
00166
00170 const Averager& operator=(const Averager&);
00171
00175 const Averager& operator+=(const Averager&);
00176
00177 private:
00178 long n_;
00179 double x_, xx_;
00180 };
00181
00182
00186 template <typename Iter>
00187 void add(Averager& a, Iter first, Iter last)
00188 {
00189 utility::check_iterator_is_unweighted(first);
00190 for ( ; first != last; ++first)
00191 a.add(*first);
00192 }
00193
00194 }}}
00195
00196 #endif