source: trunk/test/score_test.cc @ 1659

Last change on this file since 1659 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 Author Date Id Revision
File size: 3.9 KB
Line 
1// $Id: score_test.cc 1487 2008-09-10 08:41:36Z jari $
2
3/*
4  Copyright (C) 2004, 2005, 2006 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér
6  Copyright (C) 2008 Peter Johansson
7
8  This file is part of the yat library, http://dev.thep.lu.se/yat
9
10  The yat library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License as
12  published by the Free Software Foundation; either version 3 of the
13  License, or (at your option) any later version.
14
15  The yat library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with yat. If not, see <http://www.gnu.org/licenses/>.
22*/
23
24#include "Suite.h"
25
26#include "yat/classifier/Target.h"
27#include "yat/statistics/FoldChange.h"
28#include "yat/statistics/Pearson.h"
29#include "yat/statistics/AUC.h"
30#include "yat/statistics/SAMScore.h"
31#include "yat/statistics/SNRScore.h"
32#include "yat/statistics/tScore.h"
33#include "yat/statistics/WilcoxonFoldChange.h"
34#include "yat/utility/Matrix.h"
35#include "yat/utility/Vector.h"
36#include "yat/utility/VectorView.h"
37
38#include <cmath>
39#include <fstream>
40#include <iostream>
41
42
43using namespace theplu::yat;
44
45int main(int argc, char* argv[])
46{ 
47  test::Suite suite(argc, argv);
48
49  suite.err() << "testing score classes" << std::endl;
50
51  suite.err() << "testing AUC" << std::endl;
52  utility::Vector value(31);
53  std::vector<std::string> label(31,"negative");
54  for (size_t i=0; i<16; i++) 
55    label[i] = "positive";
56  classifier::Target target(label);
57  for (size_t i=0; i<value.size(); i++) 
58    value(i)=i;
59  statistics::AUC auc(false);
60  double area = auc.score(target, value);
61  if (!(suite.equal(1-area,1))){
62    suite.err() << "test_auc: area is " << area << " should be 0.0" 
63           << std::endl;
64    suite.add(false);
65  }
66  target.set_binary(0,false);
67  target.set_binary(1,true);
68  area = auc.score(target, value);
69  if (!suite.equal(area,1.0)){
70    suite.err() << "test_auc: area is " << area << " should be 1.0" 
71           << std::endl;
72    suite.add(false);
73  }
74 
75  std::ifstream is(test::filename("data/rank_data.txt").c_str());
76  utility::Matrix data(is);
77  is.close();
78
79  is.open(test::filename("data/rank_target.txt").c_str());
80  classifier::Target target2(is);
81  is.close();
82 
83  utility::Vector correct_area(3);
84  correct_area(0)=1.0/9.0;
85  correct_area(1)=3.0/9.0;
86  correct_area(2)=0.0;
87
88  for (size_t i=0; i<data.rows(); i++){
89    utility::VectorView vec(data,i);
90    if (vec.size()!=target2.size()){
91      suite.err() << "vec.size() is " << vec.size() << " and target2.size() is " 
92             << target2.size() << ". Should be equal." << std::endl; 
93      suite.add(false);
94    }
95    area = auc.score(target2,vec);
96    if (!suite.equal(area, correct_area(i)) ){
97      suite.err() << "test_roc: area is " << area << " should be " 
98             << correct_area(i) << std::endl;
99      suite.add(false);
100    }
101  }
102
103  utility::Vector weight(target2.size(),1);
104  for (size_t i=0; i<data.rows(); i++){
105    utility::VectorView vec = data.row_view(i);
106    area = auc.score(target2, vec, weight);
107    if (!suite.equal(area,correct_area(i)) ){
108      suite.err() << "test_roc: weighted area is " << area << " should be " 
109             << correct_area(i) << std::endl;
110      suite.add(false);
111    }
112  }
113
114  suite.err() << "testing FoldChange" << std::endl;
115  statistics::FoldChange fold_change(true);
116
117  suite.err() << "testing tScore" << std::endl;
118  statistics::tScore t_score(true);
119
120  suite.err() << "testing Pearson" << std::endl;
121  statistics::Pearson pearson(true);
122
123  suite.err() << "testing WilcoxonFoldChange" << std::endl;
124  statistics::WilcoxonFoldChange wfc(true);
125
126  suite.err() << "testing SAMScore" << std::endl;
127  statistics::SAMScore sam(1.0,true);
128
129  suite.err() << "testing SNRScore" << std::endl;
130  statistics::SNRScore snr(true);
131
132
133  return suite.return_value();
134}
Note: See TracBrowser for help on using the repository browser.