You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2009/05/09 11:57:05 UTC

svn commit: r773189 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/ java/org/apache/commons/math/stat/inference/ java/org/apache/commons/math/stat/regression/ site/xdoc/

Author: luc
Date: Sat May  9 09:57:04 2009
New Revision: 773189

URL: http://svn.apache.org/viewvc?rev=773189&view=rev
Log:
completed internationalization of all error messages

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/stat/inference/TTestImpl.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java?rev=773189&r1=773188&r2=773189&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java Sat May  9 09:57:04 2009
@@ -91,6 +91,8 @@
     // org.apache.commons.math.optimization.general.AbstractLeastSquaresOptimizer
     // org.apache.commons.math.ode.ContinuousOutputModel
     // org.apache.commons.math.random.UncorrelatedRandomVectorGenerator
+    // org.apache.commons.math.stat.regression.AbstractMultipleLinearRegression
+    // org.apache.commons.math.stat.inference.ChiSquareTestImpl
     { "dimension mismatch {0} != {1}",
       "dimensions incompatibles {0} != {1}" },
 
@@ -333,6 +335,7 @@
       "non sym\u00e9triques n''est pas encore disponible" },
 
     // org.apache.commons.math.linear.decomposition.NonSquareMatrixException
+    // org.apache.commons.math.stat.regression.AbstractMultipleLinearRegression
     { "a {0}x{1} matrix was provided instead of a square matrix",
       "une matrice {0}x{1} a \u00e9t\u00e9 fournie \u00e0 la place d''une matrice carr\u00e9e" },
 
@@ -382,6 +385,10 @@
       "une matrice doit comporter au moins une ligne" },
     { "matrix must have at least one column",
       "une matrice doit comporter au moins une colonne" },
+
+    // org.apache.commons.math.linear.AbstractRealMatrix
+    // org.apache.commons.math.linear.AbstractFieldMatrix
+    // org.apache.commons.math.stat.inference.ChiSquareTestImpl      
     { "some rows have length {0} while others have length {1}",
       "certaines lignes ont une longueur de {0} alors que d''autres ont une longueur de {1}" },
 
@@ -635,9 +642,48 @@
      "les statistiques bas\u00e9es sur des moments externes " +
      "ne peuvent pas \u00eatre remises \u00e0 z\u00e9ro" },
 
+   // org.apache.commons.math.stat.inference.ChiSquareTestImpl
+   { "expected array length = {0}, must be at least 2",
+     "le tableau des valeurs attendues a une longueur de {0}, elle devrait \u00eatre au moins de 2" },
+   { "observed array length = {0}, must be at least 2",
+     "le tableau des valeurs observ\u00e9es a une longueur de {0}, elle devrait \u00eatre au moins de 2" },
+   { "observed counts are all 0 in first observed array",
+     "aucune occurrence dans le premier tableau des observations" },
+   { "observed counts are all 0 in second observed array",
+     "aucune occurrence dans le second tableau des observations" },
+   { "observed counts are both zero for entry {0}",
+     "les occurrences observ\u00e9es sont toutes deux nulles pour l'entr\u00e9e {0}" },
+   { "invalid row dimension: {0} (must be at least 2)",
+     "nombre de lignes invalide : {0} (doit \u00eatre au moins de 2)" },
+   { "invalid column dimension: {0} (must be at least 2)",
+     "nombre de colonnes invalide : {0} (doit \u00eatre au moins de 2)" },
+   { "element {0} is not positive: {1}",
+     "l''\u00e9l\u00e9ment {0} n''est pas positif : {1}" },
+   { "element {0} is negative: {1}",
+     "l''\u00e9l\u00e9ment {0} est n\u00e9gatif : {1}" },
+   { "element ({0}, {1}) is negative: {2}",
+     "l''\u00e9l\u00e9ment ({0}, {1}) est n\u00e9gatif : {2}" },
+
+   // org.apache.commons.math.stat.inference.OneWayAnovaImpl
+   { "two or more categories required, got {0}",
+     "deux cat\u00e9gories ou plus sont n\u00e9cessaires, il y en a {0}" },
+   { "two or more values required in each category, one has {0}",
+     "deux valeurs ou plus sont n\u00e9cessaires pour chaque cat\u00e9gorie, une cat\u00e9gorie en a {0}" },
+
+   // org.apache.commons.math.stat.inference.TTestImpl
+   { "insufficient data for t statistic, needs at least 2, got {0}",
+     "deux valeurs ou plus sont n\u00e9cessaires pour la statistique t, il y en a {0}" },
+
+   // org.apache.commons.math.stat.inference.ChiSquareTestImpl
+   // org.apache.commons.math.stat.inference.TTestImpl
+   // org.apache.commons.math.stat.inference.OneWayAnovaImpl
    // org.apache.commons.math.stat.Regression
-   { "out of bounds significance level {0}, must be in (0, 1)",
-     "niveau de signification {0} hors domaine, doit \u00eatre dans l''intervalle ]0, 1[" },
+   { "out of bounds significance level {0}, must be between {1} and {2}",
+     "niveau de signification {0} hors domaine, doit \u00eatre entre {1} et {2}" },
+
+   // org.apache.commons.math.stat.regression.OLSMultipleLinearRegression
+   { "matrix is not upper-triangular, entry ({0}, {1}) = {2} is too large",
+     "matrice non triangulaire sup\u00e9rieure, l''\u00e9l\u00e9ment ({0}, {1}) = {2} est trop grand" },
 
    // org.apache.commons.math.distribution.AbstractContinuousDistribution
    // org.apache.commons.math.distribution.AbstractIntegerDistribution

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java?rev=773189&r1=773188&r2=773189&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java Sat May  9 09:57:04 2009
@@ -17,6 +17,7 @@
 package org.apache.commons.math.stat.inference;
 
 import org.apache.commons.math.MathException;
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.distribution.ChiSquaredDistribution;
 import org.apache.commons.math.distribution.ChiSquaredDistributionImpl;
 
@@ -62,14 +63,17 @@
      */
     public double chiSquare(double[] expected, long[] observed)
         throws IllegalArgumentException {
-        if ((expected.length < 2) || (expected.length != observed.length)) {
-            throw new IllegalArgumentException(
-                    "observed, expected array lengths incorrect");
-        }
-        if (!isPositive(expected) || !isNonNegative(observed)) {
-            throw new IllegalArgumentException(
-                "observed counts must be non-negative and expected counts must be postive");
+        if (expected.length < 2) {
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "expected array length = {0}, must be at least 2",
+                  expected.length);
+        }
+        if (expected.length != observed.length) {
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "dimension mismatch {0} != {1}", expected.length, observed.length);
         }
+        checkPositive(expected);
+        checkNonNegative(observed);
         double sumExpected = 0d;
         double sumObserved = 0d;
         for (int i = 0; i < observed.length; i++) {
@@ -132,8 +136,9 @@
     public boolean chiSquareTest(double[] expected, long[] observed, 
             double alpha) throws IllegalArgumentException, MathException {
         if ((alpha <= 0) || (alpha > 0.5)) {
-            throw new IllegalArgumentException(
-                    "bad significance level: " + alpha);
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "out of bounds significance level {0}, must be between {1} and {2}",
+                  alpha, 0, 0.5);
         }
         return (chiSquareTest(expected, observed) < alpha);
     }
@@ -199,7 +204,9 @@
     public boolean chiSquareTest(long[][] counts, double alpha)
     throws IllegalArgumentException, MathException {
         if ((alpha <= 0) || (alpha > 0.5)) {
-            throw new IllegalArgumentException("bad significance level: " + alpha);
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "out of bounds significance level {0}, must be between {1} and {2}",
+                  alpha, 0.0, 0.5);
         }
         return (chiSquareTest(counts) < alpha);
     }
@@ -215,15 +222,21 @@
         throws IllegalArgumentException {
         
         // Make sure lengths are same
-        if ((observed1.length < 2) || (observed1.length != observed2.length)) {
-            throw new IllegalArgumentException(
-                    "oberved1, observed2 array lengths incorrect");
+        if (observed1.length < 2) {
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "observed array length = {0}, must be at least 2",
+                  observed1.length);
+        }
+        if (observed1.length != observed2.length) {
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "dimension mismatch {0} != {1}",
+                  observed1.length, observed2.length);
         }
+
         // Ensure non-negative counts
-        if (!isNonNegative(observed1) || !isNonNegative(observed2)) {
-            throw new IllegalArgumentException(
-                "observed counts must be non-negative");
-        }
+        checkNonNegative(observed1);
+        checkNonNegative(observed2);
+
         // Compute and compare count sums
         long countSum1 = 0;
         long countSum2 = 0;
@@ -234,9 +247,13 @@
             countSum2 += observed2[i];   
         }
         // Ensure neither sample is uniformly 0
-        if (countSum1 * countSum2 == 0) {
-            throw new IllegalArgumentException(
-             "observed counts cannot all be 0"); 
+        if (countSum1 == 0) {
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "observed counts are all 0 in first observed array"); 
+        }
+        if (countSum2 == 0) {
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "observed counts are all 0 in second observed array"); 
         }
         // Compare and compute weight only if different
         unequalCounts = (countSum1 != countSum2);
@@ -250,8 +267,8 @@
         double obs2 = 0.0d;
         for (int i = 0; i < observed1.length; i++) {
             if (observed1[i] == 0 && observed2[i] == 0) {
-                throw new IllegalArgumentException(
-                        "observed counts must not both be zero");
+                throw MathRuntimeException.createIllegalArgumentException(
+                      "observed counts are both zero for entry {0}", i);
             } else {
                 obs1 = observed1[i];
                 obs2 = observed2[i];
@@ -294,8 +311,9 @@
     public boolean chiSquareTestDataSetsComparison(long[] observed1, long[] observed2,
             double alpha) throws IllegalArgumentException, MathException {
         if ((alpha <= 0) || (alpha > 0.5)) {
-            throw new IllegalArgumentException(
-                    "bad significance level: " + alpha);
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "out of bounds significance level {0}, must be between {1} and {2}",
+                  alpha, 0.0, 0.5);
         }
         return (chiSquareTestDataSetsComparison(observed1, observed2) < alpha);
     }
@@ -311,20 +329,19 @@
     private void checkArray(long[][] in) throws IllegalArgumentException {
         
         if (in.length < 2) {
-            throw new IllegalArgumentException("Input table must have at least two rows");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "invalid row dimension: {0} (must be at least 2)",
+                  in.length);
         }
         
         if (in[0].length < 2) {
-            throw new IllegalArgumentException("Input table must have at least two columns");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "invalid column dimension: {0} (must be at least 2)",
+                  in[0].length);
         }    
         
-        if (!isRectangular(in)) {
-            throw new IllegalArgumentException("Input table must be rectangular");
-        }
-        
-        if (!isNonNegative(in)) {
-            throw new IllegalArgumentException("All entries in input 2-way table must be non-negative");
-        }
+        checkRectangular(in);
+        checkNonNegative(in);
         
     }
     
@@ -338,66 +355,64 @@
      * @throws NullPointerException if input array is null
      * @throws ArrayIndexOutOfBoundsException if input array is empty
      */
-    private boolean isRectangular(long[][] in) {
+    private void checkRectangular(long[][] in) {
         for (int i = 1; i < in.length; i++) {
             if (in[i].length != in[0].length) {
-                return false;
+                throw MathRuntimeException.createIllegalArgumentException(
+                      "some rows have length {0} while others have length {1}",
+                      in[i].length, in[0].length);
             }
         }  
-        return true;
     }
     
     /**
-     * Returns true iff all entries of the input array are > 0.
-     * Returns true if the array is non-null, but empty
+     * Check all entries of the input array are > 0.
      * 
      * @param in array to be tested
-     * @return true if all entries of the array are positive
-     * @throws NullPointerException if input array is null
+     * @exception IllegalArgumentException if one entry is not positive
      */
-    private boolean isPositive(double[] in) {
-        for (int i = 0; i < in.length; i ++) {
+    private void checkPositive(double[] in) throws IllegalArgumentException {
+        for (int i = 0; i < in.length; i++) {
             if (in[i] <= 0) {
-                return false;
+                throw MathRuntimeException.createIllegalArgumentException(
+                      "element {0} is not positive: {1}",
+                      i, in[i]);
             }
         }
-        return true;
     }
     
     /**
-     * Returns true iff all entries of the input array are >= 0.
-     * Returns true if the array is non-null, but empty
+     * Check all entries of the input array are >= 0.
      * 
      * @param in array to be tested
-     * @return true if all entries of the array are non-negative
-     * @throws NullPointerException if input array is null
+     * @exception IllegalArgumentException if one entry is negative
      */
-    private boolean isNonNegative(long[] in) {
-        for (int i = 0; i < in.length; i ++) {
+    private void checkNonNegative(long[] in) throws IllegalArgumentException {
+        for (int i = 0; i < in.length; i++) {
             if (in[i] < 0) {
-                return false;
+                throw MathRuntimeException.createIllegalArgumentException(
+                      "element {0} is negative: {1}",
+                      i, in[i]);
             }
         }
-        return true;
     }
     
     /**
-     * Returns true iff all entries of (all subarrays of) the input array are >= 0.
-     * Returns true if the array is non-null, but empty
+     * Check all entries of the input array are >= 0.
      * 
      * @param in array to be tested
-     * @return true if all entries of the array are non-negative
-     * @throws NullPointerException if input array is null
+     * @exception IllegalArgumentException if one entry is negative
      */
-    private boolean isNonNegative(long[][] in) {
+    private void checkNonNegative(long[][] in) throws IllegalArgumentException {
         for (int i = 0; i < in.length; i ++) {
             for (int j = 0; j < in[i].length; j++) {
                 if (in[i][j] < 0) {
-                    return false;
+                    throw MathRuntimeException.createIllegalArgumentException(
+                          "element ({0}, {1}) is negative: {2}",
+                          i, j, in[i][j]);
                 }
             }
         }
-        return true;
     }
  
     /**

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java?rev=773189&r1=773188&r2=773189&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java Sat May  9 09:57:04 2009
@@ -19,6 +19,7 @@
 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.distribution.FDistributionImpl;
 import org.apache.commons.math.stat.descriptive.summary.Sum;
@@ -100,7 +101,9 @@
     public boolean anovaTest(Collection<double[]> categoryData, double alpha)
         throws IllegalArgumentException, MathException {
         if ((alpha <= 0) || (alpha > 0.5)) {
-            throw new IllegalArgumentException("bad significance level: " + alpha);
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "out of bounds significance level {0}, must be between {1} and {2}",
+                  alpha, 0, 0.5);
         }
         return (anovaPValue(categoryData) < alpha);
     }
@@ -121,15 +124,17 @@
 
         // check if we have enough categories
         if (categoryData.size() < 2) {
-            throw new IllegalArgumentException(
-                    "ANOVA: two or more categories required");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "two or more categories required, got {0}",
+                  categoryData.size());
         }
         
         // check if each category has enough data and all is double[]
         for (double[] array : categoryData) {
             if (array.length <= 1) {
-                throw new IllegalArgumentException(
-                        "ANOVA: one element of categoryData has fewer than 2 values.");
+                throw MathRuntimeException.createIllegalArgumentException(
+                      "two or more values required in each category, one has {0}",
+                      array.length);
             }
         }
 

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/inference/TTestImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/inference/TTestImpl.java?rev=773189&r1=773188&r2=773189&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/inference/TTestImpl.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/inference/TTestImpl.java Sat May  9 09:57:04 2009
@@ -17,6 +17,7 @@
 package org.apache.commons.math.stat.inference;
 
 import org.apache.commons.math.MathException;
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.distribution.TDistribution;
 import org.apache.commons.math.distribution.TDistributionImpl;
 import org.apache.commons.math.stat.StatUtils;
@@ -75,10 +76,8 @@
      */
     public double pairedT(double[] sample1, double[] sample2)
         throws IllegalArgumentException, MathException {
-        if ((sample1 == null) || (sample2 == null ||
-                Math.min(sample1.length, sample2.length) < 2)) {
-            throw new IllegalArgumentException("insufficient data for t statistic");
-        }
+        checkSampleData(sample1);
+        checkSampleData(sample2);
         double meanDifference = StatUtils.meanDifference(sample1, sample2);
         return t(meanDifference, 0,  
                 StatUtils.varianceDifference(sample1, sample2, meanDifference),
@@ -160,9 +159,7 @@
      */
     public boolean pairedTTest(double[] sample1, double[] sample2, double alpha)
         throws IllegalArgumentException, MathException {
-        if ((alpha <= 0) || (alpha > 0.5)) {
-            throw new IllegalArgumentException("bad significance level: " + alpha);
-        }
+        checkSignificanceLevel(alpha);
         return (pairedTTest(sample1, sample2) < alpha);
     }
 
@@ -183,9 +180,7 @@
      */
     public double t(double mu, double[] observed)
     throws IllegalArgumentException {
-        if ((observed == null) || (observed.length < 2)) {
-            throw new IllegalArgumentException("insufficient data for t statistic");
-        }
+        checkSampleData(observed);
         return t(StatUtils.mean(observed), mu, StatUtils.variance(observed),
                 observed.length);
     }
@@ -208,9 +203,7 @@
      */
     public double t(double mu, StatisticalSummary sampleStats)
     throws IllegalArgumentException {
-        if ((sampleStats == null) || (sampleStats.getN() < 2)) {
-            throw new IllegalArgumentException("insufficient data for t statistic");
-        }
+        checkSampleData(sampleStats);
         return t(sampleStats.getMean(), mu, sampleStats.getVariance(),
                 sampleStats.getN());
     }
@@ -250,10 +243,8 @@
      */
     public double homoscedasticT(double[] sample1, double[] sample2)
     throws IllegalArgumentException {
-        if ((sample1 == null) || (sample2 == null ||
-                Math.min(sample1.length, sample2.length) < 2)) {
-            throw new IllegalArgumentException("insufficient data for t statistic");
-        }
+        checkSampleData(sample1);
+        checkSampleData(sample2);
         return homoscedasticT(StatUtils.mean(sample1), StatUtils.mean(sample2),
                 StatUtils.variance(sample1), StatUtils.variance(sample2),
                 sample1.length, sample2.length);
@@ -289,10 +280,8 @@
      */
     public double t(double[] sample1, double[] sample2)
     throws IllegalArgumentException {
-        if ((sample1 == null) || (sample2 == null ||
-                Math.min(sample1.length, sample2.length) < 2)) {
-            throw new IllegalArgumentException("insufficient data for t statistic");
-        }
+        checkSampleData(sample1);
+        checkSampleData(sample2);
         return t(StatUtils.mean(sample1), StatUtils.mean(sample2),
                 StatUtils.variance(sample1), StatUtils.variance(sample2),
                 sample1.length, sample2.length);
@@ -330,13 +319,10 @@
      * @throws IllegalArgumentException if the precondition is not met
      */
     public double t(StatisticalSummary sampleStats1, 
-            StatisticalSummary sampleStats2)
+                    StatisticalSummary sampleStats2)
     throws IllegalArgumentException {
-        if ((sampleStats1 == null) ||
-                (sampleStats2 == null ||
-                        Math.min(sampleStats1.getN(), sampleStats2.getN()) < 2)) {
-            throw new IllegalArgumentException("insufficient data for t statistic");
-        }
+        checkSampleData(sampleStats1);
+        checkSampleData(sampleStats2);
         return t(sampleStats1.getMean(), sampleStats2.getMean(), 
                 sampleStats1.getVariance(), sampleStats2.getVariance(),
                 sampleStats1.getN(), sampleStats2.getN());
@@ -380,11 +366,8 @@
     public double homoscedasticT(StatisticalSummary sampleStats1, 
             StatisticalSummary sampleStats2)
     throws IllegalArgumentException {
-        if ((sampleStats1 == null) ||
-                (sampleStats2 == null ||
-                        Math.min(sampleStats1.getN(), sampleStats2.getN()) < 2)) {
-            throw new IllegalArgumentException("insufficient data for t statistic");
-        }
+        checkSampleData(sampleStats1);
+        checkSampleData(sampleStats2);
         return homoscedasticT(sampleStats1.getMean(), sampleStats2.getMean(), 
                 sampleStats1.getVariance(), sampleStats2.getVariance(), 
                 sampleStats1.getN(), sampleStats2.getN());
@@ -418,9 +401,7 @@
      */
     public double tTest(double mu, double[] sample)
     throws IllegalArgumentException, MathException {
-        if ((sample == null) || (sample.length < 2)) {
-            throw new IllegalArgumentException("insufficient data for t statistic");
-        }
+        checkSampleData(sample);
         return tTest( StatUtils.mean(sample), mu, StatUtils.variance(sample),
                 sample.length);
     }
@@ -462,9 +443,7 @@
      */
     public boolean tTest(double mu, double[] sample, double alpha)
     throws IllegalArgumentException, MathException {
-        if ((alpha <= 0) || (alpha > 0.5)) {
-            throw new IllegalArgumentException("bad significance level: " + alpha);
-        }
+        checkSignificanceLevel(alpha);
         return (tTest(mu, sample) < alpha);
     }
 
@@ -498,9 +477,7 @@
      */
     public double tTest(double mu, StatisticalSummary sampleStats)
     throws IllegalArgumentException, MathException {
-        if ((sampleStats == null) || (sampleStats.getN() < 2)) {
-            throw new IllegalArgumentException("insufficient data for t statistic");
-        }
+        checkSampleData(sampleStats);
         return tTest(sampleStats.getMean(), mu, sampleStats.getVariance(),
                 sampleStats.getN());
     }
@@ -544,9 +521,7 @@
     public boolean tTest( double mu, StatisticalSummary sampleStats,
             double alpha)
     throws IllegalArgumentException, MathException {
-        if ((alpha <= 0) || (alpha > 0.5)) {
-            throw new IllegalArgumentException("bad significance level: " + alpha);
-        }
+        checkSignificanceLevel(alpha);
         return (tTest(mu, sampleStats) < alpha);
     }
 
@@ -588,10 +563,8 @@
      */
     public double tTest(double[] sample1, double[] sample2)
     throws IllegalArgumentException, MathException {
-        if ((sample1 == null) || (sample2 == null ||
-                Math.min(sample1.length, sample2.length) < 2)) {
-            throw new IllegalArgumentException("insufficient data");
-        }
+        checkSampleData(sample1);
+        checkSampleData(sample2);
         return tTest(StatUtils.mean(sample1), StatUtils.mean(sample2),
                 StatUtils.variance(sample1), StatUtils.variance(sample2),
                 sample1.length, sample2.length);
@@ -632,10 +605,8 @@
      */
     public double homoscedasticTTest(double[] sample1, double[] sample2)
     throws IllegalArgumentException, MathException {
-        if ((sample1 == null) || (sample2 == null ||
-                Math.min(sample1.length, sample2.length) < 2)) {
-            throw new IllegalArgumentException("insufficient data");
-        }
+        checkSampleData(sample1);
+        checkSampleData(sample2);
         return homoscedasticTTest(StatUtils.mean(sample1), 
                 StatUtils.mean(sample2), StatUtils.variance(sample1),
                 StatUtils.variance(sample2), sample1.length, 
@@ -697,9 +668,7 @@
     public boolean tTest(double[] sample1, double[] sample2,
             double alpha)
     throws IllegalArgumentException, MathException {
-        if ((alpha <= 0) || (alpha > 0.5)) {
-            throw new IllegalArgumentException("bad significance level: " + alpha);
-        }
+        checkSignificanceLevel(alpha);
         return (tTest(sample1, sample2) < alpha);
     }
     
@@ -757,9 +726,7 @@
     public boolean homoscedasticTTest(double[] sample1, double[] sample2,
             double alpha)
     throws IllegalArgumentException, MathException {
-        if ((alpha <= 0) || (alpha > 0.5)) {
-            throw new IllegalArgumentException("bad significance level: " + alpha);
-        }
+        checkSignificanceLevel(alpha);
         return (homoscedasticTTest(sample1, sample2) < alpha);
     }
 
@@ -799,10 +766,8 @@
      */
     public double tTest(StatisticalSummary sampleStats1, StatisticalSummary sampleStats2)
     throws IllegalArgumentException, MathException {
-        if ((sampleStats1 == null) || (sampleStats2 == null ||
-                Math.min(sampleStats1.getN(), sampleStats2.getN()) < 2)) {
-            throw new IllegalArgumentException("insufficient data for t statistic");
-        }
+        checkSampleData(sampleStats1);
+        checkSampleData(sampleStats2);
         return tTest(sampleStats1.getMean(), sampleStats2.getMean(), sampleStats1.getVariance(),
                 sampleStats2.getVariance(), sampleStats1.getN(), 
                 sampleStats2.getN());
@@ -842,12 +807,10 @@
      * @throws MathException if an error occurs computing the p-value
      */
     public double homoscedasticTTest(StatisticalSummary sampleStats1, 
-            StatisticalSummary sampleStats2)
+                                     StatisticalSummary sampleStats2)
     throws IllegalArgumentException, MathException {
-        if ((sampleStats1 == null) || (sampleStats2 == null ||
-                Math.min(sampleStats1.getN(), sampleStats2.getN()) < 2)) {
-            throw new IllegalArgumentException("insufficient data for t statistic");
-        }
+        checkSampleData(sampleStats1);
+        checkSampleData(sampleStats2);
         return homoscedasticTTest(sampleStats1.getMean(),
                 sampleStats2.getMean(), sampleStats1.getVariance(),
                 sampleStats2.getVariance(), sampleStats1.getN(), 
@@ -910,9 +873,7 @@
     public boolean tTest(StatisticalSummary sampleStats1,
             StatisticalSummary sampleStats2, double alpha)
     throws IllegalArgumentException, MathException {
-        if ((alpha <= 0) || (alpha > 0.5)) {
-            throw new IllegalArgumentException("bad significance level: " + alpha);
-        }
+        checkSignificanceLevel(alpha);
         return (tTest(sampleStats1, sampleStats2) < alpha);
     }
     
@@ -1056,4 +1017,44 @@
     public void setDistribution(TDistribution value) {
         distribution = value;
     }
+
+    /** Check significance level.
+     * @param alpha significance level
+     * @exception IllegalArgumentException if significance level is out of bounds
+     */
+    private void checkSignificanceLevel(final double alpha)
+        throws IllegalArgumentException {
+        if ((alpha <= 0) || (alpha > 0.5)) {
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "out of bounds significance level {0}, must be between {1} and {2}",
+                  alpha, 0.0, 0.5);
+        }
+    }
+
+    /** Check sample data.
+     * @param data sample data
+     * @exception IllegalArgumentException if there is not enough sample data
+     */
+    private void checkSampleData(final double[] data)
+        throws IllegalArgumentException {
+        if ((data == null) || (data.length < 2)) {
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "insufficient data for t statistic, needs at least 2, got {0}",
+                  (data == null) ? 0 : data.length);
+        }
+    }
+
+    /** Check sample data.
+     * @param stat statistical summary
+     * @exception IllegalArgumentException if there is not enough sample data
+     */
+    private void checkSampleData(final StatisticalSummary stat)
+        throws IllegalArgumentException {
+        if ((stat == null) || (stat.getN() < 2)) {
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "insufficient data for t statistic, needs at least 2, got {0}",
+                  (stat == null) ? 0 : stat.getN());
+        }
+    }
+
 }

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java?rev=773189&r1=773188&r2=773189&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java Sat May  9 09:57:04 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.math.stat.regression;
 
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.linear.RealMatrix;
 import org.apache.commons.math.linear.RealMatrixImpl;
 import org.apache.commons.math.linear.RealVector;
@@ -85,15 +86,11 @@
      *             compatible for the regression
      */
     protected void validateSampleData(double[][] x, double[] y) {
-        if (x == null) {
-            throw new IllegalArgumentException("The regressors matrix x cannot be null.");
-        }
-        if (y == null) {
-            throw new IllegalArgumentException("The regressand vector y cannot be null.");
-        }
-        if (x.length != y.length) {
-            throw new IllegalArgumentException(
-                    "The regressors matrix x columns must have the same length of the regressand vector y");
+        if ((x == null) || (y == null) || (x.length != y.length)) {
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "dimension mismatch {0} != {1}",
+                  (x == null) ? 0 : x.length,
+                  (y == null) ? 0 : y.length);
         }
     }
 
@@ -106,15 +103,14 @@
      *             matrix are not compatible for the regression
      */
     protected void validateCovarianceData(double[][] x, double[][] covariance) {
-        if (covariance == null) {
-            throw new IllegalArgumentException("Covariance matrix cannot be null.");
-        }
         if (x.length != covariance.length) {
-            throw new IllegalArgumentException(
-                    "The regressors matrix x columns must have the same length of the covariance matrix columns");
+            throw MathRuntimeException.createIllegalArgumentException(
+                 "dimension mismatch {0} != {1}", x.length, covariance.length);
         }
         if (covariance.length > 0 && covariance.length != covariance[0].length) {
-            throw new IllegalArgumentException("The covariance matrix must be square");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "a {0}x{1} matrix was provided instead of a square matrix",
+                  covariance.length, covariance[0].length);
         }
     }
 

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java?rev=773189&r1=773188&r2=773189&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java Sat May  9 09:57:04 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.math.stat.regression;
 
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.linear.RealMatrix;
 import org.apache.commons.math.linear.RealMatrixImpl;
 import org.apache.commons.math.linear.RealVector;
@@ -199,10 +200,7 @@
      */
     private static RealVector solveUpperTriangular(RealMatrix coefficients,
                                                    RealVector constants) {
-        if (!isUpperTriangular(coefficients, 1E-12)) {
-            throw new IllegalArgumentException(
-                   "Coefficients is not upper-triangular");
-        }
+        checkUpperTriangular(coefficients, 1E-12);
         int length = coefficients.getColumnDimension();
         double x[] = new double[length];
         for (int i = 0; i < length; i++) {
@@ -217,7 +215,7 @@
     }
     
     /**
-     * <p>Returns true iff m is an upper-triangular matrix.</p>
+     * <p>Check if a matrix is upper-triangular.</p>
      * 
      * <p>Makes sure all below-diagonal elements are within epsilon of 0.</p>
      * 
@@ -225,20 +223,20 @@
      * @param epsilon maximum allowable absolute value for elements below
      * the main diagonal
      * 
-     * @return true if m is upper-triangular; false otherwise
-     * @throws NullPointerException if m is null
+     * @throws IllegalArgumentException if m is not upper-triangular
      */
-    private static boolean isUpperTriangular(RealMatrix m, double epsilon) {
+    private static void checkUpperTriangular(RealMatrix m, double epsilon) {
         int nCols = m.getColumnDimension();
         int nRows = m.getRowDimension();
         for (int r = 0; r < nRows; r++) {
             int bound = Math.min(r, nCols);
             for (int c = 0; c < bound; c++) {
                 if (Math.abs(m.getEntry(r, c)) > epsilon) {
-                    return false;
+                    throw MathRuntimeException.createIllegalArgumentException(
+                          "matrix is not upper-triangular, entry ({0}, {1}) = {2} is too large",
+                          r, c, m.getEntry(r, c));
                 }
             }
         }
-        return true;
     }
 }

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java?rev=773189&r1=773188&r2=773189&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java Sat May  9 09:57:04 2009
@@ -548,8 +548,8 @@
         throws MathException {
         if (alpha >= 1 || alpha <= 0) {
             throw MathRuntimeException.createIllegalArgumentException(
-                  "out of bounds significance level {0}, must be in (0, 1)",
-                  alpha);
+                  "out of bounds significance level {0}, must be between {1} and {2}",
+                  alpha, 0.0, 1.0);
         }
         return getSlopeStdErr() *
             distribution.inverseCumulativeProbability(1d - alpha / 2d);

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=773189&r1=773188&r2=773189&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Sat May  9 09:57:04 2009
@@ -39,6 +39,9 @@
   </properties>
   <body>
     <release version="2.0" date="TBD" description="TBD">
+      <action dev="luc" type="update" >
+        Completed internationalization of all error messages
+      </action>
       <action dev="luc" type="add" issue="MATH-266" due-to="Benjamin McCann">
         Added a clustering package with an implementation of the k-means++ algorithm
       </action>