Changeset 1593 for trunk/yat/statistics
 Timestamp:
 Oct 21, 2008, 6:48:24 PM (13 years ago)
 Location:
 trunk/yat/statistics
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/statistics/KolmogorovSmirnov.cc
r1487 r1593 31 31 32 32 33 #include <iostream> 34 33 35 namespace theplu { 34 36 namespace yat { … … 49 51 data_.insert(std::make_pair(std::make_pair(x,w),target)); 50 52 if (target){ 51 ++n1_;52 53 sum_w1_+=w; 53 54 } 54 55 else { 55 ++n2_;56 56 sum_w2_+=w; 57 57 } 58 58 cached_=false; 59 } 60 61 62 double KolmogorovSmirnov::p_value(void) const 63 { 64 double res=0; 65 double res2=0; 66 double s2 = score() * sqrt(sum_w1_*sum_w2_/(sum_w1_+sum_w2_)); 67 s2 *= s2; 68 int sign = 1; 69 for (size_t k = 1; k<100; ++k) { 70 res += sign * exp(2.0 * k * k * s2); 71 sign *= 1; 72 if (res==res2) 73 return res; 74 res2 = res; 75 } 76 77 return res; 59 78 } 60 79 
trunk/yat/statistics/KolmogorovSmirnov.h
r1487 r1593 47 47 48 48 /** 49 \brief LargeSample Approximation 50 51 This analytical approximation of pvalue can be used when all 52 weight equal unity and sample sizes \a n and \a m are 53 large. The pvalue is calcuated as \f$ P = \displaystyle  2 54 \sum_{k=1}^{\infty} (1)^ke^{2k^2s^2}\f$, where s is the 55 scaled score: 56 57 \f$ s = \sqrt\frac{nm}{n+m} \f$ score(). 58 59 \since New in yat 0.5 60 61 Following Hollander and Wolfe 62 */ 63 double p_value(void) const; 64 65 /** 49 66 \brief pvalue 50 67 … … 64 81 65 82 \f$ sup_x  F_1(x)  F_2(x)  \f$ where 66 \f$ F(x) = \ sum_{i:x_i\le x}w_i\f$83 \f$ F(x) = \frac {\sum_{i:x_i\le x}w_i }{ \sum w_i }\f$ 67 84 */ 68 85 double score(void) const; … … 76 93 typedef std::set<trip, std::greater<trip> > data_w; 77 94 data_w data_; 78 size_t n1_;79 size_t n2_;80 95 double sum_w1_; 81 96 double sum_w2_;
Note: See TracChangeset
for help on using the changeset viewer.