Changeset 511 for trunk/lib/statistics/utility.h
 Timestamp:
 Feb 18, 2006, 3:46:46 PM (17 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/lib/statistics/utility.h
r502 r511 14 14 namespace statistics { 15 15 16 //forward declarations 17 template <class T> 18 double percentile(const std::vector<T>& vec, const double p, 19 const bool sorted=false); 20 21 16 22 /// 17 23 /// Calculates the probabilty to get \a k or smaller from a … … 26 32 double cdf_hypergeometric_P(u_int k, u_int n1, u_int n2, u_int t); 27 33 34 35 /// 36 /// Median is defined to be value in the middle. If number of values 37 /// is even median is the average of the two middle values. the 38 /// median value is given by p equal to 50. If @a sorted is false 39 /// (default), the vector is copied, the copy is sorted, and then 40 /// used to calculate the median. 41 /// 42 /// @return median 43 /// 44 /// @note interface will change 45 /// 46 template <class T> 47 inline double median(const std::vector<T>& v, const bool sorted=false) 48 { return percentile(v, 50.0, sorted); } 49 50 /// 51 /// Median is defined to be value in the middle. If number of values 52 /// is even median is the average of the two middle values. If @a 53 /// sorted is true, the function assumes vector @a vec to be 54 /// sorted. If @a sorted is false, the vector is copied, the copy is 55 /// sorted (default), and then used to calculate the median. 56 /// 57 /// @return median 58 /// 59 double median(const gslapi::vector& vec, const bool sorted=false); 28 60 29 61 /// … … 63 95 64 96 /// 65 /// Median is defined to be value in the middle. If number of values 66 /// is even median is the average of the two middle values. the 67 /// median value is given by p equal to 50. If @a sorted is false 68 /// (default), the vector is copied, the copy is sorted, and then 69 /// used to calculate the median. 97 /// The percentile is determined by the \a p, a number between 0 and 98 /// 100. The percentile is found by interpolation, using the formula 99 /// \f$ percentile = (1  \delta) x_i + \delta x_{i+1} \f$ where \a 100 /// p is floor\f$((n  1)p/100)\f$ and \f$ \delta \f$ is \f$ 101 /// (n1)p/100  i \f$.Thus the minimum value of the vector is given 102 /// by p equal to zero, the maximum is given by p equal to 100 and 103 /// the median value is given by p equal to 50. If @a sorted 104 /// is false (default), the vector is copied, the copy is sorted, 105 /// and then used to calculate the median. 106 /// 107 /// @return \a p'th percentile 70 108 /// 71 /// @return median 72 /// 73 /// @note interface will change 74 /// 75 template <class T> 76 inline double median(const std::vector<T>& v, const bool sorted=false) 77 { return percentile(v, 50.0, sorted); } 78 79 /// 80 /// Median is defined to be value in the middle. If number of values 81 /// is even median is the average of the two middle values. If @a 82 /// sorted is true, the function assumes vector @a vec to be 83 /// sorted. If @a sorted is false, the vector is copied, the copy is 84 /// sorted (default), and then used to calculate the median. 85 /// 86 /// @return median 87 /// 88 double median(const gslapi::vector& vec, const bool sorted=false); 109 double median(const gslapi::vector& vec, const double, 110 const bool sorted=false); 89 111 90 112 }} // of namespace statistics and namespace theplu
Note: See TracChangeset
for help on using the changeset viewer.