source: trunk/yat/statistics/KolmogorovSmirnovOneSample.h @ 3001

Last change on this file since 3001 was 3001, checked in by Peter, 10 years ago

simplify docs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1#ifndef theplu_yat_statistics_kolmogorov_smirnov_one_sample
2#define theplu_yat_statistics_kolmogorov_smirnov_one_sample
3
4// $Id: KolmogorovSmirnovOneSample.h 3001 2013-03-19 00:22:58Z peter $
5
6/*
7  Copyright (C) 2013 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 <iosfwd>
26
27#include <map>
28
29namespace theplu {
30namespace yat {
31namespace statistics {
32
33  /**
34     \brief Kolmogorov Smirnov Test for one class
35
36     Class can be used to test if data follows standard uniform
37     distribution. Other distributions are not supported directly, but
38     it is possible to check against other distribution by tranforming
39     the data. If, for example, X is standard exponentially
40     distributed log(X) is standard uniform. Therefore, rather than
41     testing if X is exponential it is equivalent to test if log(X) is
42     standard uniform.
43
44     \since New in yat 0.11
45   */
46  class KolmogorovSmirnovOneSample
47  {
48  public:
49    /**
50       \brief Constructor
51     */
52    KolmogorovSmirnovOneSample(void);
53
54    /**
55       \brief add a value
56
57       \a value should be a value in range [0, 1].
58     */
59    void add(double value, double weight=1.0);
60
61    /**
62       \brief Large-Sample Approximation
63
64       This analytical approximation of p-value can be used when all
65       weight equal unity and sample size \a n is large. The p-value
66       is calcuated as \f$ P = \displaystyle - 2 \sum_{k=1}^{\infty}
67       (-1)^ke^{-2k^2s^2n}\f$, where s is the score and n is the sum
68       of weights.
69    */
70    double p_value(void) const;
71
72    /**
73       \brief Remove a data point
74
75       \throw utility::runtime_error if no data point exist with \a
76       value and \a weight.
77     */
78    void remove(double value, double weight=1.0);
79
80    /**
81       \brief resets everything to zero
82    */
83    void reset(void);
84
85    /**
86       \brief Kolmogorov Smirnov statistic
87
88       \f$ sup_x | F(x) - x | \f$ where is the empirical cumulative
89       distribution \f$ F(x) = \frac{\sum_{i:x_i\le x}w_i}{ \sum w_i}
90       \f$
91    */
92    double score(void) const;
93
94    /**
95       Same as score() but keeping the sign, in other words,
96       abs(signed_score())==score()
97
98       A positive score implies that values \em on \em average are
99       smaller 0.5.
100     */
101    double signed_score(void) const;
102
103  private:
104    mutable double score_;
105    mutable bool cached_;
106    std::multimap<double, double> data_;
107    double sum_w_;
108
109    friend std::ostream& operator<<(std::ostream&,
110                                    const KolmogorovSmirnovOneSample&);
111
112    // using compiler generated copy and assignment
113    //KolmogorovSmirnovOneSample(const KolmogorovSmirnovOneSample&);
114    //KolmogorovSmirnovOneSample& operator=(const KolmogorovSmirnovOneSample&);
115  };
116
117}}} // of namespace theplu yat statistics
118
119#endif
Note: See TracBrowser for help on using the repository browser.