source: branches/peters_vector/lib/statistics/tScore.cc @ 469

Last change on this file since 469 was 469, checked in by Peter, 16 years ago

non compiling checking before revision after design meeting

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
Line 
1// $Id: tScore.cc 469 2005-12-19 14:58:29Z peter $
2
3// System includes
4#include <cmath>
5
6// Thep C++ Tools
7#include <c++_tools/statistics/tScore.h>
8#include <c++_tools/statistics/Averager.h>
9#include <c++_tools/statistics/AveragerWeighted.h>
10#include <c++_tools/classifier/Target.h>
11#include <c++_tools/classifier/VectorAbstract.h>
12
13namespace theplu {
14namespace statistics { 
15
16  tScore::tScore(bool b) 
17    : Score(b),  t_(0)
18  {
19  }
20
21  double tScore::score(const classifier::Target& target, 
22                       const classifier::VectorAbstract& value)
23  {
24    weighted_=false;
25    statistics::Averager positive;
26    statistics::Averager negative;
27    dof_=target.size()-2;
28    for(size_t i=0; i<target.size(); i++){
29      if (class_one(target(i)))
30        positive.add(value(i));
31      else
32        negative.add(value(i));
33    }
34    double diff = positive.mean() - negative.mean();
35    double s=sqrt((positive.sum_xsqr()+negative.sum_xsqr())
36                  /(positive.n()+negative.n()-2));
37    t_=diff/s/(1.0/positive.n()+1.0/negative.n());
38    if (t_<0 && absolute_)
39      t_=-t_;
40     
41    return t_;
42  }
43
44  double tScore::score(const classifier::Target& target, 
45                       const classifier::VectorAbstract& value,
46                       const classifier::VectorAbstract& weight)
47  {
48    weighted_=true;
49
50    statistics::AveragerWeighted positive;
51    statistics::AveragerWeighted negative;
52    dof_=target.size()-2;
53    for(size_t i=0; i<target.size(); i++){
54      if (class_one(target(i)))
55        positive.add(value(i),weight(i));
56      else
57        negative.add(value(i),weight(i));
58    }
59    double diff = positive.mean() - negative.mean();
60    double s=sqrt((positive.sum_xsqr_centered()+negative.sum_xsqr_centered())/
61                  (positive.sum_w()+negative.sum_w()-2));
62    t_=diff/s/(1.0/positive.sum_w()+1.0/negative.sum_w());
63    if (t_<0 && absolute_)
64      t_=-t_;
65     
66    return t_;
67  }
68
69  double tScore::p_value(void) const
70  {
71    double p = gsl_cdf_tdist_Q(t_, dof_);
72    return (dof_ > 0 && !weighted_) ? p : 1;
73  }
74
75
76
77}} // of namespace statistics and namespace theplu
Note: See TracBrowser for help on using the repository browser.