1031 |
04 Feb 08 |
markus |
1 |
#ifndef theplu_yat_statistics_pearson_distance_h |
1031 |
04 Feb 08 |
markus |
2 |
#define theplu_yat_statistics_pearson_distance_h |
889 |
25 Sep 07 |
markus |
3 |
|
889 |
25 Sep 07 |
markus |
// $Id$ |
889 |
25 Sep 07 |
markus |
5 |
|
999 |
23 Dec 07 |
jari |
6 |
/* |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson, Markus Ringnér |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2010 Peter Johansson |
999 |
23 Dec 07 |
jari |
9 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
999 |
23 Dec 07 |
jari |
11 |
|
999 |
23 Dec 07 |
jari |
The yat library is free software; you can redistribute it and/or |
999 |
23 Dec 07 |
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 |
999 |
23 Dec 07 |
jari |
License, or (at your option) any later version. |
999 |
23 Dec 07 |
jari |
16 |
|
999 |
23 Dec 07 |
jari |
The yat library is distributed in the hope that it will be useful, |
999 |
23 Dec 07 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
999 |
23 Dec 07 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
999 |
23 Dec 07 |
jari |
General Public License for more details. |
999 |
23 Dec 07 |
jari |
21 |
|
999 |
23 Dec 07 |
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/>. |
999 |
23 Dec 07 |
jari |
24 |
*/ |
999 |
23 Dec 07 |
jari |
25 |
|
1306 |
14 May 08 |
peter |
26 |
#include "averager_traits.h" |
937 |
05 Oct 07 |
peter |
27 |
#include "yat/utility/iterator_traits.h" |
889 |
25 Sep 07 |
markus |
28 |
|
889 |
25 Sep 07 |
markus |
29 |
namespace theplu { |
889 |
25 Sep 07 |
markus |
30 |
namespace yat { |
889 |
25 Sep 07 |
markus |
31 |
namespace statistics { |
889 |
25 Sep 07 |
markus |
32 |
|
1069 |
11 Feb 08 |
markus |
33 |
/// |
3531 |
11 Oct 16 |
peter |
/// @brief Calculates the %Pearson correlation distance between two points given by elements of ranges. |
1069 |
11 Feb 08 |
markus |
35 |
/// |
1115 |
21 Feb 08 |
markus |
/// This class is modelling the concept \ref concept_distance. |
1069 |
11 Feb 08 |
markus |
37 |
/// |
1050 |
07 Feb 08 |
peter |
38 |
struct PearsonDistance |
889 |
25 Sep 07 |
markus |
39 |
{ |
1115 |
21 Feb 08 |
markus |
40 |
/** |
1115 |
21 Feb 08 |
markus |
\brief Calculates the %Pearson correlation distance between |
1115 |
21 Feb 08 |
markus |
elements of two ranges. |
3531 |
11 Oct 16 |
peter |
43 |
|
1115 |
21 Feb 08 |
markus |
If elements of both ranges are unweighted the distance is |
1115 |
21 Feb 08 |
markus |
calculated as \f$ 1-\mbox{C}(x,y) \f$, where \f$ x \f$ and \f$ |
1115 |
21 Feb 08 |
markus |
y \f$ are the two points and C is the %Pearson correlation. |
1115 |
21 Feb 08 |
markus |
47 |
|
1115 |
21 Feb 08 |
markus |
If elements of one or both of ranges have weights the distance |
1115 |
21 Feb 08 |
markus |
is calculated as \f$ 1-[\sum w_{x,i}w_{y,i}(x_i-y_i)^2/(\sum |
1115 |
21 Feb 08 |
markus |
w_{x,i}w_{y,i}(x_i-m_x)^2\sum w_{x,i}w_{y,i}(y_i-m_y)^2)] \f$, |
1115 |
21 Feb 08 |
markus |
where and \f$ w_x \f$ and \f$ w_y \f$ are weights for the |
1115 |
21 Feb 08 |
markus |
elements of the first and the second range, respectively, and |
1115 |
21 Feb 08 |
markus |
\f$ m_x=\sum w_{x,i}w_{y,i}x_i/\sum w_{x,i}w_{y,i} \f$ and |
1115 |
21 Feb 08 |
markus |
correspondingly for \f$ m_y \f$. If the elements of one of the |
1115 |
21 Feb 08 |
markus |
two ranges are unweighted, the weights for these elements are |
1115 |
21 Feb 08 |
markus |
set to unity. |
3531 |
11 Oct 16 |
peter |
57 |
*/ |
2202 |
21 Feb 10 |
peter |
58 |
template <typename ForwardIterator1, typename ForwardIterator2> |
3531 |
11 Oct 16 |
peter |
59 |
double operator()(ForwardIterator1 beg1, ForwardIterator1 end1, |
2202 |
21 Feb 10 |
peter |
60 |
ForwardIterator2 beg2) const |
1050 |
07 Feb 08 |
peter |
61 |
{ |
2202 |
21 Feb 10 |
peter |
62 |
typename averager_pair<ForwardIterator1, ForwardIterator2>::type ap; |
1050 |
07 Feb 08 |
peter |
63 |
add(ap,beg1,end1,beg2); |
1050 |
07 Feb 08 |
peter |
64 |
return 1-ap.correlation(); |
1050 |
07 Feb 08 |
peter |
65 |
} |
1050 |
07 Feb 08 |
peter |
66 |
}; |
890 |
25 Sep 07 |
markus |
67 |
|
889 |
25 Sep 07 |
markus |
68 |
}}} // of namespace statistics, yat, and theplu |
3531 |
11 Oct 16 |
peter |
69 |
|
889 |
25 Sep 07 |
markus |
70 |
#endif |