source: trunk/test/subset_generator_test.cc @ 781

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

changing name to ROCScore and also added some cassert includes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1// $Id: subset_generator_test.cc 781 2007-03-05 19:44:03Z peter $
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/classifier/CrossValidationSampler.h"
25#include "yat/classifier/EnsembleBuilder.h"
26#include "yat/classifier/FeatureSelectorIR.h"
27#include "yat/classifier/Kernel_SEV.h"
28#include "yat/classifier/KernelLookup.h"
29#include "yat/classifier/MatrixLookup.h"
30#include "yat/classifier/PolynomialKernelFunction.h"
31#include "yat/classifier/SubsetGenerator.h"
32#include "yat/classifier/SVM.h"
33#include "yat/classifier/NCC.h"
34#include "yat/statistics/ROCScore.h"
35#include "yat/statistics/PearsonDistance.h"
36#include "yat/utility/matrix.h"
37
38#include <cassert>
39#include <fstream>
40#include <iostream>
41#include <string>
42
43using namespace theplu::yat;
44
45int main(const int argc,const char* argv[])
46{ 
47  std::ostream* error;
48  if (argc>1 && argv[1]==std::string("-v"))
49    error = &std::cerr;
50  else {
51    error = new std::ofstream("/dev/null");
52    if (argc>1)
53      std::cout << "feature_selection -v : for printing extra information\n";
54  }
55  *error << "testing ferature_selection" << std::endl;
56  bool ok = true;
57
58
59  std::ifstream is("data/nm_target_bin.txt");
60  *error << "loading target " << std::endl;
61  classifier::Target target(is);
62  is.close();
63  *error << "number of targets: " << target.size() << std::endl;
64  *error << "number of classes: " << target.nof_classes() << std::endl;
65  is.open("data/nm_data_centralized.txt");
66  *error << "loading data " << std::endl;
67  utility::matrix m(is);
68  is.close();
69  classifier::MatrixLookup data(m);
70  *error << "number of samples: " << data.columns() << std::endl;
71  *error << "number of features: " << data.rows() << std::endl;
72  assert(data.columns()==target.size());
73
74  *error << "building kernel" << std::endl;
75  classifier::PolynomialKernelFunction kf(1);
76  classifier::Kernel_SEV kernel_core(data,kf);
77  classifier::KernelLookup kernel(kernel_core);
78  *error << "building Sampler" << std::endl;
79  classifier::CrossValidationSampler sampler(target, 30, 3);
80
81  statistics::ROCScore score;
82  classifier::FeatureSelectorIR fs(score, 96, 0);
83  *error << "building SubsetGenerator" << std::endl;
84  classifier::SubsetGenerator subset_data(sampler, data, fs);
85  classifier::SubsetGenerator subset_kernel(sampler, kernel, fs);
86
87  classifier::SVM svm(kernel,target);
88  statistics::PearsonDistance distance;
89  classifier::NCC ncc(data,target,distance);
90  *error << "building Ensemble" << std::endl;
91  //  classifier::EnsembleBuilder ensemble_ncc(ncc,subset_data);
92  //ensemble_ncc.build();
93  classifier::EnsembleBuilder ensemble_svm(svm,sampler);
94  ensemble_svm.build();
95 
96  utility::vector out(target.size(),0);
97  for (size_t i = 0; i<out.size(); ++i)
98    out(i)=ensemble_svm.validate()[0][i].mean(); 
99  statistics::ROCScore roc;
100  *error << roc.score(target,out) << std::endl;
101
102  if (ok)
103    return 0;
104  return -1;
105}
Note: See TracBrowser for help on using the repository browser.