1 | // $Id: inputranker_test.cc 831 2007-03-27 13:22:09Z 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://lev.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/InputRanker.h" |
---|
27 | #include "yat/statistics/AUC.h" |
---|
28 | #include "yat/utility/matrix.h" |
---|
29 | #include "yat/classifier/MatrixLookup.h" |
---|
30 | #include "yat/classifier/Target.h" |
---|
31 | |
---|
32 | #include <cstdlib> |
---|
33 | #include <fstream> |
---|
34 | #include <iostream> |
---|
35 | |
---|
36 | |
---|
37 | |
---|
38 | int main(const int argc,const char* argv[]) |
---|
39 | { |
---|
40 | using namespace theplu::yat; |
---|
41 | std::ostream* error; |
---|
42 | if (argc>1 && argv[1]==std::string("-v")) |
---|
43 | error = &std::cerr; |
---|
44 | else { |
---|
45 | error = new std::ofstream("/dev/null"); |
---|
46 | if (argc>1) |
---|
47 | std::cout << "inputranker_test -v : for printing extra information\n"; |
---|
48 | } |
---|
49 | *error << "testing inputranker" << std::endl; |
---|
50 | bool ok = true; |
---|
51 | |
---|
52 | std::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 | classifier::Target target(is); |
---|
59 | is.close(); |
---|
60 | |
---|
61 | statistics::AUC roc; |
---|
62 | classifier::InputRanker ir(data,target,roc); |
---|
63 | if (ir.id()[0]!=2 || ir.id()[1]!=0 || ir.id()[2]!=1){ |
---|
64 | *error << "wrong id" << std::endl; |
---|
65 | ok=false; |
---|
66 | } |
---|
67 | |
---|
68 | if (ir.rank()[0]!=1 || ir.rank()[1]!=2 || ir.rank()[2]!=0){ |
---|
69 | *error << "wrong rank" << std::endl; |
---|
70 | ok=false; |
---|
71 | } |
---|
72 | |
---|
73 | if (error!=&std::cerr) |
---|
74 | delete error; |
---|
75 | |
---|
76 | return (ok ? 0 : -1); |
---|
77 | |
---|
78 | } |
---|