source: trunk/test/consensus_inputranker_test.cc @ 828

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

Generalized ConsenusInputRanker?, Fixes #151

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 KB
Line 
1// $Id: consensus_inputranker_test.cc 828 2007-03-19 22:15:43Z peter $
2
3/*
4  Copyright (C) The authors contributing to this file.
5
6  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "yat/classifier/ConsensusInputRanker.h"
25#include "yat/statistics/AUC.h"
26#include "yat/utility/matrix.h"
27#include "yat/classifier/MatrixLookup.h"
28#include "yat/classifier/CrossValidationSampler.h"
29#include "yat/classifier/IRRank.h"
30#include "yat/statistics/VectorFunction.h"
31
32#include <cstdlib>
33#include <fstream>
34#include <iostream>
35
36using namespace std;
37
38int main(const int argc,const char* argv[])
39{ 
40  std::ostream* error;
41  if (argc>1 && argv[1]==std::string("-v"))
42    error = &std::cerr;
43  else {
44    error = new std::ofstream("/dev/null");
45    if (argc>1)
46      std::cout << "consensus_inputranker_test -v : for printing extra " 
47                << "information\n";
48  }
49  *error << "testing consensus_inputranker" << std::endl;
50  bool ok = true;
51
52  ifstream is("data/rank_data.txt");
53  theplu::yat::utility::matrix data_tmp(is);
54  theplu::yat::classifier::MatrixLookup data(data_tmp);
55  is.close();
56
57  is.open("data/rank_target.txt");
58  theplu::yat::classifier::Target target(is);
59  is.close();
60
61 
62  theplu::yat::statistics::AUC roc;
63  theplu::yat::classifier::CrossValidationSampler sampler(target,30,3);
64  *error << "Building Consensus_Inputranker" << std::endl;
65  theplu::yat::classifier::IRRank retrieve;
66  theplu::yat::statistics::Median median;
67  theplu::yat::classifier::ConsensusInputRanker cir(retrieve,median);
68  cir.add(sampler,data,roc);
69
70  *error << "test ids... ";
71  if (cir.id(0)!=2 || cir.id(1)!=0 || cir.id(2)!=1){
72    *error << "\nincorrect id for weighted" << endl;
73    ok=false;
74  }
75  else 
76    *error << "ok." << std::endl;
77
78  *error << "test ranks... ";
79  if (cir.rank(0)!=1 || cir.rank(1)!=2 || cir.rank(2)!=0){
80    *error << "\nincorrect rank for weighted" << endl;
81    ok=false;
82  }
83  else 
84    *error << "ok." << std::endl;
85
86  theplu::yat::utility::matrix flag(data.rows(),data.columns(),1);
87  // Peter, fix weighted version instead
88  theplu::yat::classifier::ConsensusInputRanker cir2(retrieve,median);
89  cir2.add(sampler,data,roc);
90
91  *error << "test ids... ";
92  if (cir2.id(0)!=2 || cir2.id(1)!=0 || cir2.id(2)!=1){
93    *error << "\nincorrect id for weighted" << endl;
94    ok=false;
95  }
96  else 
97    *error << "ok." << std::endl;
98 
99  *error << "test ranks... ";
100  if (cir2.rank(0)!=1 || cir2.rank(1)!=2 || cir2.rank(2)!=0){
101    *error << "\nincorrect rank for weighted" << endl;
102    ok=false;
103  }
104  else 
105    *error << "ok." << std::endl;
106
107  if (error!=&std::cerr)
108    delete error;
109
110  if(ok)
111    return 0;
112  return -1;
113}
Note: See TracBrowser for help on using the repository browser.