source: trunk/yat/statistics/Pearson.h @ 767

Last change on this file since 767 was 767, checked in by Peter, 15 years ago

Fixes #65

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1#ifndef _theplu_yat_statistics_pearson_
2#define _theplu_yat_statistics_pearson_
3
4// $Id: Pearson.h 767 2007-02-22 15:14:40Z peter $
5
6/*
7  Copyright (C) The authors contributing to this file.
8
9  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 2 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26
27#include "Score.h"
28
29namespace theplu {
30namespace yat {
31namespace utility {
32  class vector;
33}
34namespace classifier {
35  class VectorAbstract;
36}
37namespace statistics { 
38
39  ///
40  /// @brief Class for calculating Pearson correlation.
41  ///   
42 
43  class Pearson : public Score
44  {
45  public:
46    ///
47    /// @brief The default constructor.
48    ///
49    Pearson(bool absolute=true);
50
51    ///
52    /// @brief The destructor.
53    ///
54    virtual ~Pearson(void);
55         
56   
57    ///
58    /// \f$ \frac{\vert \sum_i(x_i-\bar{x})(y_i-\bar{y})\vert
59    /// }{\sqrt{\sum_i (x_i-\bar{x})^2\sum_i (x_i-\bar{x})^2}} \f$.
60    /// @return Pearson correlation, if absolute=true absolute value
61    /// of Pearson is used.
62    ///
63    double score(const classifier::Target& target, 
64                 const utility::vector& value);
65
66    ///
67    /// \f$ \frac{\vert \sum_iw^2_i(x_i-\bar{x})(y_i-\bar{y})\vert }
68    /// {\sqrt{\sum_iw^2_i(x_i-\bar{x})^2\sum_iw^2_i(y_i-\bar{y})^2}}
69    /// \f$, where \f$ m_x = \frac{\sum w_ix_i}{\sum w_i} \f$ and \f$
70    /// m_x = \frac{\sum w_ix_i}{\sum w_i} \f$. This expression is
71    /// chosen to get a correlation equal to unity when \a x and \a y
72    /// are equal. @return absolute value of weighted version of
73    /// Pearson correlation.
74    ///
75    double score(const classifier::Target& target, 
76                 const classifier::DataLookupWeighted1D& value); 
77
78    ///
79    /// \f$ \frac{\vert \sum_iw^2_i(x_i-\bar{x})(y_i-\bar{y})\vert }
80    /// {\sqrt{\sum_iw^2_i(x_i-\bar{x})^2\sum_iw^2_i(y_i-\bar{y})^2}}
81    /// \f$, where \f$ m_x = \frac{\sum w_ix_i}{\sum w_i} \f$ and \f$
82    /// m_x = \frac{\sum w_ix_i}{\sum w_i} \f$. This expression is
83    /// chosen to get a correlation equal to unity when \a x and \a y
84    /// are equal. @return absolute value of weighted version of
85    /// Pearson correlation.
86    ///
87    double score(const classifier::Target& target, 
88                 const utility::vector& value,
89                 const utility::vector& weight); 
90
91    ///
92    /// The p-value is the probability of getting a correlation as
93    /// large as the observed value by random chance, when the true
94    /// correlation is zero (and the data is Gaussian). Note that this
95    /// function can only be used together with the unweighted
96    /// score. @return two-sided p-value
97    ///
98    double p_value() const;
99         
100  private:
101    double r_;
102    int nof_samples_;
103
104    //    void centralize(utility::vector&, const utility::vector&);
105  };
106
107}}} // of namespace statistics, yat, and theplu
108
109#endif
Note: See TracBrowser for help on using the repository browser.