680 |
11 Oct 06 |
jari |
1 |
#ifndef _theplu_yat_statistics_pearson_ |
4200 |
19 Aug 22 |
peter |
2 |
#define _theplu_yat_statistics_pearson_ |
139 |
20 Aug 04 |
peter |
3 |
|
616 |
31 Aug 06 |
jari |
// $Id$ |
616 |
31 Aug 06 |
jari |
5 |
|
675 |
10 Oct 06 |
jari |
6 |
/* |
831 |
27 Mar 07 |
peter |
Copyright (C) 2004, 2005 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 |
139 |
20 Aug 04 |
peter |
11 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
675 |
10 Oct 06 |
jari |
13 |
|
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 |
18 |
|
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 |
23 |
|
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 |
26 |
*/ |
675 |
10 Oct 06 |
jari |
27 |
|
680 |
11 Oct 06 |
jari |
28 |
#include "Score.h" |
675 |
10 Oct 06 |
jari |
29 |
|
295 |
29 Apr 05 |
peter |
30 |
namespace theplu { |
680 |
11 Oct 06 |
jari |
31 |
namespace yat { |
616 |
31 Aug 06 |
jari |
32 |
namespace utility { |
1023 |
01 Feb 08 |
peter |
33 |
class VectorBase; |
616 |
31 Aug 06 |
jari |
34 |
} |
4200 |
19 Aug 22 |
peter |
35 |
namespace statistics { |
149 |
09 Sep 04 |
peter |
36 |
|
139 |
20 Aug 04 |
peter |
37 |
/// |
767 |
22 Feb 07 |
peter |
/// @brief Class for calculating Pearson correlation. |
4200 |
19 Aug 22 |
peter |
39 |
/// |
4200 |
19 Aug 22 |
peter |
40 |
|
139 |
20 Aug 04 |
peter |
41 |
class Pearson : public Score |
139 |
20 Aug 04 |
peter |
42 |
{ |
139 |
20 Aug 04 |
peter |
43 |
public: |
139 |
20 Aug 04 |
peter |
44 |
/// |
703 |
18 Dec 06 |
jari |
/// @brief The default constructor. |
139 |
20 Aug 04 |
peter |
46 |
/// |
181 |
04 Oct 04 |
peter |
47 |
Pearson(bool absolute=true); |
139 |
20 Aug 04 |
peter |
48 |
|
139 |
20 Aug 04 |
peter |
49 |
/// |
703 |
18 Dec 06 |
jari |
/// @brief The destructor. |
139 |
20 Aug 04 |
peter |
51 |
/// |
703 |
18 Dec 06 |
jari |
52 |
virtual ~Pearson(void); |
4200 |
19 Aug 22 |
peter |
53 |
|
4200 |
19 Aug 22 |
peter |
54 |
|
779 |
05 Mar 07 |
peter |
55 |
/** |
779 |
05 Mar 07 |
peter |
\f$ \frac{\vert \sum_i(x_i-\bar{x})(y_i-\bar{y})\vert |
779 |
05 Mar 07 |
peter |
}{\sqrt{\sum_i (x_i-\bar{x})^2\sum_i (x_i-\bar{x})^2}} \f$. |
779 |
05 Mar 07 |
peter |
@return Pearson correlation, if absolute=true absolute value |
779 |
05 Mar 07 |
peter |
of Pearson is used. |
779 |
05 Mar 07 |
peter |
60 |
*/ |
4200 |
19 Aug 22 |
peter |
61 |
double score(const classifier::Target& target, |
1023 |
01 Feb 08 |
peter |
62 |
const utility::VectorBase& value) const; |
139 |
20 Aug 04 |
peter |
63 |
|
779 |
05 Mar 07 |
peter |
64 |
/** |
779 |
05 Mar 07 |
peter |
\f$ \frac{\vert \sum_iw^2_i(x_i-\bar{x})(y_i-\bar{y})\vert } |
779 |
05 Mar 07 |
peter |
{\sqrt{\sum_iw^2_i(x_i-\bar{x})^2\sum_iw^2_i(y_i-\bar{y})^2}} |
779 |
05 Mar 07 |
peter |
\f$, where \f$ m_x = \frac{\sum w_ix_i}{\sum w_i} \f$ and \f$ |
779 |
05 Mar 07 |
peter |
m_x = \frac{\sum w_ix_i}{\sum w_i} \f$. This expression is |
779 |
05 Mar 07 |
peter |
chosen to get a correlation equal to unity when \a x and \a y |
779 |
05 Mar 07 |
peter |
are equal. @return absolute value of weighted version of |
779 |
05 Mar 07 |
peter |
Pearson correlation. |
779 |
05 Mar 07 |
peter |
72 |
*/ |
4200 |
19 Aug 22 |
peter |
73 |
double score(const classifier::Target& target, |
4200 |
19 Aug 22 |
peter |
74 |
const classifier::DataLookupWeighted1D& value) const; |
623 |
05 Sep 06 |
peter |
75 |
|
779 |
05 Mar 07 |
peter |
76 |
/** |
779 |
05 Mar 07 |
peter |
\f$ \frac{\vert \sum_iw^2_i(x_i-\bar{x})(y_i-\bar{y})\vert } |
779 |
05 Mar 07 |
peter |
{\sqrt{\sum_iw^2_i(x_i-\bar{x})^2\sum_iw^2_i(y_i-\bar{y})^2}} |
779 |
05 Mar 07 |
peter |
\f$, where \f$ m_x = \frac{\sum w_ix_i}{\sum w_i} \f$ and \f$ |
779 |
05 Mar 07 |
peter |
m_x = \frac{\sum w_ix_i}{\sum w_i} \f$. This expression is |
779 |
05 Mar 07 |
peter |
chosen to get a correlation equal to unity when \a x and \a y |
779 |
05 Mar 07 |
peter |
are equal. @return absolute value of weighted version of |
779 |
05 Mar 07 |
peter |
Pearson correlation. |
779 |
05 Mar 07 |
peter |
84 |
*/ |
4200 |
19 Aug 22 |
peter |
85 |
double score(const classifier::Target& target, |
1023 |
01 Feb 08 |
peter |
86 |
const utility::VectorBase& value, |
4200 |
19 Aug 22 |
peter |
87 |
const utility::VectorBase& weight) const; |
139 |
20 Aug 04 |
peter |
88 |
|
139 |
20 Aug 04 |
peter |
89 |
}; |
139 |
20 Aug 04 |
peter |
90 |
|
683 |
11 Oct 06 |
jari |
91 |
}}} // of namespace statistics, yat, and theplu |
139 |
20 Aug 04 |
peter |
92 |
|
139 |
20 Aug 04 |
peter |
93 |
#endif |