Changeset 102


Ignore:
Timestamp:
Jun 15, 2004, 11:40:52 AM (18 years ago)
Author:
Peter
Message:

Fixed bug in interface between InputRanker? & ROC

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/InputRanker.cc

    r89 r102  
    1616InputRanker::InputRanker(const gslapi::matrix& data,
    1717                         const gslapi::vector& target,
    18                          const std::vector<size_t> train_set)
     18                         const std::vector<size_t>& train_set)
    1919  :train_set_(train_set),
    2020   id_(std::vector<size_t>(data.rows())),
     
    3030  size_t nof_genes = data_transposed.rows();
    3131  size_t nof_samples = data_transposed.columns();
    32   if (!train_set_.size())
     32  if (!train_set_.size()){
     33    train_set_.resize(nof_samples);
    3334    for (size_t i=0; i<nof_samples; i++)
    34       train_set_.push_back(i)
    35 
    36   //scoring each gene
     35      train_set_[i]=i
     36  }
     37  //scoring each input
    3738  std::vector<pair<size_t, double> > score;
    38   for (size_t i=0; i<nof_genes; i++){
    39     ROC roc(data_transposed[train_set_[i]], target);
    40     std::pair<size_t, double> tmp(i,roc.area());
     39  ROC roc = ROC();
     40  for (size_t i=0; i<nof_genes; i++){
     41    double area = roc.score(data_transposed[i], target); 
     42    std::pair<size_t, double> tmp(i,area);
    4143    score.push_back(tmp);
    4244  }
     
    4749  for (size_t i=0; i<nof_genes; i++){
    4850    id_[i]=score[i].first;
    49     rank_[id_[i]]=i;
     51    rank_[id_[i]]=i;           
    5052  }
     53}
    5154 
    52  
    53 }
    54 
    5555}} // of namespace cpptools and namespace theplu
  • trunk/src/InputRanker.h

    r89 r102  
    1616namespace cpptools { 
    1717  ///
    18   /// Class for ranking the columns in a matrix, using ROC (this could
    19   /// and the target vector.
     18  /// Class for ranking the columns in a matrix, using a Score and a
     19  /// target vector.
    2020  ///   
    2121  class InputRanker
     
    2424  public:
    2525    ///
    26     /// Constructor taking data, target and vector defining what
     26    /// Constructor taking data, target, and vector defining what
    2727    /// samples to use (default is to use all samples)
    2828    ///
    2929    InputRanker(const gslapi::matrix&, const gslapi::vector&,
    30            const std::vector<size_t> = std::vector<size_t>());
     30                const std::vector<size_t>& = std::vector<size_t>());
    3131
    3232    ///
  • trunk/src/ROC.cc

    r98 r102  
    1717 
    1818    : Score(), value_(), nof_pos_(0), minimum_size_(10), area_(-1)
    19 
    20        
     19   
    2120  {
    2221    for (unsigned int i=0; i<target.size(); i++){
     
    3231  }
    3332
     33  ROC::ROC()
     34    : Score(), value_(), nof_pos_(0), minimum_size_(10), area_(-1)
     35       
     36  {
     37  }
     38
     39
     40  double ROC::score(const gslapi::vector& target, const gslapi::vector& value)
     41  {
     42    for (unsigned int i=0; i<target.size(); i++){
     43      int targ=static_cast<int>(target(i));
     44      std::pair<int, double> tmp(targ, value(i));
     45      value_.push_back(tmp);
     46      if (targ==1)
     47        nof_pos_++;
     48    }
     49    sort(value_.begin(),value_.end(),
     50         pair_value_compare<int,double>());
     51    double area_=0;
     52    for (unsigned int i=0; i<value_.size(); i++)
     53      if (value_[i].first==1)
     54        area_+=i;
     55    // Normalizing the area to 0-1
     56    area_ = (area_/nof_pos_ - (nof_pos_ - 1)/2 )/(value_.size() - nof_pos_);
     57
     58    return area_;
     59  }
    3460
    3561  double ROC::score()
    3662  {
    37     using namespace std;
    3863    if (area_==-1){
    3964      double area_=0;
     
    6287
    6388
    64   double ROC::get_p_approx(const double area)
     89  double ROC::get_p_approx(const double area) const
    6590  {
    6691    double x = area - 0.5;
  • trunk/src/ROC.h

    r98 r102  
    2626  public:
    2727    ///
     28    /// Default constructor
     29    ///
     30    ROC(void);
     31         
     32    ///
    2833    /// Constructor taking a value vector and a target vector (+1 or -1).
    2934    ///
     
    3843    /// between zero and one.  @return the area under the ROC curve
    3944    ///
    40     double score();
     45    double score() ;
     46   
     47    /// Function taking a vector of values and a vector of target (+1
     48    /// or -1). The score is equivalent to the Mann-Whitney score but
     49    /// normalized to be between zero and one. @return the area under
     50    /// the ROC curve
     51    ///
     52    double score(const gslapi::vector&, const gslapi::vector&);
    4153       
    4254    ///
     
    5163    /// @return the one-sided p-value
    5264    ///
    53     double p_value();
     65    double p_value() ;
    5466         
    5567    ///
     
    6072
    6173  private:
    62     std::vector<std::pair<int, double> > value_;
     74    std::vector<std::pair<int, double> > value_; //sorted pair of id and value
    6375    double nof_pos_;
    6476    u_int minimum_size_;
     
    6981    /// @return the p-value
    7082    ///
    71     double ROC::get_p_approx(const double);
     83    double ROC::get_p_approx(const double) const;
    7284   
    7385    ///
  • trunk/src/Score.h

    r98 r102  
    2727    virtual ~Score(void) {};
    2828   
    29     virtual double score() = 0;
     29    virtual double score(const gslapi::vector&,
     30                         const gslapi::vector&) = 0;
    3031 
    3132    virtual double p_value() = 0;
  • trunk/src/tScore.cc

    r98 r102  
    1212namespace cpptools { 
    1313
     14  tScore::tScore()
     15      : Score(), value_(), target_()
     16  {
     17  }
     18
    1419  tScore::tScore( const gslapi::vector& target,
    1520                  const gslapi::vector& value)
    1621      : Score(), value_(value), target_(target)
    17      
    1822  {
    1923  }
  • trunk/src/tScore.h

    r98 r102  
    2525 
    2626  public:
     27    ///
     28    /// Default Constructor.
     29    ///
     30    tScore();
     31
    2732    ///
    2833    /// Constructor taking a value vector and a target vector (+1 or -1).
Note: See TracChangeset for help on using the changeset viewer.