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

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

Addresses #436.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1#ifndef _theplu_yat_statistics_kolmogorov_smirnov_
2#define _theplu_yat_statistics_kolmogorov_smirnov_
3
4// $Id: KolmogorovSmirnov.h 1486 2008-09-09 21:17:19Z 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 this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26
27#include <set>
28#include <vector>
29
30namespace theplu {
31namespace yat {
32namespace statistics { 
33
34  /**
35     \brief Kolmogow Smirnov Test
36   */
37  class KolmogorovSmirnov
38  {
39  public:
40    /**
41       \brief Constructor
42     */ 
43    KolmogorovSmirnov(void);
44
45    /**
46       \brief add a value
47     */
48    void add(double value, bool class_label, double weight=1.0);
49
50    /**
51       \brief p-value
52
53       Performs a permutation test using \a perm label randomizations
54       and calculate how often a score equal or larger than score() is
55       obtained.
56    */
57    double p_value(size_t perm) const;
58
59    /**
60       \brief resets everything to zero
61    */
62    void reset(void);
63
64    /**
65       \brief Kolmogorov Smirnov statistic
66
67       \f$ sup_x | F_1(x) - F_2(x) | \f$ where
68       \f$ F(x) = \sum_{i:x_i\le x}w_i \f$
69    */
70    double score(void) const;
71
72  private:
73    void scores(std::vector<double>&) const;
74
75    mutable bool cached_;
76    mutable double score_;
77    typedef std::pair<std::pair<double,double>, bool> trip;
78    typedef std::set<trip, std::greater<trip> > data_w;
79    data_w data_;
80    size_t n1_;
81    size_t n2_;
82    double sum_w1_;
83    double sum_w2_;
84
85    friend std::ostream& operator<<(std::ostream&, const KolmogorovSmirnov&);
86
87    // Copy not allowed
88    KolmogorovSmirnov(const KolmogorovSmirnov&);
89    KolmogorovSmirnov& operator=(const KolmogorovSmirnov&);
90  };
91
92  /**
93     \brief output operator
94   */
95  std::ostream& operator<<(std::ostream&, const KolmogorovSmirnov&);
96
97
98}}} // of namespace theplu yat statistics
99
100#endif
Note: See TracBrowser for help on using the repository browser.