You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2012/02/03 20:28:50 UTC
svn commit: r1240310 - in
/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference:
OneWayAnova.java OneWayAnovaImpl.java
Author: tn
Date: Fri Feb 3 19:28:49 2012
New Revision: 1240310
URL: http://svn.apache.org/viewvc?rev=1240310&view=rev
Log:
Fixed exceptions for OneWayAnova interface and impl, removed never thrown MathException.
JIRA: MATH-488 MATH-459
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/OneWayAnova.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/OneWayAnova.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/OneWayAnova.java?rev=1240310&r1=1240309&r2=1240310&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/OneWayAnova.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/OneWayAnova.java Fri Feb 3 19:28:49 2012
@@ -16,7 +16,10 @@
*/
package org.apache.commons.math.stat.inference;
-import org.apache.commons.math.MathException;
+import org.apache.commons.math.exception.DimensionMismatchException;
+import org.apache.commons.math.exception.NullArgumentException;
+import org.apache.commons.math.exception.OutOfRangeException;
+
import java.util.Collection;
/**
@@ -47,12 +50,13 @@ public interface OneWayAnova {
* @param categoryData <code>Collection</code> of <code>double[]</code>
* arrays each containing data for one category
* @return Fvalue
- * @throws IllegalArgumentException if the preconditions are not met
- * @throws MathException if the statistic can not be computed do to a
- * convergence or other numerical error.
+ * @throws NullArgumentException if <code>categoryData</code> is <code>null</code>
+ * @throws DimensionMismatchException if the length of the <code>categoryData</code>
+ * array is less than 2 or a contained <code>double[]</code> array does not have
+ * at least two values
*/
double anovaFValue(Collection<double[]> categoryData)
- throws IllegalArgumentException, MathException;
+ throws NullArgumentException, DimensionMismatchException;
/**
* Computes the ANOVA P-value for a collection of <code>double[]</code>
@@ -68,12 +72,13 @@ public interface OneWayAnova {
* @param categoryData <code>Collection</code> of <code>double[]</code>
* arrays each containing data for one category
* @return Pvalue
- * @throws IllegalArgumentException if the preconditions are not met
- * @throws MathException if the statistic can not be computed do to a
- * convergence or other numerical error.
+ * @throws NullArgumentException if <code>categoryData</code> is <code>null</code>
+ * @throws DimensionMismatchException if the length of the <code>categoryData</code>
+ * array is less than 2 or a contained <code>double[]</code> array does not have
+ * at least two values
*/
double anovaPValue(Collection<double[]> categoryData)
- throws IllegalArgumentException, MathException;
+ throws NullArgumentException, DimensionMismatchException;
/**
* Performs an ANOVA test, evaluating the null hypothesis that there
@@ -93,11 +98,13 @@ public interface OneWayAnova {
* @param alpha significance level of the test
* @return true if the null hypothesis can be rejected with
* confidence 1 - alpha
- * @throws IllegalArgumentException if the preconditions are not met
- * @throws MathException if the statistic can not be computed do to a
- * convergence or other numerical error.
+ * @throws NullArgumentException if <code>categoryData</code> is <code>null</code>
+ * @throws DimensionMismatchException if the length of the <code>categoryData</code>
+ * array is less than 2 or a contained <code>double[]</code> array does not have
+ * at least two values
+ * @throws OutOfRangeException if <code>alpha</code> is not in the range (0, 0.5]
*/
boolean anovaTest(Collection<double[]> categoryData, double alpha)
- throws IllegalArgumentException, MathException;
+ throws NullArgumentException, DimensionMismatchException, OutOfRangeException;
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java?rev=1240310&r1=1240309&r2=1240310&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java Fri Feb 3 19:28:49 2012
@@ -18,9 +18,11 @@ package org.apache.commons.math.stat.inf
import java.util.Collection;
-import org.apache.commons.math.MathException;
-import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.distribution.FDistribution;
+import org.apache.commons.math.exception.DimensionMismatchException;
+import org.apache.commons.math.exception.MathIllegalArgumentException;
+import org.apache.commons.math.exception.NullArgumentException;
+import org.apache.commons.math.exception.OutOfRangeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.stat.descriptive.summary.Sum;
import org.apache.commons.math.stat.descriptive.summary.SumOfSquares;
@@ -65,7 +67,7 @@ public class OneWayAnovaImpl implements
* here</a></p>
*/
public double anovaFValue(Collection<double[]> categoryData)
- throws IllegalArgumentException, MathException {
+ throws MathIllegalArgumentException {
AnovaStats a = anovaStats(categoryData);
return a.F;
}
@@ -81,7 +83,7 @@ public class OneWayAnovaImpl implements
* is the commons-math implementation of the F distribution.</p>
*/
public double anovaPValue(Collection<double[]> categoryData)
- throws IllegalArgumentException, MathException {
+ throws NullArgumentException, DimensionMismatchException {
AnovaStats a = anovaStats(categoryData);
FDistribution fdist = new FDistribution(a.dfbg, a.dfwg);
return 1.0 - fdist.cumulativeProbability(a.F);
@@ -99,11 +101,10 @@ public class OneWayAnovaImpl implements
* <p>True is returned iff the estimated p-value is less than alpha.</p>
*/
public boolean anovaTest(Collection<double[]> categoryData, double alpha)
- throws IllegalArgumentException, MathException {
+ throws NullArgumentException, DimensionMismatchException, OutOfRangeException {
if ((alpha <= 0) || (alpha > 0.5)) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL,
- alpha, 0, 0.5);
+ throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL,
+ alpha, 0, 0.5);
}
return anovaPValue(categoryData) < alpha;
}
@@ -115,26 +116,30 @@ public class OneWayAnovaImpl implements
* @param categoryData <code>Collection</code> of <code>double[]</code>
* arrays each containing data for one category
* @return computed AnovaStats
- * @throws IllegalArgumentException if categoryData does not meet
- * preconditions specified in the interface definition
- * @throws MathException if an error occurs computing the Anova stats
+ * @throws NullArgumentException if <code>categoryData</code> is <code>null</code>
+ * @throws DimensionMismatchException if the length of the <code>categoryData</code>
+ * array is less than 2 or a contained <code>double[]</code> array does not contain
+ * at least two values
*/
private AnovaStats anovaStats(Collection<double[]> categoryData)
- throws IllegalArgumentException, MathException {
+ throws NullArgumentException, DimensionMismatchException {
+
+ if (categoryData == null) {
+ throw new NullArgumentException();
+ }
// check if we have enough categories
if (categoryData.size() < 2) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.TWO_OR_MORE_CATEGORIES_REQUIRED,
- categoryData.size());
+ throw new DimensionMismatchException(LocalizedFormats.TWO_OR_MORE_CATEGORIES_REQUIRED,
+ categoryData.size(), 2);
}
// check if each category has enough data and all is double[]
for (double[] array : categoryData) {
if (array.length <= 1) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.TWO_OR_MORE_VALUES_IN_CATEGORY_REQUIRED,
- array.length);
+ throw new DimensionMismatchException(
+ LocalizedFormats.TWO_OR_MORE_VALUES_IN_CATEGORY_REQUIRED,
+ array.length, 2);
}
}