Changeset 117
- Timestamp:
- Jul 19, 2004, 5:09:14 PM (18 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Statistics.cc
r115 r117 25 25 } 26 26 27 double Statistics::median(std::vector<size_t>& vec) 28 { 29 return percentile(vec, 50.0); 30 } 31 27 32 double Statistics::percentile(std::vector<double>& vec, double percentile) 28 33 { … … 35 40 if (k<.500000000001 && k>.499999999999){ 36 41 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; 41 43 } 42 44 else{ … … 47 49 } 48 50 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 49 72 50 73 }} // of namespace cpptools and namespace theplu -
trunk/src/Statistics.h
r115 r117 31 31 double median(std::vector<double>&); 32 32 33 /// 34 /// @return median 35 /// 36 double median(std::vector<size_t>&); 37 33 38 /// 34 39 /// @return \a i'th percentile 35 40 /// 36 41 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); 37 47 38 48 private:
Note: See TracChangeset
for help on using the changeset viewer.