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

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

ref #96 Changed InputRanker? to return vector of index rather than element. Also added draft to FeatureSelection? class.

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