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

Last change on this file since 1194 was 1194, checked in by Peter, 13 years ago

minor correction

  • 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 1194 2008-02-29 20:24:53Z peter $
5
6/*
7  Copyright (C) 2008 Peter Johansson
8
9  This file is part of the yat library, http://trac.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 2 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::set<std::pair<std::pair<double,double>, bool> > data_w;
78    data_w data_;
79    size_t n1_;
80    size_t n2_;
81    double sum_w1_;
82    double sum_w2_;
83
84    friend std::ostream& operator<<(std::ostream&, const KolmogorovSmirnov&);
85
86    // Copy not allowed
87    KolmogorovSmirnov(const KolmogorovSmirnov&);
88    KolmogorovSmirnov& operator=(const KolmogorovSmirnov&);
89  };
90
91  /**
92     \brief output operator
93   */
94  std::ostream& operator<<(std::ostream&, const KolmogorovSmirnov&);
95
96
97}}} // of namespace theplu yat statistics
98
99#endif
Note: See TracBrowser for help on using the repository browser.