MATH-1277: Fixed incorrect Kendall's tau coefficient calculation due to
internal integer overflow. Thanks to Marc Rosen.
This commit is contained in:
parent
6fe2094e30
commit
fb0078159d
|
@ -54,6 +54,9 @@ If the output is not quite correct, check for invisible trailing spaces!
|
||||||
</release>
|
</release>
|
||||||
|
|
||||||
<release version="4.0" date="XXXX-XX-XX" description="">
|
<release version="4.0" date="XXXX-XX-XX" description="">
|
||||||
|
<action dev="oertl" type="fix" issue="MATH-1277" due-to="Marc Rosen"> <!-- backported to 3.6 -->
|
||||||
|
Fixed incorrect Kendall's tau coefficient calculation due to internal integer overflow.
|
||||||
|
</action>
|
||||||
<action dev="oertl" type="update" issue="MATH-1274"> <!-- backported to 3.6 -->
|
<action dev="oertl" type="update" issue="MATH-1274"> <!-- backported to 3.6 -->
|
||||||
Representation of Kolmogorov-Smirnov statistic as integral value.
|
Representation of Kolmogorov-Smirnov statistic as integral value.
|
||||||
</action>
|
</action>
|
||||||
|
|
|
@ -201,7 +201,7 @@ public class KendallsCorrelation {
|
||||||
tiedXPairs += sum(consecutiveXTies - 1);
|
tiedXPairs += sum(consecutiveXTies - 1);
|
||||||
tiedXYPairs += sum(consecutiveXYTies - 1);
|
tiedXYPairs += sum(consecutiveXYTies - 1);
|
||||||
|
|
||||||
int swaps = 0;
|
long swaps = 0;
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Pair<Double, Double>[] pairsDestination = new Pair[n];
|
Pair<Double, Double>[] pairsDestination = new Pair[n];
|
||||||
for (int segmentSize = 1; segmentSize < n; segmentSize <<= 1) {
|
for (int segmentSize = 1; segmentSize < n; segmentSize <<= 1) {
|
||||||
|
|
|
@ -21,6 +21,8 @@ import java.util.Arrays;
|
||||||
import org.apache.commons.math4.TestUtils;
|
import org.apache.commons.math4.TestUtils;
|
||||||
import org.apache.commons.math4.linear.BlockRealMatrix;
|
import org.apache.commons.math4.linear.BlockRealMatrix;
|
||||||
import org.apache.commons.math4.linear.RealMatrix;
|
import org.apache.commons.math4.linear.RealMatrix;
|
||||||
|
import org.apache.commons.math4.random.RandomGenerator;
|
||||||
|
import org.apache.commons.math4.random.Well1024a;
|
||||||
import org.apache.commons.math4.stat.correlation.KendallsCorrelation;
|
import org.apache.commons.math4.stat.correlation.KendallsCorrelation;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -259,4 +261,21 @@ public class KendallsCorrelationTest extends PearsonsCorrelationTest {
|
||||||
|
|
||||||
Assert.assertEquals(1.0, correlation.correlation(xArray, xArray), 1e-6);
|
Assert.assertEquals(1.0, correlation.correlation(xArray, xArray), 1e-6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMath1277() {
|
||||||
|
// example that led to a correlation coefficient outside of [-1, 1]
|
||||||
|
// due to a bug reported in MATH-1277
|
||||||
|
RandomGenerator rng = new Well1024a(0);
|
||||||
|
double[] xArray = new double[120000];
|
||||||
|
double[] yArray = new double[120000];
|
||||||
|
for (int i = 0; i < xArray.length; ++i) {
|
||||||
|
xArray[i] = rng.nextDouble();
|
||||||
|
}
|
||||||
|
for (int i = 0; i < yArray.length; ++i) {
|
||||||
|
yArray[i] = rng.nextDouble();
|
||||||
|
}
|
||||||
|
double coefficient = correlation.correlation(xArray, yArray);
|
||||||
|
Assert.assertTrue(1.0 >= coefficient && -1.0 <= coefficient);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue