source: trunk/test/consensus_inputranker_test.cc @ 865

Last change on this file since 865 was 865, checked in by Peter, 16 years ago

changing URL to http://trac.thep.lu.se/trac/yat

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