1 | // $Id: ensemble_test.cc 704 2006-12-18 16:01:41Z markus $ |
---|
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/utility/matrix.h" |
---|
25 | #include "yat/classifier/SubsetGenerator.h" |
---|
26 | #include "yat/classifier/CrossValidationSampler.h" |
---|
27 | #include "yat/classifier/EnsembleBuilder.h" |
---|
28 | #include "yat/classifier/Kernel.h" |
---|
29 | #include "yat/classifier/KernelLookup.h" |
---|
30 | #include "yat/classifier/Kernel_SEV.h" |
---|
31 | #include "yat/classifier/Kernel_MEV.h" |
---|
32 | #include "yat/classifier/MatrixLookup.h" |
---|
33 | #include "yat/classifier/NCC.h" |
---|
34 | #include "yat/statistics/PearsonDistance.h" |
---|
35 | #include "yat/classifier/PolynomialKernelFunction.h" |
---|
36 | #include "yat/classifier/SVM.h" |
---|
37 | |
---|
38 | #include <cassert> |
---|
39 | #include <fstream> |
---|
40 | #include <iostream> |
---|
41 | #include <cstdlib> |
---|
42 | #include <limits> |
---|
43 | |
---|
44 | |
---|
45 | int main(const int argc,const char* argv[]) |
---|
46 | { |
---|
47 | using namespace theplu::yat; |
---|
48 | |
---|
49 | std::ostream* error; |
---|
50 | if (argc>1 && argv[1]==std::string("-v")) |
---|
51 | error = &std::cerr; |
---|
52 | else { |
---|
53 | error = new std::ofstream("/dev/null"); |
---|
54 | if (argc>1) |
---|
55 | std::cout << "ensemble_test -v : for printing extra information\n"; |
---|
56 | } |
---|
57 | *error << "testing ensemble" << std::endl; |
---|
58 | bool ok = true; |
---|
59 | |
---|
60 | *error << "loading data" << std::endl; |
---|
61 | std::ifstream is("data/nm_data_centralized.txt"); |
---|
62 | utility::matrix data_core(is); |
---|
63 | is.close(); |
---|
64 | |
---|
65 | *error << "create MatrixLookup" << std::endl; |
---|
66 | classifier::MatrixLookup data(data_core); |
---|
67 | classifier::KernelFunction* kf = new classifier::PolynomialKernelFunction(); |
---|
68 | *error << "Building kernel" << std::endl; |
---|
69 | classifier::Kernel_SEV kernel(data,*kf); |
---|
70 | |
---|
71 | |
---|
72 | *error << "load target" << std::endl; |
---|
73 | is.open("data/nm_target_bin.txt"); |
---|
74 | classifier::Target target(is); |
---|
75 | is.close(); |
---|
76 | assert(data.columns()==target.size()); |
---|
77 | |
---|
78 | *error << "create KernelLookup" << std::endl; |
---|
79 | classifier::KernelLookup kernel_lookup(kernel); |
---|
80 | *error << "create svm" << std::endl; |
---|
81 | classifier::SVM svm(kernel_lookup, target); |
---|
82 | *error << "create Subsets" << std::endl; |
---|
83 | classifier::CrossValidationSampler sampler(target,3,3); |
---|
84 | classifier::SubsetGenerator cv(sampler,kernel_lookup); |
---|
85 | *error << "create ensemble" << std::endl; |
---|
86 | classifier::EnsembleBuilder ensemble(svm,cv); |
---|
87 | *error << "build ensemble" << std::endl; |
---|
88 | ensemble.build(); |
---|
89 | |
---|
90 | delete kf; |
---|
91 | |
---|
92 | if (error!=&std::cerr) |
---|
93 | delete error; |
---|
94 | |
---|
95 | if(ok) |
---|
96 | return 0; |
---|
97 | return -1; |
---|
98 | |
---|
99 | } |
---|