source: trunk/test/consensus_inputranker_test.cc @ 615

Last change on this file since 615 was 615, checked in by Peter, 15 years ago

ref #60 NOTE: there is most likely a bug around. I have removed the ensemble.build() test in the ensemble_test to get the test go through. I will try to find and remove this bug asap.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
Line 
1// $Id: consensus_inputranker_test.cc 615 2006-08-31 05:33:35Z 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/gslapi/matrix.h>
8#include <c++_tools/classifier/MatrixLookup.h>
9#include <c++_tools/classifier/CrossValidationSampler.h>
10
11#include <cstdlib>
12#include <fstream>
13#include <iostream>
14//#include <vector>
15
16using namespace std;
17
18int main(const int argc,const char* argv[])
19{ 
20  std::ostream* error;
21  if (argc>1 && argv[1]==std::string("-v"))
22    error = &std::cerr;
23  else {
24    error = new std::ofstream("/dev/null");
25    if (argc>1)
26      std::cout << "consensus_inputranker_test -v : for printing extra " 
27                << "information\n";
28  }
29  *error << "testing consensus_inputranker" << std::endl;
30  bool ok = true;
31
32  ifstream is("data/rank_data.txt");
33  theplu::gslapi::matrix data_tmp(is);
34  theplu::classifier::MatrixLookup data(data_tmp);
35  is.close();
36
37  is.open("data/rank_target.txt");
38  theplu::classifier::Target target(is);
39  is.close();
40
41 
42  theplu::statistics::ROC roc;
43  theplu::classifier::CrossValidationSampler sampler(target,30,3);
44  *error << "Building Consensus_Inputranker" << std::endl;
45  theplu::classifier::ConsensusInputRanker cir(sampler,data,roc);
46  *error << "Done" << std::endl;
47
48  if (cir.id(0)!=2 || cir.id(1)!=0 || cir.id(2)!=1){
49    *error << "incorrect id" << endl;
50    ok = false;
51  }
52 
53  if (cir.rank(0)!=1 || cir.rank(1)!=2 || cir.rank(2)!=0){
54    *error << "incorrect rank" << endl;
55    ok=false;
56  }
57
58  theplu::gslapi::matrix flag(data.rows(),data.columns(),1);
59  // Peter, fix weighted version instead
60  theplu::classifier::ConsensusInputRanker cir2(sampler,data,roc);
61
62  if (cir2.id(0)!=2 || cir2.id(1)!=0 || cir2.id(2)!=1){
63    *error << "incorrect id for weighted" << endl;
64    ok=false;
65  }
66 
67  if (cir2.rank(0)!=1 || cir2.rank(1)!=2 || cir2.rank(2)!=0){
68    *error << "incorrect rank for weighted" << endl;
69    ok=false;
70  }
71 
72 
73  if (error!=&std::cerr)
74    delete error;
75
76  if(ok)
77    return 0;
78  return -1;
79}
Note: See TracBrowser for help on using the repository browser.