1 | // $Id: consensus_inputranker_test.cc 667 2006-10-06 07:03:19Z peter $ |
---|
2 | |
---|
3 | // C++ tools include |
---|
4 | //////////////////// |
---|
5 | #include <c++_tools/classifier/ConsensusInputRanker.h> |
---|
6 | #include <c++_tools/statistics/ROC.h> |
---|
7 | #include <c++_tools/utility/matrix.h> |
---|
8 | #include <c++_tools/classifier/MatrixLookup.h> |
---|
9 | #include <c++_tools/classifier/CrossValidationSampler.h> |
---|
10 | #include <c++_tools/classifier/IRRank.h> |
---|
11 | |
---|
12 | #include <cstdlib> |
---|
13 | #include <fstream> |
---|
14 | #include <iostream> |
---|
15 | //#include <vector> |
---|
16 | |
---|
17 | using namespace std; |
---|
18 | |
---|
19 | int main(const int argc,const char* argv[]) |
---|
20 | { |
---|
21 | std::ostream* error; |
---|
22 | if (argc>1 && argv[1]==std::string("-v")) |
---|
23 | error = &std::cerr; |
---|
24 | else { |
---|
25 | error = new std::ofstream("/dev/null"); |
---|
26 | if (argc>1) |
---|
27 | std::cout << "consensus_inputranker_test -v : for printing extra " |
---|
28 | << "information\n"; |
---|
29 | } |
---|
30 | *error << "testing consensus_inputranker" << std::endl; |
---|
31 | bool ok = true; |
---|
32 | |
---|
33 | ifstream is("data/rank_data.txt"); |
---|
34 | theplu::utility::matrix data_tmp(is); |
---|
35 | theplu::classifier::MatrixLookup data(data_tmp); |
---|
36 | is.close(); |
---|
37 | |
---|
38 | is.open("data/rank_target.txt"); |
---|
39 | theplu::classifier::Target target(is); |
---|
40 | is.close(); |
---|
41 | |
---|
42 | |
---|
43 | theplu::statistics::ROC roc; |
---|
44 | theplu::classifier::CrossValidationSampler sampler(target,30,3); |
---|
45 | *error << "Building Consensus_Inputranker" << std::endl; |
---|
46 | theplu::classifier::IRRank retrieve; |
---|
47 | theplu::classifier::ConsensusInputRanker cir(sampler,data,roc,retrieve); |
---|
48 | *error << "Done" << std::endl; |
---|
49 | |
---|
50 | if (cir.id(0)!=2 || cir.id(1)!=0 || cir.id(2)!=1){ |
---|
51 | *error << "incorrect id" << endl; |
---|
52 | std::cout << cir.id(0) << "=2" << std::endl; |
---|
53 | std::cout << cir.id(1) << "=0" << std::endl; |
---|
54 | std::cout << cir.id(2) << "=1" << std::endl; |
---|
55 | ok = false; |
---|
56 | } |
---|
57 | |
---|
58 | if (cir.rank(0)!=1 || cir.rank(1)!=2 || cir.rank(2)!=0){ |
---|
59 | *error << "incorrect rank" << endl; |
---|
60 | ok=false; |
---|
61 | } |
---|
62 | |
---|
63 | theplu::utility::matrix flag(data.rows(),data.columns(),1); |
---|
64 | // Peter, fix weighted version instead |
---|
65 | theplu::classifier::ConsensusInputRanker cir2(sampler,data,roc,retrieve); |
---|
66 | |
---|
67 | if (cir2.id(0)!=2 || cir2.id(1)!=0 || cir2.id(2)!=1){ |
---|
68 | *error << "incorrect id for weighted" << endl; |
---|
69 | ok=false; |
---|
70 | } |
---|
71 | |
---|
72 | if (cir2.rank(0)!=1 || cir2.rank(1)!=2 || cir2.rank(2)!=0){ |
---|
73 | *error << "incorrect rank for weighted" << endl; |
---|
74 | ok=false; |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | if (error!=&std::cerr) |
---|
79 | delete error; |
---|
80 | |
---|
81 | if(ok) |
---|
82 | return 0; |
---|
83 | return -1; |
---|
84 | } |
---|