source: trunk/test/roc_test.cc @ 1658

Last change on this file since 1658 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

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