Changeset 120


Ignore:
Timestamp:
Jul 20, 2004, 6:25:29 PM (18 years ago)
Author:
Peter
Message:

modified to handle weights

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/InputRanker.cc

    r108 r120  
    3939  std::vector<pair<size_t, double> > score;
    4040  for (size_t i=0; i<nof_genes; i++){
    41     double area = score_object.score(data_transposed[i], target);
     41    double area = score_object.score(data_transposed[i], target, train_set_);
     42    std::pair<size_t, double> tmp(i,area);
     43    score.push_back(tmp);
     44  }
     45  //sort the scores and assign id_ and rank_
     46  sort(score.begin(), score.end(),
     47       pair_value_compare<size_t, double>());
     48 
     49  for (size_t i=0; i<nof_genes; i++){
     50    id_[i]=score[i].first;
     51    rank_[id_[i]]=i;           
     52  }
     53}
     54
     55InputRanker::InputRanker(const gslapi::matrix& data,
     56                         const gslapi::vector& target,
     57                         const gslapi::matrix& weight,
     58                         Score& score_object,
     59                         const std::vector<size_t>& train_set)
     60  :train_set_(train_set),
     61   id_(std::vector<size_t>(data.rows())),
     62   rank_(std::vector<size_t>(data.rows()))
     63 
     64{
     65  using namespace std;
     66  // Peter, this copying and transposing is done since it seems
     67  // problematic to get a column vector from a matrix
     68  gslapi::matrix data_transposed = data;
     69  data_transposed.transpose();
     70  gslapi::matrix weight_transposed = weight;
     71  weight_transposed.transpose();
     72 
     73  size_t nof_genes = data_transposed.rows();
     74  size_t nof_samples = data_transposed.columns();
     75  if (!train_set_.size()){
     76    train_set_.resize(nof_samples);
     77    for (size_t i=0; i<nof_samples; i++)
     78      train_set_[i]=i; 
     79  }
     80  //scoring each input
     81  std::vector<pair<size_t, double> > score;
     82  for (size_t i=0; i<nof_genes; i++){
     83    double area = score_object.score(data_transposed[i], target,
     84                                     weight_transposed[i], train_set_);
    4285    std::pair<size_t, double> tmp(i,area);
    4386    score.push_back(tmp);
  • trunk/src/InputRanker.h

    r108 r120  
    3535
    3636    ///
     37    /// Constructor taking data, target, weight, pointer to a Score
     38    /// object and vector defining what samples to use (default is to
     39    /// use all samples)
     40    ///
     41    InputRanker(const gslapi::matrix&,
     42                const gslapi::vector&,
     43                const gslapi::matrix&,
     44                Score&,
     45                const std::vector<size_t>& = std::vector<size_t>());
     46
     47    ///
    3748    /// @return id of input ranked as number i
    3849    ///
Note: See TracChangeset for help on using the changeset viewer.