source: trunk/test/roc_test.cc @ 1797

Last change on this file since 1797 was 1797, checked in by Peter, 13 years ago

updating copyright statements

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1// $Id: roc_test.cc 1797 2009-02-12 18:07:10Z peter $
2
3/*
4  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
5
6  This file is part of the yat library, http://dev.thep.lu.se/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 3 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with yat. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "Suite.h"
23
24#include "yat/classifier/DataLookupWeighted1D.h"
25#include "yat/classifier/Target.h"
26#include "yat/statistics/ROC.h"
27#include "yat/statistics/utility.h"
28#include "yat/utility/Vector.h"
29
30#include <cmath>
31#include <fstream>
32#include <iostream>
33
34
35using namespace theplu::yat;
36
37int main(int argc, char* argv[])
38{ 
39  test::Suite suite(argc, argv);
40
41  suite.err() << "testing ROC" << std::endl;
42  utility::Vector value(31);
43  std::vector<std::string> label(31,"negative");
44  for (size_t i=0; i<16; i++) 
45    label[i] = "positive";
46  classifier::Target target(label);
47  for (size_t i=0; i<value.size(); i++) 
48    value(i)=i;
49  statistics::ROC roc;
50  add(roc, value.begin(), value.end(), target);
51  double area = roc.area();
52  if (!suite.equal(area,0.0)){
53    suite.err() << "test_roc: area is " << area << " should be 0.0" 
54           << std::endl;
55    suite.add(false);
56  }
57  target.set_binary(0,false);
58  target.set_binary(1,true);
59  roc.reset();
60  add(roc, value.begin(), value.end(), target);
61  area = roc.area();
62  if (!suite.equal(area,1.0)){
63    suite.err() << "test_roc: area is " << area << " should be 1.0" 
64           << std::endl;
65    suite.add(false);
66  }
67 
68  double p = roc.p_value_one_sided();
69  double p2 = roc.p_value();
70  double p_matlab = 0.00000115;
71  if (!(p/p_matlab < 1.01 && p/p_matlab > 0.99)){
72    suite.err() << "get_p_approx: p-value not correct" << std::endl;
73    suite.err() << p << " expected " << p_matlab << std::endl;
74    suite.add(false);
75  }
76  if (!(p2==2*p)) {
77    suite.add(false);
78    suite.err() << "Two-sided P-value should equal 2 * one-sided P-value.\n";
79  }
80  roc.minimum_size() = 20;
81  p = roc.p_value_one_sided();
82  p2 = roc.p_value();
83  if (!( p < 1e-8 && p > 1e-9) ){
84    suite.err() << "get_p_exact: p-value not correct" << std::endl;
85    suite.add(false);
86  }
87  if (!( p2==2*p)) {
88    suite.add(false);
89    suite.err() << "Two-sided P-value should equal 2 * one-sided P-value.\n";
90  }
91 
92  classifier::DataLookupWeighted1D dlw(target.size(),1.3);
93  add(roc, dlw.begin(), dlw.end(), target);
94
95  return suite.return_value();
96}
Note: See TracBrowser for help on using the repository browser.