You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2009/09/05 19:37:05 UTC
svn commit: r811685 [23/24] - in /commons/proper/math/trunk: ./
src/main/java/org/apache/commons/math/
src/main/java/org/apache/commons/math/analysis/
src/main/java/org/apache/commons/math/analysis/integration/
src/main/java/org/apache/commons/math/ana...
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/rank/PercentileTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/rank/PercentileTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/rank/PercentileTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/rank/PercentileTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,7 +29,7 @@
public class PercentileTest extends UnivariateStatisticAbstractTest{
protected Percentile stat;
-
+
/**
* @param name
*/
@@ -42,12 +42,12 @@
suite.setName("Percentile Tests");
return suite;
}
-
+
/**
* {@inheritDoc}
*/
@Override
- public UnivariateStatistic getUnivariateStatistic() {
+ public UnivariateStatistic getUnivariateStatistic() {
return new Percentile(95.0);
}
@@ -64,7 +64,7 @@
Percentile p = new Percentile(75);
assertEquals(3.0, p.evaluate(d), 1.0e-5);
}
-
+
public void testPercentile() {
double[] d = new double[] {1, 3, 2, 4};
Percentile p = new Percentile(30);
@@ -75,7 +75,7 @@
assertEquals(3.75, p.evaluate(d), 1.0e-5);
p.setQuantile(50);
assertEquals(2.5, p.evaluate(d), 1.0e-5);
-
+
// invalid percentiles
try {
p.evaluate(d, 0, d.length, -1.0);
@@ -90,21 +90,21 @@
// success
}
}
-
+
public void testNISTExample() {
- double[] d = new double[] {95.1772, 95.1567, 95.1937, 95.1959,
+ double[] d = new double[] {95.1772, 95.1567, 95.1937, 95.1959,
95.1442, 95.0610, 95.1591, 95.1195, 95.1772, 95.0925, 95.1990, 95.1682
};
- Percentile p = new Percentile(90);
+ Percentile p = new Percentile(90);
assertEquals(95.1981, p.evaluate(d), 1.0e-4);
assertEquals(95.1990, p.evaluate(d,0,d.length, 100d), 0);
}
-
+
public void test5() {
Percentile percentile = new Percentile(5);
assertEquals(this.percentile5, percentile.evaluate(testArray), getTolerance());
}
-
+
public void testNullEmpty() {
Percentile percentile = new Percentile(50);
double[] nullArray = null;
@@ -114,20 +114,20 @@
fail("Expecting IllegalArgumentException for null array");
} catch (IllegalArgumentException ex) {
// expected
- }
- assertTrue(Double.isNaN(percentile.evaluate(emptyArray)));
+ }
+ assertTrue(Double.isNaN(percentile.evaluate(emptyArray)));
}
-
+
public void testSingleton() {
Percentile percentile = new Percentile(50);
double[] singletonArray = new double[] {1d};
assertEquals(1d, percentile.evaluate(singletonArray), 0);
assertEquals(1d, percentile.evaluate(singletonArray, 0, 1), 0);
assertEquals(1d, percentile.evaluate(singletonArray, 0, 1, 5), 0);
- assertEquals(1d, percentile.evaluate(singletonArray, 0, 1, 100), 0);
- assertTrue(Double.isNaN(percentile.evaluate(singletonArray, 0, 0)));
+ assertEquals(1d, percentile.evaluate(singletonArray, 0, 1, 100), 0);
+ assertTrue(Double.isNaN(percentile.evaluate(singletonArray, 0, 0)));
}
-
+
public void testSpecialValues() {
Percentile percentile = new Percentile(50);
double[] specialValues = new double[] {0d, 1d, 2d, 3d, 4d, Double.NaN};
@@ -135,22 +135,22 @@
specialValues = new double[] {Double.NEGATIVE_INFINITY, 1d, 2d, 3d,
Double.NaN, Double.POSITIVE_INFINITY};
assertEquals(2.5d, percentile.evaluate(specialValues), 0);
- specialValues = new double[] {1d, 1d, Double.POSITIVE_INFINITY,
+ specialValues = new double[] {1d, 1d, Double.POSITIVE_INFINITY,
Double.POSITIVE_INFINITY};
assertTrue(Double.isInfinite(percentile.evaluate(specialValues)));
- specialValues = new double[] {1d, 1d, Double.NaN,
+ specialValues = new double[] {1d, 1d, Double.NaN,
Double.NaN};
assertTrue(Double.isNaN(percentile.evaluate(specialValues)));
- specialValues = new double[] {1d, 1d, Double.NEGATIVE_INFINITY,
+ specialValues = new double[] {1d, 1d, Double.NEGATIVE_INFINITY,
Double.NEGATIVE_INFINITY};
// Interpolation results in NEGATIVE_INFINITY + POSITIVE_INFINITY
- assertTrue(Double.isNaN(percentile.evaluate(specialValues)));
+ assertTrue(Double.isNaN(percentile.evaluate(specialValues)));
}
-
+
public void testSetQuantile() {
Percentile percentile = new Percentile(10);
percentile.setQuantile(100); // OK
- assertEquals(100, percentile.getQuantile(), 0);
+ assertEquals(100, percentile.getQuantile(), 0);
try {
percentile.setQuantile(0);
fail("Expecting IllegalArgumentException");
@@ -162,7 +162,7 @@
fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// expected
- }
+ }
}
-
+
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/summary/SumLogTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/summary/SumLogTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/summary/SumLogTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/summary/SumLogTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,7 +29,7 @@
public class SumLogTest extends StorelessUnivariateStatisticAbstractTest{
protected SumOfLogs stat;
-
+
/**
* @param name
*/
@@ -42,12 +42,12 @@
suite.setName("SumLog Tests");
return suite;
}
-
+
/**
* {@inheritDoc}
*/
@Override
- public UnivariateStatistic getUnivariateStatistic() {
+ public UnivariateStatistic getUnivariateStatistic() {
return new SumOfLogs();
}
@@ -58,32 +58,32 @@
public double expectedValue() {
return this.sumLog;
}
-
+
public void testSpecialValues() {
SumOfLogs sum = new SumOfLogs();
// empty
assertTrue(Double.isNaN(sum.getResult()));
-
+
// finite data
sum.increment(1d);
assertFalse(Double.isNaN(sum.getResult()));
-
+
// add negative infinity
sum.increment(0d);
assertEquals(Double.NEGATIVE_INFINITY, sum.getResult(), 0);
-
+
// add positive infinity -- should make NaN
sum.increment(Double.POSITIVE_INFINITY);
assertTrue(Double.isNaN(sum.getResult()));
-
+
// clear
sum.clear();
assertTrue(Double.isNaN(sum.getResult()));
-
+
// positive infinity by itself
sum.increment(Double.POSITIVE_INFINITY);
assertEquals(Double.POSITIVE_INFINITY, sum.getResult(), 0);
-
+
// negative value -- should make NaN
sum.increment(-2d);
assertTrue(Double.isNaN(sum.getResult()));
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/summary/SumSqTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/summary/SumSqTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/summary/SumSqTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/summary/SumSqTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,13 +24,13 @@
/**
* Test cases for the {@link SumOfSquares} class.
- *
+ *
* @version $Revision$ $Date$
*/
public class SumSqTest extends StorelessUnivariateStatisticAbstractTest{
protected SumOfSquares stat;
-
+
/**
* @param name
*/
@@ -43,7 +43,7 @@
suite.setName("SumSq Tests");
return suite;
}
-
+
/**
* {@inheritDoc}
*/
@@ -59,7 +59,7 @@
public double expectedValue() {
return this.sumSq;
}
-
+
public void testSpecialValues() {
SumOfSquares sumSq = new SumOfSquares();
assertTrue(Double.isNaN(sumSq.getResult()));
@@ -70,9 +70,9 @@
sumSq.increment(Double.NEGATIVE_INFINITY);
assertEquals(Double.POSITIVE_INFINITY, sumSq.getResult(), 0);
sumSq.increment(Double.NaN);
- assertTrue(Double.isNaN(sumSq.getResult()));
+ assertTrue(Double.isNaN(sumSq.getResult()));
sumSq.increment(1);
- assertTrue(Double.isNaN(sumSq.getResult()));
+ assertTrue(Double.isNaN(sumSq.getResult()));
}
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/ChiSquareFactoryTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/ChiSquareFactoryTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/ChiSquareFactoryTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/ChiSquareFactoryTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/ChiSquareTestTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/ChiSquareTestTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/ChiSquareTestTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/ChiSquareTestTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -41,17 +41,17 @@
}
public void testChiSquare() throws Exception {
-
- // Target values computed using R version 1.8.1
- // Some assembly required ;-)
+
+ // Target values computed using R version 1.8.1
+ // Some assembly required ;-)
// Use sum((obs - exp)^2/exp) for the chi-square statistic and
// 1 - pchisq(sum((obs - exp)^2/exp), length(obs) - 1) for the p-value
-
+
long[] observed = {10, 9, 11};
double[] expected = {10, 10, 10};
assertEquals("chi-square statistic", 0.2, testStatistic.chiSquare(expected, observed), 10E-12);
assertEquals("chi-square p-value", 0.904837418036, testStatistic.chiSquareTest(expected, observed), 1E-10);
-
+
long[] observed1 = { 500, 623, 72, 70, 31 };
double[] expected1 = { 485, 541, 82, 61, 37 };
assertEquals( "chi-square test statistic", 9.023307936427388, testStatistic.chiSquare(expected1, observed1), 1E-10);
@@ -64,8 +64,8 @@
fail("alpha out of range, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
long[] tooShortObs = { 0 };
double[] tooShortEx = { 1 };
try {
@@ -84,7 +84,7 @@
} catch (IllegalArgumentException ex) {
// expected
}
-
+
// 0 expected count
expected[0] = 0;
try {
@@ -92,8 +92,8 @@
fail("bad expected count, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
// negative observed count
expected[0] = 1;
observed[0] = -1;
@@ -102,25 +102,25 @@
fail("bad expected count, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
}
public void testChiSquareIndependence() throws Exception {
-
- // Target values computed using R version 1.8.1
-
+
+ // Target values computed using R version 1.8.1
+
long[][] counts = { {40, 22, 43}, {91, 21, 28}, {60, 10, 22}};
assertEquals( "chi-square test statistic", 22.709027688, testStatistic.chiSquare(counts), 1E-9);
assertEquals("chi-square p-value", 0.000144751460134, testStatistic.chiSquareTest(counts), 1E-9);
assertTrue("chi-square test reject", testStatistic.chiSquareTest(counts, 0.0002));
- assertTrue("chi-square test accept", !testStatistic.chiSquareTest(counts, 0.0001));
-
+ assertTrue("chi-square test accept", !testStatistic.chiSquareTest(counts, 0.0001));
+
long[][] counts2 = {{10, 15}, {30, 40}, {60, 90} };
assertEquals( "chi-square test statistic", 0.168965517241, testStatistic.chiSquare(counts2), 1E-9);
assertEquals("chi-square p-value",0.918987499852, testStatistic.chiSquareTest(counts2), 1E-9);
- assertTrue("chi-square test accept", !testStatistic.chiSquareTest(counts2, 0.1));
-
+ assertTrue("chi-square test accept", !testStatistic.chiSquareTest(counts2, 0.1));
+
// ragged input array
long[][] counts3 = { {40, 22, 43}, {91, 21, 28}, {60, 10}};
try {
@@ -129,7 +129,7 @@
} catch (IllegalArgumentException ex) {
// expected
}
-
+
// insufficient data
long[][] counts4 = {{40, 22, 43}};
try {
@@ -137,15 +137,15 @@
fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// expected
- }
+ }
long[][] counts5 = {{40}, {40}, {30}, {10}};
try {
testStatistic.chiSquare(counts5);
fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
// negative counts
long[][] counts6 = {{10, -2}, {30, 40}, {60, 90} };
try {
@@ -153,20 +153,20 @@
fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
// bad alpha
try {
testStatistic.chiSquareTest(counts, 0);
fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// expected
- }
+ }
}
-
+
public void testChiSquareLargeTestStatistic() throws Exception {
double[] exp = new double[] {
- 3389119.5, 649136.6, 285745.4, 25357364.76, 11291189.78, 543628.0,
+ 3389119.5, 649136.6, 285745.4, 25357364.76, 11291189.78, 543628.0,
232921.0, 437665.75
};
@@ -174,58 +174,58 @@
2372383, 584222, 257170, 17750155, 7903832, 489265, 209628, 393899
};
org.apache.commons.math.stat.inference.ChiSquareTestImpl csti =
- new org.apache.commons.math.stat.inference.ChiSquareTestImpl();
- double cst = csti.chiSquareTest(exp, obs);
+ new org.apache.commons.math.stat.inference.ChiSquareTestImpl();
+ double cst = csti.chiSquareTest(exp, obs);
assertEquals("chi-square p-value", 0.0, cst, 1E-3);
- assertEquals( "chi-square test statistic",
+ assertEquals( "chi-square test statistic",
114875.90421929007, testStatistic.chiSquare(exp, obs), 1E-9);
}
-
+
/** Contingency table containing zeros - PR # 32531 */
public void testChiSquareZeroCount() throws Exception {
- // Target values computed using R version 1.8.1
+ // Target values computed using R version 1.8.1
long[][] counts = { {40, 0, 4}, {91, 1, 2}, {60, 2, 0}};
assertEquals( "chi-square test statistic", 9.67444662263,
testStatistic.chiSquare(counts), 1E-9);
assertEquals("chi-square p-value", 0.0462835770603,
- testStatistic.chiSquareTest(counts), 1E-9);
+ testStatistic.chiSquareTest(counts), 1E-9);
}
-
+
/** Target values verified using DATAPLOT version 2006.3 */
public void testChiSquareDataSetsComparisonEqualCounts()
throws Exception {
long[] observed1 = {10, 12, 12, 10};
- long[] observed2 = {5, 15, 14, 10};
- assertEquals("chi-square p value", 0.541096,
+ long[] observed2 = {5, 15, 14, 10};
+ assertEquals("chi-square p value", 0.541096,
testStatistic.chiSquareTestDataSetsComparison(
observed1, observed2), 1E-6);
assertEquals("chi-square test statistic", 2.153846,
testStatistic.chiSquareDataSetsComparison(
observed1, observed2), 1E-6);
- assertFalse("chi-square test result",
+ assertFalse("chi-square test result",
testStatistic.chiSquareTestDataSetsComparison(
observed1, observed2, 0.4));
}
-
+
/** Target values verified using DATAPLOT version 2006.3 */
public void testChiSquareDataSetsComparisonUnEqualCounts()
throws Exception {
long[] observed1 = {10, 12, 12, 10, 15};
- long[] observed2 = {15, 10, 10, 15, 5};
- assertEquals("chi-square p value", 0.124115,
+ long[] observed2 = {15, 10, 10, 15, 5};
+ assertEquals("chi-square p value", 0.124115,
testStatistic.chiSquareTestDataSetsComparison(
observed1, observed2), 1E-6);
assertEquals("chi-square test statistic", 7.232189,
testStatistic.chiSquareDataSetsComparison(
observed1, observed2), 1E-6);
- assertTrue("chi-square test result",
+ assertTrue("chi-square test result",
testStatistic.chiSquareTestDataSetsComparison(
observed1, observed2, 0.13));
- assertFalse("chi-square test result",
+ assertFalse("chi-square test result",
testStatistic.chiSquareTestDataSetsComparison(
observed1, observed2, 0.12));
}
-
+
public void testChiSquareDataSetsComparisonBadCounts()
throws Exception {
long[] observed1 = {10, -1, 12, 10, 15};
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/OneWayAnovaTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/OneWayAnovaTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/OneWayAnovaTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/OneWayAnovaTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -32,7 +32,7 @@
public class OneWayAnovaTest extends TestCase {
protected OneWayAnova testStatistic = new OneWayAnovaImpl();
-
+
private double[] emptyArray = {};
private double[] classA =
@@ -65,7 +65,7 @@
List<double[]> twoClasses = new ArrayList<double[]>();
twoClasses.add(classA);
twoClasses.add(classB);
-
+
assertEquals("ANOVA F-value", 0.0150579150579,
testStatistic.anovaFValue(twoClasses), 1E-12);
@@ -77,7 +77,7 @@
fail("empty array for key classX, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
+ }
List<double[]> tooFew = new ArrayList<double[]>();
tooFew.add(classA);
@@ -86,9 +86,9 @@
fail("less than two classes, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
+ }
}
-
+
public void testAnovaPValue() throws Exception {
// Target comparison values computed using R version 2.6.0 (Linux version)
@@ -103,7 +103,7 @@
List<double[]> twoClasses = new ArrayList<double[]>();
twoClasses.add(classA);
twoClasses.add(classB);
-
+
assertEquals("ANOVA P-value", 0.904212960464,
testStatistic.anovaPValue(twoClasses), 1E-12);
@@ -121,8 +121,8 @@
List<double[]> twoClasses = new ArrayList<double[]>();
twoClasses.add(classA);
twoClasses.add(classB);
-
+
assertFalse("ANOVA Test P>0.01", testStatistic.anovaTest(twoClasses, 0.01));
}
-}
\ No newline at end of file
+}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/TTestFactoryTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/TTestFactoryTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/TTestFactoryTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/TTestFactoryTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/TTestTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/TTestTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/TTestTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/TTestTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -30,11 +30,11 @@
public class TTestTest extends TestCase {
protected TTest testStatistic = new TTestImpl();
-
+
private double[] tooShortObs = { 1.0 };
private double[] emptyObs = {};
- private SummaryStatistics emptyStats = new SummaryStatistics();
- SummaryStatistics tooShortStats = null;
+ private SummaryStatistics emptyStats = new SummaryStatistics();
+ SummaryStatistics tooShortStats = null;
public TTestTest(String name) {
super(name);
@@ -92,7 +92,7 @@
} catch (IllegalArgumentException ex) {
// expected
}
-
+
try {
testStatistic.t(mu, emptyStats);
fail("arguments too short, IllegalArgumentException expected");
@@ -111,7 +111,7 @@
fail("insufficient data to perform t test, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
+ }
try {
testStatistic.t(mu, tooShortStats);
@@ -124,20 +124,20 @@
fail("insufficient data to perform t test, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
+ }
}
-
+
public void testOneSampleTTest() throws Exception {
double[] oneSidedP =
{2d, 0d, 6d, 6d, 3d, 3d, 2d, 3d, -6d, 6d, 6d, 6d, 3d, 0d, 1d, 1d, 0d, 2d, 3d, 3d };
- SummaryStatistics oneSidedPStats = new SummaryStatistics();
+ SummaryStatistics oneSidedPStats = new SummaryStatistics();
for (int i = 0; i < oneSidedP.length; i++) {
oneSidedPStats.addValue(oneSidedP[i]);
}
// Target comparison values computed using R version 1.8.1 (Linux version)
- assertEquals("one sample t stat", 3.86485535541,
+ assertEquals("one sample t stat", 3.86485535541,
testStatistic.t(0d, oneSidedP), 10E-10);
- assertEquals("one sample t stat", 3.86485535541,
+ assertEquals("one sample t stat", 3.86485535541,
testStatistic.t(0d, oneSidedPStats),1E-10);
assertEquals("one sample p value", 0.000521637019637,
testStatistic.tTest(0d, oneSidedP) / 2d, 10E-10);
@@ -147,102 +147,102 @@
assertTrue("one sample t-test reject", testStatistic.tTest(0d, oneSidedPStats, 0.01));
assertTrue("one sample t-test accept", !testStatistic.tTest(0d, oneSidedP, 0.0001));
assertTrue("one sample t-test accept", !testStatistic.tTest(0d, oneSidedPStats, 0.0001));
-
+
try {
testStatistic.tTest(0d, oneSidedP, 95);
fail("alpha out of range, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
try {
testStatistic.tTest(0d, oneSidedPStats, 95);
fail("alpha out of range, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
}
-
+
public void testTwoSampleTHeterscedastic() throws Exception {
double[] sample1 = { 7d, -4d, 18d, 17d, -3d, -5d, 1d, 10d, 11d, -2d };
double[] sample2 = { -1d, 12d, -1d, -3d, 3d, -5d, 5d, 2d, -11d, -1d, -3d };
- SummaryStatistics sampleStats1 = new SummaryStatistics();
+ SummaryStatistics sampleStats1 = new SummaryStatistics();
for (int i = 0; i < sample1.length; i++) {
sampleStats1.addValue(sample1[i]);
}
- SummaryStatistics sampleStats2 = new SummaryStatistics();
+ SummaryStatistics sampleStats2 = new SummaryStatistics();
for (int i = 0; i < sample2.length; i++) {
sampleStats2.addValue(sample2[i]);
}
-
+
// Target comparison values computed using R version 1.8.1 (Linux version)
- assertEquals("two sample heteroscedastic t stat", 1.60371728768,
+ assertEquals("two sample heteroscedastic t stat", 1.60371728768,
testStatistic.t(sample1, sample2), 1E-10);
- assertEquals("two sample heteroscedastic t stat", 1.60371728768,
+ assertEquals("two sample heteroscedastic t stat", 1.60371728768,
testStatistic.t(sampleStats1, sampleStats2), 1E-10);
- assertEquals("two sample heteroscedastic p value", 0.128839369622,
+ assertEquals("two sample heteroscedastic p value", 0.128839369622,
testStatistic.tTest(sample1, sample2), 1E-10);
- assertEquals("two sample heteroscedastic p value", 0.128839369622,
- testStatistic.tTest(sampleStats1, sampleStats2), 1E-10);
- assertTrue("two sample heteroscedastic t-test reject",
+ assertEquals("two sample heteroscedastic p value", 0.128839369622,
+ testStatistic.tTest(sampleStats1, sampleStats2), 1E-10);
+ assertTrue("two sample heteroscedastic t-test reject",
testStatistic.tTest(sample1, sample2, 0.2));
- assertTrue("two sample heteroscedastic t-test reject",
+ assertTrue("two sample heteroscedastic t-test reject",
testStatistic.tTest(sampleStats1, sampleStats2, 0.2));
- assertTrue("two sample heteroscedastic t-test accept",
+ assertTrue("two sample heteroscedastic t-test accept",
!testStatistic.tTest(sample1, sample2, 0.1));
- assertTrue("two sample heteroscedastic t-test accept",
+ assertTrue("two sample heteroscedastic t-test accept",
!testStatistic.tTest(sampleStats1, sampleStats2, 0.1));
-
+
try {
testStatistic.tTest(sample1, sample2, .95);
fail("alpha out of range, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
try {
testStatistic.tTest(sampleStats1, sampleStats2, .95);
fail("alpha out of range, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
- // expected
- }
-
+ // expected
+ }
+
try {
testStatistic.tTest(sample1, tooShortObs, .01);
fail("insufficient data, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
try {
testStatistic.tTest(sampleStats1, tooShortStats, .01);
fail("insufficient data, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
try {
testStatistic.tTest(sample1, tooShortObs);
fail("insufficient data, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
try {
testStatistic.tTest(sampleStats1, tooShortStats);
fail("insufficient data, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
try {
testStatistic.t(sample1, tooShortObs);
fail("insufficient data, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
}
-
+
try {
testStatistic.t(sampleStats1, tooShortStats);
fail("insufficient data, IllegalArgumentException expected");
@@ -253,37 +253,37 @@
public void testTwoSampleTHomoscedastic() throws Exception {
double[] sample1 ={2, 4, 6, 8, 10, 97};
double[] sample2 = {4, 6, 8, 10, 16};
- SummaryStatistics sampleStats1 = new SummaryStatistics();
+ SummaryStatistics sampleStats1 = new SummaryStatistics();
for (int i = 0; i < sample1.length; i++) {
sampleStats1.addValue(sample1[i]);
}
- SummaryStatistics sampleStats2 = new SummaryStatistics();
+ SummaryStatistics sampleStats2 = new SummaryStatistics();
for (int i = 0; i < sample2.length; i++) {
sampleStats2.addValue(sample2[i]);
}
-
+
// Target comparison values computed using R version 1.8.1 (Linux version)
- assertEquals("two sample homoscedastic t stat", 0.73096310086,
+ assertEquals("two sample homoscedastic t stat", 0.73096310086,
testStatistic.homoscedasticT(sample1, sample2), 10E-11);
- assertEquals("two sample homoscedastic p value", 0.4833963785,
- testStatistic.homoscedasticTTest(sampleStats1, sampleStats2), 1E-10);
- assertTrue("two sample homoscedastic t-test reject",
+ assertEquals("two sample homoscedastic p value", 0.4833963785,
+ testStatistic.homoscedasticTTest(sampleStats1, sampleStats2), 1E-10);
+ assertTrue("two sample homoscedastic t-test reject",
testStatistic.homoscedasticTTest(sample1, sample2, 0.49));
- assertTrue("two sample homoscedastic t-test accept",
+ assertTrue("two sample homoscedastic t-test accept",
!testStatistic.homoscedasticTTest(sample1, sample2, 0.48));
}
-
+
public void testSmallSamples() throws Exception {
double[] sample1 = {1d, 3d};
- double[] sample2 = {4d, 5d};
-
+ double[] sample2 = {4d, 5d};
+
// Target values computed using R, version 1.8.1 (linux version)
assertEquals(-2.2360679775, testStatistic.t(sample1, sample2),
1E-10);
assertEquals(0.198727388935, testStatistic.tTest(sample1, sample2),
1E-10);
}
-
+
public void testPaired() throws Exception {
double[] sample1 = {1d, 3d, 5d, 7d};
double[] sample2 = {0d, 6d, 11d, 2d};
@@ -294,6 +294,6 @@
assertEquals(0.774544295819, testStatistic.pairedTTest(sample1, sample2), 1E-10);
assertEquals(0.001208, testStatistic.pairedTTest(sample1, sample3), 1E-6);
assertFalse(testStatistic.pairedTTest(sample1, sample3, .001));
- assertTrue(testStatistic.pairedTTest(sample1, sample3, .002));
+ assertTrue(testStatistic.pairedTTest(sample1, sample3, .002));
}
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/TestUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/TestUtilsTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/TestUtilsTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/inference/TestUtilsTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -42,17 +42,17 @@
}
public void testChiSquare() throws Exception {
-
- // Target values computed using R version 1.8.1
- // Some assembly required ;-)
+
+ // Target values computed using R version 1.8.1
+ // Some assembly required ;-)
// Use sum((obs - exp)^2/exp) for the chi-square statistic and
// 1 - pchisq(sum((obs - exp)^2/exp), length(obs) - 1) for the p-value
-
+
long[] observed = {10, 9, 11};
double[] expected = {10, 10, 10};
assertEquals("chi-square statistic", 0.2, TestUtils.chiSquare(expected, observed), 10E-12);
assertEquals("chi-square p-value", 0.904837418036, TestUtils.chiSquareTest(expected, observed), 1E-10);
-
+
long[] observed1 = { 500, 623, 72, 70, 31 };
double[] expected1 = { 485, 541, 82, 61, 37 };
assertEquals( "chi-square test statistic", 9.023307936427388, TestUtils.chiSquare(expected1, observed1), 1E-10);
@@ -65,8 +65,8 @@
fail("alpha out of range, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
long[] tooShortObs = { 0 };
double[] tooShortEx = { 1 };
try {
@@ -85,7 +85,7 @@
} catch (IllegalArgumentException ex) {
// expected
}
-
+
// 0 expected count
expected[0] = 0;
try {
@@ -93,8 +93,8 @@
fail("bad expected count, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
// negative observed count
expected[0] = 1;
observed[0] = -1;
@@ -103,25 +103,25 @@
fail("bad expected count, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
}
public void testChiSquareIndependence() throws Exception {
-
- // Target values computed using R version 1.8.1
-
+
+ // Target values computed using R version 1.8.1
+
long[][] counts = { {40, 22, 43}, {91, 21, 28}, {60, 10, 22}};
assertEquals( "chi-square test statistic", 22.709027688, TestUtils.chiSquare(counts), 1E-9);
assertEquals("chi-square p-value", 0.000144751460134, TestUtils.chiSquareTest(counts), 1E-9);
assertTrue("chi-square test reject", TestUtils.chiSquareTest(counts, 0.0002));
- assertTrue("chi-square test accept", !TestUtils.chiSquareTest(counts, 0.0001));
-
+ assertTrue("chi-square test accept", !TestUtils.chiSquareTest(counts, 0.0001));
+
long[][] counts2 = {{10, 15}, {30, 40}, {60, 90} };
assertEquals( "chi-square test statistic", 0.168965517241, TestUtils.chiSquare(counts2), 1E-9);
assertEquals("chi-square p-value",0.918987499852, TestUtils.chiSquareTest(counts2), 1E-9);
- assertTrue("chi-square test accept", !TestUtils.chiSquareTest(counts2, 0.1));
-
+ assertTrue("chi-square test accept", !TestUtils.chiSquareTest(counts2, 0.1));
+
// ragged input array
long[][] counts3 = { {40, 22, 43}, {91, 21, 28}, {60, 10}};
try {
@@ -130,7 +130,7 @@
} catch (IllegalArgumentException ex) {
// expected
}
-
+
// insufficient data
long[][] counts4 = {{40, 22, 43}};
try {
@@ -138,15 +138,15 @@
fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// expected
- }
+ }
long[][] counts5 = {{40}, {40}, {30}, {10}};
try {
TestUtils.chiSquare(counts5);
fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
// negative counts
long[][] counts6 = {{10, -2}, {30, 40}, {60, 90} };
try {
@@ -154,20 +154,20 @@
fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
// bad alpha
try {
TestUtils.chiSquareTest(counts, 0);
fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// expected
- }
+ }
}
-
+
public void testChiSquareLargeTestStatistic() throws Exception {
double[] exp = new double[] {
- 3389119.5, 649136.6, 285745.4, 25357364.76, 11291189.78, 543628.0,
+ 3389119.5, 649136.6, 285745.4, 25357364.76, 11291189.78, 543628.0,
232921.0, 437665.75
};
@@ -175,26 +175,26 @@
2372383, 584222, 257170, 17750155, 7903832, 489265, 209628, 393899
};
org.apache.commons.math.stat.inference.ChiSquareTestImpl csti =
- new org.apache.commons.math.stat.inference.ChiSquareTestImpl();
- double cst = csti.chiSquareTest(exp, obs);
+ new org.apache.commons.math.stat.inference.ChiSquareTestImpl();
+ double cst = csti.chiSquareTest(exp, obs);
assertEquals("chi-square p-value", 0.0, cst, 1E-3);
- assertEquals( "chi-square test statistic",
+ assertEquals( "chi-square test statistic",
114875.90421929007, TestUtils.chiSquare(exp, obs), 1E-9);
}
-
+
/** Contingency table containing zeros - PR # 32531 */
public void testChiSquareZeroCount() throws Exception {
- // Target values computed using R version 1.8.1
+ // Target values computed using R version 1.8.1
long[][] counts = { {40, 0, 4}, {91, 1, 2}, {60, 2, 0}};
assertEquals( "chi-square test statistic", 9.67444662263,
TestUtils.chiSquare(counts), 1E-9);
assertEquals("chi-square p-value", 0.0462835770603,
- TestUtils.chiSquareTest(counts), 1E-9);
+ TestUtils.chiSquareTest(counts), 1E-9);
}
-
+
private double[] tooShortObs = { 1.0 };
private double[] emptyObs = {};
- private SummaryStatistics emptyStats = new SummaryStatistics();
+ private SummaryStatistics emptyStats = new SummaryStatistics();
public void testOneSampleT() throws Exception {
double[] observed =
@@ -236,7 +236,7 @@
} catch (IllegalArgumentException ex) {
// expected
}
-
+
try {
TestUtils.t(mu, emptyStats);
fail("arguments too short, IllegalArgumentException expected");
@@ -255,7 +255,7 @@
fail("insufficient data to perform t test, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
+ }
try {
TestUtils.t(mu, (SummaryStatistics) null);
@@ -268,20 +268,20 @@
fail("insufficient data to perform t test, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
+ }
}
-
+
public void testOneSampleTTest() throws Exception {
double[] oneSidedP =
{2d, 0d, 6d, 6d, 3d, 3d, 2d, 3d, -6d, 6d, 6d, 6d, 3d, 0d, 1d, 1d, 0d, 2d, 3d, 3d };
- SummaryStatistics oneSidedPStats = new SummaryStatistics();
+ SummaryStatistics oneSidedPStats = new SummaryStatistics();
for (int i = 0; i < oneSidedP.length; i++) {
oneSidedPStats.addValue(oneSidedP[i]);
}
// Target comparison values computed using R version 1.8.1 (Linux version)
- assertEquals("one sample t stat", 3.86485535541,
+ assertEquals("one sample t stat", 3.86485535541,
TestUtils.t(0d, oneSidedP), 10E-10);
- assertEquals("one sample t stat", 3.86485535541,
+ assertEquals("one sample t stat", 3.86485535541,
TestUtils.t(0d, oneSidedPStats),1E-10);
assertEquals("one sample p value", 0.000521637019637,
TestUtils.tTest(0d, oneSidedP) / 2d, 10E-10);
@@ -291,102 +291,102 @@
assertTrue("one sample t-test reject", TestUtils.tTest(0d, oneSidedPStats, 0.01));
assertTrue("one sample t-test accept", !TestUtils.tTest(0d, oneSidedP, 0.0001));
assertTrue("one sample t-test accept", !TestUtils.tTest(0d, oneSidedPStats, 0.0001));
-
+
try {
TestUtils.tTest(0d, oneSidedP, 95);
fail("alpha out of range, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
try {
TestUtils.tTest(0d, oneSidedPStats, 95);
fail("alpha out of range, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
}
-
+
public void testTwoSampleTHeterscedastic() throws Exception {
double[] sample1 = { 7d, -4d, 18d, 17d, -3d, -5d, 1d, 10d, 11d, -2d };
double[] sample2 = { -1d, 12d, -1d, -3d, 3d, -5d, 5d, 2d, -11d, -1d, -3d };
- SummaryStatistics sampleStats1 = new SummaryStatistics();
+ SummaryStatistics sampleStats1 = new SummaryStatistics();
for (int i = 0; i < sample1.length; i++) {
sampleStats1.addValue(sample1[i]);
}
- SummaryStatistics sampleStats2 = new SummaryStatistics();
+ SummaryStatistics sampleStats2 = new SummaryStatistics();
for (int i = 0; i < sample2.length; i++) {
sampleStats2.addValue(sample2[i]);
}
-
+
// Target comparison values computed using R version 1.8.1 (Linux version)
- assertEquals("two sample heteroscedastic t stat", 1.60371728768,
+ assertEquals("two sample heteroscedastic t stat", 1.60371728768,
TestUtils.t(sample1, sample2), 1E-10);
- assertEquals("two sample heteroscedastic t stat", 1.60371728768,
+ assertEquals("two sample heteroscedastic t stat", 1.60371728768,
TestUtils.t(sampleStats1, sampleStats2), 1E-10);
- assertEquals("two sample heteroscedastic p value", 0.128839369622,
+ assertEquals("two sample heteroscedastic p value", 0.128839369622,
TestUtils.tTest(sample1, sample2), 1E-10);
- assertEquals("two sample heteroscedastic p value", 0.128839369622,
- TestUtils.tTest(sampleStats1, sampleStats2), 1E-10);
- assertTrue("two sample heteroscedastic t-test reject",
+ assertEquals("two sample heteroscedastic p value", 0.128839369622,
+ TestUtils.tTest(sampleStats1, sampleStats2), 1E-10);
+ assertTrue("two sample heteroscedastic t-test reject",
TestUtils.tTest(sample1, sample2, 0.2));
- assertTrue("two sample heteroscedastic t-test reject",
+ assertTrue("two sample heteroscedastic t-test reject",
TestUtils.tTest(sampleStats1, sampleStats2, 0.2));
- assertTrue("two sample heteroscedastic t-test accept",
+ assertTrue("two sample heteroscedastic t-test accept",
!TestUtils.tTest(sample1, sample2, 0.1));
- assertTrue("two sample heteroscedastic t-test accept",
+ assertTrue("two sample heteroscedastic t-test accept",
!TestUtils.tTest(sampleStats1, sampleStats2, 0.1));
-
+
try {
TestUtils.tTest(sample1, sample2, .95);
fail("alpha out of range, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
try {
TestUtils.tTest(sampleStats1, sampleStats2, .95);
fail("alpha out of range, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
- // expected
- }
-
+ // expected
+ }
+
try {
TestUtils.tTest(sample1, tooShortObs, .01);
fail("insufficient data, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
try {
TestUtils.tTest(sampleStats1, (SummaryStatistics) null, .01);
fail("insufficient data, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
try {
TestUtils.tTest(sample1, tooShortObs);
fail("insufficient data, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
try {
TestUtils.tTest(sampleStats1, (SummaryStatistics) null);
fail("insufficient data, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
- }
-
+ }
+
try {
TestUtils.t(sample1, tooShortObs);
fail("insufficient data, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
// expected
}
-
+
try {
TestUtils.t(sampleStats1, (SummaryStatistics) null);
fail("insufficient data, IllegalArgumentException expected");
@@ -397,37 +397,37 @@
public void testTwoSampleTHomoscedastic() throws Exception {
double[] sample1 ={2, 4, 6, 8, 10, 97};
double[] sample2 = {4, 6, 8, 10, 16};
- SummaryStatistics sampleStats1 = new SummaryStatistics();
+ SummaryStatistics sampleStats1 = new SummaryStatistics();
for (int i = 0; i < sample1.length; i++) {
sampleStats1.addValue(sample1[i]);
}
- SummaryStatistics sampleStats2 = new SummaryStatistics();
+ SummaryStatistics sampleStats2 = new SummaryStatistics();
for (int i = 0; i < sample2.length; i++) {
sampleStats2.addValue(sample2[i]);
}
-
+
// Target comparison values computed using R version 1.8.1 (Linux version)
- assertEquals("two sample homoscedastic t stat", 0.73096310086,
+ assertEquals("two sample homoscedastic t stat", 0.73096310086,
TestUtils.homoscedasticT(sample1, sample2), 10E-11);
- assertEquals("two sample homoscedastic p value", 0.4833963785,
- TestUtils.homoscedasticTTest(sampleStats1, sampleStats2), 1E-10);
- assertTrue("two sample homoscedastic t-test reject",
+ assertEquals("two sample homoscedastic p value", 0.4833963785,
+ TestUtils.homoscedasticTTest(sampleStats1, sampleStats2), 1E-10);
+ assertTrue("two sample homoscedastic t-test reject",
TestUtils.homoscedasticTTest(sample1, sample2, 0.49));
- assertTrue("two sample homoscedastic t-test accept",
+ assertTrue("two sample homoscedastic t-test accept",
!TestUtils.homoscedasticTTest(sample1, sample2, 0.48));
}
-
+
public void testSmallSamples() throws Exception {
double[] sample1 = {1d, 3d};
- double[] sample2 = {4d, 5d};
-
+ double[] sample2 = {4d, 5d};
+
// Target values computed using R, version 1.8.1 (linux version)
assertEquals(-2.2360679775, TestUtils.t(sample1, sample2),
1E-10);
assertEquals(0.198727388935, TestUtils.tTest(sample1, sample2),
1E-10);
}
-
+
public void testPaired() throws Exception {
double[] sample1 = {1d, 3d, 5d, 7d};
double[] sample2 = {0d, 6d, 11d, 2d};
@@ -438,28 +438,28 @@
assertEquals(0.774544295819, TestUtils.pairedTTest(sample1, sample2), 1E-10);
assertEquals(0.001208, TestUtils.pairedTTest(sample1, sample3), 1E-6);
assertFalse(TestUtils.pairedTTest(sample1, sample3, .001));
- assertTrue(TestUtils.pairedTTest(sample1, sample3, .002));
+ assertTrue(TestUtils.pairedTTest(sample1, sample3, .002));
}
-
+
private double[] classA =
{93.0, 103.0, 95.0, 101.0};
private double[] classB =
{99.0, 92.0, 102.0, 100.0, 102.0};
private double[] classC =
{110.0, 115.0, 111.0, 117.0, 128.0};
-
+
private List<double[]> classes = new ArrayList<double[]>();
private OneWayAnova oneWayAnova = new OneWayAnovaImpl();
-
+
public void testOneWayAnovaUtils() throws Exception {
classes.add(classA);
classes.add(classB);
classes.add(classC);
- assertEquals(oneWayAnova.anovaFValue(classes),
+ assertEquals(oneWayAnova.anovaFValue(classes),
TestUtils.oneWayAnovaFValue(classes), 10E-12);
- assertEquals(oneWayAnova.anovaPValue(classes),
+ assertEquals(oneWayAnova.anovaPValue(classes),
TestUtils.oneWayAnovaPValue(classes), 10E-12);
- assertEquals(oneWayAnova.anovaTest(classes, 0.01),
- TestUtils.oneWayAnovaTest(classes, 0.01));
- }
+ assertEquals(oneWayAnova.anovaTest(classes, 0.01),
+ TestUtils.oneWayAnovaTest(classes, 0.01));
+ }
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/ranking/NaturalRankingTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/ranking/NaturalRankingTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/ranking/NaturalRankingTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/ranking/NaturalRankingTest.java Sat Sep 5 17:36:48 2009
@@ -24,7 +24,7 @@
/**
* Test cases for NaturalRanking class
- *
+ *
* @since 2.0
* @version $Revision$ $Date$
*/
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/GLSMultipleLinearRegressionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/GLSMultipleLinearRegressionTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/GLSMultipleLinearRegressionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/GLSMultipleLinearRegressionTest.java Sat Sep 5 17:36:48 2009
@@ -45,7 +45,7 @@
omega[5] = new double[]{0, 0, 0, 0, 0, 6.0};
super.setUp();
}
-
+
@Test(expected=IllegalArgumentException.class)
public void cannotAddXSampleData() {
createRegression().newSampleData(new double[]{}, null, null);
@@ -55,7 +55,7 @@
public void cannotAddNullYSampleData() {
createRegression().newSampleData(null, new double[][]{}, null);
}
-
+
@Test(expected=IllegalArgumentException.class)
public void cannotAddSampleDataWithSizeMismatch() {
double[] y = new double[]{1.0, 2.0};
@@ -63,12 +63,12 @@
x[0] = new double[]{1.0, 0};
createRegression().newSampleData(y, x, null);
}
-
+
@Test(expected=IllegalArgumentException.class)
public void cannotAddNullCovarianceData() {
createRegression().newSampleData(new double[]{}, new double[][]{}, null);
}
-
+
@Test(expected=IllegalArgumentException.class)
public void notEnoughData() {
double[] reducedY = new double[y.length - 1];
@@ -79,7 +79,7 @@
System.arraycopy(omega, 0, reducedO, 0, reducedO.length);
createRegression().newSampleData(reducedY, reducedX, reducedO);
}
-
+
@Test(expected=IllegalArgumentException.class)
public void cannotAddCovarianceDataWithSampleSizeMismatch() {
double[] y = new double[]{1.0, 2.0};
@@ -120,5 +120,5 @@
protected int getSampleSize() {
return y.length;
}
-
+
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/MultipleLinearRegressionAbstractTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/MultipleLinearRegressionAbstractTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/MultipleLinearRegressionAbstractTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/MultipleLinearRegressionAbstractTest.java Sat Sep 5 17:36:48 2009
@@ -33,14 +33,14 @@
}
protected abstract MultipleLinearRegression createRegression();
-
+
protected abstract int getNumberOfRegressors();
-
+
protected abstract int getSampleSize();
@Test
public void canEstimateRegressionParameters(){
- double[] beta = regression.estimateRegressionParameters();
+ double[] beta = regression.estimateRegressionParameters();
assertEquals(getNumberOfRegressors(), beta.length);
}
@@ -49,7 +49,7 @@
double[] e = regression.estimateResiduals();
assertEquals(getSampleSize(), e.length);
}
-
+
@Test
public void canEstimateRegressionParametersVariance(){
double[][] variance = regression.estimateRegressionParametersVariance();
@@ -62,6 +62,6 @@
double variance = regression.estimateRegressandVariance();
assertTrue(variance > 0.0);
}
- }
+ }
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegressionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegressionTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegressionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegressionTest.java Sat Sep 5 17:36:48 2009
@@ -31,7 +31,7 @@
private double[] y;
private double[][] x;
-
+
@Before
@Override
public void setUp(){
@@ -62,7 +62,7 @@
protected int getSampleSize() {
return y.length;
}
-
+
@Test(expected=IllegalArgumentException.class)
public void cannotAddXSampleData() {
createRegression().newSampleData(new double[]{}, null);
@@ -72,7 +72,7 @@
public void cannotAddNullYSampleData() {
createRegression().newSampleData(null, new double[][]{});
}
-
+
@Test(expected=IllegalArgumentException.class)
public void cannotAddSampleDataWithSizeMismatch() {
double[] y = new double[]{1.0, 2.0};
@@ -80,11 +80,11 @@
x[0] = new double[]{1.0, 0};
createRegression().newSampleData(y, x);
}
-
+
@Test
public void testPerfectFit() {
double[] betaHat = regression.estimateRegressionParameters();
- TestUtils.assertEquals(betaHat,
+ TestUtils.assertEquals(betaHat,
new double[]{ 11.0, 1.0 / 2.0, 2.0 / 3.0, 3.0 / 4.0, 4.0 / 5.0, 5.0 / 6.0 },
1e-14);
double[] residuals = regression.estimateResiduals();
@@ -109,15 +109,15 @@
errors.subtract(referenceVariance).getNorm(),
5.0e-16 * referenceVariance.getNorm());
}
-
-
+
+
/**
* Test Longley dataset against certified values provided by NIST.
* Data Source: J. Longley (1967) "An Appraisal of Least Squares
* Programs for the Electronic Computer from the Point of View of the User"
* Journal of the American Statistical Association, vol. 62. September,
* pp. 819-841.
- *
+ *
* Certified values (and data) are from NIST:
* http://www.itl.nist.gov/div898/strd/lls/data/LINKS/DATA/Longley.dat
*/
@@ -143,23 +143,23 @@
69331,115.7,518173,4806,2572,127852,1961,
70551,116.9,554894,4007,2827,130081,1962
};
-
+
// Transform to Y and X required by interface
int nobs = 16;
int nvars = 6;
-
+
// Estimate the model
OLSMultipleLinearRegression model = new OLSMultipleLinearRegression();
model.newSampleData(design, nobs, nvars);
-
+
// Check expected beta values from NIST
double[] betaHat = model.estimateRegressionParameters();
- TestUtils.assertEquals(betaHat,
+ TestUtils.assertEquals(betaHat,
new double[]{-3482258.63459582, 15.0618722713733,
-0.358191792925910E-01,-2.02022980381683,
-1.03322686717359,-0.511041056535807E-01,
- 1829.15146461355}, 2E-8); //
-
+ 1829.15146461355}, 2E-8); //
+
// Check expected residuals from R
double[] residuals = model.estimateResiduals();
TestUtils.assertEquals(residuals, new double[]{
@@ -170,7 +170,7 @@
-155.5499735953195,-85.6713080421283,341.9315139607727,
-206.7578251937366},
1E-8);
-
+
// Check standard errors from NIST
double[] errors = model.estimateRegressionParametersStandardErrors();
TestUtils.assertEquals(new double[] {890420.383607373,
@@ -179,9 +179,9 @@
0.488399681651699,
0.214274163161675,
0.226073200069370,
- 455.478499142212}, errors, 1E-6);
+ 455.478499142212}, errors, 1E-6);
}
-
+
/**
* Test R Swiss fertility dataset against R.
* Data Source: R datasets package
@@ -248,7 +248,7 @@
// Check expected beta values from R
double[] betaHat = model.estimateRegressionParameters();
- TestUtils.assertEquals(betaHat,
+ TestUtils.assertEquals(betaHat,
new double[]{91.05542390271397,
-0.22064551045715,
-0.26058239824328,
@@ -274,30 +274,30 @@
5.4326230830188482,-7.2375578629692230,2.1671550814448222,
15.0147574652763112,4.8625103516321015,-7.1597256413907706,
-0.4515205619767598,-10.2916870903837587,-15.7812984571900063},
- 1E-12);
-
+ 1E-12);
+
// Check standard errors from R
double[] errors = model.estimateRegressionParametersStandardErrors();
TestUtils.assertEquals(new double[] {6.94881329475087,
0.07360008972340,
0.27410957467466,
0.19454551679325,
- 0.03726654773803}, errors, 1E-10);
+ 0.03726654773803}, errors, 1E-10);
}
-
+
/**
* Test hat matrix computation
- *
+ *
* @throws Exception
*/
@Test
public void testHat() throws Exception {
-
+
/*
- * This example is from "The Hat Matrix in Regression and ANOVA",
- * David C. Hoaglin and Roy E. Welsch,
+ * This example is from "The Hat Matrix in Regression and ANOVA",
+ * David C. Hoaglin and Roy E. Welsch,
* The American Statistician, Vol. 32, No. 1 (Feb., 1978), pp. 17-22.
- *
+ *
*/
double[] design = new double[] {
11.14, .499, 11.1,
@@ -311,16 +311,16 @@
11.02, .406, 10.5,
11.41, .467, 10.7
};
-
+
int nobs = 10;
int nvars = 2;
-
+
// Estimate the model
OLSMultipleLinearRegression model = new OLSMultipleLinearRegression();
model.newSampleData(design, nobs, nvars);
-
+
RealMatrix hat = model.calculateHat();
-
+
// Reference data is upper half of symmetric hat matrix
double[] referenceData = new double[] {
.418, -.002, .079, -.274, -.046, .181, .128, .222, .050, .242,
@@ -334,24 +334,24 @@
.315, .148,
.187
};
-
+
// Check against reference data and verify symmetry
int k = 0;
for (int i = 0; i < 10; i++) {
for (int j = i; j < 10; j++) {
assertEquals(referenceData[k], hat.getEntry(i, j), 10e-3);
assertEquals(hat.getEntry(i, j), hat.getEntry(j, i), 10e-12);
- k++;
+ k++;
}
}
-
- /*
- * Verify that residuals computed using the hat matrix are close to
+
+ /*
+ * Verify that residuals computed using the hat matrix are close to
* what we get from direct computation, i.e. r = (I - H) y
*/
double[] residuals = model.estimateResiduals();
RealMatrix I = MatrixUtils.createRealIdentityMatrix(10);
double[] hatResiduals = I.subtract(hat).operate(model.Y).getData();
- TestUtils.assertEquals(residuals, hatResiduals, 10e-12);
+ TestUtils.assertEquals(residuals, hatResiduals, 10e-12);
}
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/SimpleRegressionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/SimpleRegressionTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/SimpleRegressionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/regression/SimpleRegressionTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,39 +29,39 @@
public final class SimpleRegressionTest extends TestCase {
- /*
- * NIST "Norris" refernce data set from
+ /*
+ * NIST "Norris" refernce data set from
* http://www.itl.nist.gov/div898/strd/lls/data/LINKS/DATA/Norris.dat
* Strangely, order is {y,x}
*/
- private double[][] data = { { 0.1, 0.2 }, {338.8, 337.4 }, {118.1, 118.2 },
- {888.0, 884.6 }, {9.2, 10.1 }, {228.1, 226.5 }, {668.5, 666.3 }, {998.5, 996.3 },
- {449.1, 448.6 }, {778.9, 777.0 }, {559.2, 558.2 }, {0.3, 0.4 }, {0.1, 0.6 }, {778.1, 775.5 },
- {668.8, 666.9 }, {339.3, 338.0 }, {448.9, 447.5 }, {10.8, 11.6 }, {557.7, 556.0 },
- {228.3, 228.1 }, {998.0, 995.8 }, {888.8, 887.6 }, {119.6, 120.2 }, {0.3, 0.3 },
- {0.6, 0.3 }, {557.6, 556.8 }, {339.3, 339.1 }, {888.0, 887.2 }, {998.5, 999.0 },
- {778.9, 779.0 }, {10.2, 11.1 }, {117.6, 118.3 }, {228.9, 229.2 }, {668.4, 669.1 },
+ private double[][] data = { { 0.1, 0.2 }, {338.8, 337.4 }, {118.1, 118.2 },
+ {888.0, 884.6 }, {9.2, 10.1 }, {228.1, 226.5 }, {668.5, 666.3 }, {998.5, 996.3 },
+ {449.1, 448.6 }, {778.9, 777.0 }, {559.2, 558.2 }, {0.3, 0.4 }, {0.1, 0.6 }, {778.1, 775.5 },
+ {668.8, 666.9 }, {339.3, 338.0 }, {448.9, 447.5 }, {10.8, 11.6 }, {557.7, 556.0 },
+ {228.3, 228.1 }, {998.0, 995.8 }, {888.8, 887.6 }, {119.6, 120.2 }, {0.3, 0.3 },
+ {0.6, 0.3 }, {557.6, 556.8 }, {339.3, 339.1 }, {888.0, 887.2 }, {998.5, 999.0 },
+ {778.9, 779.0 }, {10.2, 11.1 }, {117.6, 118.3 }, {228.9, 229.2 }, {668.4, 669.1 },
{449.2, 448.9 }, {0.2, 0.5 }
};
- /*
- * Correlation example from
+ /*
+ * Correlation example from
* http://www.xycoon.com/correlation.htm
*/
- private double[][] corrData = { { 101.0, 99.2 }, {100.1, 99.0 }, {100.0, 100.0 },
- {90.6, 111.6 }, {86.5, 122.2 }, {89.7, 117.6 }, {90.6, 121.1 }, {82.8, 136.0 },
- {70.1, 154.2 }, {65.4, 153.6 }, {61.3, 158.5 }, {62.5, 140.6 }, {63.6, 136.2 },
+ private double[][] corrData = { { 101.0, 99.2 }, {100.1, 99.0 }, {100.0, 100.0 },
+ {90.6, 111.6 }, {86.5, 122.2 }, {89.7, 117.6 }, {90.6, 121.1 }, {82.8, 136.0 },
+ {70.1, 154.2 }, {65.4, 153.6 }, {61.3, 158.5 }, {62.5, 140.6 }, {63.6, 136.2 },
{52.6, 168.0 }, {59.7, 154.3 }, {59.5, 149.0 }, {61.3, 165.5 }
};
/*
* From Moore and Mcabe, "Introduction to the Practice of Statistics"
- * Example 10.3
+ * Example 10.3
*/
private double[][] infData = { { 15.6, 5.2 }, {26.8, 6.1 }, {37.8, 8.7 }, {36.4, 8.5 },
{35.5, 8.8 }, {18.6, 4.9 }, {15.3, 4.5 }, {7.9, 2.5 }, {0.0, 1.1 }
};
-
+
/*
* Points to remove in the remove tests
*/
@@ -69,8 +69,8 @@
private double[][] removeMultiple = { infData[1], infData[2] };
private double removeX = infData[0][0];
private double removeY = infData[0][1];
-
-
+
+
/*
* Data with bad linear fit
*/
@@ -93,7 +93,7 @@
for (int i = 0; i < data.length; i++) {
regression.addData(data[i][1], data[i][0]);
}
- // Tests against certified values from
+ // Tests against certified values from
// http://www.itl.nist.gov/div898/strd/lls/data/LINKS/DATA/Norris.dat
assertEquals("slope", 1.00211681802045, regression.getSlope(), 10E-12);
assertEquals("slope std err", 0.429796848199937E-03,
@@ -112,7 +112,7 @@
assertEquals("SSE", 26.6173985294224,
regression.getSumSquaredErrors(),10E-9);
// ------------ End certified data tests
-
+
assertEquals( "predict(0)", -0.262323073774029,
regression.predict(0), 10E-12);
assertEquals("predict(1)", 1.00211681802045 - 0.262323073774029,
@@ -164,7 +164,7 @@
regression.addData(1, 2);
regression.addData(3, 3);
- // All should be OK except MSE, s(b0), s(b1) which need one more df
+ // All should be OK except MSE, s(b0), s(b1) which need one more df
assertTrue("interceptNaN", !Double.isNaN(regression.getIntercept()));
assertTrue("slope NaN", !Double.isNaN(regression.getSlope()));
assertTrue ("slope std err not NaN", Double.isNaN(regression.getSlopeStdErr()));
@@ -207,8 +207,8 @@
assertEquals("std err intercept", 0.286036932,
regression.getInterceptStdErr(),1E-8);
assertEquals("significance", 4.596e-07,
- regression.getSignificance(),1E-8);
- assertEquals("slope conf interval half-width", 0.0270713794287,
+ regression.getSignificance(),1E-8);
+ assertEquals("slope conf interval half-width", 0.0270713794287,
regression.getSlopeConfidenceInterval(),1E-8);
// infData2
regression = new SimpleRegression();
@@ -218,21 +218,21 @@
assertEquals("std err intercept",4.17718672,
regression.getInterceptStdErr(),1E-8);
assertEquals("significance", 0.261829133982,
- regression.getSignificance(),1E-11);
- assertEquals("slope conf interval half-width", 2.97802204827,
+ regression.getSignificance(),1E-11);
+ assertEquals("slope conf interval half-width", 2.97802204827,
regression.getSlopeConfidenceInterval(),1E-8);
//------------- End R-verified tests -------------------------------
-
+
//FIXME: get a real example to test against with alpha = .01
assertTrue("tighter means wider",
regression.getSlopeConfidenceInterval() < regression.getSlopeConfidenceInterval(0.01));
-
+
try {
regression.getSlopeConfidenceInterval(1);
fail("expecting IllegalArgumentException for alpha = 1");
} catch (IllegalArgumentException ex) {
// ignored
- }
+ }
}
@@ -253,9 +253,9 @@
for (int i = 0; i < n; i++) {
regression.addData(- ((double) i) / (n - 1), i);
}
-
+
assertEquals(0.0, regression.getSignificance(), 1.0e-5);
- assertTrue(regression.getSlope() < 0.0);
+ assertTrue(regression.getSlope() < 0.0);
}
public void testRandom() throws Exception {
@@ -267,10 +267,10 @@
}
assertTrue( 0.0 < regression.getSignificance()
- && regression.getSignificance() < 1.0);
+ && regression.getSignificance() < 1.0);
}
-
-
+
+
// Jira MATH-85 = Bugzilla 39432
public void testSSENonNegative() {
double[] y = { 8915.102, 8919.302, 8923.502 };
@@ -280,8 +280,8 @@
reg.addData(x[i], y[i]);
}
assertTrue(reg.getSumSquaredErrors() >= 0.0);
- }
-
+ }
+
// Test remove X,Y (single observation)
public void testRemoveXY() throws Exception {
// Create regression with inference data then remove to test
@@ -295,12 +295,12 @@
assertEquals("std err intercept", 0.286036932,
regression.getInterceptStdErr(),1E-8);
assertEquals("significance", 4.596e-07,
- regression.getSignificance(),1E-8);
- assertEquals("slope conf interval half-width", 0.0270713794287,
+ regression.getSignificance(),1E-8);
+ assertEquals("slope conf interval half-width", 0.0270713794287,
regression.getSlopeConfidenceInterval(),1E-8);
}
-
-
+
+
// Test remove single observation in array
public void testRemoveSingle() throws Exception {
// Create regression with inference data then remove to test
@@ -314,11 +314,11 @@
assertEquals("std err intercept", 0.286036932,
regression.getInterceptStdErr(),1E-8);
assertEquals("significance", 4.596e-07,
- regression.getSignificance(),1E-8);
- assertEquals("slope conf interval half-width", 0.0270713794287,
+ regression.getSignificance(),1E-8);
+ assertEquals("slope conf interval half-width", 0.0270713794287,
regression.getSlopeConfidenceInterval(),1E-8);
}
-
+
// Test remove multiple observations
public void testRemoveMultiple() throws Exception {
// Create regression with inference data then remove to test
@@ -332,18 +332,18 @@
assertEquals("std err intercept", 0.286036932,
regression.getInterceptStdErr(),1E-8);
assertEquals("significance", 4.596e-07,
- regression.getSignificance(),1E-8);
- assertEquals("slope conf interval half-width", 0.0270713794287,
+ regression.getSignificance(),1E-8);
+ assertEquals("slope conf interval half-width", 0.0270713794287,
regression.getSlopeConfidenceInterval(),1E-8);
}
-
+
// Remove observation when empty
public void testRemoveObsFromEmpty() {
SimpleRegression regression = new SimpleRegression();
regression.removeData(removeX, removeY);
assertEquals(regression.getN(), 0);
}
-
+
// Remove single observation to empty
public void testRemoveObsFromSingle() {
SimpleRegression regression = new SimpleRegression();
@@ -351,7 +351,7 @@
regression.removeData(removeX, removeY);
assertEquals(regression.getN(), 0);
}
-
+
// Remove multiple observations to empty
public void testRemoveMultipleToEmpty() {
SimpleRegression regression = new SimpleRegression();
@@ -359,7 +359,7 @@
regression.removeData(removeMultiple);
assertEquals(regression.getN(), 0);
}
-
+
// Remove multiple observations past empty (i.e. size of array > n)
public void testRemoveMultiplePastEmpty() {
SimpleRegression regression = new SimpleRegression();
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastCosineTransformerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastCosineTransformerTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastCosineTransformerTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastCosineTransformerTest.java Sat Sep 5 17:36:48 2009
@@ -25,8 +25,8 @@
* <p>
* FCT algorithm is exact, the small tolerance number is used only
* to account for round-off errors.
- *
- * @version $Revision$ $Date$
+ *
+ * @version $Revision$ $Date$
*/
public final class FastCosineTransformerTest extends TestCase {
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastFourierTransformerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastFourierTransformerTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastFourierTransformerTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastFourierTransformerTest.java Sat Sep 5 17:36:48 2009
@@ -26,8 +26,8 @@
* <p>
* FFT algorithm is exact, the small tolerance number is used only
* to account for round-off errors.
- *
- * @version $Revision$ $Date$
+ *
+ * @version $Revision$ $Date$
*/
public final class FastFourierTransformerTest extends TestCase {
@@ -77,7 +77,7 @@
assertEquals(y2[i].getImaginary(), result[i].getImaginary(), tolerance);
}
}
-
+
public void test2DData() {
FastFourierTransformer transformer = new FastFourierTransformer();
double tolerance = 1E-12;
@@ -90,14 +90,14 @@
-1.5), new Complex(0, .5)}};
Complex[][] output = (Complex[][])transformer.mdfft(input, true);
Complex[][] output2 = (Complex[][])transformer.mdfft(output, false);
-
+
assertEquals(input.length, output.length);
assertEquals(input.length, output2.length);
assertEquals(input[0].length, output[0].length);
assertEquals(input[0].length, output2[0].length);
assertEquals(input[1].length, output[1].length);
assertEquals(input[1].length, output2[1].length);
-
+
for (int i = 0; i < input.length; i++) {
for (int j = 0; j < input[0].length; j++) {
assertEquals(input[i][j].getImaginary(), output2[i][j].getImaginary(),
@@ -109,7 +109,7 @@
}
}
}
-
+
/**
* Test of transformer for the sine function.
*/
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastHadamardTransformerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastHadamardTransformerTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastHadamardTransformerTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastHadamardTransformerTest.java Sat Sep 5 17:36:48 2009
@@ -98,7 +98,7 @@
}
}
-
+
private void checkInverseDoubleTransform(int[]x, int[] y) {
// Initiate the transformer
FastHadamardTransformer transformer = new FastHadamardTransformer();
@@ -115,5 +115,5 @@
}
}
-
+
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java Sat Sep 5 17:36:48 2009
@@ -25,8 +25,8 @@
* <p>
* FST algorithm is exact, the small tolerance number is used only
* to account for round-off errors.
- *
- * @version $Revision$ $Date$
+ *
+ * @version $Revision$ $Date$
*/
public final class FastSineTransformerTest extends TestCase {
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/ContinuedFractionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/ContinuedFractionTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/ContinuedFractionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/ContinuedFractionTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -34,7 +34,7 @@
public void testGoldenRatio(){
ContinuedFraction cf = new ContinuedFraction() {
-
+
@Override
public double getA(int n, double x) {
return 1.0;
@@ -45,7 +45,7 @@
return 1.0;
}
};
-
+
try {
double gr = cf.evaluate(0.0, 10e-9);
assertEquals(1.61803399, gr, 10e-9);
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,7 +29,7 @@
*/
public class DefaultTransformerTest extends TestCase {
/**
- *
+ *
*/
public void testTransformDouble() throws Exception {
double expected = 1.0;
@@ -37,9 +37,9 @@
DefaultTransformer t = new DefaultTransformer();
assertEquals(expected, t.transform(input), 1.0e-4);
}
-
+
/**
- *
+ *
*/
public void testTransformNull(){
DefaultTransformer t = new DefaultTransformer();
@@ -50,29 +50,29 @@
// expected
}
}
-
+
/**
- *
+ *
*/
public void testTransformInteger() throws Exception {
double expected = 1.0;
Integer input = Integer.valueOf(1);
DefaultTransformer t = new DefaultTransformer();
assertEquals(expected, t.transform(input), 1.0e-4);
- }
-
+ }
+
/**
- *
+ *
*/
public void testTransformBigDecimal() throws Exception {
double expected = 1.0;
BigDecimal input = new BigDecimal("1.0");
DefaultTransformer t = new DefaultTransformer();
assertEquals(expected, t.transform(input), 1.0e-4);
- }
-
+ }
+
/**
- *
+ *
*/
public void testTransformString() throws Exception {
double expected = 1.0;
@@ -80,9 +80,9 @@
DefaultTransformer t = new DefaultTransformer();
assertEquals(expected, t.transform(input), 1.0e-4);
}
-
+
/**
- *
+ *
*/
public void testTransformObject(){
Boolean input = Boolean.TRUE;
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DoubleArrayAbstractTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DoubleArrayAbstractTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DoubleArrayAbstractTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DoubleArrayAbstractTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,7 +22,7 @@
/**
* This class contains test cases for the ExpandableDoubleArray.
- *
+ *
* @version $Revision$ $Date$
*/
public abstract class DoubleArrayAbstractTest extends TestCase {