Top Description Fields Constructors Methods
org.apache.commons.math3.distribution

public Class KolmogorovSmirnovDistribution

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, java.math.BigDecimal, org.apache.commons.math3.exception.MathArithmeticException, .NotStrictlyPositiveException, .NumberIsTooLargeException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.fraction.BigFraction, .BigFractionField, .FractionConversionException, org.apache.commons.math3.linear.Array2DRowFieldMatrix, .Array2DRowRealMatrix, .FieldMatrix, .RealMatrix, org.apache.commons.math3.util.FastMath

Deprecated

to be removed in version 4.0 - use org.apache.commons.math3.stat.inference.KolmogorovSmirnovTest

Implementation of the Kolmogorov-Smirnov distribution.

Treats the distribution of the two-sided P(D_n < d) where D_n = sup_x |G(x) - G_n (x)| for the theoretical cdf G and the empirical cdf G_n.

This implementation is based on [1] with certain quick decisions for extreme values given in [2].

In short, when wanting to evaluate P(D_n < d), the method in [1] is to write d = (k - h) / n for positive integer k and 0 <= h < 1. Then P(D_n < d) = (n! / n^n) * t_kk, where t_kk is the (k, k)'th entry in the special matrix H^n, i.e. H to the n'th power.

References:

Note that [1] contains an error in computing h, refer to MATH-437 for details.

See Also
Kolmogorov-Smirnov test (Wikipedia)

Field Summary

Modifier and TypeField and Description
private int
n

Number of observations.

private static final long
serialVersionUID

Serializable version identifier.

Constructor Summary

AccessConstructor and Description
public
KolmogorovSmirnovDistribution(int
Number of observations
n
)

Method Summary

Modifier and TypeMethod and Description
public double

Returns:

the two-sided probability of P(D_n < d)
cdf
(double
statistic
d
)

Calculates P(D_n < d) using method described in [1] with quick decisions for extreme values given in [2] (see above).

public double

Returns:

the two-sided probability of P(D_n < d)
cdf
(double
statistic
d
,
boolean
whether the probability should be calculated exact using org.apache.commons.math3.fraction.BigFraction everywhere at the expense of very slow execution time, or if double should be used convenient places to gain speed. Almost never choose true in real applications unless you are very sure; true is almost solely for verification purposes.
exact
)

Calculates P(D_n < d) using method described in [1] with quick decisions for extreme values given in [2] (see above).

public double

Returns:

the two-sided probability of P(D_n < d)
cdfExact
(double
statistic
d
)

Calculates P(D_n < d) using method described in [1] with quick decisions for extreme values given in [2] (see above).

private FieldMatrix<BigFraction>

Returns:

H matrix
createH
(double
statistic
d
)

Creates H of size m x m as described in [1] (see above).

private double

Returns:

the two-sided probability of P(D_n < d)
exactK
(double
statistic
d
)

Calculates the exact value of P(D_n < d) using method described in [1] and org.apache.commons.math3.fraction.BigFraction (see above).

private double

Returns:

the two-sided probability of P(D_n < d)
roundedK
(double
statistic
d
)

Calculates P(D_n < d) using method described in [1] and doubles (see above).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nback to summary
private int n

Number of observations.

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable version identifier.

Constructor Detail

KolmogorovSmirnovDistributionback to summary
public KolmogorovSmirnovDistribution(int n) throws NotStrictlyPositiveException
Parameters
n:int

Number of observations

Exceptions
NotStrictlyPositiveException:
if n <= 0

Method Detail

cdfback to summary
public double cdf(double d) throws MathArithmeticException

Calculates P(D_n < d) using method described in [1] with quick decisions for extreme values given in [2] (see above). The result is not exact as with KolmogorovSmirnovDistribution#cdfExact(double) because calculations are based on double rather than org.apache.commons.math3.fraction.BigFraction.

Parameters
d:double

statistic

Returns:double

the two-sided probability of P(D_n < d)

Exceptions
MathArithmeticException:
if algorithm fails to convert h to a org.apache.commons.math3.fraction.BigFraction in expressing d as (k - h) / m for integer k, m and 0 <= h < 1.
cdfback to summary
public double cdf(double d, boolean exact) throws MathArithmeticException

Calculates P(D_n < d) using method described in [1] with quick decisions for extreme values given in [2] (see above).

Parameters
d:double

statistic

exact:boolean

whether the probability should be calculated exact using org.apache.commons.math3.fraction.BigFraction everywhere at the expense of very slow execution time, or if double should be used convenient places to gain speed. Almost never choose true in real applications unless you are very sure; true is almost solely for verification purposes.

Returns:double

the two-sided probability of P(D_n < d)

Exceptions
MathArithmeticException:
if algorithm fails to convert h to a org.apache.commons.math3.fraction.BigFraction in expressing d as (k - h) / m for integer k, m and 0 <= h < 1.
cdfExactback to summary
public double cdfExact(double d) throws MathArithmeticException

Calculates P(D_n < d) using method described in [1] with quick decisions for extreme values given in [2] (see above). The result is exact in the sense that BigFraction/BigReal is used everywhere at the expense of very slow execution time. Almost never choose this in real applications unless you are very sure; this is almost solely for verification purposes. Normally, you would choose KolmogorovSmirnovDistribution#cdf(double)

Parameters
d:double

statistic

Returns:double

the two-sided probability of P(D_n < d)

Exceptions
MathArithmeticException:
if algorithm fails to convert h to a org.apache.commons.math3.fraction.BigFraction in expressing d as (k - h) / m for integer k, m and 0 <= h < 1.
createHback to summary
private FieldMatrix<BigFraction> createH(double d) throws NumberIsTooLargeException, FractionConversionException

Creates H of size m x m as described in [1] (see above).

Parameters
d:double

statistic

Returns:FieldMatrix<BigFraction>

H matrix

Exceptions
NumberIsTooLargeException:
if fractional part is greater than 1
FractionConversionException:
if algorithm fails to convert h to a org.apache.commons.math3.fraction.BigFraction in expressing d as (k - h) / m for integer k, m and 0 <= h < 1.
exactKback to summary
private double exactK(double d) throws MathArithmeticException

Calculates the exact value of P(D_n < d) using method described in [1] and org.apache.commons.math3.fraction.BigFraction (see above).

Parameters
d:double

statistic

Returns:double

the two-sided probability of P(D_n < d)

Exceptions
MathArithmeticException:
if algorithm fails to convert h to a org.apache.commons.math3.fraction.BigFraction in expressing d as (k - h) / m for integer k, m and 0 <= h < 1.
roundedKback to summary
private double roundedK(double d) throws MathArithmeticException

Calculates P(D_n < d) using method described in [1] and doubles (see above).

Parameters
d:double

statistic

Returns:double

the two-sided probability of P(D_n < d)

Exceptions
MathArithmeticException:
if algorithm fails to convert h to a org.apache.commons.math3.fraction.BigFraction in expressing d as (k - h) / m for integer k, m and 0 <= h < 1.