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

Last change on this file since 1003 was 1003, checked in by Peter, 14 years ago

adding class for Kolmogorov Smirnov test

  • 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 1003 2008-01-18 22:13:13Z 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 <utility>
29#include <vector>
30
31namespace theplu {
32namespace yat {
33namespace statistics { 
34
35  /**
36     \brief Kolmogow Smirnov Test
37   */
38  class KolmogorovSmirnov
39  {
40  public:
41    /**
42       \brief Constructor
43     */ 
44    KolmogorovSmirnov(void);
45
46    /**
47       \brief add a value
48     */
49    void add(double value, bool class_label, double weight=1.0);
50
51    /**
52       \brief p-value
53
54       Performs a permutation test using \a perm label randomizations
55       and calculate how often a score equal or larger than score() is
56       obtained.
57    */
58    double p_value(size_t perm) const;
59
60    /**
61       \brief resets everything to zero
62    */
63    void reset(void);
64
65    /**
66       \brief Kolmogorov Smirnov statistic
67
68       \f$ sup_x | F_1(x) - F_2(x) \f$ where
69       \f$ F(x) = \sum_{i:x_i\le x}w_i \f$
70    */
71    double score(void) const;
72
73  private:
74    void scores(std::vector<double>&) const;
75
76    mutable bool cached_;
77    mutable double score_;
78    typedef std::set<std::pair<std::pair<double,double>, bool> > 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  std::ostream& operator<<(std::ostream&, const KolmogorovSmirnov&);
93
94
95}}} // of namespace theplu yat statistics
96
97#endif
Note: See TracBrowser for help on using the repository browser.