source: trunk/test/ensemble_test.cc @ 1157

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

Refs #318

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1// $Id: ensemble_test.cc 1157 2008-02-26 13:25:19Z 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/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#include "yat/statistics/EuclideanDistance.h"
39
40#include <cassert>
41#include <fstream>
42#include <iostream>
43#include <cstdlib>
44#include <limits>
45
46
47int main(const int argc,const char* argv[])
48{ 
49  using namespace theplu::yat;
50
51  std::ostream* error;
52  if (argc>1 && argv[1]==std::string("-v"))
53    error = &std::cerr;
54  else {
55    error = new std::ofstream("/dev/null");
56    if (argc>1)
57      std::cout << "ensemble_test -v : for printing extra information\n";
58  }
59  *error << "testing ensemble" << std::endl;
60  bool ok = true;
61
62  *error << "loading data" << std::endl;
63  std::ifstream is("data/nm_data_centralized.txt");
64  utility::Matrix data_core(is);
65  is.close();
66
67  *error << "create MatrixLookup" << std::endl;
68  classifier::MatrixLookup data(data_core);
69  classifier::KernelFunction* kf = new classifier::PolynomialKernelFunction(); 
70  *error << "Building kernel" << std::endl;
71  classifier::Kernel_SEV kernel(data,*kf);
72
73
74  *error << "load target" << std::endl;
75  is.open("data/nm_target_bin.txt");
76  classifier::Target target(is);
77  is.close();
78  assert(data.columns()==target.size());
79
80  {
81    *error << "create ensemble of ncc" << std::endl;
82    classifier::NCC<statistics::EuclideanDistance> ncc;
83    classifier::CrossValidationSampler sampler(target,3,3);
84    classifier::SubsetGenerator<classifier::MatrixLookup> subdata(sampler,data);
85    classifier::EnsembleBuilder<classifier::SupervisedClassifier,
86      classifier::MatrixLookup> ensemble(ncc, data, sampler);
87    *error << "build ensemble" << std::endl;
88    ensemble.build();
89  }
90
91  *error << "create KernelLookup" << std::endl;
92  classifier::KernelLookup kernel_lookup(kernel);
93  *error << "create svm" << std::endl;
94  classifier::SVM svm();
95  *error << "create Subsets" << std::endl;
96  classifier::CrossValidationSampler sampler(target,3,3);
97  classifier::SubsetGenerator<classifier::KernelLookup> cv(sampler,
98                                                           kernel_lookup);
99  /* Peter, temporarily removed because of redesign
100  *error << "create ensemble" << std::endl;
101  classifier::EnsembleBuilder<classifier::SVM, classifier::KernelLookup>
102    ensemble(svm, kernel_lookup, sampler);
103  *error << "build ensemble" << std::endl;
104  ensemble.build();
105 
106  utility::vector out(target.size(),0);
107  for (size_t i = 0; i<out.size(); ++i)
108    out(i)=ensemble.validate()[0][i].mean();
109  statistics::AUC roc;
110  *error << roc.score(target,out) << std::endl;
111  */
112  delete kf;
113
114  if (error!=&std::cerr)
115    delete error;
116
117  if(ok)
118    return 0;
119  return -1;
120 
121}
Note: See TracBrowser for help on using the repository browser.