Ignore:
Timestamp:
Aug 16, 2004, 2:01:15 PM (18 years ago)
Author:
Peter
Message:

added sorting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ConsensusInputRanker.cc

    r115 r133  
    11// $Id$
     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"
    210
    311// System includes
    412#include <vector>
    5 
    6 // Thep C++ Tools
    7 #include "InputRanker.h"
    8 #include "ConsensusInputRanker.h"
    9 #include "CrossValidation.h"
    1013
    1114namespace theplu {
     
    1518                                             const gslapi::vector& target,
    1619                                             Score& score_object,
    17                                              const size_t nof_rankers,
     20                                             const size_t rounds,
    1821                                             const size_t k)
    19     :k_(k),
    20      nof_rankers_(nof_rankers)
     22    :id_(std::vector<size_t>()), input_rankers_(std::vector<InputRanker>()),
     23     k_(k), nof_rankers_(k*rounds), rank_(std::vector<size_t>())
    2124
    2225  {
    23     CrossValidation cv = CrossValidation(target.size(), k_);
    24     for (size_t i=0; i<k_; i++){
    25       input_rankers_.push_back(InputRanker(data, target, score_object, cv.next()));
     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));
    2630    }
    27  
     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
    2852  }
    2953   
Note: See TracChangeset for help on using the changeset viewer.