source: trunk/lib/classifier/ConsensusInputRanker.cc @ 558

Last change on this file since 558 was 558, checked in by Peter, 18 years ago

ConsensusInputRanker? now supports weights

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.8 KB
Line 
1// $Id: ConsensusInputRanker.cc 558 2006-03-10 15:58:16Z peter $
2
3
4#include <c++_tools/classifier/ConsensusInputRanker.h>
5
6#include <c++_tools/classifier/CrossSplitter.h>
7#include <c++_tools/classifier/MatrixLookup.h>
8#include <c++_tools/classifier/InputRanker.h>
9#include <c++_tools/classifier/Target.h>
10#include <c++_tools/statistics/utility.h>
11#include <c++_tools/utility/stl_utility.h>
12#include <c++_tools/gslapi/matrix.h>
13
14#include <cassert>
15#include <iostream>
16#include <utility>
17#include <vector>
18
19
20namespace theplu {
21namespace classifier { 
22
23  ConsensusInputRanker::ConsensusInputRanker
24  (CrossSplitter& sampler, statistics::Score& score_object)
25  {
26    assert(sampler.size());
27    size_t nof_inputs = sampler.training_data().rows();
28    id_.resize(nof_inputs);
29    rank_.resize(nof_inputs);
30    while (sampler.more()){
31      if (sampler.weighted()){
32        input_rankers_.push_back(InputRanker(sampler.training_data(), 
33                                             sampler.training_target(), 
34                                             score_object));
35      }
36      else{
37        input_rankers_.push_back(InputRanker(sampler.training_data(), 
38                                             sampler.training_target(), 
39                                             score_object));
40      }
41      sampler.next();
42    }
43    update();
44  }
45
46  void ConsensusInputRanker::update(void)
47  {
48
49    // Sorting with respect to median rank
50    std::vector<std::pair<double,size_t> > medians(id_.size());
51    for (size_t i=0; i<id_.size(); i++){ 
52      std::vector<size_t> ranks(input_rankers_.size());
53      for (size_t j=0; j<input_rankers_.size(); j++) {
54        ranks[j]=input_rankers_[j].rank(i);
55      }
56      medians[i].first = statistics::median(ranks);
57      medians[i].second = i;
58    }
59   
60    //sort medians and assign id_ and rank_
61    sort(medians.begin(), medians.end());
62    for (size_t i=0; i<medians.size(); i++){
63      id_[i]=medians[i].second;
64      rank_[id_[i]]=i;
65    }
66  }
67
68
69}} // of namespace classifier and namespace theplu
Note: See TracBrowser for help on using the repository browser.