source: trunk/src/tScore.cc @ 112

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

added the choice to not use all data points but just the train_set

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.5 KB
Line 
1// $Id: tScore.cc 112 2004-07-07 10:23:44Z 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_(), train_set_()
16  {
17  }
18
19  tScore::tScore( const gslapi::vector& target, 
20                  const gslapi::vector& value,
21                  const std::vector<size_t>& train_set) 
22      : Score(), value_(value), target_(target)
23  {
24    if (!train_set_.size())
25      for (size_t i=0; i<target_.size(); i++)
26        train_set_.push_back(i); 
27  }
28   
29  double tScore::score()
30  {
31    Averager positive;
32    Averager negative;
33    for(size_t i=0; i<train_set_.size(); i++){
34      if (target_[train_set_[i]]==1)
35        positive.add(value_[train_set_[i]]);
36      else
37        negative.add(value_[train_set_[i]]);
38    }
39    double diff = positive.mean() - negative.mean();
40    double s=sqrt((positive.sum_xsqr()+negative.sum_xsqr())
41                  /(positive.n()-1+negative.n()-1));
42    return diff/s;
43  }
44
45  double tScore::score(const gslapi::vector& target, 
46                       const gslapi::vector& value,
47                       const std::vector<size_t>& train_set) 
48  {
49    train_set_=train_set;
50    if (!train_set_.size())
51      for (size_t i=0; i<target_.size(); i++)
52        train_set_.push_back(i); 
53    target_ = target;
54    value_ = value;
55    return score();
56  }
57
58  double tScore::p_value(void)
59  {
60    double t = score();
61    double dof = target_.size()-2;
62    double p = gsl_cdf_tdist_Q(t, dof);
63    return dof > 0 ? p : 1;
64  }
65
66
67
68}} // of namespace cpptools and namespace theplu
Note: See TracBrowser for help on using the repository browser.