source: trunk/test/test_roc.cc @ 291

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

small changes

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