# Changeset 511

Ignore:
Timestamp:
Feb 18, 2006, 3:46:46 PM (16 years ago)
Message:

added percentile function for gslapi::vector

Location:
trunk
Files:
3 edited

### Legend:

Unmodified
 r502 namespace statistics { //forward declarations template double percentile(const std::vector& vec, const double p, const bool sorted=false); /// /// Calculates the probabilty to get \a k or smaller from a double cdf_hypergeometric_P(u_int k, u_int n1, u_int n2, u_int t); /// /// Median is defined to be value in the middle. If number of values /// is even median is the average of the two middle values.  the /// median value is given by p equal to 50. If @a sorted is false /// (default), the vector is copied, the copy is sorted, and then /// used to calculate the median. /// /// @return median /// /// @note interface will change /// template inline double median(const std::vector& v, const bool sorted=false) { return percentile(v, 50.0, sorted); } /// /// Median is defined to be value in the middle. If number of values /// is even median is the average of the two middle values. If @a /// sorted is true, the function assumes vector @a vec to be /// sorted. If @a sorted is false, the vector is copied, the copy is /// sorted (default), and then used to calculate the median. /// /// @return median /// double median(const gslapi::vector& vec, const bool sorted=false); /// /// /// Median is defined to be value in the middle. If number of values /// is even median is the average of the two middle values.  the /// median value is given by p equal to 50. If @a sorted is false /// (default), the vector is copied, the copy is sorted, and then /// used to calculate the median. /// The percentile is determined by the \a p, a number between 0 and /// 100. The percentile is found by interpolation, using the formula /// \f$percentile = (1 - \delta) x_i + \delta x_{i+1} \f$ where \a /// p is floor\f$((n - 1)p/100)\f$ and \f$\delta \f$ is \f$/// (n-1)p/100 - i \f$.Thus the minimum value of the vector is given /// by p equal to zero, the maximum is given by p equal to 100 and /// the median value is given by p equal to 50. If @a sorted /// is false (default), the vector is copied, the copy is sorted, /// and then used to calculate the median. /// /// @return \a p'th percentile /// /// @return median /// /// @note interface will change /// template inline double median(const std::vector& v, const bool sorted=false) { return percentile(v, 50.0, sorted); } /// /// Median is defined to be value in the middle. If number of values /// is even median is the average of the two middle values. If @a /// sorted is true, the function assumes vector @a vec to be /// sorted. If @a sorted is false, the vector is copied, the copy is /// sorted (default), and then used to calculate the median. /// /// @return median /// double median(const gslapi::vector& vec, const bool sorted=false); double median(const gslapi::vector& vec, const double, const bool sorted=false); }} // of namespace statistics and namespace theplu