[MATH-1240] Fix calculation of ksSum in KolmogorovSmirnovTest for zero input.
This commit is contained in:
parent
6d7ee38cee
commit
5cfd99f0dc
|
@ -54,6 +54,11 @@ If the output is not quite correct, check for invisible trailing spaces!
|
|||
</release>
|
||||
|
||||
<release version="4.0" date="XXXX-XX-XX" description="">
|
||||
<action dev="tn" type="fix" issue="MATH-1240"> <!-- backported to 3.6 -->
|
||||
"KolmogorovSmirnovTest#ksSum(...)" returned wrong result in case the provided
|
||||
t-parameters was zero. This affected the calculation of "approximateP(...)" for
|
||||
identical samples.
|
||||
</action>
|
||||
<action dev="tn" type="fix" issue="MATH-1242" due-to="Otmar Ertl"> <!-- backported to 3.6 -->
|
||||
Improved performance to calculate the two-sample Kolmogorov-Smirnov test
|
||||
via monte carlo simulation ("KolmogorovSmirnovTets#monteCarloP(...)").
|
||||
|
|
|
@ -832,7 +832,7 @@ public class KolmogorovSmirnovTest {
|
|||
*/
|
||||
public double ksSum(double t, double tolerance, int maxIterations) {
|
||||
if (t == 0.0) {
|
||||
return 1.0;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// TODO: for small t (say less than 1), the alternative expansion in part 3 of [1]
|
||||
|
|
|
@ -400,11 +400,31 @@ public class KolmogorovSmirnovTestTest {
|
|||
|
||||
@Test
|
||||
public void testTwoSamplesAllEqual() {
|
||||
int iterations = 10_000;
|
||||
final KolmogorovSmirnovTest test = new KolmogorovSmirnovTest();
|
||||
for (int i = 2; i < 30; ++i) {
|
||||
// testing values with ties
|
||||
double[] values = new double[i];
|
||||
Arrays.fill(values, i);
|
||||
// testing values without ties
|
||||
double[] ascendingValues = new double[i];
|
||||
for (int j = 0; j < ascendingValues.length; j++) {
|
||||
ascendingValues[j] = j;
|
||||
}
|
||||
|
||||
Assert.assertEquals(0., test.kolmogorovSmirnovStatistic(values, values), 0.);
|
||||
Assert.assertEquals(0., test.kolmogorovSmirnovStatistic(ascendingValues, ascendingValues), 0.);
|
||||
|
||||
if (i < 10) {
|
||||
Assert.assertEquals(1.0, test.exactP(0, values.length, values.length, true), 0.);
|
||||
Assert.assertEquals(1.0, test.exactP(0, values.length, values.length, false), 0.);
|
||||
}
|
||||
|
||||
Assert.assertEquals(1.0, test.monteCarloP(0, values.length, values.length, true, iterations), 0.);
|
||||
Assert.assertEquals(1.0, test.monteCarloP(0, values.length, values.length, false, iterations), 0.);
|
||||
|
||||
Assert.assertEquals(1.0, test.approximateP(0, values.length, values.length), 0.);
|
||||
Assert.assertEquals(1.0, test.approximateP(0, values.length, values.length), 0.);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue