source: trunk/c++_tools/classifier/ConsensusInputRanker.cc @ 607

Last change on this file since 607 was 607, checked in by Peter, 15 years ago

ref #96 included FeatureSelection? in CrossSplitter?. Also happened to add properties to files

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1// $Id: ConsensusInputRanker.cc 607 2006-08-29 14:42:28Z 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#include <cmath>
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                                             sampler.training_weight()));
36      }
37      else{
38        input_rankers_.push_back(InputRanker(sampler.training_data(), 
39                                             sampler.training_target(), 
40                                             score_object));       
41      }
42      sampler.next();
43    }
44    update();
45  }
46
47  void ConsensusInputRanker::update(void)
48  {
49
50    // Sorting with respect to median rank
51    std::vector<std::pair<double,size_t> > medians(id_.size());
52    for (size_t i=0; i<id_.size(); i++){ 
53      std::vector<size_t> ranks(input_rankers_.size());
54      for (size_t j=0; j<input_rankers_.size(); j++) {
55        ranks[j]=input_rankers_[j].rank()[i];
56      }
57      medians[i].first = statistics::median(ranks);
58      medians[i].second = i;
59    }
60   
61    //sort medians and assign id_ and rank_
62    sort(medians.begin(), medians.end());
63    for (size_t i=0; i<medians.size(); i++){
64      id_[i]=medians[i].second;
65      rank_[id_[i]]=i;
66    }
67  }
68
69
70}} // of namespace classifier and namespace theplu
Note: See TracBrowser for help on using the repository browser.