# Changeset 464 for trunk/lib

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

made median template

Location:
trunk/lib
Files:
3 edited

Unmodified
Added
Removed
• ## trunk/lib/classifier/ConsensusInputRanker.cc

 r461 } // Sorting with respect to median rank std::vector > median(data.rows()); std::vector > medians(data.rows()); for (size_t i=0; i ranks(nof_rankers_); ranks[j]=input_rankers_[j].rank(i); median[i].first = i; median[i].second = statistics::median(ranks); medians[i].first = i; medians[i].second = statistics::median(ranks); } //sort medians and assign id_ and rank_ sort(median.begin(), median.end(), sort(medians.begin(), medians.end(), utility::pair_value_compare()); id_.resize(data.rows()); rank_.resize(data.rows()); for (size_t i=0; i
• ## trunk/lib/statistics/utility.cc

 r298 #include #include #include #include #include #include #include } double median(std::vector& vec) { return percentile(vec, 50.0); } double median(std::vector& vec) { return percentile(vec, 50.0); } double percentile(std::vector& vec, double percentile) { if (percentile==100) return  vec[vec.size()-1]; else{ sort(vec.begin(), vec.end()); double j = percentile/100 * (vec.size()-1); int i = static_cast(j); return (1-j+floor(j))*vec[i] + (j-floor(j))*vec[i+1]; } } double percentile(std::vector& vec, double percentile) { if (percentile==100) return vec[vec.size()-1]; else{ sort(vec.begin(), vec.end()); double j = percentile/100 * (vec.size()-1); int i = static_cast(j); return (1-j+floor(j))*vec[i] + (j-floor(j))*vec[i+1]; } } }} // of namespace statistics and namespace theplu
• ## trunk/lib/statistics/utility.h

 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
Note: See TracChangeset for help on using the changeset viewer.