00001 #ifndef _theplu_yat_statistics_averagerweighted_
00002 #define _theplu_yat_statistics_averagerweighted_
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 "Averager.h"
00029 #include "yat/utility/iterator_traits.h"
00030
00031 #include <boost/concept_check.hpp>
00032
00033 #include <cmath>
00034
00035 namespace theplu{
00036 namespace yat{
00037 namespace statistics{
00038
00066 class AveragerWeighted
00067 {
00068 public:
00069
00073 AveragerWeighted(void);
00074
00078 AveragerWeighted(const AveragerWeighted&);
00079
00083 void add(const double d,const double w=1);
00084
00090 double mean(void) const;
00091
00103 double n(void) const;
00104
00110 void rescale(double a);
00111
00115 void reset(void);
00116
00123 double std(void) const;
00124
00136 double standard_error(void) const;
00137
00143 double sum_w(void) const;
00144
00148 double sum_ww(void) const;
00149
00155 double sum_wx(void) const;
00156
00160 double sum_wxx(void) const;
00161
00165 double sum_xx_centered(void) const;
00166
00173 double variance(const double m) const;
00174
00184 double variance(void) const;
00185
00191 const AveragerWeighted& operator+=(const AveragerWeighted&);
00192
00193 private:
00197 double sum_wwx(void) const;
00198
00202 double sum_wwxx(void) const;
00203
00204 const Averager& wx(void) const;
00205 const Averager& w(void) const;
00206
00207 Averager w_;
00208 Averager wx_;
00209 double wwx_;
00210 double wxx_;
00211 };
00212
00220 template <typename InputIterator>
00221 void add(AveragerWeighted& a, InputIterator first, InputIterator last)
00222 {
00223 BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>));
00224 utility::iterator_traits<InputIterator> traits;
00225 for ( ; first != last; ++first)
00226 a.add(traits.data(first), traits.weight(first));
00227 }
00228
00240 template <typename InputIterator1, typename InputIterator2>
00241 void add(AveragerWeighted& a, InputIterator1 first1, InputIterator1 last1,
00242 InputIterator2 first2)
00243 {
00244 BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator1>));
00245 BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator2>));
00246 utility::check_iterator_is_unweighted(first1);
00247 utility::check_iterator_is_unweighted(first2);
00248 for ( ; first1 != last1; ++first1, ++first2)
00249 a.add(*first1, *first2);
00250 }
00251
00252 }}}
00253
00254 #endif