source: trunk/test/consensus_inputranker_test.cc @ 2119

Last change on this file since 2119 was 2119, checked in by Peter, 14 years ago

converted files to utf-8. fixes #577

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