source: trunk/test/score_test.cc @ 447

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

added copy constructor for KernelView? and added construction of KernelView? in test

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