source: trunk/src/tScore.cc @ 102

Last change on this file since 102 was 102, checked in by Peter, 18 years ago

Fixed bug in interface between InputRanker? & ROC

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 956 bytes
Line 
1// $Id: tScore.cc 102 2004-06-15 09:40:52Z peter $
2
3// System includes
4#include <cmath>
5
6// Thep C++ Tools
7#include "tScore.h"
8#include "vector.h"
9#include "Averager.h"
10
11namespace theplu {
12namespace cpptools { 
13
14  tScore::tScore() 
15      : Score(), value_(), target_()
16  {
17  }
18
19  tScore::tScore( const gslapi::vector& target, 
20                  const gslapi::vector& value) 
21      : Score(), value_(value), target_(target)
22  {
23  }
24   
25  double tScore::score()
26  {
27    Averager positive;
28    Averager negative;
29    for(size_t i=0; i<target_.size(); i++){
30      if (target_[i]==1)
31        positive.add(value_[i]);
32      else
33        negative.add(value_[i]);
34    }
35    double diff = positive.mean() - negative.mean();
36    double s=sqrt((positive.sum_xsqr()+negative.sum_xsqr())
37                  /(positive.n()-1+negative.n()-1));
38    return diff/s;
39  }
40
41
42  double tScore::p_value(void)
43  {
44    double t = score();
45    double dof = target_.size()-2;
46    double p = gsl_cdf_tdist_Q(t, dof);
47    return dof > 0 ? p : 1;
48  }
49
50
51
52}} // of namespace cpptools and namespace theplu
Note: See TracBrowser for help on using the repository browser.