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

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

passing VectorBase? in regression::PearsonCorrelation? - refs #256

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
1// $Id: PearsonCorrelation.cc 1024 2008-02-01 18:18:21Z 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      std::cerr << "Warning: Only " << nof_samples_ << "samples. " 
54                << "Need at lest 3.\n";
55      return 1;
56    }
57
58    double t = sqrt(nof_samples_ - 2)*fabs(r_) /sqrt(1-r_*r_);
59    return gsl_cdf_tdist_Q(t, nof_samples_ -2 );
60  }
61
62  double PearsonCorrelation::score(const classifier::Target& target, 
63                                   const utility::VectorBase& value)
64  {
65    nof_samples_ = value.size();
66    Pearson pearson;
67    return pearson.score(target,value);
68  } 
69   
70  double 
71  PearsonCorrelation::score(const classifier::Target& target, 
72                            const classifier::DataLookupWeighted1D& value)
73  {
74    // Peter what should nof_samples be in weighted case?
75    nof_samples_=0;
76    Pearson pearson;
77    return pearson.score(target,value);
78  }
79
80  double PearsonCorrelation::score(const classifier::Target& target, 
81                                   const utility::VectorBase& value,
82                                   const utility::VectorBase& weight)
83  {
84    // Peter what should nof_samples be in weighted case?
85    nof_samples_ = 0;
86    Pearson pearson;
87    return pearson.score(target,value);
88  }
89
90}}} // of namespace statistics, yat, and theplu
Note: See TracBrowser for help on using the repository browser.