source: trunk/test/score_test.cc @ 463

Last change on this file since 463 was 463, checked in by Peter, 17 years ago

fixed bug in KernelView? constructor and updated tests

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 KB
Line 
1// $Id: score_test.cc 463 2005-12-16 17:59:15Z peter $
2
3#include <c++_tools/gslapi/matrix.h>
4#include <c++_tools/statistics/ROC.h>
5#include <c++_tools/statistics/tScore.h>
6#include <c++_tools/statistics/Pearson.h>
7#include <c++_tools/statistics/FoldChange.h>
8#include <c++_tools/gslapi/vector.h>
9#include <c++_tools/statistics/WilcoxonFoldChange.h>
10
11#include <gsl/gsl_cdf.h>
12#include <cmath>
13#include <fstream>
14#include <iostream>
15
16
17using namespace theplu;
18
19int main(const int argc,const char* argv[])
20{ 
21  std::ostream* error;
22  if (argc>1 && argv[1]==std::string("-v"))
23    error = &std::cerr;
24  else {
25    error = new std::ofstream("/dev/null");
26    if (argc>1)
27      std::cout << "score_test -v : for printing extra information\n";
28  }
29  *error << "testing score classes" << std::endl;
30  bool ok = true;
31
32  *error << "testing ROC" << std::endl;
33  gslapi::vector value(31);
34  gslapi::vector target(31,-1);
35  for (unsigned int i=0; i<16; i++) 
36    target(i) = 1;
37  for (unsigned int i=0; i<value.size(); i++) 
38    value(i)=i;
39  statistics::ROC roc;
40  double area = roc.score(target, value);
41  if (area!=1.0){
42    *error << "test_roc a: area is " << area << " should be 1.0" 
43           << std::endl;
44    ok = false;
45  }
46  target*=-1;
47  area = roc.score(target, value);
48  if (area!=1.0){
49    *error << "test_roc: area is " << area << " should be 1.0" 
50           << std::endl;
51    ok = false;
52  }
53 
54  double p = roc.p_value();
55  double p_matlab = 0.00000115;
56  if (p/p_matlab > 1.01 | p/p_matlab < 0.99){
57    *error << "get_p_approx: p-value not correct" << std::endl;
58    ok = false;
59  }
60  roc.minimum_size() = 20;
61  p = roc.p_value();
62  if (p > pow(10, -8.0) | p < pow(10, -9.0)){
63    *error << "get_p_exact: p-value not correct" << std::endl;
64    ok = false;
65  }
66 
67  std::ifstream is("data/rank_data.txt");
68  gslapi::matrix data(is);
69  is.close();
70
71  is.open("data/rank_target.txt");
72  gslapi::vector target2(is);
73  is.close();
74 
75  gslapi::vector correct_area(3);
76  correct_area(0)=8.0/9.0;
77  correct_area(1)=6.0/9.0;
78  correct_area(2)=1.0;
79
80  const double tol = 0.001;
81  for (size_t i=0; i<data.rows(); i++){
82    gslapi::vector vec(data,i);
83    area = roc.score(target2,vec);
84    if (area<correct_area(i)-tol || area>correct_area(i)+tol){
85      *error << "test_roc: area is " << area << " should be " 
86             << correct_area(i) << std::endl;
87      ok=false;
88    }
89  }
90
91  gslapi::vector weight(target2.size(),1);
92  for (size_t i=0; i<data.rows(); i++){
93    gslapi::vector vec(data,i);
94    area = roc.score(target2, vec, weight);
95    if (area<correct_area(i)-tol || area>correct_area(i)+tol){
96      *error << "test_roc: weighted area is " << area << " should be " 
97             << correct_area(i) << std::endl;
98      ok=false;
99    }
100  }
101
102  *error << "testing FoldChange" << std::endl;
103  statistics::FoldChange fold_change(true);
104
105  *error << "testing tScore" << std::endl;
106  statistics::tScore t_score(true);
107
108  *error << "testing Pearson" << std::endl;
109  statistics::Pearson pearson(true);
110
111  *error << "testing WilcoxonFoldChange" << std::endl;
112  statistics::WilcoxonFoldChange wfc(true);
113
114
115  if (ok)
116    return 0;
117  return -1;
118}
Note: See TracBrowser for help on using the repository browser.