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