yat  0.8.3pre
AveragerPair.h
00001 #ifndef _theplu_yat_statistics_averagerpair_
00002 #define _theplu_yat_statistics_averagerpair_
00003 
00004 // $Id: AveragerPair.h 2565 2011-09-26 00:53:48Z peter $
00005 
00006 /*
00007   Copyright (C) 2004, 2005 Jari Häkkinen, Peter Johansson
00008   Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
00009   Copyright (C) 2007, 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 "Averager.h"
00029 
00030 #include "yat/utility/iterator_traits.h"
00031 
00032 #include <boost/concept_check.hpp>
00033 
00034 #include <cmath>
00035 #include <utility>
00036 
00037 namespace theplu{
00038 namespace yat{
00039 namespace statistics{
00040 
00046   class AveragerPair
00047   {
00048   public:
00049 
00053     AveragerPair(void);
00054 
00058     AveragerPair(const AveragerPair&);
00059 
00063     void add(const double x, const double y, const long n=1);
00064 
00072     double ccc(void) const;
00073 
00080     double correlation(void) const;
00081   
00089     double covariance(void) const;
00090   
00094     double mean_xy(void) const;
00095 
00100     double msd(void) const;
00101 
00105     long n(void) const;
00106 
00110     void reset(void);
00111 
00115     double sum_xy(void) const;
00116 
00121     double sum_squared_deviation(void) const;
00122 
00126     double sum_xy_centered(void) const;
00127 
00131     const Averager& x_averager(void) const;
00132 
00136     const Averager& y_averager(void) const;
00137 
00141     const AveragerPair& operator=(const AveragerPair& a);
00142 
00146     const AveragerPair& operator+=(const AveragerPair&);
00147 
00148   private:
00149     Averager x_;
00150     Averager y_;
00151     double  xy_centered_;
00152 
00153     void xy_add(double mx, double my, double xy_centered, long n);
00154   };
00155 
00161   template <class InputIterator1, class InputIterator2>
00162   void add(AveragerPair& ap, InputIterator1 first1, InputIterator1 last1, 
00163            InputIterator2 first2)
00164   {
00165     BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator1>));
00166     BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator2>));
00167     utility::check_iterator_is_unweighted(first1);
00168     utility::check_iterator_is_unweighted(first2);
00169     for ( ; first1 != last1; ++first1, ++first2)
00170       ap.add(*first1, *first2);
00171   }
00172 
00173 
00174 }}} // of namespace statistics, yat, and theplu
00175 
00176 #endif

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