source: trunk/test/consensus_inputranker_test.cc @ 482

Last change on this file since 482 was 482, checked in by Peter, 17 years ago

modified interface to CrossSplitter?, added functions to DataLookup2D
that extracts trainingdata and validation data. For the time being
weights are not supported in CrossSplitter?.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.8 KB
Line 
1// $Id: consensus_inputranker_test.cc 482 2006-01-02 19:10:10Z 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/CrossSplitter.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::CrossSplitter sampler(target,data,30,3);
44  theplu::classifier::ConsensusInputRanker cir(sampler,roc);
45
46  if (cir.id(0)!=2 || cir.id(1)!=0 || cir.id(2)!=1){
47    *error << "incorrect id" << endl;
48    ok = false;
49  }
50 
51  if (cir.rank(0)!=1 || cir.rank(1)!=2 || cir.rank(2)!=0){
52    *error << "incorrect rank" << endl;
53    ok=false;
54  }
55
56  theplu::gslapi::matrix flag(data.rows(),data.columns(),1);
57  sampler.reset();  // Peter, fix weighted version instead
58  theplu::classifier::ConsensusInputRanker cir2(sampler,roc);
59
60  if (cir2.id(0)!=2 || cir2.id(1)!=0 || cir2.id(2)!=1){
61    *error << "incorrect id for weighted" << endl;
62    ok=false;
63  }
64 
65  if (cir2.rank(0)!=1 || cir2.rank(1)!=2 || cir2.rank(2)!=0){
66    *error << "incorrect rank for weighted" << endl;
67    ok=false;
68  }
69 
70 
71  if (error!=&std::cerr)
72    delete error;
73
74  if(ok)
75    return 0;
76  return -1;
77}
Note: See TracBrowser for help on using the repository browser.