yat  0.8.3pre
AveragerPairWeighted.h
00001 #ifndef _theplu_yat_statistics_averagerpairweighted_
00002 #define _theplu_yat_statistics_averagerpairweighted_
00003 
00004 // $Id: AveragerPairWeighted.h 2571 2011-09-26 02:25:08Z peter $
00005 
00006 /*
00007   Copyright (C) 2005 Peter Johansson, Markus Ringnér
00008   Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér
00009   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
00010   Copyright (C) 2009, 2010, 2011 Peter Johansson
00011 
00012   This file is part of the yat library, http://dev.thep.lu.se/yat
00013 
00014   The yat library is free software; you can redistribute it and/or
00015   modify it under the terms of the GNU General Public License as
00016   published by the Free Software Foundation; either version 3 of the
00017   License, or (at your option) any later version.
00018 
00019   The yat library is distributed in the hope that it will be useful,
00020   but WITHOUT ANY WARRANTY; without even the implied warranty of
00021   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00022   General Public License for more details.
00023 
00024   You should have received a copy of the GNU General Public License
00025   along with yat. If not, see <http://www.gnu.org/licenses/>.
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 
00140     const AveragerPairWeighted& operator+=(const AveragerPairWeighted&);
00141 
00142   private:
00143     AveragerWeighted x_; // weighted averager with w = w_x*w_y
00144     AveragerWeighted y_; // weighted averager with w = w_x*w_y
00145     double wxy_centered_;
00146 
00147     void xy_add(double mx, double my, double xy_centered, double w);
00148   };
00149 
00155   template <class InputIterator1, class InputIterator2>
00156   void add(AveragerPairWeighted& ap, InputIterator1 first1, 
00157            InputIterator1 last1, InputIterator2 first2)
00158   {
00159     BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator1>));
00160     BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator2>));
00161     utility::iterator_traits<InputIterator1> traits1;
00162     utility::iterator_traits<InputIterator2> traits2;
00163     for ( ; first1 != last1; ++first1, ++first2) {
00164       ap.add(traits1.data(first1), traits2.data(first2), 
00165              traits1.weight(first1), traits2.weight(first2));
00166     }
00167   }
00168 
00169 
00177   template <typename InputIterator1, typename InputIterator2
00178             , typename InputIterator3, typename InputIterator4>
00179   void add(AveragerPairWeighted& ap, InputIterator1 x, InputIterator1 xlast, 
00180            InputIterator2 y, InputIterator3 wx, InputIterator4 wy)
00181   {
00182     BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator1>));
00183     BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator2>));
00184     BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator3>));
00185     BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator4>));
00186     utility::check_iterator_is_unweighted(x);
00187     utility::check_iterator_is_unweighted(y);
00188     utility::check_iterator_is_unweighted(wx);
00189     utility::check_iterator_is_unweighted(wy);
00190     while (x!=xlast) {
00191       ap.add(*x, *y, *wx, *wy);
00192       ++x;
00193       ++y;
00194       ++wx;
00195       ++wy;
00196     }
00197   }
00198 
00199 
00200 }}} // of namespace statistics, yat, and theplu
00201 
00202 #endif

Generated on Thu Dec 20 2012 03:12:58 for yat by  doxygen 1.8.0-20120409