Changeset 1593 for trunk/yat

Ignore:
Timestamp:
Oct 21, 2008, 6:48:24 PM (13 years ago)
Message:

fixes #452

Location:
trunk/yat/statistics
Files:
2 edited

Unmodified
Removed
• trunk/yat/statistics/KolmogorovSmirnov.cc

 r1487 #include namespace theplu { namespace yat { data_.insert(std::make_pair(std::make_pair(x,w),target)); if (target){ ++n1_; sum_w1_+=w; } else { ++n2_; sum_w2_+=w; } cached_=false; } double KolmogorovSmirnov::p_value(void) const { double res=0; double res2=0; double s2 = score() * sqrt(sum_w1_*sum_w2_/(sum_w1_+sum_w2_)); s2 *= s2; int sign = 1; for (size_t k = 1; k<100; ++k) { res += sign * exp(-2.0 * k * k * s2); sign *= -1; if (res==res2) return res; res2 = res; } return res; }
• trunk/yat/statistics/KolmogorovSmirnov.h

 r1487 /** \brief Large-Sample Approximation This analytical approximation of p-value can be used when all weight equal unity and sample sizes \a n and \a m are large. The p-value is calcuated as \f$P = \displaystyle - 2 \sum_{k=1}^{\infty} (-1)^ke^{-2k^2s^2}\f$, where s is the scaled score: \f$s = \sqrt\frac{nm}{n+m} \f$ score(). \since New in yat 0.5 Following Hollander and Wolfe */ double p_value(void) const; /** \brief p-value \f$sup_x | F_1(x) - F_2(x) | \f$ where \f$F(x) = \sum_{i:x_i\le x}w_i \f$ \f$F(x) = \frac {\sum_{i:x_i\le x}w_i }{ \sum w_i }\f$ */ double score(void) const; typedef std::set > data_w; data_w data_; size_t n1_; size_t n2_; double sum_w1_; double sum_w2_;
Note: See TracChangeset for help on using the changeset viewer.