You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by sr...@apache.org on 2010/08/18 10:53:54 UTC

svn commit: r986599 - in /mahout/trunk: core/src/main/java/org/apache/mahout/df/data/ core/src/main/java/org/apache/mahout/df/ref/ core/src/main/java/org/apache/mahout/df/tools/ core/src/main/java/org/apache/mahout/vectors/ core/src/test/java/org/apach...

Author: srowen
Date: Wed Aug 18 08:53:53 2010
New Revision: 986599

URL: http://svn.apache.org/viewvc?rev=986599&view=rev
Log:
Use Locale.ENGLISH in String.format() and style changes to related tests

Modified:
    mahout/trunk/core/src/main/java/org/apache/mahout/df/data/DataConverter.java
    mahout/trunk/core/src/main/java/org/apache/mahout/df/ref/SequentialBuilder.java
    mahout/trunk/core/src/main/java/org/apache/mahout/df/tools/FrequenciesJob.java
    mahout/trunk/core/src/main/java/org/apache/mahout/df/tools/UDistrib.java
    mahout/trunk/core/src/main/java/org/apache/mahout/vectors/AdaptiveWordValueEncoder.java
    mahout/trunk/core/src/main/java/org/apache/mahout/vectors/ConstantValueEncoder.java
    mahout/trunk/core/src/main/java/org/apache/mahout/vectors/ContinuousValueEncoder.java
    mahout/trunk/core/src/main/java/org/apache/mahout/vectors/FeatureVectorEncoder.java
    mahout/trunk/core/src/main/java/org/apache/mahout/vectors/TextValueEncoder.java
    mahout/trunk/core/src/main/java/org/apache/mahout/vectors/WordValueEncoder.java
    mahout/trunk/core/src/test/java/org/apache/mahout/classifier/sgd/CsvRecordFactoryTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/classifier/sgd/OnlineLogisticRegressionTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/vectors/ContinuousValueEncoderTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/vectors/TextValueEncoderTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/vectors/WordLikeValueEncoderTest.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/QRDecomposition.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Property.java
    mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/GammaTest.java
    mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/NegativeBinomialTest.java
    mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/stat/GammaTest.java
    mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/stat/ProbabilityTest.java
    mahout/trunk/math/src/test/java/org/apache/mahout/math/stats/OnlineSummarizerTest.java

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/df/data/DataConverter.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/df/data/DataConverter.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/df/data/DataConverter.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/df/data/DataConverter.java Wed Aug 18 08:53:53 2010
@@ -18,6 +18,7 @@
 package org.apache.mahout.df.data;
 
 import java.util.Arrays;
+import java.util.Locale;
 import java.util.StringTokenizer;
 
 import org.apache.commons.lang.ArrayUtils;
@@ -67,8 +68,7 @@ public class DataConverter {
       if (attr == dataset.getLabelId()) {
         label = dataset.labelCode(token);
         if (label == -1) {
-          log.error(String.format("label token: %s\ndataset.labels: %s", token, Arrays
-              .toString(dataset.labels())));
+          log.error("label token: {} dataset.labels: {}", token, Arrays.toString(dataset.labels()));
           throw new IllegalStateException("Label value (" + token + ") not known");
         }
       } else if (dataset.isNumerical(aId)) {
@@ -80,7 +80,7 @@ public class DataConverter {
     }
     
     if (label == -1) {
-      log.error(String.format("Label not found, instance id : %d, \nstring : %s", id, string));
+      log.error("Label not found, instance id : {}, string : {}", id, string);
       throw new IllegalStateException("Label not found!");
     }
     

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/df/ref/SequentialBuilder.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/df/ref/SequentialBuilder.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/df/ref/SequentialBuilder.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/df/ref/SequentialBuilder.java Wed Aug 18 08:53:53 2010
@@ -70,7 +70,7 @@ public class SequentialBuilder {
   private static void logProgress(float progress) {
     int percent = (int) (progress * 100);
     if (percent % 10 == 0) {
-      log.info(String.format("Building %2d%%", percent));
+      log.info("Building {}%", percent);
     }
     
   }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/df/tools/FrequenciesJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/df/tools/FrequenciesJob.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/df/tools/FrequenciesJob.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/df/tools/FrequenciesJob.java Wed Aug 18 08:53:53 2010
@@ -158,8 +158,8 @@ public class FrequenciesJob {
     }
     
     if (index < numMaps) {
-      throw new IllegalStateException(String.format(
-        "number of output Frequencies (%d) is lesser than the number of mappers!", index));
+      throw new IllegalStateException("number of output Frequencies (" + index
+          + ") is lesser than the number of mappers!");
     }
     
     // sort the frequencies using the firstIds

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/df/tools/UDistrib.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/df/tools/UDistrib.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/df/tools/UDistrib.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/df/tools/UDistrib.java Wed Aug 18 08:53:53 2010
@@ -167,7 +167,7 @@ public final class UDistrib {
     int id = 0;
     while (scanner.hasNextLine()) {
       if (id % 1000 == 0) {
-        log.info(String.format("progress : %d / %d", id, nbInstances));
+        log.info("progress : {} / {}", id, nbInstances);
       }
       
       String line = scanner.nextLine();

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/vectors/AdaptiveWordValueEncoder.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/vectors/AdaptiveWordValueEncoder.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/vectors/AdaptiveWordValueEncoder.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/vectors/AdaptiveWordValueEncoder.java Wed Aug 18 08:53:53 2010
@@ -27,7 +27,8 @@ import org.apache.mahout.math.Vector;
  * without a pre-scan of all of the data.
  */
 public class AdaptiveWordValueEncoder extends WordValueEncoder {
-  private Multiset<String> dictionary;
+
+  private final Multiset<String> dictionary;
 
   public AdaptiveWordValueEncoder(String name) {
     super(name);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/vectors/ConstantValueEncoder.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/vectors/ConstantValueEncoder.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/vectors/ConstantValueEncoder.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/vectors/ConstantValueEncoder.java Wed Aug 18 08:53:53 2010
@@ -29,15 +29,17 @@ public class ConstantValueEncoder extend
 
   @Override
   public void addToVector(String originalForm, double weight, Vector data) {
+    int probes = getProbes();
+    String name = getName();
     for (int i = 0; i < probes; i++) {
       int n = hash(name, i, data.size());
-      trace(name, null, n);
+      trace(null, n);
       data.set(n, data.get(n) + weight);
     }
   }
 
   @Override
   public String asString(String originalForm) {
-    return name;
+    return getName();
   }
 }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/vectors/ContinuousValueEncoder.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/vectors/ContinuousValueEncoder.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/vectors/ContinuousValueEncoder.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/vectors/ContinuousValueEncoder.java Wed Aug 18 08:53:53 2010
@@ -23,6 +23,7 @@ import org.apache.mahout.math.Vector;
  * Continuous values are stored in fixed randomized location in the feature vector.
  */
 public class ContinuousValueEncoder extends FeatureVectorEncoder {
+
   public ContinuousValueEncoder(String name) {
     super(name);
   }
@@ -35,9 +36,11 @@ public class ContinuousValueEncoder exte
    */
   @Override
   public void addToVector(String originalForm, double weight, Vector data) {
+    int probes = getProbes();
+    String name = getName();
     for (int i = 0; i < probes; i++) {
       int n = hash(name, CONTINUOUS_VALUE_HASH_SEED + i, data.size());
-      trace(name, null, n);
+      trace(null, n);
       data.set(n, data.get(n) + weight * Double.parseDouble(originalForm));
     }
   }
@@ -52,6 +55,6 @@ public class ContinuousValueEncoder exte
    */
   @Override
   public String asString(String originalForm) {
-    return name + ":" + originalForm;
+    return getName() + ':' + originalForm;
   }
 }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/vectors/FeatureVectorEncoder.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/vectors/FeatureVectorEncoder.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/vectors/FeatureVectorEncoder.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/vectors/FeatureVectorEncoder.java Wed Aug 18 08:53:53 2010
@@ -18,7 +18,6 @@
 package org.apache.mahout.vectors;
 
 import com.google.common.collect.Sets;
-import org.apache.mahout.vectors.MurmurHash;
 import org.apache.mahout.math.Vector;
 
 import java.nio.charset.Charset;
@@ -33,16 +32,22 @@ import java.util.Set;
  * dictionary.
  */
 public abstract class FeatureVectorEncoder {
+
   protected static final int CONTINUOUS_VALUE_HASH_SEED = 1;
   protected static final int WORD_LIKE_VALUE_HASH_SEED = 100;
 
-  protected String name;
-  protected int probes = 1;
+  private final String name;
+  private int probes;
+
+  private Map<String, Set<Integer>> traceDictionary;
 
-  private Map<String, Set<Integer>> traceDictionary = null;
+  protected FeatureVectorEncoder(String name) {
+    this(name, 1);
+  }
 
-  public FeatureVectorEncoder(String name) {
+  protected FeatureVectorEncoder(String name, int probes) {
     this.name = name;
+    this.probes = probes;
   }
 
   /**
@@ -114,6 +119,10 @@ public abstract class FeatureVectorEncod
    */
   public abstract String asString(String originalForm);
 
+  public int getProbes() {
+    return probes;
+  }
+
   /**
    * Sets the number of locations in the feature vector that a value should be in.
    *
@@ -127,11 +136,11 @@ public abstract class FeatureVectorEncod
     return name;
   }
 
-  protected void trace(String name, String subName, int n) {
+  protected void trace(String subName, int n) {
     if (traceDictionary != null) {
       String key = name;
       if (subName != null) {
-        key = name + "=" + subName;
+        key = name + '=' + subName;
       }
       Set<Integer> trace = traceDictionary.get(key);
       if (trace == null) {

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/vectors/TextValueEncoder.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/vectors/TextValueEncoder.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/vectors/TextValueEncoder.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/vectors/TextValueEncoder.java Wed Aug 18 08:53:53 2010
@@ -28,13 +28,13 @@ import java.util.regex.Pattern;
  * words the same weight.
  */
 public class TextValueEncoder extends FeatureVectorEncoder {
-  Splitter onNonWord = Splitter.on(Pattern.compile("\\W+")).omitEmptyStrings();
+
+  private final Splitter onNonWord = Splitter.on(Pattern.compile("\\W+")).omitEmptyStrings();
   private FeatureVectorEncoder wordEncoder;
 
   public TextValueEncoder(String name) {
-    super(name);
+    super(name, 2);
     wordEncoder = new StaticWordValueEncoder(name);
-    probes = 2;
   }
 
   /**
@@ -50,7 +50,7 @@ public class TextValueEncoder extends Fe
     }
   }
 
-  private Iterable<String> tokenize(String originalForm) {
+  private Iterable<String> tokenize(CharSequence originalForm) {
     return onNonWord.split(originalForm);
   }
 
@@ -64,14 +64,15 @@ public class TextValueEncoder extends Fe
    */
   @Override
   public String asString(String originalForm) {
-    StringBuilder r = new StringBuilder("[");
-    String sep = "";
+    StringBuilder r = new StringBuilder();
+    r.append('[');
     for (String word : tokenize(originalForm)) {
-      r.append(sep);
+      if (r.length() > 1) {
+        r.append(", ");
+      }
       r.append(wordEncoder.asString(word));
-      sep = ", ";
     }
-    r.append("]");
+    r.append(']');
     return r.toString();
   }
 

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/vectors/WordValueEncoder.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/vectors/WordValueEncoder.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/vectors/WordValueEncoder.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/vectors/WordValueEncoder.java Wed Aug 18 08:53:53 2010
@@ -19,15 +19,16 @@ package org.apache.mahout.vectors;
 
 import org.apache.mahout.math.Vector;
 
+import java.util.Locale;
+
 /**
  * Encodes words as sparse vector updates to a Vector.  Weighting is defined by a
  * sub-class.
  */
 public abstract class WordValueEncoder extends FeatureVectorEncoder {
 
-  public WordValueEncoder(String name) {
-    super(name);
-    probes = 2;
+  protected WordValueEncoder(String name) {
+    super(name, 2);
   }
 
   /**
@@ -38,10 +39,12 @@ public abstract class WordValueEncoder e
    */
   @Override
   public void addToVector(String originalForm, double w, Vector data) {
+    int probes = getProbes();
+    String name = getName();
     double weight = w * weight(originalForm);
     for (int i = 0; i < probes; i++) {
       int n = hash(name, originalForm, WORD_LIKE_VALUE_HASH_SEED + i, data.size());
-      trace(name, originalForm, n);
+      trace(originalForm, n);
       data.set(n, data.get(n) + weight);
     }
   }
@@ -56,7 +59,7 @@ public abstract class WordValueEncoder e
    */
   @Override
   public String asString(String originalForm) {
-    return String.format("%s:%s:%.4f", name, originalForm, weight(originalForm));
+    return String.format(Locale.ENGLISH, "%s:%s:%.4f", getName(), originalForm, weight(originalForm));
   }
 
   protected abstract double weight(String originalForm);

Modified: mahout/trunk/core/src/test/java/org/apache/mahout/classifier/sgd/CsvRecordFactoryTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/classifier/sgd/CsvRecordFactoryTest.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/classifier/sgd/CsvRecordFactoryTest.java (original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/classifier/sgd/CsvRecordFactoryTest.java Wed Aug 18 08:53:53 2010
@@ -24,52 +24,50 @@ import org.apache.mahout.vectors.Diction
 import org.junit.Assert;
 import org.junit.Test;
 
-import static org.junit.Assert.assertEquals;
-
 public class CsvRecordFactoryTest {
   @Test
   public void testAddToVector() {
-    CsvRecordFactory csv = new CsvRecordFactory("y", ImmutableMap.of("x1", "n", "x2", "w", "x3", "t"));
+    RecordFactory csv = new CsvRecordFactory("y", ImmutableMap.of("x1", "n", "x2", "w", "x3", "t"));
     csv.firstLine("z,x1,y,x2,x3,q");
     csv.maxTargetValue(2);
 
     Vector v = new DenseVector(2000);
     int t = csv.processLine("ignore,3.1,yes,tiger, \"this is text\",ignore", v);
-    assertEquals(0, t);
+    Assert.assertEquals(0, t);
     // should have 9 values set
-    assertEquals(9.0, v.norm(0), 0);
+    Assert.assertEquals(9.0, v.norm(0), 0);
     // all should be = 1 except for the 3.1
-    assertEquals(3.1, v.maxValue(), 0);
+    Assert.assertEquals(3.1, v.maxValue(), 0);
     v.set(v.maxValueIndex(), 0);
-    assertEquals(8.0, v.norm(0), 0);
-    assertEquals(8.0, v.norm(1), 0);
-    assertEquals(1.0, v.maxValue(), 0);
+    Assert.assertEquals(8.0, v.norm(0), 0);
+    Assert.assertEquals(8.0, v.norm(1), 0);
+    Assert.assertEquals(1.0, v.maxValue(), 0);
 
     v.assign(0);
     t = csv.processLine("ignore,5.3,no,line, \"and more text and more\",ignore", v);
-    assertEquals(1, t);
+    Assert.assertEquals(1, t);
 
     // should have 9 values set
-    assertEquals(9.0, v.norm(0), 0);
+    Assert.assertEquals(9.0, v.norm(0), 0);
     // all should be = 1 except for the 3.1
-    assertEquals(5.3, v.maxValue(), 0);
+    Assert.assertEquals(5.3, v.maxValue(), 0);
     v.set(v.maxValueIndex(), 0);
-    assertEquals(8.0, v.norm(0), 0);
-    assertEquals(12.0, v.norm(1), 0);
-    assertEquals(2, v.maxValue(), 0);
+    Assert.assertEquals(8.0, v.norm(0), 0);
+    Assert.assertEquals(12.0, v.norm(1), 0);
+    Assert.assertEquals(2, v.maxValue(), 0);
 
     v.assign(0);
     t = csv.processLine("ignore,5.3,invalid,line, \"and more text and more\",ignore", v);
-    assertEquals(1, t);
+    Assert.assertEquals(1, t);
 
     // should have 9 values set
-    assertEquals(9.0, v.norm(0), 0);
+    Assert.assertEquals(9.0, v.norm(0), 0);
     // all should be = 1 except for the 3.1
-    assertEquals(5.3, v.maxValue(), 0);
+    Assert.assertEquals(5.3, v.maxValue(), 0);
     v.set(v.maxValueIndex(), 0);
-    assertEquals(8.0, v.norm(0), 0);
-    assertEquals(12.0, v.norm(1), 0);
-    assertEquals(2, v.maxValue(), 0);
+    Assert.assertEquals(8.0, v.norm(0), 0);
+    Assert.assertEquals(12.0, v.norm(1), 0);
+    Assert.assertEquals(2, v.maxValue(), 0);
   }
 
   @Test

Modified: mahout/trunk/core/src/test/java/org/apache/mahout/classifier/sgd/OnlineLogisticRegressionTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/classifier/sgd/OnlineLogisticRegressionTest.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/classifier/sgd/OnlineLogisticRegressionTest.java (original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/classifier/sgd/OnlineLogisticRegressionTest.java Wed Aug 18 08:53:53 2010
@@ -31,6 +31,7 @@ import org.apache.mahout.math.DenseVecto
 import org.apache.mahout.math.Matrix;
 import org.apache.mahout.math.Vector;
 import org.apache.mahout.math.function.Functions;
+import org.junit.Assert;
 import org.junit.Test;
 
 import java.io.IOException;
@@ -39,8 +40,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Random;
 
-import static org.junit.Assert.assertEquals;
-
 public class OnlineLogisticRegressionTest {
   private Matrix input;
 
@@ -53,7 +52,7 @@ public class OnlineLogisticRegressionTes
     Vector target = readStandardData();
 
     CrossFoldLearner lr = new CrossFoldLearner(5, 2, 8, new L1())
-            .lambda(1 * 1e-3)
+            .lambda(1 * 1.0e-3)
             .learningRate(50);
 
 
@@ -73,7 +72,7 @@ public class OnlineLogisticRegressionTes
     CrossFoldLearner lr = new CrossFoldLearner(5, 2, 10, new L1())
             .stepOffset(10)
             .decayExponent(0.7)
-            .lambda(1 * 1e-3)
+            .lambda(1 * 1.0e-3)
             .learningRate(5);
     int k = 0;
     int[] ordering = permute(gen, data.numRows());
@@ -97,52 +96,52 @@ public class OnlineLogisticRegressionTes
 
     // zero vector gives no information.  All classes are equal.
     Vector v = lr.classify(new DenseVector(new double[]{0, 0}));
-    assertEquals(1 / 3.0, v.get(0), 1e-8);
-    assertEquals(1 / 3.0, v.get(1), 1e-8);
+    Assert.assertEquals(1 / 3.0, v.get(0), 1.0e-8);
+    Assert.assertEquals(1 / 3.0, v.get(1), 1.0e-8);
 
     v = lr.classifyFull(new DenseVector(new double[]{0, 0}));
-    assertEquals(1.0, v.zSum(), 1e-8);
-    assertEquals(1 / 3.0, v.get(0), 1e-8);
-    assertEquals(1 / 3.0, v.get(1), 1e-8);
-    assertEquals(1 / 3.0, v.get(2), 1e-8);
+    Assert.assertEquals(1.0, v.zSum(), 1.0e-8);
+    Assert.assertEquals(1 / 3.0, v.get(0), 1.0e-8);
+    Assert.assertEquals(1 / 3.0, v.get(1), 1.0e-8);
+    Assert.assertEquals(1 / 3.0, v.get(2), 1.0e-8);
 
     // weights for second vector component are still zero so all classifications are equally likely
     v = lr.classify(new DenseVector(new double[]{0, 1}));
-    assertEquals(1 / 3.0, v.get(0), 1e-3);
-    assertEquals(1 / 3.0, v.get(1), 1e-3);
+    Assert.assertEquals(1 / 3.0, v.get(0), 1.0e-3);
+    Assert.assertEquals(1 / 3.0, v.get(1), 1.0e-3);
 
     v = lr.classifyFull(new DenseVector(new double[]{0, 1}));
-    assertEquals(1.0, v.zSum(), 1e-8);
-    assertEquals(1 / 3.0, v.get(0), 1e-3);
-    assertEquals(1 / 3.0, v.get(1), 1e-3);
-    assertEquals(1 / 3.0, v.get(2), 1e-3);
+    Assert.assertEquals(1.0, v.zSum(), 1.0e-8);
+    Assert.assertEquals(1 / 3.0, v.get(0), 1.0e-3);
+    Assert.assertEquals(1 / 3.0, v.get(1), 1.0e-3);
+    Assert.assertEquals(1 / 3.0, v.get(2), 1.0e-3);
 
     // but the weights on the first component are non-zero
     v = lr.classify(new DenseVector(new double[]{1, 0}));
-    assertEquals(Math.exp(-1) / (1 + Math.exp(-1) + Math.exp(-2)), v.get(0), 1e-8);
-    assertEquals(Math.exp(-2) / (1 + Math.exp(-1) + Math.exp(-2)), v.get(1), 1e-8);
+    Assert.assertEquals(Math.exp(-1) / (1 + Math.exp(-1) + Math.exp(-2)), v.get(0), 1.0e-8);
+    Assert.assertEquals(Math.exp(-2) / (1 + Math.exp(-1) + Math.exp(-2)), v.get(1), 1.0e-8);
 
     v = lr.classifyFull(new DenseVector(new double[]{1, 0}));
-    assertEquals(1.0, v.zSum(), 1e-8);
-    assertEquals(1 / (1 + Math.exp(-1) + Math.exp(-2)), v.get(0), 1e-8);
-    assertEquals(Math.exp(-1) / (1 + Math.exp(-1) + Math.exp(-2)), v.get(1), 1e-8);
-    assertEquals(Math.exp(-2) / (1 + Math.exp(-1) + Math.exp(-2)), v.get(2), 1e-8);
+    Assert.assertEquals(1.0, v.zSum(), 1.0e-8);
+    Assert.assertEquals(1 / (1 + Math.exp(-1) + Math.exp(-2)), v.get(0), 1.0e-8);
+    Assert.assertEquals(Math.exp(-1) / (1 + Math.exp(-1) + Math.exp(-2)), v.get(1), 1.0e-8);
+    Assert.assertEquals(Math.exp(-2) / (1 + Math.exp(-1) + Math.exp(-2)), v.get(2), 1.0e-8);
 
     lr.setBeta(0, 1, 1);
 
     v = lr.classifyFull(new DenseVector(new double[]{1, 1}));
-    assertEquals(1.0, v.zSum(), 1e-8);
-    assertEquals(Math.exp(0) / (1 + Math.exp(0) + Math.exp(-2)), v.get(1), 1e-3);
-    assertEquals(Math.exp(-2) / (1 + Math.exp(0) + Math.exp(-2)), v.get(2), 1e-3);
-    assertEquals(1 / (1 + Math.exp(0) + Math.exp(-2)), v.get(0), 1e-3);
+    Assert.assertEquals(1.0, v.zSum(), 1.0e-8);
+    Assert.assertEquals(Math.exp(0) / (1 + Math.exp(0) + Math.exp(-2)), v.get(1), 1.0e-3);
+    Assert.assertEquals(Math.exp(-2) / (1 + Math.exp(0) + Math.exp(-2)), v.get(2), 1.0e-3);
+    Assert.assertEquals(1 / (1 + Math.exp(0) + Math.exp(-2)), v.get(0), 1.0e-3);
 
     lr.setBeta(1, 1, 3);
 
     v = lr.classifyFull(new DenseVector(new double[]{1, 1}));
-    assertEquals(1.0, v.zSum(), 1e-8);
-    assertEquals(Math.exp(0) / (1 + Math.exp(0) + Math.exp(1)), v.get(1), 1e-8);
-    assertEquals(Math.exp(1) / (1 + Math.exp(0) + Math.exp(1)), v.get(2), 1e-8);
-    assertEquals(1 / (1 + Math.exp(0) + Math.exp(1)), v.get(0), 1e-8);
+    Assert.assertEquals(1.0, v.zSum(), 1.0e-8);
+    Assert.assertEquals(Math.exp(0) / (1 + Math.exp(0) + Math.exp(1)), v.get(1), 1.0e-8);
+    Assert.assertEquals(Math.exp(1) / (1 + Math.exp(0) + Math.exp(1)), v.get(2), 1.0e-8);
+    Assert.assertEquals(1 / (1 + Math.exp(0) + Math.exp(1)), v.get(0), 1.0e-8);
   }
 
   @Test
@@ -153,9 +152,10 @@ public class OnlineLogisticRegressionTes
     // lambda here needs to be relatively small to avoid swamping the actual signal, but can be
     // larger than usual because the data are dense.  The learning rate doesn't matter too much
     // for this example, but should generally be < 1
-    // --passes 1 --rate 50 --lambda 0.001 --input sgd-y.csv --features 21 --output model --noBias --target y --categories 2 --predictors  V2 V3 V4 V5 V6 V7 --types n
+    // --passes 1 --rate 50 --lambda 0.001 --input sgd-y.csv --features 21 --output model --noBias
+    //   --target y --categories 2 --predictors  V2 V3 V4 V5 V6 V7 --types n
     OnlineLogisticRegression lr = new OnlineLogisticRegression(2, 8, new L1())
-            .lambda(1 * 1e-3)
+            .lambda(1 * 1.0e-3)
             .learningRate(50);
 
     train(input, target, lr);
@@ -175,7 +175,7 @@ public class OnlineLogisticRegressionTes
     return target;
   }
 
-  private void train(Matrix input, Vector target, OnlineLearner lr) {
+  private static void train(Matrix input, Vector target, OnlineLearner lr) {
     RandomUtils.useTestSeed();
     Random gen = RandomUtils.getRandom();
 
@@ -186,7 +186,7 @@ public class OnlineLogisticRegressionTes
     lr.close();
   }
 
-  private void test(Matrix input, Vector target, AbstractVectorClassifier lr) {
+  private static void test(Matrix input, Vector target, AbstractVectorClassifier lr) {
     // now test the accuracy
     Matrix tmp = lr.classify(input);
     // mean(abs(tmp - target))
@@ -196,14 +196,14 @@ public class OnlineLogisticRegressionTes
     double maxAbsoluteError = tmp.getColumn(0).minus(target).aggregate(Functions.MAX, Functions.ABS);
 
     System.out.printf("mAE = %.4f, maxAE = %.4f\n", meanAbsoluteError, maxAbsoluteError);
-    assertEquals(0, meanAbsoluteError , 0.05);
-    assertEquals(0, maxAbsoluteError, 0.3);
+    Assert.assertEquals(0, meanAbsoluteError , 0.05);
+    Assert.assertEquals(0, maxAbsoluteError, 0.3);
 
     // convenience methods should give the same results
     Vector v = lr.classifyScalar(input);
-    assertEquals(0, v.minus(tmp.getColumn(0)).norm(1), 1e-5);
+    Assert.assertEquals(0, v.minus(tmp.getColumn(0)).norm(1), 1.0e-5);
     v = lr.classifyFull(input).getColumn(1);
-    assertEquals(0, v.minus(tmp.getColumn(0)).norm(1), 1e-4);
+    Assert.assertEquals(0, v.minus(tmp.getColumn(0)).norm(1), 1.0e-4);
   }
 
   /**
@@ -213,16 +213,16 @@ public class OnlineLogisticRegressionTes
    * @param max The number of integers to permute
    * @return An array of jumbled integer values
    */
-  private int[] permute(Random gen, int max) {
+  private static int[] permute(Random gen, int max) {
     int[] permutation = new int[max];
     permutation[0] = 0;
     for (int i = 1; i < max; i++) {
       int n = gen.nextInt(i + 1);
-      if (n != i) {
+      if (n == i) {
+        permutation[i] = i;
+      } else {
         permutation[i] = permutation[n];
         permutation[n] = i;
-      } else {
-        permutation[i] = i;
       }
     }
     return permutation;
@@ -236,12 +236,12 @@ public class OnlineLogisticRegressionTes
    *
    * @param resourceName Where to get the data.
    * @return A matrix of the results.
-   * @throws java.io.IOException If there is an error reading the data
+   * @throws IOException If there is an error reading the data
    */
-  private Matrix readCsv(String resourceName) throws IOException {
+  private static Matrix readCsv(String resourceName) throws IOException {
     Splitter onCommas = Splitter.on(",").trimResults(CharMatcher.anyOf(" \""));
 
-    InputStreamReader isr = new InputStreamReader(Resources.getResource(resourceName).openStream());
+    Readable isr = new InputStreamReader(Resources.getResource(resourceName).openStream());
     List<String> data = CharStreams.readLines(isr);
     String first = data.get(0);
     data = data.subList(1, data.size());

Modified: mahout/trunk/core/src/test/java/org/apache/mahout/vectors/ContinuousValueEncoderTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/vectors/ContinuousValueEncoderTest.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/vectors/ContinuousValueEncoderTest.java (original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/vectors/ContinuousValueEncoderTest.java Wed Aug 18 08:53:53 2010
@@ -19,64 +19,60 @@ package org.apache.mahout.vectors;
 
 import org.apache.mahout.math.DenseVector;
 import org.apache.mahout.math.Vector;
-import org.apache.mahout.vectors.ContinuousValueEncoder;
-import org.apache.mahout.vectors.FeatureVectorEncoder;
+import org.junit.Assert;
 import org.junit.Test;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
 public class ContinuousValueEncoderTest {
   @Test
   public void testAddToVector() {
     FeatureVectorEncoder enc = new ContinuousValueEncoder("foo");
     Vector v1 = new DenseVector(20);
     enc.addToVector("-123", v1);
-    assertEquals(-123, v1.minValue(), 0);
-    assertEquals(0, v1.maxValue(), 0);
-    assertEquals(123, v1.norm(1), 0);
+    Assert.assertEquals(-123, v1.minValue(), 0);
+    Assert.assertEquals(0, v1.maxValue(), 0);
+    Assert.assertEquals(123, v1.norm(1), 0);
 
     v1 = new DenseVector(20);
     enc.addToVector("123", v1);
-    assertEquals(123, v1.maxValue(), 0);
-    assertEquals(0, v1.minValue(), 0);
-    assertEquals(123, v1.norm(1), 0);
+    Assert.assertEquals(123, v1.maxValue(), 0);
+    Assert.assertEquals(0, v1.minValue(), 0);
+    Assert.assertEquals(123, v1.norm(1), 0);
 
     Vector v2 = new DenseVector(20);
     enc.setProbes(2);
     enc.addToVector("123", v2);
-    assertEquals(123, v2.maxValue(), 0);
-    assertEquals(2 * 123, v2.norm(1), 0);
+    Assert.assertEquals(123, v2.maxValue(), 0);
+    Assert.assertEquals(2 * 123, v2.norm(1), 0);
 
     v1 = v2.minus(v1);
-    assertEquals(123, v1.maxValue(), 0);
-    assertEquals(123, v1.norm(1), 0);
+    Assert.assertEquals(123, v1.maxValue(), 0);
+    Assert.assertEquals(123, v1.norm(1), 0);
 
     Vector v3 = new DenseVector(20);
     enc.setProbes(2);
     enc.addToVector("100", v3);
     v1 = v2.minus(v3);
-    assertEquals(23, v1.maxValue(), 0);
-    assertEquals(2 * 23, v1.norm(1), 0);
+    Assert.assertEquals(23, v1.maxValue(), 0);
+    Assert.assertEquals(2 * 23, v1.norm(1), 0);
 
     enc.addToVector("7", v1);
-    assertEquals(30, v1.maxValue(), 0);
-    assertEquals(2 * 30, v1.norm(1), 0);
-    assertEquals(30, v1.get(10), 0);
-    assertEquals(30, v1.get(18), 0);
+    Assert.assertEquals(30, v1.maxValue(), 0);
+    Assert.assertEquals(2 * 30, v1.norm(1), 0);
+    Assert.assertEquals(30, v1.get(10), 0);
+    Assert.assertEquals(30, v1.get(18), 0);
 
     try {
       enc.addToVector("foobar", v1);
-      fail("Should have noticed back numeric format");
+      Assert.fail("Should have noticed bad numeric format");
     } catch (NumberFormatException e) {
-      assertEquals("For input string: \"foobar\"", e.getMessage());
+      Assert.assertEquals("For input string: \"foobar\"", e.getMessage());
     }
   }
 
   @Test
   public void testAsString() {
     ContinuousValueEncoder enc = new ContinuousValueEncoder("foo");
-    assertEquals("foo:123", enc.asString("123"));
+    Assert.assertEquals("foo:123", enc.asString("123"));
   }
 
 }

Modified: mahout/trunk/core/src/test/java/org/apache/mahout/vectors/TextValueEncoderTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/vectors/TextValueEncoderTest.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/vectors/TextValueEncoderTest.java (original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/vectors/TextValueEncoderTest.java Wed Aug 18 08:53:53 2010
@@ -20,14 +20,9 @@ package org.apache.mahout.vectors;
 import com.google.common.collect.ImmutableMap;
 import org.apache.mahout.math.DenseVector;
 import org.apache.mahout.math.Vector;
-import org.apache.mahout.vectors.StaticWordValueEncoder;
-import org.apache.mahout.vectors.TextValueEncoder;
+import org.junit.Assert;
 import org.junit.Test;
 
-import java.util.Locale;
-
-import static org.junit.Assert.assertEquals;
-
 public class TextValueEncoderTest {
   @Test
   public void testAddToVector() {
@@ -35,8 +30,8 @@ public class TextValueEncoderTest {
     Vector v1 = new DenseVector(200);
     enc.addToVector("test1 and more", v1);
     // should set 6 distinct locations to 1
-    assertEquals(6.0, v1.norm(1), 0);
-    assertEquals(1.0, v1.maxValue(), 0);
+    Assert.assertEquals(6.0, v1.norm(1), 0);
+    Assert.assertEquals(1.0, v1.maxValue(), 0);
 
     // now some fancy weighting
     StaticWordValueEncoder w = new StaticWordValueEncoder("text");
@@ -53,16 +48,15 @@ public class TextValueEncoderTest {
     w.addToVector("and", v3);
     w.addToVector("more", v3);
 
-    assertEquals(0, v3.minus(v2).norm(1), 0);
+    Assert.assertEquals(0, v3.minus(v2).norm(1), 0);
 
     // moreover, the locations set in the unweighted case should be the same as in the weighted case
-    assertEquals(v3.zSum(), v3.dot(v1), 0);
+    Assert.assertEquals(v3.zSum(), v3.dot(v1), 0);
   }
 
   @Test
   public void testAsString() {
-    Locale.setDefault(new Locale("EN", "US"));
-    TextValueEncoder enc = new TextValueEncoder("text");
-    assertEquals("[text:test1:1.0000, text:and:1.0000, text:more:1.0000]", enc.asString("test1 and more"));
+    FeatureVectorEncoder enc = new TextValueEncoder("text");
+    Assert.assertEquals("[text:test1:1.0000, text:and:1.0000, text:more:1.0000]", enc.asString("test1 and more"));
   }
 }

Modified: mahout/trunk/core/src/test/java/org/apache/mahout/vectors/WordLikeValueEncoderTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/vectors/WordLikeValueEncoderTest.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/vectors/WordLikeValueEncoderTest.java (original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/vectors/WordLikeValueEncoderTest.java Wed Aug 18 08:53:53 2010
@@ -21,17 +21,12 @@ import com.google.common.collect.Immutab
 import com.google.common.collect.ImmutableMap;
 import org.apache.mahout.math.DenseVector;
 import org.apache.mahout.math.Vector;
-import org.apache.mahout.vectors.AdaptiveWordValueEncoder;
-import org.apache.mahout.vectors.FeatureVectorEncoder;
-import org.apache.mahout.vectors.StaticWordValueEncoder;
+import org.junit.Assert;
 import org.junit.Test;
 
 import java.util.Iterator;
 import java.util.Locale;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-
 public class WordLikeValueEncoderTest {
   @Test
   public void testAddToVector() {
@@ -43,17 +38,17 @@ public class WordLikeValueEncoderTest {
     Iterator<Integer> j = ImmutableList.of(7, 118, 119, 199).iterator();
     while (i.hasNext()) {
       Vector.Element element = i.next();
-      assertEquals(j.next().intValue(), element.index());
-      assertEquals(1, element.get(), 0);
+      Assert.assertEquals(j.next().intValue(), element.index());
+      Assert.assertEquals(1, element.get(), 0);
     }
-    assertFalse(j.hasNext());
+    Assert.assertFalse(j.hasNext());
   }
 
   @Test
   public void testAsString() {
     Locale.setDefault(new Locale("EN", "US"));
     FeatureVectorEncoder enc = new StaticWordValueEncoder("word");
-    assertEquals("word:w1:1.0000", enc.asString("w1"));
+    Assert.assertEquals("word:w1:1.0000", enc.asString("w1"));
   }
 
   @Test
@@ -69,10 +64,10 @@ public class WordLikeValueEncoderTest {
     Iterator<Double> k = ImmutableList.of(3.0, 0.75, 1.5, 1.5, 0.75, 3.0).iterator();
     while (i.hasNext()) {
       Vector.Element element = i.next();
-      assertEquals(j.next().intValue(), element.index());
-      assertEquals(k.next(), element.get(), 0);
+      Assert.assertEquals(j.next().intValue(), element.index());
+      Assert.assertEquals(k.next(), element.get(), 0);
     }
-    assertFalse(j.hasNext());
+    Assert.assertFalse(j.hasNext());
   }
 
   @Test
@@ -85,12 +80,15 @@ public class WordLikeValueEncoderTest {
     enc.addToVector("word3", v);  // weight is log(6 / 1.5)
     Iterator<Vector.Element> i = v.iterateNonZero();
     Iterator<Integer> j = ImmutableList.of(7, 101, 118, 119, 152, 199).iterator();
-    Iterator<Double> k = ImmutableList.of(Math.log(2 / 1.5) + Math.log(4.5 / 2.5), Math.log(6 / 1.5), Math.log(3.5 / 1.5), Math.log(3.5 / 1.5), Math.log(6 / 1.5), Math.log(2 / 1.5) + Math.log(4.5 / 2.5)).iterator();
+    Iterator<Double> k = ImmutableList.of(Math.log(2 / 1.5) + Math.log(4.5 / 2.5),
+                                          Math.log(6 / 1.5), Math.log(3.5 / 1.5),
+                                          Math.log(3.5 / 1.5), Math.log(6 / 1.5),
+                                          Math.log(2 / 1.5) + Math.log(4.5 / 2.5)).iterator();
     while (i.hasNext()) {
       Vector.Element element = i.next();
-      assertEquals(j.next().intValue(), element.index());
-      assertEquals(k.next(), element.get(), 1e-6);
+      Assert.assertEquals(j.next().intValue(), element.index());
+      Assert.assertEquals(k.next(), element.get(), 1.0e-6);
     }
-    assertFalse(j.hasNext());
+    Assert.assertFalse(j.hasNext());
   }
 }

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/QRDecomposition.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/QRDecomposition.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/QRDecomposition.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/QRDecomposition.java Wed Aug 18 08:53:53 2010
@@ -27,6 +27,8 @@ package org.apache.mahout.math;
 
 import org.apache.mahout.math.function.Functions;
 
+import java.util.Locale;
+
 
 /**
  For an <tt>m x n</tt> matrix <tt>A</tt> with <tt>m >= n</tt>, the QR decomposition is an <tt>m x n</tt>
@@ -243,6 +245,6 @@ public class QRDecomposition {
    * Returns a rough string rendition of a QR.
    */
   public String toString() {
-    return String.format("QR(%d,%d,fullRank=%s)", originalColumns, originalRows, hasFullRank());
+    return String.format(Locale.ENGLISH, "QR(%d,%d,fullRank=%s)", originalColumns, originalRows, hasFullRank());
   }
 }

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Property.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Property.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Property.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Property.java Wed Aug 18 08:53:53 2010
@@ -19,6 +19,7 @@ import org.apache.mahout.math.matrix.imp
 import org.apache.mahout.math.matrix.impl.AbstractMatrix2D;
 
 import java.util.Formatter;
+import java.util.Locale;
 import java.util.TreeMap;
 
 /** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
@@ -1026,7 +1027,7 @@ public class Property extends Persistent
     for (String key : messages.keySet()) {
       maxLength = Math.max(key.length(), maxLength);
     }
-    String format = String.format("\\%%ds: \\%s\n", maxLength);
+    String format = String.format(Locale.ENGLISH, "\\%%ds: \\%s\n", maxLength);
 
     Formatter r = new Formatter();
     for (String key : messages.keySet()) {

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/GammaTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/GammaTest.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/GammaTest.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/GammaTest.java Wed Aug 18 08:53:53 2010
@@ -23,8 +23,7 @@ import org.junit.Assert;
 import org.junit.Test;
 
 import java.util.Arrays;
-
-import static org.junit.Assert.assertEquals;
+import java.util.Locale;
 
 public class GammaTest {
   @Test
@@ -41,7 +40,7 @@ public class GammaTest {
       // verify that empirical CDF matches theoretical one pretty closely
       for (double q : seq(0.01, 1, 0.01)) {
         double p = z[(int) (q * z.length)];
-        assertEquals(q, g.cdf(p), 0.01);
+        Assert.assertEquals(q, g.cdf(p), 0.01);
       }
     }
   }
@@ -55,10 +54,10 @@ public class GammaTest {
       Gamma g1 = new Gamma(1, beta, gen);
       Gamma g2 = new Gamma(1, 1, gen);
       for (double x : seq(0, 0.99, 0.1)) {
-        assertEquals(String.format("Rate invariance: x = %.4f, alpha = 1, beta = %.1f", x, beta),
-                1 - Math.exp(-x * beta), g1.cdf(x), 1e-9);
-        assertEquals(String.format("Rate invariance: x = %.4f, alpha = 1, beta = %.1f", x, beta),
-                g2.cdf(beta * x), g1.cdf(x), 1e-9);
+        Assert.assertEquals(String.format(Locale.ENGLISH, "Rate invariance: x = %.4f, alpha = 1, beta = %.1f", x, beta),
+                1 - Math.exp(-x * beta), g1.cdf(x), 1.0e-9);
+        Assert.assertEquals(String.format(Locale.ENGLISH, "Rate invariance: x = %.4f, alpha = 1, beta = %.1f", x, beta),
+                g2.cdf(beta * x), g1.cdf(x), 1.0e-9);
       }
     }
 
@@ -68,8 +67,9 @@ public class GammaTest {
       for (double beta : new double[]{0.1, 1, 2, 100}) {
         Gamma g1 = new Gamma(alpha, beta, gen);
         for (double x : seq(0, 0.9999, 0.001)) {
-          Assert.assertEquals(String.format("Rate invariance: x = %.4f, alpha = %.2f, beta = %.1f", x, alpha, beta),
-                  g.cdf(x * beta), g1.cdf(x), 0);
+          Assert.assertEquals(
+              String.format(Locale.ENGLISH, "Rate invariance: x = %.4f, alpha = %.2f, beta = %.1f", x, alpha, beta),
+                            g.cdf(x * beta), g1.cdf(x), 0);
         }
       }
     }
@@ -93,19 +93,20 @@ public class GammaTest {
 //     [1] 0.000000e+00 3.488879e-37 1.206254e-15 1.481528e-06 1.710831e-02 5.132988e-01 9.721363e-01 9.998389e-01 9.999999e-01 1.000000e+00 1.000000e+00
   }
 
-  private void checkGammaCdf(double alpha, double beta, double... values) {
+  private static void checkGammaCdf(double alpha, double beta, double... values) {
     Gamma g = new Gamma(alpha, beta, new MersenneTwister());
     int i = 0;
     for (double x : seq(0, 2 * alpha, 2 * alpha / 10)) {
-      assertEquals(String.format("alpha=%.2f, i=%d, x=%.2f", alpha, i, x), values[i], g.cdf(x), 1e-7);
+      Assert.assertEquals(String.format(Locale.ENGLISH, "alpha=%.2f, i=%d, x=%.2f", alpha, i, x),
+                                        values[i], g.cdf(x), 1.0e-7);
       i++;
     }
   }
 
-  private double[] seq(double from, double to, double by) {
+  private static double[] seq(double from, double to, double by) {
     double[] r = new double[(int) Math.ceil(0.999999 * (to - from) / by)];
     int i = 0;
-    for (double x = from; x < to - (to - from) * 1e-6; x += by) {
+    for (double x = from; x < to - (to - from) * 1.0e-6; x += by) {
       r[i++] = x;
     }
     return r;
@@ -118,8 +119,10 @@ public class GammaTest {
       for (double beta : new double[]{0.1, 1, 2, 100}) {
         Gamma g1 = new Gamma(alpha, beta, gen);
         for (double x : seq(0, 0.99, 0.1)) {
-          double p = Math.pow(beta, alpha) * Math.pow(x, alpha - 1) * Math.exp(-beta * x - org.apache.mahout.math.jet.stat.Gamma.logGamma(alpha));
-          assertEquals(String.format("alpha=%.2f, beta=%.2f, x=%.2f\n", alpha, beta, x), p, g1.pdf(x), 1e-9);
+          double p = Math.pow(beta, alpha) * Math.pow(x, alpha - 1) *
+                     Math.exp(-beta * x - org.apache.mahout.math.jet.stat.Gamma.logGamma(alpha));
+          Assert.assertEquals(String.format(Locale.ENGLISH, "alpha=%.2f, beta=%.2f, x=%.2f\n", alpha, beta, x),
+                                            p, g1.pdf(x), 1.0e-9);
         }
       }
     }

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/NegativeBinomialTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/NegativeBinomialTest.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/NegativeBinomialTest.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/NegativeBinomialTest.java Wed Aug 18 08:53:53 2010
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.apache.mahout.math.jet.random;
 
 import com.google.common.base.Charsets;
@@ -7,20 +24,21 @@ import com.google.common.io.CharStreams;
 import com.google.common.io.InputSupplier;
 import com.google.common.io.Resources;
 import org.apache.mahout.math.jet.random.engine.MersenneTwister;
+import org.junit.Assert;
 import org.junit.Test;
 
 import java.io.IOException;
 import java.io.InputStreamReader;
-
-import static org.junit.Assert.assertEquals;
+import java.util.Locale;
 
 public class NegativeBinomialTest {
-  private Splitter onComma = Splitter.on(",").trimResults();
+  private final Splitter onComma = Splitter.on(",").trimResults();
   private static final int N = 10000;
 
   @Test
   public void testDistributionFunctions() throws IOException {
-    InputSupplier<InputStreamReader> input = Resources.newReaderSupplier(Resources.getResource("negative-binomial-test-data.csv"), Charsets.UTF_8);
+    InputSupplier<InputStreamReader> input =
+        Resources.newReaderSupplier(Resources.getResource("negative-binomial-test-data.csv"), Charsets.UTF_8);
     boolean header = true;
     for (String line : CharStreams.readLines(input)) {
       if (header) {
@@ -34,8 +52,8 @@ public class NegativeBinomialTest {
         double density = Double.parseDouble(Iterables.get(values, 3));
         double cume = Double.parseDouble(Iterables.get(values, 4));
         NegativeBinomial nb = new NegativeBinomial(r, p, new MersenneTwister());
-        assertEquals("cumulative " + k + "," + p + "," + r, cume, nb.cdf(k), cume * 1e-05);
-        assertEquals("density " + k + "," + p + "," + r, density, nb.pdf(k), density * 1e-05);
+        Assert.assertEquals("cumulative " + k + ',' + p + ',' + r, cume, nb.cdf(k), cume * 1e-05);
+        Assert.assertEquals("density " + k + ',' + p + ',' + r, density, nb.pdf(k), density * 1e-05);
       }
     }
   }
@@ -55,7 +73,12 @@ public class NegativeBinomialTest {
 
         // probably should do a chi^2 or LLR test here especially since we know the PDF
         for (int k = 0; k < counts.length; k++) {
-          assertEquals(String.format("r=%d,p=%.3f,k=%d,count=%d,pdf=%.3f", r, p, k, counts[k], nb.pdf(k)), N * nb.pdf(k), counts[k], Math.max(3, 4 * Math.sqrt(N * nb.pdf(k) * (1 - nb.pdf(k)))));
+          Assert.assertEquals(String.format(Locale.ENGLISH,
+                                            "r=%d,p=%.3f,k=%d,count=%d,pdf=%.3f",
+                                            r, p, k, counts[k], nb.pdf(k)),
+                              N * nb.pdf(k),
+                              counts[k],
+                              Math.max(3, 4 * Math.sqrt(N * nb.pdf(k) * (1 - nb.pdf(k)))));
         }
       }
     }

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/stat/GammaTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/stat/GammaTest.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/stat/GammaTest.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/stat/GammaTest.java Wed Aug 18 08:53:53 2010
@@ -20,40 +20,41 @@ package org.apache.mahout.math.jet.stat;
 import com.google.common.base.Charsets;
 import com.google.common.base.Splitter;
 import com.google.common.collect.Iterables;
-import com.google.common.io.*;
+import com.google.common.io.CharStreams;
+import com.google.common.io.InputSupplier;
+import com.google.common.io.Resources;
+import org.junit.Assert;
 import org.junit.Test;
 
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.Random;
 
-import static org.junit.Assert.assertEquals;
-
 public class GammaTest {
   @Test
   public void testGamma() {
-    double[] x = new double[]{1, 2, 5, 10, 20, 50, 100};
-    double[] expected = new double[]{1.000000e+00, 1.000000e+00, 2.400000e+01, 3.628800e+05, 1.216451e+17, 6.082819e+62, 9.332622e+155};
+    double[] x = {1, 2, 5, 10, 20, 50, 100};
+    double[] expected = {1.000000e+00, 1.000000e+00, 2.400000e+01, 3.628800e+05, 1.216451e+17, 6.082819e+62, 9.332622e+155};
 
     for (int i = 0; i < x.length; i++) {
-      assertEquals(expected[i], Gamma.gamma(x[i]), expected[i] * 1e-5);
-      assertEquals(gammaInteger(x[i]), Gamma.gamma(x[i]), expected[i] * 1e-5);
-      assertEquals(gammaInteger(x[i]), Math.exp(Gamma.logGamma(x[i])), expected[i] * 1e-5);
+      Assert.assertEquals(expected[i], Gamma.gamma(x[i]), expected[i] * 1.0e-5);
+      Assert.assertEquals(gammaInteger(x[i]), Gamma.gamma(x[i]), expected[i] * 1.0e-5);
+      Assert.assertEquals(gammaInteger(x[i]), Math.exp(Gamma.logGamma(x[i])), expected[i] * 1.0e-5);
     }
   }
 
   @Test
   public void testNegativeArgForGamma() {
-    double[] x = new double[]{-30.3, -20.7, -10.5, -1.1, 0.5, 0.99, -0.999};
-    double[] expected = new double[]{-5.243216e-33, -1.904051e-19, -2.640122e-07, 9.714806e+00, 1.772454e+00, 1.005872e+00, -1.000424e+03};
+    double[] x = {-30.3, -20.7, -10.5, -1.1, 0.5, 0.99, -0.999};
+    double[] expected = {-5.243216e-33, -1.904051e-19, -2.640122e-07, 9.714806e+00, 1.772454e+00, 1.005872e+00, -1.000424e+03};
 
     for (int i = 0; i < x.length; i++) {
-      assertEquals(expected[i], Gamma.gamma(x[i]), Math.abs(expected[i] * 1e-5));
-      assertEquals(Math.abs(expected[i]), Math.abs(Math.exp(Gamma.logGamma(x[i]))), Math.abs(expected[i] * 1e-5));
+      Assert.assertEquals(expected[i], Gamma.gamma(x[i]), Math.abs(expected[i] * 1.0e-5));
+      Assert.assertEquals(Math.abs(expected[i]), Math.abs(Math.exp(Gamma.logGamma(x[i]))), Math.abs(expected[i] * 1.0e-5));
     }
   }
 
-  private double gammaInteger(double x) {
+  private static double gammaInteger(double x) {
     double r = 1;
     for (int i = 2; i < x; i++) {
       r *= i;
@@ -63,27 +64,27 @@ public class GammaTest {
 
   @Test
   public void testBigX() {
-    assertEquals(factorial(4), 4 * 3 * 2, 0);
-    assertEquals(factorial(4), Gamma.gamma(5), 0);
-    assertEquals(factorial(14), Gamma.gamma(15), 0);
-    assertEquals(factorial(34), Gamma.gamma(35), 1e-15 * factorial(34));
-    assertEquals(factorial(44), Gamma.gamma(45), 1e-15 * factorial(44));
-
-    assertEquals(-6.884137e-40 + 3.508309e-47, Gamma.gamma(-35.1), 1e-52);
-    assertEquals(-3.915646e-41 - 3.526813e-48 - 1.172516e-55, Gamma.gamma(-35.9), 1e-52);
-    assertEquals(-2000000000.577215, Gamma.gamma(-0.5e-9), 1e-15 * 2000000000.577215);
-    assertEquals(1999999999.422784, Gamma.gamma(0.5e-9), 1e-15 * 1999999999.422784);
-    assertEquals(1.324296658017984e+252, Gamma.gamma(146.1), 1e-10 * 1.324296658017984e+252);
+    Assert.assertEquals(factorial(4), 4 * 3 * 2, 0);
+    Assert.assertEquals(factorial(4), Gamma.gamma(5), 0);
+    Assert.assertEquals(factorial(14), Gamma.gamma(15), 0);
+    Assert.assertEquals(factorial(34), Gamma.gamma(35), 1.0e-15 * factorial(34));
+    Assert.assertEquals(factorial(44), Gamma.gamma(45), 1.0e-15 * factorial(44));
+
+    Assert.assertEquals(-6.884137e-40 + 3.508309e-47, Gamma.gamma(-35.1), 1.0e-52);
+    Assert.assertEquals(-3.915646e-41 - 3.526813e-48 - 1.172516e-55, Gamma.gamma(-35.9), 1.0e-52);
+    Assert.assertEquals(-2000000000.577215, Gamma.gamma(-0.5e-9), 1.0e-15 * 2000000000.577215);
+    Assert.assertEquals(1999999999.422784, Gamma.gamma(0.5e-9), 1.0e-15 * 1999999999.422784);
+    Assert.assertEquals(1.324296658017984e+252, Gamma.gamma(146.1), 1.0e-10 * 1.324296658017984e+252);
 
     for (double x : new double[]{5, 15, 35, 45, -35.1, -35.9, -0.5e-9, 0.5e-9, 146.1}) {
       double ref = Math.log(Math.abs(Gamma.gamma(x)));
       double actual = Gamma.logGamma(x);
       double diff = Math.abs(ref - actual) / ref;
-      assertEquals("gamma versus logGamma at " + x + " (diff = " + diff + ")", 0, (ref - actual) / ref, 1e-8);
+      Assert.assertEquals("gamma versus logGamma at " + x + " (diff = " + diff + ')', 0, (ref - actual) / ref, 1.0e-8);
     }
   }
 
-  private double factorial(int n) {
+  private static double factorial(int n) {
     double r = 1;
     for (int i = 2; i <= n; i++) {
       r *= i;
@@ -100,7 +101,7 @@ public class GammaTest {
       double ref = Math.exp(Gamma.logGamma(alpha) + Gamma.logGamma(beta) - Gamma.logGamma(alpha + beta));
       double actual = Gamma.beta(alpha, beta);
       double err = (ref - actual) / ref;
-      assertEquals("beta at (" + alpha + ", " + beta + ") relative error = " + err, 0, err, 1e-10);
+      Assert.assertEquals("beta at (" + alpha + ", " + beta + ") relative error = " + err, 0, err, 1.0e-10);
     }
   }
 
@@ -108,7 +109,8 @@ public class GammaTest {
   public void incompleteBeta() throws IOException {
     Splitter onComma = Splitter.on(",").trimResults();
 
-    InputSupplier<InputStreamReader> input = Resources.newReaderSupplier(Resources.getResource("beta-test-data.csv"), Charsets.UTF_8);
+    InputSupplier<InputStreamReader> input =
+        Resources.newReaderSupplier(Resources.getResource("beta-test-data.csv"), Charsets.UTF_8);
     boolean header = true;
     for (String line : CharStreams.readLines(input)) {
       if (header) {
@@ -121,8 +123,10 @@ public class GammaTest {
         double x = Double.parseDouble(Iterables.get(values, 2));
         double ref = Double.parseDouble(Iterables.get(values, 3));
         double actual = Gamma.incompleteBeta(alpha, beta, x);
-        assertEquals(alpha + "," + beta + "," + x, ref, actual, ref * 1e-05);
+        Assert.assertEquals(alpha + "," + beta + ',' + x, ref, actual, ref * 1.0e-5);
       }
     }
   }
+
+
 }

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/stat/ProbabilityTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/stat/ProbabilityTest.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/stat/ProbabilityTest.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/stat/ProbabilityTest.java Wed Aug 18 08:53:53 2010
@@ -19,6 +19,8 @@ package org.apache.mahout.math.jet.stat;
 
 import junit.framework.TestCase;
 
+import java.util.Locale;
+
 public class ProbabilityTest extends TestCase {
   public void testNormalCdf() {
     // computed by R
@@ -168,7 +170,9 @@ public class ProbabilityTest extends Tes
     for (int j = 0; j < 4; j++) {
       for (int i = 0; i < 100; i++) {
         double x = i / 99.0;
-        String p = String.format("pbeta(q=%6.4f, shape1=%5.3f shape2=%5.3f) = %.8f", x, alpha[j], beta[j], ref[j][i]);
+        String p = String.format(Locale.ENGLISH,
+                                 "pbeta(q=%6.4f, shape1=%5.3f shape2=%5.3f) = %.8f", 
+                                 x, alpha[j], beta[j], ref[j][i]);
         assertEquals(p, ref[j][i], Probability.beta(alpha[j], beta[j], x), 1.0e-7);
       }
     }

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/stats/OnlineSummarizerTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/stats/OnlineSummarizerTest.java?rev=986599&r1=986598&r2=986599&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/stats/OnlineSummarizerTest.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/stats/OnlineSummarizerTest.java Wed Aug 18 08:53:53 2010
@@ -80,7 +80,7 @@ public class OnlineSummarizerTest {
 
   private static void check(OnlineSummarizer x, double... values) {
     for (int i = 0; i < 5; i++) {
-      checkRange(String.format("quartile %d", i), x.quartile(i), values[2 * i], values[2 * i + 1]);
+      checkRange("quartile " + i, x.quartile(i), values[2 * i], values[2 * i + 1]);
     }
     Assert.assertEquals(x.quartile(2), x.median(), 0);
 
@@ -90,7 +90,7 @@ public class OnlineSummarizerTest {
 
   private static void checkRange(String msg, double v, double low, double high) {
     if (v < low || v > high) {
-      Assert.fail(String.format("Wanted %s to be in range [%e,%e] but got %e", msg, low, high, v));
+      Assert.fail("Wanted " + msg + " to be in range [" + low + "," + high + "] but got " + v);
     }
   }