# Changeset 464

Ignore:
Timestamp:
Dec 16, 2005, 11:15:25 PM (16 years ago)
Message:

Location:
trunk/lib
Files:
3 edited

### Legend:

Unmodified
 r303 #define _theplu_statistics_utility_ #include #include #include namespace statistics { /// /// Calculates the probabilty to get \a k or smaller from a /// hypergeometric distribution with parameters \a n1 \a n2 \a /// t. Hypergeomtric situation you get in the following situation: /// Let there be \a n1 ways for a "good" selection and \a n2 ways /// for a "bad" selection out of a total of possibilities. Take \a /// t samples without replacement and \a k of those are "good" /// samples. \a k will follow a hypergeomtric distribution. /// @cumulative hypergeomtric distribution functions P(k). /// double cdf_hypergeometric_P(u_int k, u_int n1, u_int n2, u_int t); /// /// Calculates the probabilty to get \a k or smaller from a /// hypergeometric distribution with parameters \a n1 \a n2 \a /// t. Hypergeomtric situation you get in the following situation: /// Let there be \a n1 ways for a "good" selection and \a n2 ways /// for a "bad" selection out of a total of possibilities. Take \a /// t samples without replacement and \a k of those are "good" /// samples. \a k will follow a hypergeomtric distribution. /// @cumulative hypergeomtric distribution functions P(k). /// 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. @return median /// double median(std::vector&); /// /// 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. /// /// @return \a p'th percentile /// template double percentile(std::vector& vec, double p) { if (p==100) return  vec[vec.size()-1]; sort(vec.begin(), vec.end()); double j = p/100 * (vec.size()-1); int i = static_cast(j); return (1-j+floor(j))*vec[i] + (j-floor(j))*vec[i+1]; } /// /// Median is defined to be value in the middle. If number of /// values is even median is the average of the two middle /// values. @return median /// double median(std::vector&); /// /// Median is defined to be value in the middle. If number of /// values is even median is the average of the two middle /// values. @return median /// template inline double median(std::vector& v) { return percentile(v,50.0); } /// /// 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. /// /// @return \a i'th percentile /// double percentile(std::vector&, double p); /// /// 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. /// /// @return \a i'th percentile /// double percentile(std::vector&, double i); }} // of namespace statistics and namespace theplu