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

fixes #452

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