Changeset 117


Ignore:
Timestamp:
Jul 19, 2004, 5:09:14 PM (18 years ago)
Author:
Peter
Message:

modified to take vector<size_t>

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Statistics.cc

    r115 r117  
    2525  }
    2626
     27  double Statistics::median(std::vector<size_t>& vec)
     28  {
     29    return percentile(vec, 50.0);
     30  }
     31
    2732  double Statistics::percentile(std::vector<double>& vec, double percentile)
    2833  {
     
    3540    if (k<.500000000001 && k>.499999999999){
    3641      int i = static_cast<int>(j+0.5);
    37       double r = (vec[i]+vec[i-1])/2;
    38      
    39       return r;
    40       //return (vec[i]+vec[i-1])/2;
     42      return (vec[i]+vec[i-1])/2;
    4143    }
    4244    else{
     
    4749  }
    4850
     51  double Statistics::percentile(std::vector<size_t>& vec, double percentile)
     52  {
     53    sort(vec.begin(), vec.end());
     54    double j = percentile/100 * vec.size();
     55    if (percentile==100)
     56      return vec[vec.size()-1];   
     57   
     58    double k = j + 0.5 - static_cast<int> (j+0.5);
     59    if (k<.500000000001 && k>.499999999999){
     60      int i = static_cast<int>(j+0.5);
     61      double r = static_cast<double>(vec[i]+vec[i-1])/2;
     62      return r;
     63     
     64    }
     65    else{
     66      int i = static_cast<int>(j);
     67      return  static_cast<double>(vec[i]);
     68    }
     69   
     70  }
     71
    4972
    5073}} // of namespace cpptools and namespace theplu
  • trunk/src/Statistics.h

    r115 r117  
    3131    double median(std::vector<double>&); 
    3232
     33    ///
     34    /// @return median
     35    ///
     36    double median(std::vector<size_t>&); 
     37
    3338    ///
    3439    /// @return \a i'th percentile
    3540    ///
    3641    double percentile(std::vector<double>&, double i);
     42
     43    ///
     44    /// @return \a i'th percentile
     45    ///
     46    double percentile(std::vector<size_t>&, double i);
    3747
    3848  private:
Note: See TracChangeset for help on using the changeset viewer.