source: trunk/test/feature_selection_test.cc @ 862

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

Fixed bug in InputRanker? that sometimes gave rise to a bus error crash. Also added more testing in some tests

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1// $Id: feature_selection_test.cc 862 2007-09-10 13:18:40Z markus $
2
3/*
4  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2007 Peter Johansson
6
7  This file is part of the yat library, http://lev.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/classifier/FeatureSelectorIR.h"
26#include "yat/classifier/FeatureSelectorRandom.h"
27#include "yat/classifier/MatrixLookupWeighted.h"
28#include "yat/classifier/Target.h"
29#include "yat/statistics/AUC.h"
30
31#include "yat/utility/matrix.h"
32
33#include <algorithm>
34#include <cmath>
35#include <fstream>
36#include <iterator>
37#include <iostream>
38#include <string>
39
40using namespace theplu::yat;
41
42int main(const int argc,const char* argv[])
43{ 
44  std::ostream* error;
45  if (argc>1 && argv[1]==std::string("-v"))
46    error = &std::cerr;
47  else {
48    error = new std::ofstream("/dev/null");
49    if (argc>1)
50      std::cout << "feature_selection -v : for printing extra information\n";
51  }
52  *error << "testing feature_selection" << std::endl;
53  bool ok = true;
54
55  statistics::AUC roc;
56  classifier::FeatureSelectorIR f(roc, 12);
57  classifier::FeatureSelectorRandom f2(12);
58
59  *error << "Reading in Sorlie data to identify top gene ..." << std::endl;
60  std::ifstream is("data/sorlie_centroid_data.txt");
61  utility::matrix data(is,'\t');
62  is.close();
63
64  is.open("data/sorlie_centroid_classes.txt");
65  classifier::Target targets(is);
66  is.close();
67
68  *error << "... done" << std::endl;
69
70  // Generate weight matrix with 0 for missing values and 1 for others.
71  utility::matrix weights(data.rows(),data.columns(),0.0);
72  for(size_t i=0;i<data.rows();++i)
73    for(size_t j=0;j<data.columns();++j)
74      if(!std::isnan(data(i,j)))
75        weights(i,j)=1.0;
76 
77  classifier::MatrixLookupWeighted dataviewweighted(data,weights);
78 
79  f2.update(dataviewweighted,targets);
80  *error << "\nRandomly ordered features (top 12):\n";
81  std::vector<size_t> features=f2.features();
82  std::copy(features.begin(),features.end(),
83            std::ostream_iterator<size_t>(*error," ")); 
84  *error << std::endl;
85
86  f.update(dataviewweighted,targets);
87  *error << "\nAUC ordered ordered features (top 12):\n";
88  features=f.features();
89  std::copy(features.begin(),features.end(),
90            std::ostream_iterator<size_t>(*error," ")); 
91  *error << std::endl;
92
93
94  if (ok)
95    return 0;
96  return -1;
97}
Note: See TracBrowser for help on using the repository browser.