Author: mikl Date: Fri Jun 8 11:04:11 2012 New Revision: 1348024 URL: http://svn.apache.org/viewvc?rev=1348024&view=rev Log: MATH-790: Patch applied to fix the overflow issue.
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java?rev=1348024&r1=1348023&r2=1348024&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java Fri Jun 8 11:04:11 2012 @@ -170,11 +170,11 @@ public class MannWhitneyUTest { final int n2) throws ConvergenceException, MaxCountExceededException { - final int n1n2prod = n1 * n2; + final double n1n2prod = n1 * n2; // http://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U#Normal_approximation - final double EU = (double) n1n2prod / 2.0; - final double VarU = (double) (n1n2prod * (n1 + n2 + 1)) / 12.0; + final double EU = n1n2prod / 2.0; + final double VarU = n1n2prod * (n1 + n2 + 1) / 12.0; final double z = (Umin - EU) / FastMath.sqrt(VarU); Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java?rev=1348024&r1=1348023&r2=1348024&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java Fri Jun 8 11:04:11 2012 @@ -100,4 +100,16 @@ public class MannWhitneyUTestTest { // expected } } + + @Test + public void testBigDataSet() throws Exception { + double[] d1 = new double[1500]; + double[] d2 = new double[1500]; + for (int i = 0; i < 1500; i++) { + d1[i] = 2 * i; + d2[i] = 2 * i + 1; + } + double result = testStatistic.mannWhitneyUTest(d1, d2); + Assert.assertTrue(result > 0.1); + } }