Changeset 134


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

fixed bug

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/InputRanker.cc

    r120 r134  
    1414namespace cpptools { 
    1515
    16 InputRanker::InputRanker(const gslapi::matrix& data,
    17                          const gslapi::vector& target,
    18                          Score& score_object,
    19                          const std::vector<size_t>& train_set)
    20   :train_set_(train_set),
    21    id_(std::vector<size_t>(data.rows())),
    22    rank_(std::vector<size_t>(data.rows()))
     16  InputRanker::InputRanker()
     17    :train_set_(std::vector<size_t>()),
     18     id_(std::vector<size_t>()),
     19     rank_(std::vector<size_t>())
    2320 
    24 {
    25   using namespace std;
    26   // Peter, this copying and transposing is done since it seems
    27   // problematic to get a column vector from a matrix
    28   gslapi::matrix data_transposed = data;
    29   data_transposed.transpose();
     21  {
     22  }
    3023 
    31   size_t nof_genes = data_transposed.rows();
    32   size_t nof_samples = data_transposed.columns();
    33   if (!train_set_.size()){
    34     train_set_.resize(nof_samples);
    35     for (size_t i=0; i<nof_samples; i++)
    36       train_set_[i]=i; 
     24  InputRanker::InputRanker(const gslapi::matrix& data,
     25                           const gslapi::vector& target,
     26                           Score& score_object,
     27                           const std::vector<size_t>& train_set)
     28    :train_set_(train_set),
     29     id_(std::vector<size_t>(data.rows())),
     30     rank_(std::vector<size_t>(data.rows()))
     31 
     32  {
     33    size_t nof_genes = data.rows();
     34    size_t nof_samples = data.columns();
     35    if (!train_set_.size()){
     36      train_set_.resize(nof_samples);
     37      for (size_t i=0; i<nof_samples; i++)
     38        train_set_[i]=i; 
     39    }
     40
     41    //scoring each input
     42    std::vector<std::pair<size_t, double> > score;
     43    for (size_t i=0; i<nof_genes; i++){
     44      double area = score_object.score(target, data[i], train_set_); 
     45      std::pair<size_t, double> tmp(i,area);
     46      score.push_back(tmp);
     47    }
     48
     49    //sort the scores and assign id_ and rank_
     50    sort(score.begin(), score.end(),
     51         pair_value_compare<size_t, double>());
     52   
     53    for (size_t i=0; i<nof_genes; i++){
     54      id_[i]=score[i].first;
     55      rank_[id_[i]]=i;           
     56    }
    3757  }
    38   //scoring each input
    39   std::vector<pair<size_t, double> > score;
    40   for (size_t i=0; i<nof_genes; i++){
    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);
     58
     59  InputRanker::InputRanker(const gslapi::matrix& data,
     60                           const gslapi::vector& target,
     61                           const gslapi::matrix& weight,
     62                           Score& score_object,
     63                           const std::vector<size_t>& train_set)
     64    :train_set_(train_set),
     65     id_(std::vector<size_t>(data.rows())),
     66     rank_(std::vector<size_t>(data.rows()))
     67 
     68  {
     69    size_t nof_genes = data.rows();
     70    size_t nof_samples = data.columns();
     71    if (!train_set_.size()){
     72      train_set_.resize(nof_samples);
     73      for (size_t i=0; i<nof_samples; i++)
     74        train_set_[i]=i; 
     75    }
     76    //scoring each input
     77    std::vector<std::pair<size_t, double> > score;
     78    for (size_t i=0; i<nof_genes; i++){
     79      double area = score_object.score(data[i], target,
     80                                       weight[i], train_set_); 
     81      std::pair<size_t, double> tmp(i,area);
     82      score.push_back(tmp);
     83    }
     84    //sort the scores and assign id_ and rank_
     85    sort(score.begin(), score.end(),
     86         pair_value_compare<size_t, double>());
     87   
     88    for (size_t i=0; i<nof_genes; i++){
     89      id_[i]=score[i].first;
     90      rank_[id_[i]]=i;           
     91    }
    4492  }
    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 
    55 InputRanker::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_);
    85     std::pair<size_t, double> tmp(i,area);
    86     score.push_back(tmp);
    87   }
    88   //sort the scores and assign id_ and rank_
    89   sort(score.begin(), score.end(),
    90        pair_value_compare<size_t, double>());
    91  
    92   for (size_t i=0; i<nof_genes; i++){
    93     id_[i]=score[i].first;
    94     rank_[id_[i]]=i;           
    95   }
    96 }
    9793 
    9894}} // of namespace cpptools and namespace theplu
  • trunk/src/InputRanker.h

    r120 r134  
    1717namespace cpptools { 
    1818  ///
    19   /// Class for ranking the columns in a matrix, using a Score and a
     19  /// Class for ranking rows in a matrix, using a Score and a
    2020  /// target vector.
    2121  ///   
     
    2525  public:
    2626    ///
    27     /// Constructor taking data, target, pointer to a Score
     27    /// Default constructor. Not implemented.
     28    ///
     29    InputRanker();
     30
     31    ///
     32    /// Constructor taking data, target, a Score
    2833    /// object and vector defining what samples to use (default is to
    2934    /// use all samples)
Note: See TracChangeset for help on using the changeset viewer.