source: trunk/test/ensemble_test.cc @ 931

Last change on this file since 931 was 931, checked in by Markus Ringnér, 16 years ago

Working on ticket:259. Removed old Distance see ticket:250

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1// $Id: ensemble_test.cc 931 2007-10-05 15:42:25Z markus $
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/trac/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 cv(sampler,kernel_lookup);
86  *error << "create ensemble" << std::endl;
87  classifier::EnsembleBuilder ensemble(svm,sampler);
88  *error << "build ensemble" << std::endl;
89  ensemble.build();
90 
91  utility::vector out(target.size(),0);
92  for (size_t i = 0; i<out.size(); ++i)
93    out(i)=ensemble.validate()[0][i].mean(); 
94  statistics::AUC roc;
95  *error << roc.score(target,out) << std::endl;
96
97  delete kf;
98
99  if (error!=&std::cerr)
100    delete error;
101
102  if(ok)
103    return 0;
104  return -1;
105 
106}
Note: See TracBrowser for help on using the repository browser.