source: trunk/test/consensus_inputranker_test.cc @ 779

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

Refs #101

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1// $Id: consensus_inputranker_test.cc 779 2007-03-05 18:58:30Z 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/ROCscore.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
31#include <cstdlib>
32#include <fstream>
33#include <iostream>
34
35using namespace std;
36
37int main(const int argc,const char* argv[])
38{ 
39  std::ostream* error;
40  if (argc>1 && argv[1]==std::string("-v"))
41    error = &std::cerr;
42  else {
43    error = new std::ofstream("/dev/null");
44    if (argc>1)
45      std::cout << "consensus_inputranker_test -v : for printing extra " 
46                << "information\n";
47  }
48  *error << "testing consensus_inputranker" << std::endl;
49  bool ok = true;
50
51  ifstream is("data/rank_data.txt");
52  theplu::yat::utility::matrix data_tmp(is);
53  theplu::yat::classifier::MatrixLookup data(data_tmp);
54  is.close();
55
56  is.open("data/rank_target.txt");
57  theplu::yat::classifier::Target target(is);
58  is.close();
59
60 
61  theplu::yat::statistics::ROCscore roc;
62  theplu::yat::classifier::CrossValidationSampler sampler(target,30,3);
63  *error << "Building Consensus_Inputranker" << std::endl;
64  theplu::yat::classifier::IRRank retrieve;
65  theplu::yat::classifier::ConsensusInputRanker cir(sampler,data,roc,retrieve);
66  *error << "Done" << std::endl;
67
68  if (cir.id(0)!=2 || cir.id(1)!=0 || cir.id(2)!=1){
69    *error << "incorrect id" << endl;
70    ok = false;
71  }
72 
73  if (cir.rank(0)!=1 || cir.rank(1)!=2 || cir.rank(2)!=0){
74    *error << "incorrect rank" << endl;
75    ok=false;
76  }
77
78  theplu::yat::utility::matrix flag(data.rows(),data.columns(),1);
79  // Peter, fix weighted version instead
80  theplu::yat::classifier::ConsensusInputRanker cir2(sampler,data,roc,retrieve);
81
82  if (cir2.id(0)!=2 || cir2.id(1)!=0 || cir2.id(2)!=1){
83    *error << "incorrect id for weighted" << endl;
84    ok=false;
85  }
86 
87  if (cir2.rank(0)!=1 || cir2.rank(1)!=2 || cir2.rank(2)!=0){
88    *error << "incorrect rank for weighted" << endl;
89    ok=false;
90  }
91
92  if (error!=&std::cerr)
93    delete error;
94
95  if(ok)
96    return 0;
97  return -1;
98}
Note: See TracBrowser for help on using the repository browser.