1 | // $Id: InputRanker.cc 89 2004-05-28 17:44:42Z peter $ |
---|
2 | |
---|
3 | // Thep C++ Tools |
---|
4 | #include "InputRanker.h" |
---|
5 | #include "ROC.h" |
---|
6 | #include "matrix.h" |
---|
7 | #include "vector.h" |
---|
8 | #include "stl_utility.h" |
---|
9 | |
---|
10 | #include <vector> |
---|
11 | #include <utility> |
---|
12 | |
---|
13 | namespace theplu { |
---|
14 | namespace cpptools { |
---|
15 | |
---|
16 | InputRanker::InputRanker(const gslapi::matrix& data, |
---|
17 | const gslapi::vector& target, |
---|
18 | const std::vector<size_t> train_set) |
---|
19 | :train_set_(train_set), |
---|
20 | id_(std::vector<size_t>(data.rows())), |
---|
21 | rank_(std::vector<size_t>(data.rows())) |
---|
22 | |
---|
23 | { |
---|
24 | using namespace std; |
---|
25 | // Peter, this copying and transposing is done since it seems |
---|
26 | // problematic to get a column vector from a matrix |
---|
27 | gslapi::matrix data_transposed = data; |
---|
28 | data_transposed.transpose(); |
---|
29 | |
---|
30 | size_t nof_genes = data_transposed.rows(); |
---|
31 | size_t nof_samples = data_transposed.columns(); |
---|
32 | if (!train_set_.size()) |
---|
33 | for (size_t i=0; i<nof_samples; i++) |
---|
34 | train_set_.push_back(i); |
---|
35 | |
---|
36 | //scoring each gene |
---|
37 | std::vector<pair<size_t, double> > score; |
---|
38 | for (size_t i=0; i<nof_genes; i++){ |
---|
39 | ROC roc(data_transposed[train_set_[i]], target); |
---|
40 | std::pair<size_t, double> tmp(i,roc.area()); |
---|
41 | score.push_back(tmp); |
---|
42 | } |
---|
43 | //sort the scores and assign id_ and rank_ |
---|
44 | sort(score.begin(), score.end(), |
---|
45 | pair_value_compare<size_t, double>()); |
---|
46 | |
---|
47 | for (size_t i=0; i<nof_genes; i++){ |
---|
48 | id_[i]=score[i].first; |
---|
49 | rank_[id_[i]]=i; |
---|
50 | } |
---|
51 | |
---|
52 | |
---|
53 | } |
---|
54 | |
---|
55 | }} // of namespace cpptools and namespace theplu |
---|