yat  0.8.3pre
Averager.h
00001 #ifndef _theplu_yat_statistics_averager_
00002 #define _theplu_yat_statistics_averager_
00003 
00004 // $Id: Averager.h 2558 2011-09-24 20:53:04Z peter $
00005 
00006 /*
00007   Copyright (C) 2004 Jari Häkkinen, Peter Johansson
00008   Copyright (C) 2005, 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 "yat/utility/iterator_traits.h"
00029 
00030 #include <boost/concept_check.hpp>
00031 
00032 #include <cmath>
00033 
00034 namespace theplu{
00035 namespace yat{
00036 namespace statistics{
00037 
00038   class ostream;
00039 
00045   class Averager
00046   {
00047   public:
00048 
00052     Averager(void);
00053     
00058     Averager(double x, double xx, long n);
00059 
00063     Averager(const Averager& a);
00064 
00068     void add(double d, long n=1);
00069 
00078     double cv(void) const;
00079 
00083     double mean(void) const;
00084 
00088     long n(void) const;
00089 
00095     void rescale(double a);
00096 
00101     double standard_error(void) const;
00102 
00109     double std(void) const;
00110 
00117     double std(double m) const;
00118 
00122     double sum_x(void)  const;
00123 
00127     double sum_xx(void) const;
00128 
00132     double sum_xx_centered(void)  const;
00133 
00142     double variance(double m) const;
00143 
00152     double variance(void) const;
00153 
00162     double variance_unbiased(void) const;
00163 
00167     void reset(void);
00168 
00172     const Averager& operator=(const Averager&);
00173 
00177     const Averager& operator+=(const Averager&);
00178 
00179   private:
00180     long  n_;
00181     double  mean_, m2_;
00182   };
00183   
00184 
00190   template <typename InputIterator>
00191   void add(Averager& a, InputIterator first, InputIterator last)
00192   {
00193     BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>));
00194     utility::check_iterator_is_unweighted(first);
00195     for ( ; first != last; ++first)
00196       a.add(*first);
00197   }
00198 
00199 }}} // of namespace statistics, yat, and theplu
00200 
00201 #endif

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