Click or drag to resize
Accord.NET (logo)

KolmogorovSmirnovDistribution Class

Kolmogorov-Smirnov distribution.
Inheritance Hierarchy
SystemObject
  Accord.Statistics.DistributionsDistributionBase
    Accord.Statistics.Distributions.UnivariateUnivariateContinuousDistribution
      Accord.Statistics.Distributions.UnivariateKolmogorovSmirnovDistribution

Namespace:  Accord.Statistics.Distributions.Univariate
Assembly:  Accord.Statistics (in Accord.Statistics.dll) Version: 3.8.0
Syntax
[SerializableAttribute]
public class KolmogorovSmirnovDistribution : UnivariateContinuousDistribution, 
	IFormattable
Request Example View Source

The KolmogorovSmirnovDistribution type exposes the following members.

Constructors
  NameDescription
Public methodKolmogorovSmirnovDistribution
Creates a new Kolmogorov-Smirnov distribution.
Top
Properties
  NameDescription
Public propertyEntropy
Gets the entropy for this distribution.
(Overrides UnivariateContinuousDistributionEntropy.)
Public propertyCode exampleMean
Gets the mean for this distribution.
(Overrides UnivariateContinuousDistributionMean.)
Public propertyMedian
Gets the median for this distribution.
(Inherited from UnivariateContinuousDistribution.)
Public propertyMode
Not supported.
(Overrides UnivariateContinuousDistributionMode.)
Public propertyNumberOfSamples
Gets the number of samples distribution parameter.
Public propertyQuartiles
Gets the Quartiles for this distribution.
(Inherited from UnivariateContinuousDistribution.)
Public propertyStandardDeviation
Gets the Standard Deviation (the square root of the variance) for the current distribution.
(Inherited from UnivariateContinuousDistribution.)
Public propertySupport
Gets the support interval for this distribution.
(Overrides UnivariateContinuousDistributionSupport.)
Public propertyCode exampleVariance
Gets the variance for this distribution.
(Overrides UnivariateContinuousDistributionVariance.)
Top
Methods
  NameDescription
Public methodClone
Creates a new object that is a copy of the current instance.
(Overrides DistributionBaseClone.)
Public methodComplementaryDistributionFunction(Double)
Gets the complementary cumulative distribution function (ccdf) for this distribution evaluated at point x. This function is also known as the Survival function.
(Inherited from UnivariateContinuousDistribution.)
Public methodStatic memberComplementaryDistributionFunction(Double, Double)
Computes the Complementary Cumulative Distribution Function (1-CDF) for the Kolmogorov-Smirnov statistic's distribution.
Public methodStatic memberCumulativeFunction
Computes the Cumulative Distribution Function (CDF) for the Kolmogorov-Smirnov statistic's distribution.
Public methodCumulativeHazardFunction
Gets the cumulative hazard function for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Public methodDistributionFunction(Double)
Gets the cumulative distribution function (cdf) for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Public methodDistributionFunction(Double, Double)
Gets the cumulative distribution function (cdf) for this distribution in the semi-closed interval (a; b] given as P(a < X ≤ b).
(Inherited from UnivariateContinuousDistribution.)
Public methodStatic memberDurbin
Durbin's algorithm for computing P[Dn < d]
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodCode exampleFit(Double)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodCode exampleFit(Double, IFittingOptions)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodCode exampleFit(Double, Double)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodCode exampleFit(Double, Int32)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodFit(Double, Double, IFittingOptions)
Not supported.
(Overrides UnivariateContinuousDistributionFit(Double, Double, IFittingOptions).)
Public methodCode exampleFit(Double, Int32, IFittingOptions)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodGenerate
Generates a random observation from the current distribution.
(Inherited from UnivariateContinuousDistribution.)
Public methodGenerate(Int32)
Generates a random vector of observations from the current distribution.
(Inherited from UnivariateContinuousDistribution.)
Public methodGenerate(Random)
Generates a random observation from the current distribution.
(Inherited from UnivariateContinuousDistribution.)
Public methodGenerate(Int32, Double)
Generates a random vector of observations from the current distribution.
(Inherited from UnivariateContinuousDistribution.)
Public methodGenerate(Int32, Random)
Generates a random vector of observations from the current distribution.
(Inherited from UnivariateContinuousDistribution.)
Public methodGenerate(Int32, Double, Random)
Generates a random vector of observations from the current distribution.
(Inherited from UnivariateContinuousDistribution.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetRange
Gets the distribution range within a given percentile.
(Inherited from UnivariateContinuousDistribution.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodHazardFunction
Gets the hazard function, also known as the failure rate or the conditional failure density function for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Protected methodCode exampleInnerComplementaryDistributionFunction
Gets the complementary cumulative distribution function (ccdf) for this distribution evaluated at point x. This function is also known as the Survival function.
(Overrides UnivariateContinuousDistributionInnerComplementaryDistributionFunction(Double).)
Protected methodCode exampleInnerDistributionFunction
Gets the cumulative distribution function (cdf) for this distribution evaluated at point x.
(Overrides UnivariateContinuousDistributionInnerDistributionFunction(Double).)
Protected methodInnerInverseDistributionFunction
Gets the inverse of the cumulative distribution function (icdf) for this distribution evaluated at probability p. This function is also known as the Quantile function.
(Inherited from UnivariateContinuousDistribution.)
Protected methodInnerLogProbabilityDensityFunction
Gets the log-probability density function (pdf) for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Protected methodInnerProbabilityDensityFunction
Not supported.
(Overrides UnivariateContinuousDistributionInnerProbabilityDensityFunction(Double).)
Public methodInverseDistributionFunction
Gets the inverse of the cumulative distribution function (icdf) for this distribution evaluated at probability p. This function is also known as the Quantile function.
(Inherited from UnivariateContinuousDistribution.)
Public methodLogCumulativeHazardFunction
Gets the log of the cumulative hazard function for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Public methodLogProbabilityDensityFunction
Gets the log-probability density function (pdf) for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodOneSideDistributionFunction
Computes the Upper Tail of the P[Dn >= x] distribution.
Public methodStatic memberOneSideUpperTail
Computes the Upper Tail of the P[Dn >= x] distribution.
Public methodStatic memberPelzGood
Pelz-Good algorithm for computing lower-tail areas of the Kolmogorov-Smirnov distribution.
Public methodStatic memberPomeranz
Pomeranz algorithm.
Public methodProbabilityDensityFunction
Gets the probability density function (pdf) for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Public methodQuantileDensityFunction
Gets the first derivative of the inverse distribution function (icdf) for this distribution evaluated at probability p.
(Inherited from UnivariateContinuousDistribution.)
Public methodToString
Returns a String that represents this instance.
(Inherited from DistributionBase.)
Public methodToString(IFormatProvider)
Returns a String that represents this instance.
(Inherited from DistributionBase.)
Public methodToString(String)
Returns a String that represents this instance.
(Inherited from DistributionBase.)
Public methodToString(String, IFormatProvider)
Returns a String that represents this instance.
(Overrides DistributionBaseToString(String, IFormatProvider).)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

This class is based on the excellent paper and original Java code by Simard and L'Ecuyer (2010). Includes additional modifications for increased performance and readability, shared under the LGPL under permission of original authors.

L'Ecuyer and Simard partitioned the problem of evaluating the CDF using multiple approximation and asymptotic methods in order to achieve a best compromise between speed and precision. The distribution function of this class follows the same partitioning scheme as described by L'Ecuyer and Simard, which is described in the table below.

For n <= 140 and:
1/n > x >= 1-1/nUses the Ruben-Gambino formula.
1/n < nx² < 0.754693Uses the Durbin matrix algorithm.
0.754693 <= nx² < 4Uses the Pomeranz algorithm.
4 <= nx² < 18Uses the complementary distribution function.
nx² >= 18Returns the constant 1.
For 140 < n <= 10^5
nx² >= 18Returns the constant 1.
nx^(3/2) < 1.4Durbin matrix algorithm.
nx^(3/2) > 1.4Pelz-Good asymptotic series.
For n > 10^5
nx² >= 18Returns the constant 1.
nx² < 18Pelz-Good asymptotic series.

References:

  • R. Simard and P. L'Ecuyer. (2011). "Computing the Two-Sided Kolmogorov-Smirnov Distribution", Journal of Statistical Software, Vol. 39, Issue 11, Mar 2011. Available on: http://www.iro.umontreal.ca/~lecuyer/myftp/papers/ksdist.pdf
  • Marsaglia, G., Tsang, W. W., Wang, J. (2003) "Evaluating Kolmogorov's Distribution", Journal of Statistical Software, 8 (18), 1–4. jstor. Available on: http://www.jstatsoft.org/v08/i18/paper
  • Durbin, J. (1972). Distribution Theory for Tests Based on The Sample Distribution Function, Society for Industrial & Applied Mathematics, Philadelphia.

Examples

The following example shows how to build a Kolmogorov-Smirnov distribution for 42 samples and compute its main functions and characteristics:

// Create a Kolmogorov-Smirnov distribution with n = 42
var ks = new KolmogorovSmirnovDistribution(samples: 42);

// Common measures
double mean   = ks.Mean;     // 0.13404812830261556
double median = ks.Median;   // 0.12393613519421857
double var    = ks.Variance; // 0.019154717445778062

// Cumulative distribution functions
double cdf  = ks.DistributionFunction(x: 0.27);              // 0.99659863602996079
double ccdf = ks.ComplementaryDistributionFunction(x: 0.27); // 0.0034013639700392062
double icdf = ks.InverseDistributionFunction(p: cdf);        // 0.26999997446092017

// Hazard (failure rate) functions
double chf  = ks.CumulativeHazardFunction(x: 0.27);          // 5.6835787601476619

// String representation
string str = ks.ToString(); // "KS(x; n = 42)"
See Also