680 |
11 Oct 06 |
jari |
1 |
#ifndef _theplu_yat_statistics_averagerpair_ |
680 |
11 Oct 06 |
jari |
2 |
#define _theplu_yat_statistics_averagerpair_ |
138 |
20 Aug 04 |
peter |
3 |
|
675 |
10 Oct 06 |
jari |
// $Id$ |
295 |
29 Apr 05 |
peter |
5 |
|
675 |
10 Oct 06 |
jari |
6 |
/* |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2004, 2005 Jari Häkkinen, Peter Johansson |
2119 |
12 Dec 09 |
peter |
Copyright (C) 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, 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 |
|
680 |
11 Oct 06 |
jari |
29 |
#include "Averager.h" |
675 |
10 Oct 06 |
jari |
30 |
|
937 |
05 Oct 07 |
peter |
31 |
#include "yat/utility/iterator_traits.h" |
912 |
29 Sep 07 |
peter |
32 |
|
2202 |
21 Feb 10 |
peter |
33 |
#include <boost/concept_check.hpp> |
3529 |
11 Oct 16 |
peter |
34 |
#include <boost/iterator/iterator_concepts.hpp> |
2202 |
21 Feb 10 |
peter |
35 |
|
138 |
20 Aug 04 |
peter |
36 |
#include <cmath> |
180 |
04 Oct 04 |
peter |
37 |
#include <utility> |
138 |
20 Aug 04 |
peter |
38 |
|
138 |
20 Aug 04 |
peter |
39 |
namespace theplu{ |
680 |
11 Oct 06 |
jari |
40 |
namespace yat{ |
197 |
27 Oct 04 |
jari |
41 |
namespace statistics{ |
487 |
04 Jan 06 |
peter |
42 |
|
138 |
20 Aug 04 |
peter |
43 |
/// |
767 |
22 Feb 07 |
peter |
/// @brief Class for taking care of mean and covariance of two variables. |
138 |
20 Aug 04 |
peter |
45 |
/// |
490 |
04 Jan 06 |
peter |
/// @see Averager AveragerWeighted AveragerPairWeighted |
489 |
04 Jan 06 |
peter |
47 |
/// |
138 |
20 Aug 04 |
peter |
48 |
class AveragerPair |
138 |
20 Aug 04 |
peter |
49 |
{ |
138 |
20 Aug 04 |
peter |
50 |
public: |
138 |
20 Aug 04 |
peter |
51 |
|
138 |
20 Aug 04 |
peter |
52 |
/// |
703 |
18 Dec 06 |
jari |
/// @brief The default constructor |
138 |
20 Aug 04 |
peter |
54 |
/// |
703 |
18 Dec 06 |
jari |
55 |
AveragerPair(void); |
703 |
18 Dec 06 |
jari |
56 |
|
138 |
20 Aug 04 |
peter |
57 |
/// |
703 |
18 Dec 06 |
jari |
/// The copy constructor |
138 |
20 Aug 04 |
peter |
59 |
/// |
703 |
18 Dec 06 |
jari |
60 |
AveragerPair(const AveragerPair&); |
703 |
18 Dec 06 |
jari |
61 |
|
138 |
20 Aug 04 |
peter |
62 |
/// |
197 |
27 Oct 04 |
jari |
/// Adding \a n pairs of data points with value \a x and \a y. |
138 |
20 Aug 04 |
peter |
64 |
/// |
1295 |
12 May 08 |
jari |
65 |
void add(const double x, const double y, const long n=1); |
138 |
20 Aug 04 |
peter |
66 |
|
1043 |
06 Feb 08 |
peter |
67 |
/** |
1187 |
28 Feb 08 |
peter |
\brief Concordence correlation coefficient. |
1187 |
28 Feb 08 |
peter |
69 |
|
1043 |
06 Feb 08 |
peter |
\f$ \frac{\sum_i (x_i-m_x)(y_i-m_y)}{\sum_i |
3529 |
11 Oct 16 |
peter |
(x_i-m_x)^2+\sum_i (y_i-m_y)^2 + n(m_x-m_y)^2} \f$ |
3529 |
11 Oct 16 |
peter |
72 |
|
1043 |
06 Feb 08 |
peter |
73 |
*/ |
718 |
26 Dec 06 |
jari |
74 |
double ccc(void) const; |
718 |
26 Dec 06 |
jari |
75 |
|
1187 |
28 Feb 08 |
peter |
76 |
/** |
1187 |
28 Feb 08 |
peter |
\f$ \frac{\sum_i (x_i-m_x)(y_i-m_y)}{\sqrt{\sum_i |
3529 |
11 Oct 16 |
peter |
(x_i-m_x)^2\sum_i (y_i-m_y)^2}} \f$ |
3529 |
11 Oct 16 |
peter |
79 |
|
1187 |
28 Feb 08 |
peter |
\return %Pearson correlation coefficient. |
1187 |
28 Feb 08 |
peter |
81 |
*/ |
718 |
26 Dec 06 |
jari |
82 |
double correlation(void) const; |
3529 |
11 Oct 16 |
peter |
83 |
|
138 |
20 Aug 04 |
peter |
84 |
/// |
487 |
04 Jan 06 |
peter |
/// Calculating covariance using |
597 |
28 Aug 06 |
markus |
/// \f$ \frac{1}{N}\sum_i (x_i-m_x)(y_i-m_y) \f$, |
597 |
28 Aug 06 |
markus |
/// where \f$ m \f$ is the mean. |
138 |
20 Aug 04 |
peter |
88 |
/// |
197 |
27 Oct 04 |
jari |
/// @return The covariance. |
197 |
27 Oct 04 |
jari |
90 |
/// |
718 |
26 Dec 06 |
jari |
91 |
double covariance(void) const; |
3529 |
11 Oct 16 |
peter |
92 |
|
138 |
20 Aug 04 |
peter |
93 |
/// |
197 |
27 Oct 04 |
jari |
/// @return The mean of xy. |
138 |
20 Aug 04 |
peter |
95 |
/// |
718 |
26 Dec 06 |
jari |
96 |
double mean_xy(void) const; |
138 |
20 Aug 04 |
peter |
97 |
|
1187 |
28 Feb 08 |
peter |
98 |
/** |
1187 |
28 Feb 08 |
peter |
\return Average squared deviation between x and y \f$ |
1187 |
28 Feb 08 |
peter |
\frac{1}{N} \sum (x-y)^2 \f$ |
1187 |
28 Feb 08 |
peter |
101 |
*/ |
718 |
26 Dec 06 |
jari |
102 |
double msd(void) const; |
138 |
20 Aug 04 |
peter |
103 |
|
138 |
20 Aug 04 |
peter |
104 |
/// |
219 |
30 Dec 04 |
peter |
/// @return The number of pair of data points. |
219 |
30 Dec 04 |
peter |
106 |
/// |
1295 |
12 May 08 |
jari |
107 |
long n(void) const; |
219 |
30 Dec 04 |
peter |
108 |
|
219 |
30 Dec 04 |
peter |
109 |
/// |
703 |
18 Dec 06 |
jari |
/// @brief Reset everything to zero |
138 |
20 Aug 04 |
peter |
111 |
/// |
703 |
18 Dec 06 |
jari |
112 |
void reset(void); |
138 |
20 Aug 04 |
peter |
113 |
|
138 |
20 Aug 04 |
peter |
114 |
/// |
197 |
27 Oct 04 |
jari |
/// @return The sum of xy. |
138 |
20 Aug 04 |
peter |
116 |
/// |
718 |
26 Dec 06 |
jari |
117 |
double sum_xy(void) const; |
138 |
20 Aug 04 |
peter |
118 |
|
1187 |
28 Feb 08 |
peter |
119 |
/** |
1187 |
28 Feb 08 |
peter |
\return Sum of squared deviation between x and y \f$ |
1187 |
28 Feb 08 |
peter |
\sum (x-y)^2 \f$ |
1187 |
28 Feb 08 |
peter |
122 |
*/ |
772 |
25 Feb 07 |
peter |
123 |
double sum_squared_deviation(void) const; |
772 |
25 Feb 07 |
peter |
124 |
|
772 |
25 Feb 07 |
peter |
125 |
/// |
597 |
28 Aug 06 |
markus |
/// @return \f$ \sum_i (x_i-m_x)(y_i-m_y) \f$ |
219 |
30 Dec 04 |
peter |
127 |
/// |
718 |
26 Dec 06 |
jari |
128 |
double sum_xy_centered(void) const; |
219 |
30 Dec 04 |
peter |
129 |
|
219 |
30 Dec 04 |
peter |
130 |
/// |
197 |
27 Oct 04 |
jari |
/// @return A const refencer to the averager object for x. |
138 |
20 Aug 04 |
peter |
132 |
/// |
718 |
26 Dec 06 |
jari |
133 |
const Averager& x_averager(void) const; |
138 |
20 Aug 04 |
peter |
134 |
|
138 |
20 Aug 04 |
peter |
135 |
/// |
197 |
27 Oct 04 |
jari |
/// @return A const reference to the averager object for y |
138 |
20 Aug 04 |
peter |
137 |
/// |
718 |
26 Dec 06 |
jari |
138 |
const Averager& y_averager(void) const; |
138 |
20 Aug 04 |
peter |
139 |
|
138 |
20 Aug 04 |
peter |
140 |
/// |
703 |
18 Dec 06 |
jari |
/// @brief The assigment operator |
138 |
20 Aug 04 |
peter |
142 |
/// |
703 |
18 Dec 06 |
jari |
143 |
const AveragerPair& operator=(const AveragerPair& a); |
138 |
20 Aug 04 |
peter |
144 |
|
138 |
20 Aug 04 |
peter |
145 |
/// |
197 |
27 Oct 04 |
jari |
/// Operator to add another Averager |
138 |
20 Aug 04 |
peter |
147 |
/// |
138 |
20 Aug 04 |
peter |
148 |
const AveragerPair& operator+=(const AveragerPair&); |
138 |
20 Aug 04 |
peter |
149 |
|
138 |
20 Aug 04 |
peter |
150 |
private: |
138 |
20 Aug 04 |
peter |
151 |
Averager x_; |
138 |
20 Aug 04 |
peter |
152 |
Averager y_; |
2565 |
26 Sep 11 |
peter |
153 |
double xy_centered_; |
138 |
20 Aug 04 |
peter |
154 |
|
2565 |
26 Sep 11 |
peter |
155 |
void xy_add(double mx, double my, double xy_centered, long n); |
138 |
20 Aug 04 |
peter |
156 |
}; |
138 |
20 Aug 04 |
peter |
157 |
|
886 |
24 Sep 07 |
peter |
158 |
/** |
1043 |
06 Feb 08 |
peter |
\brief adding data from two ranges to AveragerPair \a ap |
1886 |
31 Mar 09 |
peter |
160 |
|
3529 |
11 Oct 16 |
peter |
Type Requirements: |
3529 |
11 Oct 16 |
peter |
- \c InputIterator1 is \readable_iterator |
3529 |
11 Oct 16 |
peter |
- \c InputIterator1 is unweighted |
3529 |
11 Oct 16 |
peter |
- \c InputIterator1 is \single_pass_iterator |
3529 |
11 Oct 16 |
peter |
- \c InputIterator2 is \readable_iterator |
3529 |
11 Oct 16 |
peter |
- \c InputIterator2 is unweighted |
3529 |
11 Oct 16 |
peter |
- \c InputIterator2 is \single_pass_iterator |
3529 |
11 Oct 16 |
peter |
168 |
|
1886 |
31 Mar 09 |
peter |
\relates AveragerPair |
886 |
24 Sep 07 |
peter |
170 |
*/ |
2202 |
21 Feb 10 |
peter |
171 |
template <class InputIterator1, class InputIterator2> |
3529 |
11 Oct 16 |
peter |
172 |
void add(AveragerPair& ap, InputIterator1 first1, InputIterator1 last1, |
2202 |
21 Feb 10 |
peter |
173 |
InputIterator2 first2) |
886 |
24 Sep 07 |
peter |
174 |
{ |
3529 |
11 Oct 16 |
peter |
175 |
BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<InputIterator1>)); |
3529 |
11 Oct 16 |
peter |
176 |
BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<InputIterator1>)); |
3529 |
11 Oct 16 |
peter |
177 |
BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<InputIterator2>)); |
3529 |
11 Oct 16 |
peter |
178 |
BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<InputIterator2>)); |
3529 |
11 Oct 16 |
peter |
179 |
|
914 |
29 Sep 07 |
peter |
180 |
utility::check_iterator_is_unweighted(first1); |
914 |
29 Sep 07 |
peter |
181 |
utility::check_iterator_is_unweighted(first2); |
886 |
24 Sep 07 |
peter |
182 |
for ( ; first1 != last1; ++first1, ++first2) |
886 |
24 Sep 07 |
peter |
183 |
ap.add(*first1, *first2); |
886 |
24 Sep 07 |
peter |
184 |
} |
886 |
24 Sep 07 |
peter |
185 |
|
886 |
24 Sep 07 |
peter |
186 |
|
680 |
11 Oct 06 |
jari |
187 |
}}} // of namespace statistics, yat, and theplu |
138 |
20 Aug 04 |
peter |
188 |
|
138 |
20 Aug 04 |
peter |
189 |
#endif |