605 |
29 Aug 06 |
peter |
// $Id$ |
605 |
29 Aug 06 |
peter |
2 |
|
675 |
10 Oct 06 |
jari |
3 |
/* |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2006 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson, Markus Ringnér |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2009, 2012 Peter Johansson |
605 |
29 Aug 06 |
peter |
8 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
675 |
10 Oct 06 |
jari |
10 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
675 |
10 Oct 06 |
jari |
15 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
675 |
10 Oct 06 |
jari |
General Public License for more details. |
675 |
10 Oct 06 |
jari |
20 |
|
675 |
10 Oct 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
675 |
10 Oct 06 |
jari |
23 |
*/ |
675 |
10 Oct 06 |
jari |
24 |
|
2881 |
18 Nov 12 |
peter |
25 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
26 |
|
1237 |
15 Mar 08 |
peter |
27 |
#include "Suite.h" |
1237 |
15 Mar 08 |
peter |
28 |
|
864 |
10 Sep 07 |
markus |
29 |
#include "yat/classifier/DataLookupWeighted1D.h" |
675 |
10 Oct 06 |
jari |
30 |
#include "yat/classifier/FeatureSelectorIR.h" |
675 |
10 Oct 06 |
jari |
31 |
#include "yat/classifier/FeatureSelectorRandom.h" |
862 |
10 Sep 07 |
markus |
32 |
#include "yat/classifier/MatrixLookupWeighted.h" |
862 |
10 Sep 07 |
markus |
33 |
#include "yat/classifier/Target.h" |
864 |
10 Sep 07 |
markus |
34 |
#include "yat/statistics/SNRScore.h" |
675 |
10 Oct 06 |
jari |
35 |
|
1121 |
22 Feb 08 |
peter |
36 |
#include "yat/utility/Matrix.h" |
1584 |
15 Oct 08 |
peter |
37 |
#include "yat/utility/MatrixWeighted.h" |
862 |
10 Sep 07 |
markus |
38 |
|
862 |
10 Sep 07 |
markus |
39 |
#include <algorithm> |
862 |
10 Sep 07 |
markus |
40 |
#include <cmath> |
605 |
29 Aug 06 |
peter |
41 |
#include <fstream> |
862 |
10 Sep 07 |
markus |
42 |
#include <iterator> |
605 |
29 Aug 06 |
peter |
43 |
#include <iostream> |
605 |
29 Aug 06 |
peter |
44 |
#include <string> |
605 |
29 Aug 06 |
peter |
45 |
|
680 |
11 Oct 06 |
jari |
46 |
using namespace theplu::yat; |
605 |
29 Aug 06 |
peter |
47 |
|
1237 |
15 Mar 08 |
peter |
48 |
int main(int argc, char* argv[]) |
4200 |
19 Aug 22 |
peter |
49 |
{ |
1237 |
15 Mar 08 |
peter |
50 |
test::Suite suite(argc, argv); |
1237 |
15 Mar 08 |
peter |
51 |
suite.err() << "testing feature_selection" << std::endl; |
605 |
29 Aug 06 |
peter |
52 |
|
864 |
10 Sep 07 |
markus |
53 |
statistics::SNRScore snr; |
864 |
10 Sep 07 |
markus |
54 |
classifier::FeatureSelectorIR f(snr, 12); |
642 |
07 Sep 06 |
peter |
55 |
classifier::FeatureSelectorRandom f2(12); |
605 |
29 Aug 06 |
peter |
56 |
|
1237 |
15 Mar 08 |
peter |
57 |
suite.err() << "Reading in Sorlie data to identify top gene ..." << std::endl; |
1251 |
03 Apr 08 |
peter |
58 |
std::ifstream is(test::filename("data/sorlie_centroid_data.txt").c_str()); |
1121 |
22 Feb 08 |
peter |
59 |
utility::Matrix data(is,'\t'); |
862 |
10 Sep 07 |
markus |
60 |
is.close(); |
862 |
10 Sep 07 |
markus |
61 |
|
1251 |
03 Apr 08 |
peter |
62 |
is.open(test::filename("data/sorlie_centroid_classes.txt").c_str()); |
862 |
10 Sep 07 |
markus |
63 |
classifier::Target targets(is); |
862 |
10 Sep 07 |
markus |
64 |
is.close(); |
862 |
10 Sep 07 |
markus |
65 |
|
1237 |
15 Mar 08 |
peter |
66 |
suite.err() << "... done" << std::endl; |
862 |
10 Sep 07 |
markus |
67 |
|
1584 |
15 Oct 08 |
peter |
// Generate matrix with weight 0 for missing values and 1 for others. |
1584 |
15 Oct 08 |
peter |
69 |
utility::MatrixWeighted xw(data); |
1584 |
15 Oct 08 |
peter |
70 |
classifier::MatrixLookupWeighted dataviewweighted(xw); |
4200 |
19 Aug 22 |
peter |
71 |
|
862 |
10 Sep 07 |
markus |
72 |
f2.update(dataviewweighted,targets); |
1237 |
15 Mar 08 |
peter |
73 |
suite.err() << "\nRandomly ordered features (top 12):\n"; |
1134 |
23 Feb 08 |
peter |
74 |
std::vector<size_t> features=f2.features().vector(); |
862 |
10 Sep 07 |
markus |
75 |
std::copy(features.begin(),features.end(), |
4200 |
19 Aug 22 |
peter |
76 |
std::ostream_iterator<size_t>(suite.err()," ")); |
1237 |
15 Mar 08 |
peter |
77 |
suite.err() << std::endl; |
862 |
10 Sep 07 |
markus |
78 |
|
862 |
10 Sep 07 |
markus |
79 |
f.update(dataviewweighted,targets); |
1237 |
15 Mar 08 |
peter |
80 |
suite.err() << "\nSNR ordered ordered features (top 12):\n"; |
1134 |
23 Feb 08 |
peter |
81 |
features=f.features().vector(); |
862 |
10 Sep 07 |
markus |
82 |
std::copy(features.begin(),features.end(), |
4200 |
19 Aug 22 |
peter |
83 |
std::ostream_iterator<size_t>(suite.err()," ")); |
1237 |
15 Mar 08 |
peter |
84 |
suite.err() << std::endl; |
862 |
10 Sep 07 |
markus |
85 |
|
864 |
10 Sep 07 |
markus |
86 |
size_t best_feature=features[0]; |
864 |
10 Sep 07 |
markus |
87 |
if(best_feature!=69) { |
1237 |
15 Mar 08 |
peter |
88 |
suite.err() << "\nERROR: Incorrect best feature found!\n" << std::endl; |
1237 |
15 Mar 08 |
peter |
89 |
suite.add(false); |
864 |
10 Sep 07 |
markus |
90 |
} |
862 |
10 Sep 07 |
markus |
91 |
|
864 |
10 Sep 07 |
markus |
92 |
classifier::DataLookupWeighted1D row(dataviewweighted,best_feature,true); |
1704 |
08 Jan 09 |
peter |
93 |
if(!suite.equal_fix(snr.score(targets, row), 1.47804, 0.00001) ) { |
1237 |
15 Mar 08 |
peter |
94 |
suite.err() << "\nERROR: Best score not what expected!\n" << std::endl; |
1237 |
15 Mar 08 |
peter |
95 |
suite.add(false); |
864 |
10 Sep 07 |
markus |
96 |
} |
4200 |
19 Aug 22 |
peter |
97 |
|
4200 |
19 Aug 22 |
peter |
// Re-rank the best features |
864 |
10 Sep 07 |
markus |
99 |
classifier::MatrixLookupWeighted ranked=f.get(dataviewweighted); |
864 |
10 Sep 07 |
markus |
100 |
f.update(ranked,targets); |
1134 |
23 Feb 08 |
peter |
101 |
features=f.features().vector(); |
864 |
10 Sep 07 |
markus |
102 |
for(size_t i=0;i<features.size();i++) { |
864 |
10 Sep 07 |
markus |
103 |
if(features[i]!=i) { |
1237 |
15 Mar 08 |
peter |
104 |
suite.add(false); |
1237 |
15 Mar 08 |
peter |
105 |
suite.err() << "ERROR: Problem with top-ranked feature" << std::endl; |
864 |
10 Sep 07 |
markus |
106 |
} |
864 |
10 Sep 07 |
markus |
107 |
} |
864 |
10 Sep 07 |
markus |
108 |
|
1237 |
15 Mar 08 |
peter |
109 |
return suite.return_value(); |
605 |
29 Aug 06 |
peter |
110 |
} |