Changeset 1593 for trunk/yat


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

fixes #452

Location:
trunk/yat/statistics
Files:
2 edited

Legend:

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

    r1487 r1593  
    3131
    3232
     33#include <iostream>
     34
    3335namespace theplu {
    3436namespace yat {
     
    4951    data_.insert(std::make_pair(std::make_pair(x,w),target));
    5052    if (target){
    51       ++n1_;
    5253      sum_w1_+=w;
    5354    }
    5455    else {
    55       ++n2_;
    5656      sum_w2_+=w;
    5757    }
    5858    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;
    5978  }
    6079
  • trunk/yat/statistics/KolmogorovSmirnov.h

    r1487 r1593  
    4747
    4848    /**
     49       \brief Large-Sample Approximation
     50
     51       This analytical approximation of p-value can be used when all
     52       weight equal unity and sample sizes \a n and \a m are
     53       large. The p-value 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    /**
    4966       \brief p-value
    5067
     
    6481
    6582       \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$
    6784    */
    6885    double score(void) const;
     
    7693    typedef std::set<trip, std::greater<trip> > data_w;
    7794    data_w data_;
    78     size_t n1_;
    79     size_t n2_;
    8095    double sum_w1_;
    8196    double sum_w2_;
Note: See TracChangeset for help on using the changeset viewer.