1 | // $Id: ConsensusInputRanker.cc 133 2004-08-16 12:01:15Z peter $ |
---|
2 | |
---|
3 | |
---|
4 | #include "ConsensusInputRanker.h" |
---|
5 | // Thep C++ Tools |
---|
6 | #include "CrossValidation.h" |
---|
7 | #include "InputRanker.h" |
---|
8 | #include "Statistics.h" |
---|
9 | #include "stl_utility.h" |
---|
10 | |
---|
11 | // System includes |
---|
12 | #include <vector> |
---|
13 | |
---|
14 | namespace theplu { |
---|
15 | namespace cpptools { |
---|
16 | |
---|
17 | ConsensusInputRanker::ConsensusInputRanker(const gslapi::matrix& data, |
---|
18 | const gslapi::vector& target, |
---|
19 | Score& score_object, |
---|
20 | const size_t rounds, |
---|
21 | const size_t k) |
---|
22 | :id_(std::vector<size_t>()), input_rankers_(std::vector<InputRanker>()), |
---|
23 | k_(k), nof_rankers_(k*rounds), rank_(std::vector<size_t>()) |
---|
24 | |
---|
25 | { |
---|
26 | CrossValidation cv(target, k_); |
---|
27 | for (size_t i=0; i<nof_rankers_; i++){ |
---|
28 | //InputRanker ir(data, target, score_object); |
---|
29 | input_rankers_.push_back(InputRanker(data, target, score_object)); |
---|
30 | } |
---|
31 | // Sorting with respect to median rank |
---|
32 | theplu::cpptools::Statistics stat; |
---|
33 | std::vector<std::pair<size_t,double> > median(data.rows()); |
---|
34 | for (size_t i=0; i<data.rows(); i++){ |
---|
35 | std::vector<size_t> ranks(nof_rankers_); |
---|
36 | for (size_t j=0; j<nof_rankers_; j++) |
---|
37 | ranks[j]=input_rankers_[j].rank(i+1); |
---|
38 | median[i].first = i; |
---|
39 | median[i].second = stat.median(ranks); |
---|
40 | } |
---|
41 | |
---|
42 | //sort medians and assign id_ and rank_ |
---|
43 | sort(median.begin(), median.end(), |
---|
44 | pair_value_compare<size_t, double>()); |
---|
45 | id_.resize(data.rows()); |
---|
46 | rank_.resize(data.rows()); |
---|
47 | for (size_t i=0; i<data.rows(); i++){ |
---|
48 | id_[i]=median[i].first; |
---|
49 | rank_[id_[i]]=i; |
---|
50 | } |
---|
51 | |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | }} // of namespace cpptools and namespace theplu |
---|