source: trunk/test/consensus_inputranker_test.cc @ 1658

Last change on this file since 1658 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

  • 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 1487 2008-09-10 08:41:36Z jari $
2
3/*
4  Copyright (C) 2004, 2005 Peter Johansson
5  Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson
6  Copyright (C) 2008 Peter Johansson
7
8  This file is part of the yat library, http://dev.thep.lu.se/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 3 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 yat. If not, see <http://www.gnu.org/licenses/>.
22*/
23
24#include "Suite.h"
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(int argc, char* argv[])
41{ 
42  using namespace theplu::yat;
43  theplu::yat::test::Suite suite(argc, argv);
44  suite.err() << "testing consensus_inputranker" << std::endl;
45
46  ifstream is(test::filename("data/rank_data.txt").c_str());
47  theplu::yat::utility::Matrix data_tmp(is);
48  theplu::yat::classifier::MatrixLookup data(data_tmp);
49  is.close();
50
51  is.open(test::filename("data/rank_target.txt").c_str());
52  theplu::yat::classifier::Target target(is);
53  is.close();
54
55 
56  theplu::yat::statistics::AUC roc;
57  theplu::yat::classifier::CrossValidationSampler sampler(target,30,3);
58  suite.err() << "Building Consensus_Inputranker" << std::endl;
59  theplu::yat::classifier::IRRank retrieve;
60  theplu::yat::statistics::Median median;
61  theplu::yat::classifier::ConsensusInputRanker cir(retrieve,median);
62  cir.add(sampler,data,roc);
63
64  suite.err() << "test ids... ";
65  if (cir.id(0)!=2 || cir.id(1)!=0 || cir.id(2)!=1){
66    suite.err() << "\nincorrect id for weighted" << endl;
67    suite.add(false);
68  }
69  else 
70    suite.err() << "ok." << std::endl;
71
72  suite.err() << "test ranks... ";
73  if (cir.rank(0)!=1 || cir.rank(1)!=2 || cir.rank(2)!=0){
74    suite.err() << "\nincorrect rank for weighted" << endl;
75    suite.add(false);
76  }
77  else 
78    suite.err() << "ok." << std::endl;
79
80  theplu::yat::utility::Matrix flag(data.rows(),data.columns(),1);
81  // Peter, fix weighted version instead
82  theplu::yat::classifier::ConsensusInputRanker cir2(retrieve,median);
83  cir2.add(sampler,data,roc);
84
85  suite.err() << "test ids... ";
86  if (cir2.id(0)!=2 || cir2.id(1)!=0 || cir2.id(2)!=1){
87    suite.err() << "\nincorrect id for weighted" << endl;
88    suite.add(false);
89  }
90  else 
91    suite.err() << "ok." << std::endl;
92 
93  suite.err() << "test ranks... ";
94  if (cir2.rank(0)!=1 || cir2.rank(1)!=2 || cir2.rank(2)!=0){
95    suite.err() << "\nincorrect rank for weighted" << endl;
96    suite.add(false);
97  }
98  else 
99    suite.err() << "ok." << std::endl;
100
101  return suite.return_value();
102}
Note: See TracBrowser for help on using the repository browser.