yat  0.12.3pre
Averager.h
1 #ifndef _theplu_yat_statistics_averager_
2 #define _theplu_yat_statistics_averager_
3 
4 // $Id: Averager.h 2817 2012-08-29 00:38:17Z peter $
5 
6 /*
7  Copyright (C) 2004 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
9  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
10  Copyright (C) 2009, 2010, 2011, 2012 Peter Johansson
11 
12  This file is part of the yat library, http://dev.thep.lu.se/yat
13 
14  The yat library is free software; you can redistribute it and/or
15  modify it under the terms of the GNU General Public License as
16  published by the Free Software Foundation; either version 3 of the
17  License, or (at your option) any later version.
18 
19  The yat library is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  General Public License for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with yat. If not, see <http://www.gnu.org/licenses/>.
26 */
27 
28 #include "averager_base.h"
29 
30 #include "yat/utility/iterator_traits.h"
31 
32 #include <boost/concept_check.hpp>
33 
34 #include <cmath>
35 
36 namespace theplu{
37 namespace yat{
38 namespace statistics{
39 
45  class Averager : public averager_base2<Averager>
46  {
47  public:
48 
52  Averager(void);
53 
58  Averager(double x, double xx, long n);
59 
63  Averager(const Averager& a);
64 
68  const Averager& operator=(const Averager&);
69 
75  template<class Derived>
76  const Averager& operator+=(const averager_base2<Derived>& other);
77 
78  private:
79  friend class averager_base<Averager>;
80  void add_impl(double, long int);
81  void rescale_impl(double);
82  };
83 
84 
90  template <typename InputIterator>
91  void add(Averager& a, InputIterator first, InputIterator last)
92  {
93  BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>));
95  for ( ; first != last; ++first)
96  a.add(*first);
97  }
98 
99  // template implementation
100  template<class Derived>
102  {
103  if (other.n())
104  add2(other.mean(), other.sum_xx_centered(), other.n());
105  return *this;
106  }
107 
108 
109 }}} // of namespace statistics, yat, and theplu
110 
111 #endif
Class to calculate simple (first and second moments) averages.
Definition: Averager.h:45
const Averager & operator=(const Averager &)
The assignment operator.
Base class for averager classes.
Definition: averager_base.h:69
void add2(double mean, double cm2, long int n)
void add(Averager &a, InputIterator first, InputIterator last)
adding a range of values to Averager a
Definition: Averager.h:91
const Averager & operator+=(const averager_base2< Derived > &other)
plus assignment operator
Definition: Averager.h:101
long n(void) const
number of data points
Definition: averager_base.h:105
Base class for averagers calculating mean and variance.
Definition: averager_base.h:170
void check_iterator_is_unweighted(Iter iter)
check (at compile time) that iterator is unweighted.
Definition: iterator_traits.h:194
double mean(void) const
mean
Definition: averager_base.h:97
double sum_xx_centered(void) const
Definition: averager_base.h:225

Generated on Mon Jun 1 2015 12:29:52 for yat by  doxygen 1.8.5