source: trunk/yat/statistics/PearsonCorrelation.cc @ 1049

Last change on this file since 1049 was 1049, checked in by Peter, 14 years ago

replaced some cerr outputs with exception throws - refs #189

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.4 KB
Line 
1// $Id: PearsonCorrelation.cc 1049 2008-02-07 14:50:38Z peter $
2
3/*
4  Copyright (C) 2004, 2005 Peter Johansson
5  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
6  Copyright (C) 2007 Peter Johansson
7
8  This file is part of the yat library, http://trac.thep.lu.se/yat
9
10  The yat library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License as
12  published by the Free Software Foundation; either version 2 of the
13  License, or (at your option) any later version.
14
15  The yat library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23  02111-1307, USA.
24*/
25
26#include "PearsonCorrelation.h"
27#include "Pearson.h"
28#include "AveragerPair.h"
29#include "AveragerPairWeighted.h"
30#include "yat/utility/VectorBase.h"
31#include "yat/classifier/DataLookupWeighted1D.h"
32#include "yat/classifier/Target.h"
33
34#include <cmath>
35#include <gsl/gsl_cdf.h>
36
37namespace theplu {
38namespace yat {
39namespace statistics { 
40
41  PearsonCorrelation::PearsonCorrelation(void) 
42    : r_(0), nof_samples_(0)
43  {
44  }
45
46  PearsonCorrelation::~PearsonCorrelation(void)
47  {
48  }
49
50  double PearsonCorrelation::p_value_one_sided() const
51  {
52    if(nof_samples_<=2)
53      return 1;
54
55    double t = sqrt(nof_samples_ - 2)*fabs(r_) /sqrt(1-r_*r_);
56    return gsl_cdf_tdist_Q(t, nof_samples_ -2 );
57  }
58
59  double PearsonCorrelation::score(const classifier::Target& target, 
60                                   const utility::VectorBase& value)
61  {
62    nof_samples_ = value.size();
63    Pearson pearson;
64    return pearson.score(target,value);
65  } 
66   
67  double 
68  PearsonCorrelation::score(const classifier::Target& target, 
69                            const classifier::DataLookupWeighted1D& value)
70  {
71    // Peter what should nof_samples be in weighted case?
72    nof_samples_=0;
73    Pearson pearson;
74    return pearson.score(target,value);
75  }
76
77  double PearsonCorrelation::score(const classifier::Target& target, 
78                                   const utility::VectorBase& value,
79                                   const utility::VectorBase& weight)
80  {
81    // Peter what should nof_samples be in weighted case?
82    nof_samples_ = 0;
83    Pearson pearson;
84    return pearson.score(target,value);
85  }
86
87}}} // of namespace statistics, yat, and theplu
Note: See TracBrowser for help on using the repository browser.