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
00028 #include "AveragerWeighted.h"
00029
00030 #include "yat/utility/iterator_traits.h"
00031 #include "yat/utility/yat_assert.h"
00032
00033 #include <boost/concept_check.hpp>
00034
00035 #include <cmath>
00036 #include <stdexcept>
00037
00038 namespace theplu{
00039 namespace yat{
00040 namespace statistics{
00056 class AveragerPairWeighted
00057 {
00058 public:
00059
00063 AveragerPairWeighted(void);
00064
00070 void add(const double x, const double y,
00071 const double wx, const double wy);
00072
00080 double correlation(void) const;
00081
00086 double covariance(void) const;
00087
00091 double msd(void) const;
00092
00096 double n(void) const;
00097
00101 void reset(void);
00102
00106 double sum_w(void) const;
00107
00111 double sum_xy(void) const;
00112
00117 double sum_xy_centered(void) const;
00118
00124 const AveragerWeighted& x_averager(void) const;
00125
00131 const AveragerWeighted& y_averager(void) const;
00132
00133 private:
00134 AveragerWeighted x_;
00135 AveragerWeighted y_;
00136 double wxy_;
00137 double w_;
00138
00139 };
00140
00146 template <class InputIterator1, class InputIterator2>
00147 void add(AveragerPairWeighted& ap, InputIterator1 first1,
00148 InputIterator1 last1, InputIterator2 first2)
00149 {
00150 BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator1>));
00151 BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator2>));
00152 utility::iterator_traits<InputIterator1> traits1;
00153 utility::iterator_traits<InputIterator2> traits2;
00154 for ( ; first1 != last1; ++first1, ++first2) {
00155 ap.add(traits1.data(first1), traits2.data(first2),
00156 traits1.weight(first1), traits2.weight(first2));
00157 }
00158 }
00159
00160
00168 template <typename InputIterator1, typename InputIterator2
00169 , typename InputIterator3, typename InputIterator4>
00170 void add(AveragerPairWeighted& ap, InputIterator1 x, InputIterator1 xlast,
00171 InputIterator2 y, InputIterator3 wx, InputIterator4 wy)
00172 {
00173 BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator1>));
00174 BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator2>));
00175 BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator3>));
00176 BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator4>));
00177 utility::check_iterator_is_unweighted(x);
00178 utility::check_iterator_is_unweighted(y);
00179 utility::check_iterator_is_unweighted(wx);
00180 utility::check_iterator_is_unweighted(wy);
00181 while (x!=xlast) {
00182 ap.add(*x, *y, *wx, *wy);
00183 ++x;
00184 ++y;
00185 ++wx;
00186 ++wy;
00187 }
00188 }
00189
00190
00191 }}}
00192
00193 #endif