680 |
11 Oct 06 |
jari |
1 |
#ifndef _theplu_yat_statistics_averager_ |
680 |
11 Oct 06 |
jari |
2 |
#define _theplu_yat_statistics_averager_ |
87 |
27 May 04 |
peter |
3 |
|
616 |
31 Aug 06 |
jari |
// $Id$ |
433 |
13 Dec 05 |
markus |
5 |
|
675 |
10 Oct 06 |
jari |
6 |
/* |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2004 Jari Häkkinen, Peter Johansson |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
3550 |
03 Jan 17 |
peter |
Copyright (C) 2009, 2010, 2011, 2012, 2016 Peter Johansson |
675 |
10 Oct 06 |
jari |
12 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
675 |
10 Oct 06 |
jari |
14 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
675 |
10 Oct 06 |
jari |
19 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
675 |
10 Oct 06 |
jari |
General Public License for more details. |
675 |
10 Oct 06 |
jari |
24 |
|
675 |
10 Oct 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
675 |
10 Oct 06 |
jari |
27 |
*/ |
675 |
10 Oct 06 |
jari |
28 |
|
2809 |
06 Aug 12 |
peter |
29 |
#include "averager_base.h" |
2809 |
06 Aug 12 |
peter |
30 |
|
937 |
05 Oct 07 |
peter |
31 |
#include "yat/utility/iterator_traits.h" |
911 |
29 Sep 07 |
peter |
32 |
|
2159 |
19 Jan 10 |
peter |
33 |
#include <boost/concept_check.hpp> |
3527 |
11 Oct 16 |
peter |
34 |
#include <boost/iterator/iterator_concepts.hpp> |
2159 |
19 Jan 10 |
peter |
35 |
|
87 |
27 May 04 |
peter |
36 |
#include <cmath> |
87 |
27 May 04 |
peter |
37 |
|
87 |
27 May 04 |
peter |
38 |
namespace theplu{ |
680 |
11 Oct 06 |
jari |
39 |
namespace yat{ |
680 |
11 Oct 06 |
jari |
40 |
namespace statistics{ |
295 |
29 Apr 05 |
peter |
41 |
|
87 |
27 May 04 |
peter |
42 |
/// |
767 |
22 Feb 07 |
peter |
/// @brief Class to calculate simple (first and second moments) averages. |
87 |
27 May 04 |
peter |
44 |
/// |
490 |
04 Jan 06 |
peter |
/// @see AveragerWeighted AveragerPair AveragerPairWeighted |
194 |
27 Oct 04 |
jari |
46 |
/// |
2809 |
06 Aug 12 |
peter |
47 |
class Averager : public averager_base2<Averager> |
87 |
27 May 04 |
peter |
48 |
{ |
87 |
27 May 04 |
peter |
49 |
public: |
87 |
27 May 04 |
peter |
50 |
|
87 |
27 May 04 |
peter |
51 |
/// |
87 |
27 May 04 |
peter |
/// Default constructor |
87 |
27 May 04 |
peter |
53 |
/// |
620 |
04 Sep 06 |
markus |
54 |
Averager(void); |
2809 |
06 Aug 12 |
peter |
55 |
|
87 |
27 May 04 |
peter |
56 |
/// |
197 |
27 Oct 04 |
jari |
/// Constructor taking sum of \a x, sum of squared x, \a xx, and |
197 |
27 Oct 04 |
jari |
/// number of samples \a n. |
87 |
27 May 04 |
peter |
59 |
/// |
1295 |
12 May 08 |
jari |
60 |
Averager(double x, double xx, long n); |
137 |
19 Aug 04 |
peter |
61 |
|
137 |
19 Aug 04 |
peter |
62 |
/// |
87 |
27 May 04 |
peter |
/// Copy constructor |
87 |
27 May 04 |
peter |
64 |
/// |
620 |
04 Sep 06 |
markus |
65 |
Averager(const Averager& a); |
420 |
02 Dec 05 |
jari |
66 |
|
87 |
27 May 04 |
peter |
67 |
/// |
2809 |
06 Aug 12 |
peter |
/// @brief The assignment operator |
87 |
27 May 04 |
peter |
69 |
/// |
2809 |
06 Aug 12 |
peter |
70 |
const Averager& operator=(const Averager&); |
87 |
27 May 04 |
peter |
71 |
|
670 |
07 Oct 06 |
peter |
72 |
/** |
2809 |
06 Aug 12 |
peter |
\brief plus assignment operator |
670 |
07 Oct 06 |
peter |
74 |
|
2809 |
06 Aug 12 |
peter |
Add another Averager |
2809 |
06 Aug 12 |
peter |
76 |
*/ |
2809 |
06 Aug 12 |
peter |
77 |
template<class Derived> |
2809 |
06 Aug 12 |
peter |
78 |
const Averager& operator+=(const averager_base2<Derived>& other); |
670 |
07 Oct 06 |
peter |
79 |
|
87 |
27 May 04 |
peter |
80 |
private: |
2809 |
06 Aug 12 |
peter |
81 |
friend class averager_base<Averager>; |
2809 |
06 Aug 12 |
peter |
82 |
void add_impl(double, long int); |
2809 |
06 Aug 12 |
peter |
83 |
void rescale_impl(double); |
87 |
27 May 04 |
peter |
84 |
}; |
886 |
24 Sep 07 |
peter |
85 |
|
2809 |
06 Aug 12 |
peter |
86 |
|
886 |
24 Sep 07 |
peter |
87 |
/** |
1445 |
27 Aug 08 |
peter |
\brief adding a range of values to Averager \a a |
1886 |
31 Mar 09 |
peter |
89 |
|
3527 |
11 Oct 16 |
peter |
Type Requirements: |
3527 |
11 Oct 16 |
peter |
- \c InputIterator is a \readable_iterator |
3527 |
11 Oct 16 |
peter |
- \c InputIterator is \single_pass_iterator |
3527 |
11 Oct 16 |
peter |
- \c InputIterator 's value type is convertible to \c double |
3527 |
11 Oct 16 |
peter |
94 |
|
1886 |
31 Mar 09 |
peter |
\relates Averager |
886 |
24 Sep 07 |
peter |
96 |
*/ |
2159 |
19 Jan 10 |
peter |
97 |
template <typename InputIterator> |
2159 |
19 Jan 10 |
peter |
98 |
void add(Averager& a, InputIterator first, InputIterator last) |
886 |
24 Sep 07 |
peter |
99 |
{ |
3527 |
11 Oct 16 |
peter |
100 |
BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<InputIterator>)); |
3527 |
11 Oct 16 |
peter |
101 |
BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<InputIterator>)); |
3527 |
11 Oct 16 |
peter |
102 |
typedef typename boost::iterator_value<InputIterator>::type T; |
3527 |
11 Oct 16 |
peter |
103 |
BOOST_CONCEPT_ASSERT((boost::Convertible<T, double>)); |
914 |
29 Sep 07 |
peter |
104 |
utility::check_iterator_is_unweighted(first); |
886 |
24 Sep 07 |
peter |
105 |
for ( ; first != last; ++first) |
886 |
24 Sep 07 |
peter |
106 |
a.add(*first); |
886 |
24 Sep 07 |
peter |
107 |
} |
886 |
24 Sep 07 |
peter |
108 |
|
2809 |
06 Aug 12 |
peter |
// template implementation |
2809 |
06 Aug 12 |
peter |
110 |
template<class Derived> |
2809 |
06 Aug 12 |
peter |
111 |
const Averager& Averager::operator+=(const averager_base2<Derived>& other) |
2809 |
06 Aug 12 |
peter |
112 |
{ |
2809 |
06 Aug 12 |
peter |
113 |
if (other.n()) |
2809 |
06 Aug 12 |
peter |
114 |
add2(other.mean(), other.sum_xx_centered(), other.n()); |
2809 |
06 Aug 12 |
peter |
115 |
return *this; |
2809 |
06 Aug 12 |
peter |
116 |
} |
2809 |
06 Aug 12 |
peter |
117 |
|
2809 |
06 Aug 12 |
peter |
118 |
|
680 |
11 Oct 06 |
jari |
119 |
}}} // of namespace statistics, yat, and theplu |
582 |
09 May 06 |
markus |
120 |
|
87 |
27 May 04 |
peter |
121 |
#endif |