1 | // $Id$ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2004 Peter Johansson |
---|
5 | Copyright (C) 2005 Jari Häkkinen, Peter Johansson |
---|
6 | Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér |
---|
7 | |
---|
8 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
9 | |
---|
10 | The yat library is free software; you can redistribute it and/or |
---|
11 | modify it under the terms of the GNU General Public License as |
---|
12 | published by the Free Software Foundation; either version 2 of the |
---|
13 | License, or (at your option) any later version. |
---|
14 | |
---|
15 | The yat library is distributed in the hope that it will be useful, |
---|
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
18 | General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU General Public License |
---|
21 | along with this program; if not, write to the Free Software |
---|
22 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
23 | 02111-1307, USA. |
---|
24 | */ |
---|
25 | |
---|
26 | #include "InputRanker.h" |
---|
27 | #include "MatrixLookup.h" |
---|
28 | #include "MatrixLookupWeighted.h" |
---|
29 | #include "DataLookup1D.h" |
---|
30 | #include "DataLookupWeighted1D.h" |
---|
31 | #include "Target.h" |
---|
32 | #include "yat/statistics/Score.h" |
---|
33 | #include "yat/utility/stl_utility.h" |
---|
34 | |
---|
35 | #include <cassert> |
---|
36 | #include <cmath> |
---|
37 | #include <functional> |
---|
38 | #include <utility> |
---|
39 | #include <vector> |
---|
40 | |
---|
41 | namespace theplu { |
---|
42 | namespace yat { |
---|
43 | namespace classifier { |
---|
44 | |
---|
45 | |
---|
46 | InputRanker::InputRanker(const MatrixLookup& data, |
---|
47 | const Target& target, |
---|
48 | const statistics::Score& score_object) |
---|
49 | { |
---|
50 | assert(data.columns()==target.size()); |
---|
51 | size_t nof_genes = data.rows(); |
---|
52 | |
---|
53 | //scoring each input |
---|
54 | std::vector<std::pair<double, size_t> > score; |
---|
55 | for (size_t i=0; i<nof_genes; i++) { |
---|
56 | double area = score_object.score(target,DataLookup1D(data,i,true)); |
---|
57 | score.push_back(std::make_pair(area,i)); |
---|
58 | } |
---|
59 | |
---|
60 | //sort the scores and assign id_ and rank_ |
---|
61 | sort(score.begin(), score.end(), std::greater<std::pair<double,size_t> >()); |
---|
62 | |
---|
63 | id_.resize(nof_genes); |
---|
64 | rank_.resize(nof_genes); |
---|
65 | score_.resize(nof_genes); |
---|
66 | for (size_t i=0; i<nof_genes; i++){ |
---|
67 | id_[i]=score[i].second; |
---|
68 | score_[i]=score[i].first; |
---|
69 | rank_[id_[i]]=i; |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | InputRanker::InputRanker(const MatrixLookupWeighted& data, |
---|
75 | const Target& target, |
---|
76 | const statistics::Score& score_object) |
---|
77 | { |
---|
78 | assert(data.columns()==target.size()); |
---|
79 | size_t nof_genes = data.rows(); |
---|
80 | |
---|
81 | //scoring each input |
---|
82 | std::vector<std::pair<double, size_t> > score; |
---|
83 | for (size_t i=0; i<nof_genes; i++) { |
---|
84 | double area=score_object.score(target,DataLookupWeighted1D(data,i,true)); |
---|
85 | score.push_back(std::make_pair(area,i)); |
---|
86 | } |
---|
87 | |
---|
88 | //sort the scores and assign id_ and rank_ |
---|
89 | sort(score.begin(), score.end(), std::greater<std::pair<double,size_t> >()); |
---|
90 | |
---|
91 | id_.resize(nof_genes); |
---|
92 | rank_.resize(nof_genes); |
---|
93 | score_.resize(nof_genes); |
---|
94 | for (size_t i=0; i<nof_genes; i++){ |
---|
95 | id_[i]=score[i].second; |
---|
96 | score_[i]=score[i].first; |
---|
97 | rank_[id_[i]]=i; |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | const std::vector<size_t>& InputRanker::id(void) const |
---|
103 | { |
---|
104 | return id_; |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | const std::vector<size_t>& InputRanker::rank(void) const |
---|
109 | { |
---|
110 | return rank_; |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | double InputRanker::score(size_t rank) const |
---|
115 | { |
---|
116 | return score_[rank]; |
---|
117 | } |
---|
118 | |
---|
119 | }}} // of namespace classifier, yat, and theplu |
---|