source: trunk/yat/statistics/KolmogorovSmirnov.h @ 1487

Last change on this file since 1487 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1#ifndef _theplu_yat_statistics_kolmogorov_smirnov_
2#define _theplu_yat_statistics_kolmogorov_smirnov_
3
4// $Id: KolmogorovSmirnov.h 1487 2008-09-10 08:41:36Z jari $
5
6/*
7  Copyright (C) 2008 Peter Johansson
8
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25#include <set>
26#include <vector>
27
28namespace theplu {
29namespace yat {
30namespace statistics { 
31
32  /**
33     \brief Kolmogow Smirnov Test
34   */
35  class KolmogorovSmirnov
36  {
37  public:
38    /**
39       \brief Constructor
40     */ 
41    KolmogorovSmirnov(void);
42
43    /**
44       \brief add a value
45     */
46    void add(double value, bool class_label, double weight=1.0);
47
48    /**
49       \brief p-value
50
51       Performs a permutation test using \a perm label randomizations
52       and calculate how often a score equal or larger than score() is
53       obtained.
54    */
55    double p_value(size_t perm) const;
56
57    /**
58       \brief resets everything to zero
59    */
60    void reset(void);
61
62    /**
63       \brief Kolmogorov Smirnov statistic
64
65       \f$ sup_x | F_1(x) - F_2(x) | \f$ where
66       \f$ F(x) = \sum_{i:x_i\le x}w_i \f$
67    */
68    double score(void) const;
69
70  private:
71    void scores(std::vector<double>&) const;
72
73    mutable bool cached_;
74    mutable double score_;
75    typedef std::pair<std::pair<double,double>, bool> trip;
76    typedef std::set<trip, std::greater<trip> > data_w;
77    data_w data_;
78    size_t n1_;
79    size_t n2_;
80    double sum_w1_;
81    double sum_w2_;
82
83    friend std::ostream& operator<<(std::ostream&, const KolmogorovSmirnov&);
84
85    // Copy not allowed
86    KolmogorovSmirnov(const KolmogorovSmirnov&);
87    KolmogorovSmirnov& operator=(const KolmogorovSmirnov&);
88  };
89
90  /**
91     \brief output operator
92   */
93  std::ostream& operator<<(std::ostream&, const KolmogorovSmirnov&);
94
95
96}}} // of namespace theplu yat statistics
97
98#endif
Note: See TracBrowser for help on using the repository browser.