 Timestamp:
 May 21, 2008, 2:23:18 PM (14 years ago)
 Location:
 trunk/yat/statistics
 Files:

 3 added
 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/statistics/Makefile.am
r1310 r1317 31 31 Fisher.cc FoldChange.cc Histogram.cc \ 32 32 KolmogorovSmirnov.cc Pearson.cc \ 33 PearsonCorrelation.cc ROC.cc \33 PearsonCorrelation.cc Percentiler.cc ROC.cc \ 34 34 SAMScore.cc Score.cc Smoother.cc SNRScore.cc tScore.cc tTest.cc \ 35 35 utility.cc VectorFunction.cc WilcoxonFoldChange.cc … … 37 37 include_statisticsdir = $(includedir)/yat/statistics 38 38 39 include_statistics_HEADERS = AUC.h Average r.h AveragerPair.h \39 include_statistics_HEADERS = AUC.h Average.h Averager.h AveragerPair.h \ 40 40 AveragerWeighted.h AveragerPairWeighted.h \ 41 41 averager_traits.h EuclideanDistance.h Fisher.h \ … … 43 43 KolmogorovSmirnov.h \ 44 44 Pearson.h PearsonCorrelation.h \ 45 PearsonDistance.h ROC.h \45 PearsonDistance.h Percentiler.h ROC.h \ 46 46 SAMScore.h Score.h Smoother.h SNRScore.h tScore.h tTest.h \ 47 47 utility.h VectorFunction.h WilcoxonFoldChange.h 
trunk/yat/statistics/utility.h
r1305 r1317 29 29 */ 30 30 31 #include "averager_traits.h" 31 #include "Percentiler.h" 32 32 33 #include "yat/classifier/DataLookupWeighted1D.h" 33 34 #include "yat/classifier/Target.h" … … 47 48 48 49 /** 49 \brief Functor to take average of a range. 50 */ 51 struct Average 52 { 53 /** 54 If range is weighted an AveragerWeighted is used else a Averager. 55 56 \return average of range 57 */ 58 template<typename ForwardIterator> 59 inline double operator()(ForwardIterator first, ForwardIterator last) const 60 { 61 typename averager<ForwardIterator>::type a; 62 add(a, first, last); 63 return a.mean(); 64 } 65 66 }; 67 68 69 70 //forward declarations 50 \brief 50th percentile 51 @see Percentiler 52 */ 71 53 template <class T> 72 54 double median(T first, T last, const bool sorted=false); 73 55 56 /** 57 \see Percentiler 58 */ 74 59 template <class T> 75 60 double percentile(T first, T last, double p, bool sorted=false); … … 101 86 /// @return cumulative hypergeomtric distribution functions P(k). 102 87 /// 103 /// \deprecated 88 /// \deprecated use gsl_cdf_hypergeometric_P 104 89 /// 105 90 double cdf_hypergeometric_P(unsigned int k, unsigned int n1, … … 192 177 double percentile(T first, T last, double p, bool sorted=false) 193 178 { 194 utility::yat_assert<std::range_error>(first<last, 195 "percentile: invalid range"); 196 utility::yat_assert<std::runtime_error>(p>=0, "percentage is negative"); 197 utility::yat_assert<std::runtime_error>(p<=100, 198 "percentage is larger than 100"); 199 if (sorted){ 200 if (p>=100) 201 return *(last); 202 // range is one value only is a special case 203 if (std::distance(first, last)==1) 204 return *first; 205 double j = p/100 * (std::distance(first,last)1); 206 int i = static_cast<int>(j); 207 return (1j+floor(j))*first[i] + (jfloor(j))*first[i+1]; 208 } 209 210 std::vector<double> v_copy; 211 v_copy.reserve(std::distance(first,last)); 212 std::copy(first, last, std::back_inserter(v_copy)); 213 double j = p/100 * (v_copy.size()1); 214 size_t i = static_cast<size_t>(j); 215 if (i+2 < v_copy.size()) { 216 utility::yat_assert<std::out_of_range>(i+2 < v_copy.size(), 217 "in utility::percentile"); 218 std::partial_sort(v_copy.begin(), v_copy.begin()+i+2, v_copy.end()); 219 } 220 else 221 std::sort(v_copy.begin(), v_copy.end()); 222 223 return percentile(v_copy.begin(), v_copy.end(), p, true); 179 Percentiler percentiler(p, sorted); 180 return percentiler(first, last); 224 181 } 225 182
Note: See TracChangeset
for help on using the changeset viewer.