yat  0.20.3pre
Averager.h
1 #ifndef _theplu_yat_statistics_averager_
2 #define _theplu_yat_statistics_averager_
3 
4 // $Id: Averager.h 3550 2017-01-03 05:41:02Z 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, 2016 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 #include <boost/iterator/iterator_concepts.hpp>
34 
35 #include <cmath>
36 
37 namespace theplu{
38 namespace yat{
39 namespace statistics{
40 
46  class Averager : public averager_base2<Averager>
47  {
48  public:
49 
53  Averager(void);
54 
59  Averager(double x, double xx, long n);
60 
64  Averager(const Averager& a);
65 
69  const Averager& operator=(const Averager&);
70 
76  template<class Derived>
77  const Averager& operator+=(const averager_base2<Derived>& other);
78 
79  private:
80  friend class averager_base<Averager>;
81  void add_impl(double, long int);
82  void rescale_impl(double);
83  };
84 
85 
96  template <typename InputIterator>
97  void add(Averager& a, InputIterator first, InputIterator last)
98  {
99  BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<InputIterator>));
100  BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<InputIterator>));
101  typedef typename boost::iterator_value<InputIterator>::type T;
102  BOOST_CONCEPT_ASSERT((boost::Convertible<T, double>));
104  for ( ; first != last; ++first)
105  a.add(*first);
106  }
107 
108  // template implementation
109  template<class Derived>
111  {
112  if (other.n())
113  add2(other.mean(), other.sum_xx_centered(), other.n());
114  return *this;
115  }
116 
117 
118 }}} // of namespace statistics, yat, and theplu
119 
120 #endif
Class to calculate simple (first and second moments) averages.
Definition: Averager.h:46
The Department of Theoretical Physics namespace as we define it.
const Averager & operator=(const Averager &)
The assignment operator.
Base class for averager classes.
Definition: averager_base.h:69
double sum_xx_centered(void) const
Definition: averager_base.h:225
void add2(double mean, double cm2, long int n)
Definition: averager_base.h:469
void add(Averager &a, InputIterator first, InputIterator last)
adding a range of values to Averager a
Definition: Averager.h:97
const Averager & operator+=(const averager_base2< Derived > &other)
plus assignment operator
Definition: Averager.h:110
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:200
double mean(void) const
mean
Definition: averager_base.h:97

Generated on Sat Feb 18 2023 03:31:44 for yat by  doxygen 1.8.14