#ifndef _theplu_yat_statistics_kolmogorov_smirnov_ #define _theplu_yat_statistics_kolmogorov_smirnov_ // $Id: KolmogorovSmirnov.h 1595 2008-10-22 21:58:26Z peter$ /* Copyright (C) 2008 Peter Johansson This file is part of the yat library, http://dev.thep.lu.se/yat The yat library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. The yat library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with yat. If not, see . */ #include #include namespace theplu { namespace yat { namespace statistics { /** \brief Kolmogow Smirnov Test */ class KolmogorovSmirnov { public: /** \brief Constructor */ KolmogorovSmirnov(void); /** \brief add a value */ void add(double value, bool class_label, double weight=1.0); /** \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 Performs a permutation test using \a perm label randomizations and calculate how often a score equal or larger than score() is obtained. */ double p_value(size_t perm) const; /** \brief resets everything to zero */ void reset(void); /** \brief Kolmogorov Smirnov statistic \f$sup_x | F_1(x) - F_2(x) | \f$ where \f$F(x) = \frac {\sum_{i:x_i\le x}w_i }{ \sum w_i }\f$ */ double score(void) const; /** Same as score() but keeping the sign, in other words, abs(signed_score())==score() \since New in yat 0.5 */ double signed_score(void) const; private: void scores(std::vector&) const; mutable bool cached_; mutable double score_; typedef std::pair, bool> trip; typedef std::set > data_w; data_w data_; double sum_w1_; double sum_w2_; friend std::ostream& operator<<(std::ostream&, const KolmogorovSmirnov&); // Copy not allowed KolmogorovSmirnov(const KolmogorovSmirnov&); KolmogorovSmirnov& operator=(const KolmogorovSmirnov&); }; /** \brief output operator */ std::ostream& operator<<(std::ostream&, const KolmogorovSmirnov&); }}} // of namespace theplu yat statistics #endif