00001 #ifndef _theplu_yat_statistics_averagerpairweighted_
00002 #define _theplu_yat_statistics_averagerpairweighted_
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 "AveragerWeighted.h"
00028
00029 #include "yat/utility/iterator_traits.h"
00030 #include "yat/utility/yat_assert.h"
00031
00032 #include <cmath>
00033 #include <stdexcept>
00034
00035 namespace theplu{
00036 namespace yat{
00037 namespace statistics{
00053 class AveragerPairWeighted
00054 {
00055 public:
00056
00060 AveragerPairWeighted(void);
00061
00067 void add(const double x, const double y,
00068 const double wx, const double wy);
00069
00077 double correlation(void) const;
00078
00083 double covariance(void) const;
00084
00088 double msd(void) const;
00089
00093 double n(void) const;
00094
00098 void reset(void);
00099
00103 double sum_w(void) const;
00104
00108 double sum_xy(void) const;
00109
00114 double sum_xy_centered(void) const;
00115
00121 const AveragerWeighted& x_averager(void) const;
00122
00128 const AveragerWeighted& y_averager(void) const;
00129
00130 private:
00131 AveragerWeighted x_;
00132 AveragerWeighted y_;
00133 double wxy_;
00134 double w_;
00135
00136 };
00137
00141 template <class Iter1, class Iter2>
00142 void add(AveragerPairWeighted& ap, Iter1 first1, Iter1 last1, Iter2 first2)
00143 {
00144 for ( ; first1 != last1; ++first1, ++first2) {
00145 ap.add(utility::iterator_traits<Iter1>().data(first1),
00146 utility::iterator_traits<Iter2>().data(first2),
00147 utility::iterator_traits<Iter1>().weight(first1),
00148 utility::iterator_traits<Iter2>().weight(first2));
00149 }
00150 }
00151
00152
00156 template <class Iter1, class Iter2, class Iter3, class Iter4>
00157 void add(AveragerPairWeighted& ap, Iter1 x, Iter1 xlast, Iter2 y, Iter3 wx,
00158 Iter4 wy)
00159 {
00160 utility::check_iterator_is_unweighted(x);
00161 utility::check_iterator_is_unweighted(y);
00162 utility::check_iterator_is_unweighted(wx);
00163 utility::check_iterator_is_unweighted(wy);
00164 while (x!=xlast) {
00165 ap.add(*x, *y, *wx, *wy);
00166 ++x;
00167 ++y;
00168 ++wx;
00169 ++wy;
00170 }
00171 }
00172
00173
00174 }}}
00175
00176 #endif