Changeset 133


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

added sorting

Location:
trunk/src
Files:
2 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   
  • trunk/src/ConsensusInputRanker.h

    r115 r133  
    66// C++ tools include
    77/////////////////////
     8#include "InputRanker.h"
     9#include "matrix.h"
     10#include "Score.h"
     11#include "vector.h"
    812
    913// Standard C++ includes
     
    1519
    1620  ///
    17   /// Class for
     21  /// Class for ranking rows in a data matrix versus a target vector
     22  /// in a cross validation manner. The rows are sorted with respect
     23  /// to median of their ranks.
    1824  ///   
    1925  class ConsensusInputRanker
     
    2228  public:
    2329    ///
    24     /// Constructor taking data, target, Score object
     30    /// Constructor taking \a data, \a target, Score object
    2531    ///
    26     ConsensusInputRanker(const gslapi::matrix&,
    27                          const gslapi::vector&,
     32    ConsensusInputRanker(const gslapi::matrix& data,
     33                         const gslapi::vector& target,
    2834                         Score&,
    2935                         const size_t = 1,
    3036                         const size_t = 3);
    3137
     38    ///
     39    /// @return id of input ranked as number \a i
     40    ///
     41    inline size_t id(const size_t i) const {return id_[i];}
     42   
     43    ///
     44    /// @return rank for id \a i
     45    ///
     46    inline size_t rank(const size_t i) const {return rank_[i];}
    3247
    3348
    3449  private:
     50    std::vector<size_t> id_;
    3551    std::vector<InputRanker> input_rankers_;
    3652    size_t k_;
    3753    size_t nof_rankers_;
     54    std::vector<size_t> rank_;
    3855  };
    3956
Note: See TracChangeset for help on using the changeset viewer.