Changeset 152


Ignore:
Timestamp:
Sep 10, 2004, 12:56:20 PM (17 years ago)
Author:
Peter
Message:

fixed cv bug

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ConsensusInputRanker.cc

    r150 r152  
    2727    for (size_t i=0; i<nof_rankers_; i++){
    2828      //InputRanker ir(data, target, score_object);
    29       input_rankers_.push_back(InputRanker(data, target, score_object));
     29      input_rankers_.push_back(InputRanker(data, target, score_object,
     30                                           cv.next()));
    3031    }
     32    // Sorting with respect to median rank
     33    theplu::cpptools::Statistics stat;
     34    std::vector<std::pair<size_t,double> > median(data.rows());
     35    for (size_t i=0; i<data.rows(); i++){
     36      std::vector<size_t> ranks(nof_rankers_);
     37      for (size_t j=0; j<nof_rankers_; j++)
     38        ranks[j]=input_rankers_[j].rank(i);
     39     
     40      median[i].first = i;
     41      median[i].second = stat.median(ranks);
     42    }
     43   
     44    //sort medians and assign id_ and rank_
     45    sort(median.begin(), median.end(),
     46         pair_value_compare<size_t, double>());
     47    id_.resize(data.rows());
     48    rank_.resize(data.rows());
     49    for (size_t i=0; i<data.rows(); i++){
     50      id_[i]=median[i].first;
     51      rank_[id_[i]]=i;           
     52    }
     53
     54  }
     55
     56  ConsensusInputRanker::ConsensusInputRanker(const gslapi::matrix& data,
     57                                             const gslapi::vector& target,
     58                                             const gslapi::matrix& weight,
     59                                             Score& score_object,
     60                                             const size_t rounds,
     61                                             const size_t k)
     62    :id_(std::vector<size_t>()), input_rankers_(std::vector<InputRanker>()),
     63     k_(k), nof_rankers_(k*rounds), rank_(std::vector<size_t>())
     64
     65  {
     66    CrossValidation cv(target, k_);
     67    for (size_t i=0; i<nof_rankers_; i++)
     68      input_rankers_.push_back(InputRanker(data,target,weight,score_object,
     69                                           cv.next()));
     70   
    3171    // Sorting with respect to median rank
    3272    theplu::cpptools::Statistics stat;
  • trunk/src/ConsensusInputRanker.h

    r150 r152  
    3939
    4040    ///
     41    /// Constructor taking \a data, \a target, \a weight and Score object. The
     42    /// constructor creates ranklists in a \a k fold crossvalidation
     43    /// manner, and in total there is \a n times \a k ranklists.
     44    ///
     45    ConsensusInputRanker(const gslapi::matrix& data,
     46                         const gslapi::vector& target,
     47                         const gslapi::matrix& weight,
     48                         Score&,
     49                         const size_t n = 1 ,
     50                         const size_t k = 3 );
     51
     52    ///
    4153    /// Highest ranked row is ranked as number zero @return index of
    4254    /// row ranked as number \a i
Note: See TracChangeset for help on using the changeset viewer.