source: trunk/test/ensemble_test.cc @ 1087

Last change on this file since 1087 was 1087, checked in by Peter, 15 years ago

fixes #312 and added passing of data in EB constructors

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1// $Id: ensemble_test.cc 1087 2008-02-14 06:05:37Z peter $
2
3/*
4  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér, Peter Johansson
5  Copyright (C) 2007 Peter Johansson
6
7  This file is part of the yat library, http://trac.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 2 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 this program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22  02111-1307, USA.
23*/
24
25#include "yat/utility/matrix.h"
26#include "yat/classifier/SubsetGenerator.h"
27#include "yat/classifier/CrossValidationSampler.h"
28#include "yat/classifier/EnsembleBuilder.h"
29#include "yat/classifier/Kernel.h"
30#include "yat/classifier/KernelLookup.h"
31#include "yat/classifier/Kernel_SEV.h"
32#include "yat/classifier/Kernel_MEV.h"
33#include "yat/classifier/MatrixLookup.h"
34#include "yat/classifier/NCC.h"
35#include "yat/classifier/PolynomialKernelFunction.h"
36#include "yat/classifier/SVM.h"
37#include "yat/statistics/AUC.h"
38
39#include <cassert>
40#include <fstream>
41#include <iostream>
42#include <cstdlib>
43#include <limits>
44
45
46int main(const int argc,const char* argv[])
47{ 
48  using namespace theplu::yat;
49
50  std::ostream* error;
51  if (argc>1 && argv[1]==std::string("-v"))
52    error = &std::cerr;
53  else {
54    error = new std::ofstream("/dev/null");
55    if (argc>1)
56      std::cout << "ensemble_test -v : for printing extra information\n";
57  }
58  *error << "testing ensemble" << std::endl;
59  bool ok = true;
60
61  *error << "loading data" << std::endl;
62  std::ifstream is("data/nm_data_centralized.txt");
63  utility::matrix data_core(is);
64  is.close();
65
66  *error << "create MatrixLookup" << std::endl;
67  classifier::MatrixLookup data(data_core);
68  classifier::KernelFunction* kf = new classifier::PolynomialKernelFunction(); 
69  *error << "Building kernel" << std::endl;
70  classifier::Kernel_SEV kernel(data,*kf);
71
72
73  *error << "load target" << std::endl;
74  is.open("data/nm_target_bin.txt");
75  classifier::Target target(is);
76  is.close();
77  assert(data.columns()==target.size());
78
79  *error << "create KernelLookup" << std::endl;
80  classifier::KernelLookup kernel_lookup(kernel);
81  *error << "create svm" << std::endl;
82  classifier::SVM svm(kernel_lookup, target);
83  *error << "create Subsets" << std::endl;
84  classifier::CrossValidationSampler sampler(target,3,3);
85  classifier::SubsetGenerator<classifier::KernelLookup> cv(sampler,
86                                                           kernel_lookup);
87  *error << "create ensemble" << std::endl;
88  classifier::EnsembleBuilder<classifier::SVM, classifier::KernelLookup> 
89    ensemble(svm, kernel_lookup, sampler);
90  *error << "build ensemble" << std::endl;
91  ensemble.build();
92 
93  utility::vector out(target.size(),0);
94  for (size_t i = 0; i<out.size(); ++i)
95    out(i)=ensemble.validate()[0][i].mean(); 
96  statistics::AUC roc;
97  *error << roc.score(target,out) << std::endl;
98
99  delete kf;
100
101  if (error!=&std::cerr)
102    delete error;
103
104  if(ok)
105    return 0;
106  return -1;
107 
108}
Note: See TracBrowser for help on using the repository browser.