-
Notifications
You must be signed in to change notification settings - Fork 248
Kolmogorov-Smirnov distribution #422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
945b432
Kolmogorov-Smirnov distribution #421
evanmiller de347f1
Fix copyright notices [CI SKIP]
evanmiller 59c4da1
Implement skewness for K-S distribution [CI SKIP]
evanmiller 73f0dec
Implement kurtosis for the K-S distribution
evanmiller 8ef4d3f
Fix "0.0" conversion errors with multiprecision types
evanmiller 91fd5f6
Kolmogorov-Smirnov build fixes
evanmiller fad8917
Kolmogorov-Smirnov needs more BOOST_MATH_STD_USING
evanmiller ae6c2d8
Kolmogorov-Smirnov build fixes
evanmiller 1599c1d
Require C++11 features for Kolmogorov-Smirnov tests
evanmiller dafb602
Fix double-to-float warnings with double literals
evanmiller 07791a7
Kolmogorov-Smirnov user documentation [CI SKIP]
evanmiller c1565d1
Fix code comment (and kick off CI build)
evanmiller 30e325a
Make suggested changes [CI SKIP]
evanmiller a1fa5e4
Tweak testing logic for K-S mode [CI SKIP]
evanmiller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Kolmogorov-Smirnov user documentation [CI SKIP]
- Loading branch information
commit 07791a70d06b14d14ac1d28cf37b6840e75ef1e2
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| [section:kolmogorov_smirnov_dist Kolmogorov-Smirnov Distribution] | ||
|
|
||
| ``#include <boost/math/distributions/kolmogorov_smirnov.hpp>`` | ||
|
|
||
| namespace boost{ namespace math{ | ||
|
|
||
| template <class RealType = double, | ||
| class ``__Policy`` = ``__policy_class`` > | ||
| class kolmogorov_smirnov_distribution; | ||
|
|
||
| typedef kolmogorov_smirnov_distribution<> kolmogorov_smirnov; | ||
|
|
||
| template <class RealType, class ``__Policy``> | ||
| class kolmogorov_smirnov_distribution | ||
| { | ||
| public: | ||
| typedef RealType value_type; | ||
| typedef Policy policy_type; | ||
|
|
||
| // Constructor: | ||
| kolmogorov_smirnov_distribution(RealType n); | ||
|
|
||
| // Accessor to parameter: | ||
| RealType number_of_observations()const; | ||
|
|
||
| }} // namespaces | ||
|
|
||
| The Kolmogorov-Smirnov test in statistics compares two empirical distributions, | ||
| or an empirical distribution against any theoretical distribution.[footnote | ||
| [@https://en.wikipedia.org/wiki/Kolmogorov–Smirnov_test Wikipedia: | ||
| Kolmogorov-Smirnov test]] It makes use of a specific distribution which is | ||
| informally known in the literature as the Kolmogorv-Smirnov distribution, | ||
| implemented here. | ||
|
|
||
| Formally, if /n/ observations are taken from a theoretical distribution /G(x)/, | ||
| and if /G/[sub /n/](/x/) represents the empirical CDF of those /n/ observations, | ||
| then the test statistic | ||
|
|
||
| [equation kolmogorov_smirnov_test_statistic] [/ D_n = \sup_x|G(x)-\hat{G}(x)| ] | ||
|
|
||
| will be distributed according to a Kolmogorov-Smirnov distribution parameterized by /n/. | ||
|
|
||
| The exact form of a Kolmogorov-Smirnov distribution is the subject of a large, | ||
| decades-old literature.[footnote | ||
| [@https://www.jstatsoft.org/article/view/v039i11 Simard, R. and L'Ecuyer, P. | ||
| (2011) "Computing the Two-Sided Kolmogorov-Smirnov Distribution". Journal of | ||
| Statistical Software, vol. 39, no. 11.]] In the interest of simplicity, Boost | ||
| implements the first-order, limiting form of this distribution (the same form | ||
| originally identified by Kolmogorov[footnote Kolmogorov A (1933). "Sulla | ||
| determinazione empirica di una legge di distribuzione". G. Ist. Ital. Attuari. | ||
| 4: 83–91.]), namely | ||
|
|
||
| [equation kolmogorov_smirnov_distribution] | ||
| [/ \lim_{n \to \infty} F_n(x/\sqrt{n})=1+2\sum_{k=1}^\infty (-1)^k e^{-2k^2x^2} ] | ||
|
|
||
| Note that while the exact distribution only has support over \[0, 1\], this | ||
| limiting form has positive mass above unity, particlularly for small /n/. The | ||
| following graph illustrations how the distribution changes for different values | ||
| of /n/: | ||
|
|
||
| [graph kolmogorov_smirnov_pdf] | ||
|
|
||
| [h4 Member Functions] | ||
|
|
||
| kolmogorov_smirnov_distribution(RealType n); | ||
|
|
||
| Constructs a Kolmogorov-Smirnov distribution with /n/ observations. | ||
|
|
||
| Requires n > 0, otherwise calls __domain_error. | ||
|
|
||
| RealType number_of_observations()const; | ||
|
|
||
| Returns the parameter /n/ from which this object was constructed. | ||
|
|
||
| [h4 Non-member Accessors] | ||
|
|
||
| All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions] | ||
| that are generic to all distributions are supported: __usual_accessors. | ||
|
|
||
| The domain of the random variable is \[0, +[infin]\]. | ||
|
|
||
| [h4 Accuracy] | ||
|
|
||
| The CDF of the Kolmogorov-Smirnov distribution is implemented in terms of the | ||
| fourth [link math_toolkit.jacobi_theta.jacobi_theta_overview Jacobi Theta | ||
| function]; please refer to the accuracy ULP plots for that function. | ||
|
|
||
| The PDF is implemented separately, and the following ULP plot illustrates its | ||
| accuracy: | ||
|
|
||
| [graph kolmogorov_smirnov_pdf_ulp] | ||
|
|
||
| Because PDF values are simply scaled out and up by the square root of /n/, the | ||
| above plot is representative for all values of /n/. Note that for present | ||
| purposes, "accuracy" refers to deviations from the limiting approximation, | ||
| rather than deviations from the exact distribution. | ||
|
|
||
| [h4 Implementation] | ||
|
|
||
| In the following table, /n/ is the number of observations, /x/ is the random variable, | ||
| [pi] is Archimedes' constant, and [zeta](3) is Apéry's constant. | ||
|
|
||
| [table | ||
| [[Function][Implementation Notes]] | ||
| [[cdf][Using the relation: cdf = __jacobi_theta4tau(0, 2*x*x/[pi])]] | ||
| [[pdf][Using a manual derivative of the CDF]] | ||
| [[cdf complement][ | ||
| When x*x*n == 0: 1 | ||
|
|
||
| When 2*x*x*n <= [pi]: 1 - __jacobi_theta4tau(0, 2*x*x*n/[pi]) | ||
|
|
||
| When 2*x*x*n > [pi]: -__jacobi_theta4m1tau(0, 2*x*x*n/[pi])]] | ||
| [[quantile][Using a Newton-Raphson iteration]] | ||
| [[quantile from the complement][Using a Newton-Raphson iteration]] | ||
| [[mode][Using a run-time PDF maximizer]] | ||
| [[mean][sqrt([pi]/2) * ln(2) / sqrt(n)]] | ||
| [[variance][([pi][super 2]/12 - [pi]/2*ln[super 2](2))/n]] | ||
| [[skewness][(9/16*sqrt([pi]/2)*[zeta](3)/n[super 3/2] - 3 * mean * variance - mean[super 2] * variance) / (variance[super 3/2])]] | ||
| [[kurtosis][(7/720*[pi][super 4]/n[super 2] - 4 * mean * skewness * variance[super 3/2] - 6 * mean[super 2] * variance - mean[super 4]) / (variance[super 2])]] | ||
| ] | ||
|
|
||
| [endsect] [/section:kolmogorov_smirnov_dist Kolmogorov-Smirnov] | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.