mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r993365 [1/3] - in /mahout/trunk: core/src/main/java/org/apache/mahout/cf/taste/hadoop/ core/src/main/java/org/apache/mahout/classifier/bayes/ core/src/main/java/org/apache/mahout/classifier/bayes/mapreduce/cbayes/ core/src/main/java/org/ap...
Date Tue, 07 Sep 2010 13:54:24 GMT
Author: srowen
Date: Tue Sep  7 13:54:21 2010
New Revision: 993365

URL: http://svn.apache.org/viewvc?rev=993365&view=rev
Log:
More checkstyle / PMD / findbugs changes

Removed:
    mahout/trunk/utils/src/test/java/org/apache/mahout/utils/vectors/SequenceFileVectorIterableTest.java
Modified:
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityCountWritable.java
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityPrefWritable.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/TrainClassifier.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/mapreduce/cbayes/CBayesDriver.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/mapreduce/common/FeatureLabelComparator.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/evaluation/Auc.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/CrossFoldLearner.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/CsvRecordFactory.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/ElasticBandPrior.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/L2.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/ModelSerializer.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/OnlineLogisticRegression.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/TPrior.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/AbstractCluster.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/DistanceMeasureCluster.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/VectorModelClassifier.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyClusterer.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyDriver.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/DirichletDriver.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/DirichletMapper.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/models/AbstractVectorModelDistribution.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/models/GaussianCluster.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/FuzzyKMeansClusterer.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/FuzzyKMeansDriver.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/FuzzyKMeansUtil.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/SoftCluster.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansClusterMapper.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansClusterer.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansDriver.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansMapper.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansUtil.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/RandomSeedGenerator.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDADriver.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopy.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyCreatorMapper.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopyDriver.java
    mahout/trunk/core/src/main/java/org/apache/mahout/common/IntPairWritable.java
    mahout/trunk/core/src/main/java/org/apache/mahout/df/data/DataConverter.java
    mahout/trunk/core/src/main/java/org/apache/mahout/df/mapreduce/inmem/InMemInputFormat.java
    mahout/trunk/core/src/main/java/org/apache/mahout/ep/State.java
    mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/fpgrowth/FPGrowth.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/EigenVerificationJob.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/RowSimilarityJob.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/SimilarityMatrixEntryKey.java
    mahout/trunk/core/src/main/java/org/apache/mahout/vectors/Dictionary.java
    mahout/trunk/core/src/main/java/org/apache/mahout/vectors/InteractionValueEncoder.java
    mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ItemSimilarityTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/clustering/dirichlet/TestMapReduce.java
    mahout/trunk/core/src/test/java/org/apache/mahout/clustering/kmeans/TestKmeansClustering.java
    mahout/trunk/core/src/test/java/org/apache/mahout/clustering/kmeans/TestRandomSeedGenerator.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/PrepareTwentyNewsgroups.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/bayes/SplitBayesInput.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainLogistic.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/display/DisplayClustering.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/display/DisplayMeanShift.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/fuzzykmeans/Job.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/meanshift/Job.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/travellingsalesman/TravellingSalesman.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Beta.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/BreitWigner.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/BreitWignerMeanSquare.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/ChiSquare.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Empirical.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/EmpiricalWalker.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Exponential.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/ExponentialPower.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Gamma.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/HyperGeometric.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Hyperbolic.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Logarithmic.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Normal.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Poisson.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/PoissonSlow.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/StudentT.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/VonMises.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Zeta.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/engine/MersenneTwister.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/sampling/RandomSampler.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/sampling/RandomSamplingAssistant.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/sampling/WeightedRandomSampler.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/Descriptive.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleFactory1D.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleFactory2D.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Algebra.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/LUDecompositionQuick.java
    mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSingularValueDecomposition.java
    mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/NegativeBinomialTest.java
    mahout/trunk/utils/src/main/java/org/apache/mahout/clustering/cdbw/CDbwDriver.java
    mahout/trunk/utils/src/main/java/org/apache/mahout/clustering/cdbw/CDbwEvaluator.java
    mahout/trunk/utils/src/main/java/org/apache/mahout/clustering/cdbw/CDbwMapper.java
    mahout/trunk/utils/src/main/java/org/apache/mahout/clustering/lda/LDAPrintTopics.java
    mahout/trunk/utils/src/main/java/org/apache/mahout/utils/SequenceFileDumper.java
    mahout/trunk/utils/src/main/java/org/apache/mahout/utils/clustering/ClusterDumper.java
    mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocMapper.java
    mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/GramKeyGroupComparator.java
    mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/VectorDumper.java
    mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/lucene/Driver.java
    mahout/trunk/utils/src/test/java/org/apache/mahout/clustering/TestClusterDumper.java

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityCountWritable.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityCountWritable.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityCountWritable.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityCountWritable.java Tue Sep  7 13:54:21 2010
@@ -25,7 +25,7 @@ import org.apache.mahout.math.VarLongWri
 import org.apache.mahout.math.Varint;
 
 /** A {@link org.apache.hadoop.io.Writable} encapsulating an item ID and a count . */
-public final class EntityCountWritable extends VarLongWritable implements Cloneable {
+public final class EntityCountWritable extends VarLongWritable {
 
   private int count;
 

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityPrefWritable.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityPrefWritable.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityPrefWritable.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityPrefWritable.java Tue Sep  7 13:54:21 2010
@@ -25,7 +25,7 @@ import org.apache.mahout.common.RandomUt
 import org.apache.mahout.math.VarLongWritable;
 
 /** A {@link org.apache.hadoop.io.Writable} encapsulating an item ID and a preference value. */
-public final class EntityPrefWritable extends VarLongWritable implements Cloneable {
+public final class EntityPrefWritable extends VarLongWritable {
   
   private float prefValue;
   

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/TrainClassifier.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/TrainClassifier.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/TrainClassifier.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/TrainClassifier.java Tue Sep  7 13:54:21 2010
@@ -121,17 +121,21 @@ public final class TrainClassifier {
       String dataSourceType = (String) cmdLine.getValue(dataSourceOpt);
       
       BayesParameters params = new BayesParameters();
-      if (cmdLine.hasOption(gramSizeOpt)) 
+      if (cmdLine.hasOption(gramSizeOpt)) {
         params.setGramSize(Integer.parseInt((String) cmdLine.getValue(gramSizeOpt)));
+      }
       
-      if (cmdLine.hasOption(minDfOpt))
+      if (cmdLine.hasOption(minDfOpt)) {
         params.setMinDF(Integer.parseInt((String) cmdLine.getValue(minDfOpt)));
+      }
       
-      if (cmdLine.hasOption(minSupportOpt))
+      if (cmdLine.hasOption(minSupportOpt)) {
         params.setMinSupport(Integer.parseInt((String) cmdLine.getValue(minSupportOpt)));
+      }
       
-      if (cmdLine.hasOption(skipCleanupOpt))
+      if (cmdLine.hasOption(skipCleanupOpt)) {
         params.setSkipCleanup(true);
+      }
       
       String alphaI = "1.0";
       if (cmdLine.hasOption(alphaOpt)) {
@@ -140,7 +144,7 @@ public final class TrainClassifier {
       
       params.set("alpha_i", alphaI);
       
-      if (dataSourceType.equals("hbase")) {
+      if ("hbase".equals(dataSourceType)) {
         params.set("dataSource", "hbase");
       } else {
         params.set("dataSource", "hdfs");
@@ -148,11 +152,11 @@ public final class TrainClassifier {
 
       Path inputPath = new Path((String) cmdLine.getValue(inputDirOpt));
       Path outputPath = new Path((String) cmdLine.getValue(outputOpt));
-      if (classifierType.equalsIgnoreCase("bayes")) {
+      if ("bayes".equalsIgnoreCase(classifierType)) {
         log.info("Training Bayes Classifier");
         trainNaiveBayes(inputPath, outputPath, params);
         
-      } else if (classifierType.equalsIgnoreCase("cbayes")) {
+      } else if ("cbayes".equalsIgnoreCase(classifierType)) {
         log.info("Training Complementary Bayes Classifier");
         // setup the HDFS and copy the files there, then run the trainer
         trainCNaiveBayes(inputPath, outputPath, params);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/mapreduce/cbayes/CBayesDriver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/mapreduce/cbayes/CBayesDriver.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/mapreduce/cbayes/CBayesDriver.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/mapreduce/cbayes/CBayesDriver.java Tue Sep  7 13:54:21 2010
@@ -59,7 +59,9 @@ public class CBayesDriver implements Bay
     CBayesThetaNormalizerDriver normalizer = new CBayesThetaNormalizerDriver();
     normalizer.runJob(input, output, params);
     
-    if (Boolean.getBoolean(params.get("skipCleanup"))) return;
+    if (Boolean.parseBoolean(params.get("skipCleanup"))) {
+      return;
+    }
     
     Path docCountOutPath = new Path(output, "trainer-docCount");
     HadoopUtil.overwriteOutput(docCountOutPath);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/mapreduce/common/FeatureLabelComparator.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/mapreduce/common/FeatureLabelComparator.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/mapreduce/common/FeatureLabelComparator.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/mapreduce/common/FeatureLabelComparator.java Tue Sep  7 13:54:21 2010
@@ -23,7 +23,9 @@ import org.apache.hadoop.io.WritableComp
 import org.apache.hadoop.io.WritableComparator;
 import org.apache.mahout.common.StringTuple;
 
-public class FeatureLabelComparator extends WritableComparator {
+import java.io.Serializable;
+
+public class FeatureLabelComparator extends WritableComparator implements Serializable {
 
   public FeatureLabelComparator() {
     super(StringTuple.class, true);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/evaluation/Auc.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/evaluation/Auc.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/evaluation/Auc.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/evaluation/Auc.java Tue Sep  7 13:54:21 2010
@@ -35,11 +35,11 @@ import java.util.Random;
 public class Auc {
   private int maxBufferSize = 10000;
   private final DoubleArrayList[] scores = {new DoubleArrayList(), new DoubleArrayList()};
-  private Random rand;
-  private int samples = 0;
+  private final Random rand;
+  private int samples;
   private double threshold;
-  private Matrix confusion;
-  private DenseMatrix entropy;
+  private final Matrix confusion;
+  private final DenseMatrix entropy;
 
   private boolean probabilityScore = true;
 

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/CrossFoldLearner.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/CrossFoldLearner.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/CrossFoldLearner.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/CrossFoldLearner.java Tue Sep  7 13:54:21 2010
@@ -19,10 +19,10 @@ import java.util.List;
  * record should be passed with each training example.
  */
 public class CrossFoldLearner extends AbstractVectorClassifier implements OnlineLearner {
-  private int record = 0;
+  private int record;
   private OnlineAuc auc = new OnlineAuc();
-  private double logLikelihood = 0;
-  private List<OnlineLogisticRegression> models = Lists.newArrayList();
+  private double logLikelihood;
+  private final List<OnlineLogisticRegression> models = Lists.newArrayList();
 
   // lambda, learningRate, perTermOffset, perTermExponent
   private double[] parameters = new double[4];
@@ -30,7 +30,6 @@ public class CrossFoldLearner extends Ab
   private PriorFunction prior;
 
   // pretty much just for GSON
-  @SuppressWarnings({"UnusedDeclaration"})
   public CrossFoldLearner() {
   }
 

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/CsvRecordFactory.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/CsvRecordFactory.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/CsvRecordFactory.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/CsvRecordFactory.java Tue Sep  7 13:54:21 2010
@@ -69,9 +69,9 @@ public class CsvRecordFactory implements
 
   // crude CSV value splitter.  This will fail if any double quoted strings have
   // commas inside.  Also, escaped quotes will not be unescaped.  Good enough for now.
-  private Splitter onComma = Splitter.on(",").trimResults(CharMatcher.is('"'));
+  private final Splitter onComma = Splitter.on(",").trimResults(CharMatcher.is('"'));
 
-  private static Map<String, Class<? extends FeatureVectorEncoder>> typeDictionary =
+  private static final Map<String, Class<? extends FeatureVectorEncoder>> typeDictionary =
           ImmutableMap.<String, Class<? extends FeatureVectorEncoder>>builder()
                   .put("continuous", ContinuousValueEncoder.class)
                   .put("numeric", ContinuousValueEncoder.class)
@@ -82,16 +82,16 @@ public class CsvRecordFactory implements
                   .put("t", TextValueEncoder.class)
                   .build();
 
-  private Map<String, Set<Integer>> traceDictionary = Maps.newTreeMap();
+  private final Map<String, Set<Integer>> traceDictionary = Maps.newTreeMap();
 
   private int target;
-  private Dictionary targetDictionary;
+  private final Dictionary targetDictionary;
 
   private List<Integer> predictors;
   private Map<Integer, FeatureVectorEncoder> predictorEncoders;
   private int maxTargetValue = Integer.MAX_VALUE;
-  private String targetName;
-  private Map<String, String> typeMap;
+  private final String targetName;
+  private final Map<String, String> typeMap;
   private List<String> variableNames;
   private boolean includeBiasTerm;
   private static final String CANNOT_CONSTRUCT_CONVERTER = "Unable to construct type converter... shouldn't be possible";

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/ElasticBandPrior.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/ElasticBandPrior.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/ElasticBandPrior.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/ElasticBandPrior.java Tue Sep  7 13:54:21 2010
@@ -22,9 +22,9 @@ package org.apache.mahout.classifier.sgd
  * interesting mixture of sparsity and load-sharing between redundant predictors.
  */
 public class ElasticBandPrior extends PriorFunction {
-  private double alphaByLambda;
-  private L1 l1;
-  private L2 l2;
+  private final double alphaByLambda;
+  private final L1 l1;
+  private final L2 l2;
 
   public ElasticBandPrior(double alphaByLambda) {
     this.alphaByLambda = alphaByLambda;
@@ -34,11 +34,11 @@ public class ElasticBandPrior extends Pr
 
   @Override
   public double age(double oldValue, double generations, double learningRate) {
-    oldValue = oldValue * Math.pow(1 - alphaByLambda * learningRate , generations);
+    oldValue *= Math.pow(1 - alphaByLambda * learningRate, generations);
     double newValue = oldValue - Math.signum(oldValue) * learningRate * generations;
-    if (newValue * oldValue < 0) {
+    if (newValue * oldValue < 0.0) {
       // don't allow the value to change sign
-      return 0;
+      return 0.0;
     } else {
       return newValue;
     }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/L2.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/L2.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/L2.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/L2.java Tue Sep  7 13:54:21 2010
@@ -17,15 +17,13 @@
 
 package org.apache.mahout.classifier.sgd;
 
-import static java.lang.Math.log;
-
 /**
  * Implements the Gaussian prior.  This prior has a tendency to decrease large coefficients toward zero, but
  * doesn't tend to set them to exactly zero.
  */
 public class L2 extends PriorFunction {
-  private double s2;
-  private double s;
+  private final double s2;
+  private final double s;
 
   public L2(double scale) {
     this.s = scale;
@@ -34,11 +32,11 @@ public class L2 extends PriorFunction {
 
   @Override
   public double age(double oldValue, double generations, double learningRate) {
-    return oldValue * Math.pow(1 - learningRate / s2, generations);
+    return oldValue * Math.pow(1.0 - learningRate / s2, generations);
   }
 
   @Override
   public double logP(double betaIJ) {
-    return -betaIJ * betaIJ / s2 / 2 - log(s) - log(2 * Math.PI) / 2;
+    return -betaIJ * betaIJ / s2 / 2.0 - Math.log(s) - Math.log(2.0 * Math.PI) / 2.0;
   }
 }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/ModelSerializer.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/ModelSerializer.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/ModelSerializer.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/ModelSerializer.java Tue Sep  7 13:54:21 2010
@@ -1,6 +1,33 @@
+/**
+ * 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.classifier.sgd;
 
-import com.google.gson.*;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.InstanceCreator;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
 import com.google.gson.reflect.TypeToken;
 import org.apache.mahout.ep.EvolutionaryProcess;
 import org.apache.mahout.ep.Mapping;
@@ -13,6 +40,7 @@ import org.apache.mahout.math.stats.Onli
 
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 import java.io.Reader;
 import java.lang.reflect.Type;
 import java.util.List;
@@ -20,7 +48,8 @@ import java.util.List;
 /**
  * Provides the ability to store SGD model-related objects as JSON.
  */
-public class ModelSerializer {
+public final class ModelSerializer {
+
   // thread-local singleton json (de)serializer
   private static final ThreadLocal<Gson> GSON;
   static {
@@ -50,9 +79,12 @@ public class ModelSerializer {
   }
 
   public static void writeJson(String path, AdaptiveLogisticRegression model) throws IOException {
-    FileWriter out = new FileWriter(path);
-    out.write(gson().toJson(model));
-    out.close();
+    OutputStreamWriter out = new FileWriter(path);
+    try {
+      out.write(gson().toJson(model));
+    } finally {
+      out.close();
+    }
   }
 
   /**
@@ -68,12 +100,15 @@ public class ModelSerializer {
 
   private static class MappingTypeAdapter implements JsonDeserializer<Mapping>, JsonSerializer<Mapping> {
     @Override
-    public Mapping deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
+    public Mapping deserialize(JsonElement jsonElement,
+                               Type type,
+                               JsonDeserializationContext jsonDeserializationContext) {
       JsonObject x = jsonElement.getAsJsonObject();
       try {
-        return jsonDeserializationContext.deserialize(x.get("value"), (Class) Class.forName(x.get("class").getAsString()));
+        return jsonDeserializationContext.deserialize(x.get("value"), Class.forName(x.get("class").getAsString()));
       } catch (ClassNotFoundException e) {
-        throw new IllegalStateException("Can't understand serialized data, found bad type: " + x.get("class").getAsString());
+        throw new IllegalStateException("Can't understand serialized data, found bad type: "
+            + x.get("class").getAsString());
       }
     }
 
@@ -88,17 +123,22 @@ public class ModelSerializer {
 
   private static class PriorTypeAdapter implements JsonDeserializer<PriorFunction>, JsonSerializer<PriorFunction> {
     @Override
-    public PriorFunction deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
+    public PriorFunction deserialize(JsonElement jsonElement,
+                                     Type type,
+                                     JsonDeserializationContext jsonDeserializationContext) {
       JsonObject x = jsonElement.getAsJsonObject();
       try {
-        return jsonDeserializationContext.deserialize(x.get("value"), (Class) Class.forName(x.get("class").getAsString()));
+        return jsonDeserializationContext.deserialize(x.get("value"), Class.forName(x.get("class").getAsString()));
       } catch (ClassNotFoundException e) {
-        throw new IllegalStateException("Can't understand serialized data, found bad type: " + x.get("class").getAsString());
+        throw new IllegalStateException("Can't understand serialized data, found bad type: "
+            + x.get("class").getAsString());
       }
     }
 
     @Override
-    public JsonElement serialize(PriorFunction priorFunction, Type type, JsonSerializationContext jsonSerializationContext) {
+    public JsonElement serialize(PriorFunction priorFunction,
+                                 Type type,
+                                 JsonSerializationContext jsonSerializationContext) {
       JsonObject r = new JsonObject();
       r.add("class", new JsonPrimitive(priorFunction.getClass().getName()));
       r.add("value", jsonSerializationContext.serialize(priorFunction));
@@ -108,7 +148,9 @@ public class ModelSerializer {
 
   private static class CrossFoldLearnerTypeAdapter implements JsonDeserializer<CrossFoldLearner> {
     @Override
-    public CrossFoldLearner deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
+    public CrossFoldLearner deserialize(JsonElement jsonElement,
+                                        Type type,
+                                        JsonDeserializationContext jsonDeserializationContext) {
       CrossFoldLearner r = new CrossFoldLearner();
       JsonObject x = jsonElement.getAsJsonObject();
       r.setRecord(x.get("record").getAsInt());
@@ -117,7 +159,8 @@ public class ModelSerializer {
 
       JsonArray models = x.get("models").getAsJsonArray();
       for (JsonElement model : models) {
-        r.addModel(jsonDeserializationContext.<OnlineLogisticRegression>deserialize(model, OnlineLogisticRegression.class));
+        r.addModel(
+            jsonDeserializationContext.<OnlineLogisticRegression>deserialize(model, OnlineLogisticRegression.class));
       }
 
       r.setParameters(asArray(x, "parameters"));
@@ -211,7 +254,9 @@ public class ModelSerializer {
   private static class StateTypeAdapter implements JsonSerializer<State<AdaptiveLogisticRegression.Wrapper>>,
     JsonDeserializer<State<AdaptiveLogisticRegression.Wrapper>> {
     @Override
-    public State<AdaptiveLogisticRegression.Wrapper> deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
+    public State<AdaptiveLogisticRegression.Wrapper> deserialize(
+      JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) {
+
       JsonObject v = (JsonObject) jsonElement;
       double[] params = asArray(v, "params");
       double omni = v.get("omni").getAsDouble();
@@ -226,12 +271,17 @@ public class ModelSerializer {
       }.getType();
       r.setMaps(jsonDeserializationContext.<List<Mapping>>deserialize(v.get("maps"), mapListType));
 
-      r.setPayload(jsonDeserializationContext.<AdaptiveLogisticRegression.Wrapper>deserialize(v.get("payload"), AdaptiveLogisticRegression.Wrapper.class));
+      r.setPayload(
+          jsonDeserializationContext.<AdaptiveLogisticRegression.Wrapper>deserialize(
+              v.get("payload"),
+              AdaptiveLogisticRegression.Wrapper.class));
       return r;
     }
 
     @Override
-    public JsonElement serialize(State<AdaptiveLogisticRegression.Wrapper> state, Type type, JsonSerializationContext jsonSerializationContext) {
+    public JsonElement serialize(State<AdaptiveLogisticRegression.Wrapper> state,
+                                 Type type,
+                                 JsonSerializationContext jsonSerializationContext) {
       JsonObject r = new JsonObject();
       r.add("id", new JsonPrimitive(state.getId()));
       JsonArray v = new JsonArray();
@@ -258,9 +308,12 @@ public class ModelSerializer {
     JsonDeserializer<AdaptiveLogisticRegression> {
 
     @Override
-    public AdaptiveLogisticRegression deserialize(JsonElement element, Type type, JsonDeserializationContext jdc) throws JsonParseException {
+    public AdaptiveLogisticRegression deserialize(JsonElement element, Type type, JsonDeserializationContext jdc) {
       JsonObject x = element.getAsJsonObject();
-      AdaptiveLogisticRegression r = new AdaptiveLogisticRegression(x.get("numCategories").getAsInt(), x.get("numFeatures").getAsInt(), jdc.<PriorFunction>deserialize(x.get("prior"), PriorFunction.class));
+      AdaptiveLogisticRegression r =
+          new AdaptiveLogisticRegression(x.get("numCategories").getAsInt(),
+                                         x.get("numFeatures").getAsInt(),
+                                         jdc.<PriorFunction>deserialize(x.get("prior"), PriorFunction.class));
       Type stateType = new TypeToken<State<AdaptiveLogisticRegression.Wrapper>>() {
       }.getType();
       r.setEvaluationInterval(x.get("evaluationInterval").getAsInt());
@@ -272,8 +325,8 @@ public class ModelSerializer {
       r.setSeed(jdc.<State<AdaptiveLogisticRegression.Wrapper>>deserialize(x.get("seed"), stateType));
       r.setBest(jdc.<State<AdaptiveLogisticRegression.Wrapper>>deserialize(x.get("best"), stateType));
 
-      r.setBuffer(jdc.<List<AdaptiveLogisticRegression.TrainingExample>>deserialize(x.get("buffer"), new TypeToken<List<AdaptiveLogisticRegression.TrainingExample>>() {
-      }.getType()));
+      r.setBuffer(jdc.<List<AdaptiveLogisticRegression.TrainingExample>>deserialize(x.get("buffer"),
+                  new TypeToken<List<AdaptiveLogisticRegression.TrainingExample>>() {}.getType()));
       return r;
     }
 
@@ -299,11 +352,11 @@ public class ModelSerializer {
     }
   }
 
-  private static class EvolutionaryProcessTypeAdapter implements InstanceCreator<EvolutionaryProcess<AdaptiveLogisticRegression.Wrapper>>,
+  private static class EvolutionaryProcessTypeAdapter implements
+    InstanceCreator<EvolutionaryProcess<AdaptiveLogisticRegression.Wrapper>>,
     JsonDeserializer<EvolutionaryProcess<AdaptiveLogisticRegression.Wrapper>>,
     JsonSerializer<EvolutionaryProcess<AdaptiveLogisticRegression.Wrapper>> {
-    private static final Type STATE_TYPE = new TypeToken<State<AdaptiveLogisticRegression.Wrapper>>() {
-    }.getType();
+    private static final Type STATE_TYPE = new TypeToken<State<AdaptiveLogisticRegression.Wrapper>>() {}.getType();
 
     @Override
     public EvolutionaryProcess<AdaptiveLogisticRegression.Wrapper> createInstance(Type type) {
@@ -311,11 +364,13 @@ public class ModelSerializer {
     }
 
     @Override
-    public EvolutionaryProcess<AdaptiveLogisticRegression.Wrapper> deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
+    public EvolutionaryProcess<AdaptiveLogisticRegression.Wrapper> deserialize(
+        JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) {
       JsonObject x = (JsonObject) jsonElement;
       int threadCount = x.get("threadCount").getAsInt();
 
-      EvolutionaryProcess<AdaptiveLogisticRegression.Wrapper> r = new EvolutionaryProcess<AdaptiveLogisticRegression.Wrapper>();
+      EvolutionaryProcess<AdaptiveLogisticRegression.Wrapper> r =
+          new EvolutionaryProcess<AdaptiveLogisticRegression.Wrapper>();
       r.setThreadCount(threadCount);
 
       for (JsonElement element : x.get("population").getAsJsonArray()) {
@@ -326,7 +381,9 @@ public class ModelSerializer {
     }
 
     @Override
-    public JsonElement serialize(EvolutionaryProcess<AdaptiveLogisticRegression.Wrapper> x, Type type, JsonSerializationContext jsc) {
+    public JsonElement serialize(EvolutionaryProcess<AdaptiveLogisticRegression.Wrapper> x,
+                                 Type type,
+                                 JsonSerializationContext jsc) {
       JsonObject r = new JsonObject();
       r.add("threadCount", new JsonPrimitive(x.getThreadCount()));
       JsonArray v = new JsonArray();

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/OnlineLogisticRegression.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/OnlineLogisticRegression.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/OnlineLogisticRegression.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/OnlineLogisticRegression.java Tue Sep  7 13:54:21 2010
@@ -19,10 +19,6 @@ package org.apache.mahout.classifier.sgd
 
 import org.apache.mahout.math.DenseMatrix;
 import org.apache.mahout.math.DenseVector;
-import org.apache.mahout.math.Vector;
-import org.apache.mahout.math.function.BinaryFunction;
-import org.apache.mahout.math.function.Functions;
-import org.apache.mahout.math.function.UnaryFunction;
 
 /**
  * Extends the basic on-line logistic regression learner with a specific set of learning

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/TPrior.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/TPrior.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/TPrior.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/TPrior.java Tue Sep  7 13:54:21 2010
@@ -17,14 +17,13 @@
 
 package org.apache.mahout.classifier.sgd;
 
-import static java.lang.Math.log;
-import static org.apache.commons.math.special.Gamma.logGamma;
+import org.apache.commons.math.special.Gamma;
 
 /**
  * Provides a t-distribution as a prior.
  */
 public class TPrior extends PriorFunction {
-  private double df;
+  private final double df;
 
   public TPrior(double df) {
     this.df = df;
@@ -33,13 +32,16 @@ public class TPrior extends PriorFunctio
   @Override
   public double age(double oldValue, double generations, double learningRate) {
     for (int i = 0; i < generations; i++) {
-      oldValue = oldValue - learningRate * oldValue * (df + 1) / (df + oldValue * oldValue);
+      oldValue -= learningRate * oldValue * (df + 1.0) / (df + oldValue * oldValue);
     }
     return oldValue;
   }
 
   @Override
   public double logP(double betaIJ) {
-    return logGamma((df + 1) / 2) - log(df * Math.PI) - logGamma(df / 2) - (df + 1) / 2 * log(1 + betaIJ * betaIJ);
+    return Gamma.logGamma((df + 1.0) / 2.0)
+        - Math.log(df * Math.PI)
+        - Gamma.logGamma(df / 2.0)
+        - (df + 1.0) / 2.0 * Math.log(1.0 + betaIJ * betaIJ);
   }
 }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/AbstractCluster.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/AbstractCluster.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/AbstractCluster.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/AbstractCluster.java Tue Sep  7 13:54:21 2010
@@ -32,17 +32,17 @@ public abstract class AbstractCluster im
 
   private Vector radius;
 
-  public AbstractCluster() {
+  protected AbstractCluster() {
   }
 
-  public AbstractCluster(Vector point, int id2) {
+  protected AbstractCluster(Vector point, int id2) {
     this.numPoints = 0;
     this.center = new RandomAccessSparseVector(point);
     this.radius = point.like();
     this.id = id2;
   }
 
-  public AbstractCluster(Vector center2, Vector radius2, int id2) {
+  protected AbstractCluster(Vector center2, Vector radius2, int id2) {
     this.numPoints = 0;
     this.center = new RandomAccessSparseVector(center2);
     this.radius = new RandomAccessSparseVector(radius2);
@@ -121,9 +121,6 @@ public abstract class AbstractCluster im
     }
   }
 
-  /* (non-Javadoc)
-   * @see org.apache.mahout.clustering.dirichlet.models.Model#observe(java.lang.Object)
-   */
   @Override
   public void observe(VectorWritable x) {
     observe(x.get());
@@ -158,6 +155,7 @@ public abstract class AbstractCluster im
     return new ClusterObservations(s0, s1, s2);
   }
 
+  @Override
   public void computeParameters() {
     if (s0 == 0) {
       return;
@@ -197,13 +195,13 @@ public abstract class AbstractCluster im
   @Override
   public String asFormatString(String[] bindings) {
     StringBuilder buf = new StringBuilder(50);
-    buf.append(getIdentifier() + "{n=").append(numPoints).append(" c=");
+    buf.append(getIdentifier()).append("{n=").append(numPoints).append(" c=");
     if (center != null) {
-      buf.append(AbstractCluster.formatVector(center, bindings));
+      buf.append(formatVector(center, bindings));
     }
     buf.append(" r=");
     if (radius != null) {
-      buf.append(AbstractCluster.formatVector(radius, bindings));
+      buf.append(formatVector(radius, bindings));
     }
     buf.append('}');
     return buf.toString();
@@ -292,9 +290,6 @@ public abstract class AbstractCluster im
     return buf.toString();
   }
 
-  /* (non-Javadoc)
-   * @see org.apache.mahout.clustering.dirichlet.models.Model#count()
-   */
   @Override
   public int count() {
     return getNumPoints();

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/DistanceMeasureCluster.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/DistanceMeasureCluster.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/DistanceMeasureCluster.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/DistanceMeasureCluster.java Tue Sep  7 13:54:21 2010
@@ -18,18 +18,14 @@ public class DistanceMeasureCluster exte
   }
 
   public DistanceMeasureCluster() {
-    super();
   }
 
-  /* (non-Javadoc)
-   * @see org.apache.mahout.clustering.AbstractCluster#readFields(java.io.DataInput)
-   */
   @Override
   public void readFields(DataInput in) throws IOException {
     String dm = in.readUTF();
     try {
       ClassLoader ccl = Thread.currentThread().getContextClassLoader();
-      this.measure = (DistanceMeasure) ((Class<?>) ccl.loadClass(dm)).newInstance();
+      this.measure = ccl.loadClass(dm).asSubclass(DistanceMeasure.class).newInstance();
     } catch (InstantiationException e) {
       throw new IllegalStateException(e);
     } catch (IllegalAccessException e) {
@@ -40,26 +36,17 @@ public class DistanceMeasureCluster exte
     super.readFields(in);
   }
 
-  /* (non-Javadoc)
-   * @see org.apache.mahout.clustering.AbstractCluster#write(java.io.DataOutput)
-   */
   @Override
   public void write(DataOutput out) throws IOException {
     out.writeUTF(measure.getClass().getName());
     super.write(out);
   }
 
-  /* (non-Javadoc)
-   * @see org.apache.mahout.clustering.AbstractCluster#pdf(org.apache.mahout.math.VectorWritable)
-   */
   @Override
   public double pdf(VectorWritable vw) {
     return Math.exp(-measure.distance(vw.get(), getCenter()));
   }
 
-  /* (non-Javadoc)
-   * @see org.apache.mahout.clustering.dirichlet.models.Model#sampleFromPosterior()
-   */
   @Override
   public Model<VectorWritable> sampleFromPosterior() {
     return new DistanceMeasureCluster(getCenter(), getId(), measure);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/VectorModelClassifier.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/VectorModelClassifier.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/VectorModelClassifier.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/VectorModelClassifier.java Tue Sep  7 13:54:21 2010
@@ -13,10 +13,9 @@ import org.apache.mahout.math.function.T
 
 public class VectorModelClassifier extends AbstractVectorClassifier {
 
-  List<Model<VectorWritable>> models;
+  private final List<Model<VectorWritable>> models;
 
   public VectorModelClassifier(List<Model<VectorWritable>> models) {
-    super();
     this.models = models;
   }
 

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyClusterer.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyClusterer.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyClusterer.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyClusterer.java Tue Sep  7 13:54:21 2010
@@ -70,8 +70,8 @@ public class CanopyClusterer {
   public void configure(Configuration configuration) {
     try {
       ClassLoader ccl = Thread.currentThread().getContextClassLoader();
-      Class<?> cl = ccl.loadClass(configuration.get(CanopyConfigKeys.DISTANCE_MEASURE_KEY));
-      measure = (DistanceMeasure) cl.newInstance();
+      measure = ccl.loadClass(configuration.get(CanopyConfigKeys.DISTANCE_MEASURE_KEY))
+          .asSubclass(DistanceMeasure.class).newInstance();
       measure.configure(configuration);
     } catch (ClassNotFoundException e) {
       throw new IllegalStateException(e);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyDriver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyDriver.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyDriver.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/canopy/CanopyDriver.java Tue Sep  7 13:54:21 2010
@@ -19,6 +19,7 @@ package org.apache.mahout.clustering.can
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
@@ -29,7 +30,7 @@ import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.SequenceFile;
 import org.apache.hadoop.io.Text;
-import org.apache.hadoop.io.WritableComparable;
+import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.mapreduce.Job;
 import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
 import org.apache.hadoop.mapreduce.lib.input.SequenceFileInputFormat;
@@ -73,10 +74,6 @@ public class CanopyDriver extends Abstra
    * @param runClustering 
    *          true if points are to be clustered after clusters are determined
    * @param runSequential execute sequentially if true
-   * @throws ClassNotFoundException 
-   * @throws InterruptedException 
-   * @throws IllegalAccessException 
-   * @throws InstantiationException 
    */
   public static void runJob(Path input,
                             Path output,
@@ -84,9 +81,9 @@ public class CanopyDriver extends Abstra
                             double t1,
                             double t2,
                             boolean runClustering,
-                            boolean runSequential) throws IOException, InterruptedException, ClassNotFoundException,
-      InstantiationException, IllegalAccessException {
-    new CanopyDriver().job(input, output, measure, t1, t2, runClustering, runSequential);
+                            boolean runSequential)
+    throws IOException, InterruptedException, ClassNotFoundException, InstantiationException, IllegalAccessException {
+    job(input, output, measure, t1, t2, runClustering, runSequential);
   }
 
   @Override
@@ -115,9 +112,10 @@ public class CanopyDriver extends Abstra
     double t1 = Double.parseDouble(getOption(DefaultOptionCreator.T1_OPTION));
     double t2 = Double.parseDouble(getOption(DefaultOptionCreator.T2_OPTION));
     boolean runClustering = hasOption(DefaultOptionCreator.CLUSTERING_OPTION);
-    boolean runSequential = (getOption(DefaultOptionCreator.METHOD_OPTION).equalsIgnoreCase(DefaultOptionCreator.SEQUENTIAL_METHOD));
+    boolean runSequential = (getOption(DefaultOptionCreator.METHOD_OPTION)
+        .equalsIgnoreCase(DefaultOptionCreator.SEQUENTIAL_METHOD));
     ClassLoader ccl = Thread.currentThread().getContextClassLoader();
-    DistanceMeasure measure = (DistanceMeasure) ccl.loadClass(measureClass).newInstance();
+    DistanceMeasure measure = ccl.loadClass(measureClass).asSubclass(DistanceMeasure.class).newInstance();
 
     job(input, output, measure, t1, t2, runClustering, runSequential);
     return 0;
@@ -128,25 +126,19 @@ public class CanopyDriver extends Abstra
    * cluster the input vectors using these clusters
    * @param input the Path to the directory containing input vectors
    * @param output the Path for all output directories
-   * @param measureClassName the String class name of the DistanceMeasure 
    * @param t1 the double T1 distance metric
    * @param t2 the double T2 distance metric
    * @param runClustering cluster the input vectors if true
    * @param runSequential execute sequentially if true
-   * @throws IOException
-   * @throws InterruptedException
-   * @throws ClassNotFoundException
-   * @throws IllegalAccessException 
-   * @throws InstantiationException 
    */
-  public void job(Path input,
-                  Path output,
-                  DistanceMeasure measure,
-                  double t1,
-                  double t2,
-                  boolean runClustering,
-                  boolean runSequential) throws IOException, InterruptedException, ClassNotFoundException, InstantiationException,
-      IllegalAccessException {
+  public static void job(Path input,
+                         Path output,
+                         DistanceMeasure measure,
+                         double t1,
+                         double t2,
+                         boolean runClustering,
+                         boolean runSequential)
+    throws IOException, InterruptedException, ClassNotFoundException, InstantiationException, IllegalAccessException {
     Path clustersOut = buildClusters(input, output, measure, t1, t2, runSequential);
     if (runClustering) {
       clusterData(input, clustersOut, output, measure, t1, t2, runSequential);
@@ -163,15 +155,15 @@ public class CanopyDriver extends Abstra
    * @param t1 the double T1 distance metric
    * @param t2 the double T2 distance metric
    * @param runSequential a boolean indicates to run the sequential (reference) algorithm
-   * @return the canopy output directory Path 
-   * @throws IOException
-   * @throws InterruptedException
-   * @throws ClassNotFoundException
-   * @throws IllegalAccessException 
-   * @throws InstantiationException 
+   * @return the canopy output directory Path
    */
-  public Path buildClusters(Path input, Path output, DistanceMeasure measure, double t1, double t2, boolean runSequential)
-      throws IOException, InterruptedException, ClassNotFoundException, InstantiationException, IllegalAccessException {
+  public static Path buildClusters(Path input,
+                                   Path output,
+                                   DistanceMeasure measure,
+                                   double t1,
+                                   double t2,
+                                   boolean runSequential)
+    throws IOException, InterruptedException, ClassNotFoundException, InstantiationException, IllegalAccessException {
     log.info("Input: {} Out: {} " + "Measure: {} t1: {} t2: {}", new Object[] { input, output, measure, t1, t2 });
     if (runSequential) {
       return buildClustersSeq(input, output, measure, t1, t2);
@@ -191,21 +183,21 @@ public class CanopyDriver extends Abstra
    * @param t2 the double T2 distance metric
    * @return the canopy output directory Path
    */
-  private Path buildClustersSeq(Path input, Path output, DistanceMeasure measure, double t1, double t2)
-      throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException {
+  private static Path buildClustersSeq(Path input, Path output, DistanceMeasure measure, double t1, double t2)
+    throws InstantiationException, IllegalAccessException, IOException {
     CanopyClusterer clusterer = new CanopyClusterer(measure, t1, t2);
-    List<Canopy> canopies = new ArrayList<Canopy>();
+    Collection<Canopy> canopies = new ArrayList<Canopy>();
     Configuration conf = new Configuration();
     FileSystem fs = FileSystem.get(input.toUri(), conf);
     FileStatus[] status = fs.listStatus(input, new OutputLogFilter());
     for (FileStatus s : status) {
       SequenceFile.Reader reader = new SequenceFile.Reader(fs, s.getPath(), conf);
       try {
-        WritableComparable<?> key = (WritableComparable<?>) reader.getKeyClass().newInstance();
-        VectorWritable vw = (VectorWritable) reader.getValueClass().newInstance();
+        Writable key =reader.getKeyClass().asSubclass(Writable.class).newInstance();
+        VectorWritable vw = reader.getValueClass().asSubclass(VectorWritable.class).newInstance();
         while (reader.next(key, vw)) {
           clusterer.addPointToCanopies(vw.get(), canopies);
-          vw = (VectorWritable) reader.getValueClass().newInstance();
+          vw = reader.getValueClass().asSubclass(VectorWritable.class).newInstance();
         }
       } finally {
         reader.close();
@@ -238,8 +230,8 @@ public class CanopyDriver extends Abstra
    * @param t2 the double T2 distance metric
    * @return the canopy output directory Path
    */
-  private Path buildClustersMR(Path input, Path output, DistanceMeasure measure, double t1, double t2) throws IOException,
-      InterruptedException, ClassNotFoundException {
+  private static Path buildClustersMR(Path input, Path output, DistanceMeasure measure, double t1, double t2)
+    throws IOException, InterruptedException, ClassNotFoundException {
     Configuration conf = new Configuration();
     conf.set(CanopyConfigKeys.DISTANCE_MEASURE_KEY, measure.getClass().getName());
     conf.set(CanopyConfigKeys.T1_KEY, String.valueOf(t1));
@@ -274,19 +266,15 @@ public class CanopyDriver extends Abstra
    * @param t1 the T1 distance threshold
    * @param t2 the T2 distance threshold
    * @param runSequential a boolean indicates to run the sequential (reference) algorithm
-   * @throws ClassNotFoundException 
-   * @throws InterruptedException 
-   * @throws IllegalAccessException 
-   * @throws InstantiationException 
    */
-  public void clusterData(Path points,
-                          Path canopies,
-                          Path output,
-                          DistanceMeasure measure,
-                          double t1,
-                          double t2,
-                          boolean runSequential) throws IOException, InterruptedException, ClassNotFoundException,
-      InstantiationException, IllegalAccessException {
+  public static void clusterData(Path points,
+                                 Path canopies,
+                                 Path output,
+                                 DistanceMeasure measure,
+                                 double t1,
+                                 double t2,
+                                 boolean runSequential)
+    throws IOException, InterruptedException, ClassNotFoundException, InstantiationException, IllegalAccessException {
     if (runSequential) {
       clusterDataSeq(points, canopies, output, measure, t1, t2);
     } else {
@@ -294,8 +282,13 @@ public class CanopyDriver extends Abstra
     }
   }
 
-  private void clusterDataSeq(Path points, Path canopies, Path output, DistanceMeasure measure, double t1, double t2)
-      throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException {
+  private static void clusterDataSeq(Path points,
+                                     Path canopies,
+                                     Path output,
+                                     DistanceMeasure measure,
+                                     double t1,
+                                     double t2)
+    throws InstantiationException, IllegalAccessException, IOException {
     CanopyClusterer clusterer = new CanopyClusterer(measure, t1, t2);
 
     List<Canopy> clusters = new ArrayList<Canopy>();
@@ -305,11 +298,11 @@ public class CanopyDriver extends Abstra
     for (FileStatus s : status) {
       SequenceFile.Reader reader = new SequenceFile.Reader(fs, s.getPath(), conf);
       try {
-        Text key = (Text) reader.getKeyClass().newInstance();
-        Canopy value = (Canopy) reader.getValueClass().newInstance();
+        Writable key = reader.getKeyClass().asSubclass(Writable.class).newInstance();
+        Canopy value = reader.getValueClass().asSubclass(Canopy.class).newInstance();
         while (reader.next(key, value)) {
           clusters.add(value);
-          value = (Canopy) reader.getValueClass().newInstance();
+          value = reader.getValueClass().asSubclass(Canopy.class).newInstance();
         }
       } finally {
         reader.close();
@@ -328,12 +321,12 @@ public class CanopyDriver extends Abstra
                                                            IntWritable.class,
                                                            WeightedVectorWritable.class);
       try {
-        WritableComparable<?> key = (WritableComparable<?>) reader.getKeyClass().newInstance();
-        VectorWritable vw = (VectorWritable) reader.getValueClass().newInstance();
+        Writable key = reader.getKeyClass().asSubclass(Writable.class).newInstance();
+        VectorWritable vw = reader.getValueClass().asSubclass(VectorWritable.class).newInstance();
         while (reader.next(key, vw)) {
           Canopy closest = clusterer.findClosestCanopy(vw.get(), clusters);
           writer.append(new IntWritable(closest.getId()), new WeightedVectorWritable(1, vw));
-          vw = (VectorWritable) reader.getValueClass().newInstance();
+          vw = reader.getValueClass().asSubclass(VectorWritable.class).newInstance();
         }
       } finally {
         reader.close();
@@ -342,8 +335,13 @@ public class CanopyDriver extends Abstra
     }
   }
 
-  private void clusterDataMR(Path points, Path canopies, Path output, DistanceMeasure measure, double t1, double t2)
-      throws IOException, InterruptedException, ClassNotFoundException {
+  private static void clusterDataMR(Path points,
+                                    Path canopies,
+                                    Path output,
+                                    DistanceMeasure measure,
+                                    double t1,
+                                    double t2)
+    throws IOException, InterruptedException, ClassNotFoundException {
     Configuration conf = new Configuration();
     conf.set(CanopyConfigKeys.DISTANCE_MEASURE_KEY, measure.getClass().getName());
     conf.set(CanopyConfigKeys.T1_KEY, String.valueOf(t1));

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/DirichletDriver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/DirichletDriver.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/DirichletDriver.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/DirichletDriver.java Tue Sep  7 13:54:21 2010
@@ -368,17 +368,17 @@ public class DirichletDriver extends Abs
    *          a double threshold value emits all clusters having greater pdf (emitMostLikely = false)
    * @param runSequential execute sequentially if true
    */
-  public void job(Path input,
-                  Path output,
-                  ModelDistribution<VectorWritable> modelDistribution,
-                  int numClusters,
-                  int maxIterations,
-                  double alpha0,
-                  int numReducers,
-                  boolean runClustering,
-                  boolean emitMostLikely,
-                  double threshold,
-                  boolean runSequential)
+  public static void job(Path input,
+                         Path output,
+                         ModelDistribution<VectorWritable> modelDistribution,
+                         int numClusters,
+                         int maxIterations,
+                         double alpha0,
+                         int numReducers,
+                         boolean runClustering,
+                         boolean emitMostLikely,
+                         double threshold,
+                         boolean runSequential)
     throws IOException, InstantiationException, IllegalAccessException,
       ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InterruptedException {
     Path clustersOut = buildClusters(input,
@@ -474,10 +474,10 @@ public class DirichletDriver extends Abs
         SequenceFile.Reader reader = new SequenceFile.Reader(fs, s.getPath(), conf);
         try {
           Writable key = reader.getKeyClass().asSubclass(Writable.class).newInstance();
-          VectorWritable vw = (VectorWritable) reader.getValueClass().newInstance();
+          VectorWritable vw = reader.getValueClass().asSubclass(VectorWritable.class).newInstance();
           while (reader.next(key, vw)) {
             clusterer.observe(newModels, vw);
-            vw = (VectorWritable) reader.getValueClass().newInstance();
+            vw = reader.getValueClass().asSubclass(VectorWritable.class).newInstance();
           }
         } finally {
           reader.close();
@@ -527,12 +527,12 @@ public class DirichletDriver extends Abs
    *          a double threshold value emits all clusters having greater pdf (emitMostLikely = false)
    * @param runSequential execute sequentially if true
    */
-  public void clusterData(Path input,
-                          Path stateIn,
-                          Path output,
-                          boolean emitMostLikely,
-                          double threshold,
-                          boolean runSequential)
+  public static void clusterData(Path input,
+                                 Path stateIn,
+                                 Path output,
+                                 boolean emitMostLikely,
+                                 double threshold,
+                                 boolean runSequential)
     throws IOException, InterruptedException, ClassNotFoundException, InstantiationException, IllegalAccessException {
     if (runSequential) {
       clusterDataSeq(input, stateIn, output, emitMostLikely, threshold);
@@ -559,10 +559,10 @@ public class DirichletDriver extends Abs
                                                            WeightedVectorWritable.class);
       try {
         Writable key = reader.getKeyClass().asSubclass(Writable.class).newInstance();
-        VectorWritable vw = (VectorWritable) reader.getValueClass().newInstance();
+        VectorWritable vw = reader.getValueClass().asSubclass(VectorWritable.class).newInstance();
         while (reader.next(key, vw)) {
           clusterer.emitPointToClusters(vw, clusters, writer);
-          vw = (VectorWritable) reader.getValueClass().newInstance();
+          vw = reader.getValueClass().asSubclass(VectorWritable.class).newInstance();
         }
       } finally {
         reader.close();

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/DirichletMapper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/DirichletMapper.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/DirichletMapper.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/DirichletMapper.java Tue Sep  7 13:54:21 2010
@@ -90,12 +90,6 @@ public class DirichletMapper extends Map
 
     try {
       return loadState(conf, statePath, modelDistribution, Double.parseDouble(alpha0), Integer.parseInt(numClusters));
-    } catch (ClassNotFoundException e) {
-      throw new IllegalStateException(e);
-    } catch (InstantiationException e) {
-      throw new IllegalStateException(e);
-    } catch (IllegalAccessException e) {
-      throw new IllegalStateException(e);
     } catch (IOException e) {
       throw new IllegalStateException(e);
     }
@@ -105,8 +99,7 @@ public class DirichletMapper extends Map
                                             String statePath,
                                             ModelDistribution<VectorWritable> modelDistribution,
                                             double alpha,
-                                            int k) throws ClassNotFoundException, InstantiationException, IllegalAccessException,
-      NoSuchMethodException, InvocationTargetException, IOException {
+                                            int k) throws IOException {
     DirichletState state = DirichletDriver.createState(modelDistribution, k, alpha);
     Path path = new Path(statePath);
     FileSystem fs = FileSystem.get(path.toUri(), conf);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/models/AbstractVectorModelDistribution.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/models/AbstractVectorModelDistribution.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/models/AbstractVectorModelDistribution.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/models/AbstractVectorModelDistribution.java Tue Sep  7 13:54:21 2010
@@ -44,9 +44,6 @@ public abstract class AbstractVectorMode
     this.modelPrototype = modelPrototype;
   }
 
-  /* (non-Javadoc)
-   * @see org.apache.mahout.clustering.ModelDistribution#asJsonString()
-   */
   @Override
   public String asJsonString() {
     GsonBuilder builder = new GsonBuilder();

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/models/GaussianCluster.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/models/GaussianCluster.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/models/GaussianCluster.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/models/GaussianCluster.java Tue Sep  7 13:54:21 2010
@@ -9,7 +9,6 @@ import org.apache.mahout.math.VectorWrit
 public class GaussianCluster extends AbstractCluster {
 
   public GaussianCluster() {
-    super();
   }
 
   public GaussianCluster(Vector point, int id2) {
@@ -30,9 +29,6 @@ public class GaussianCluster extends Abs
     return new GaussianCluster(getCenter(), getRadius(), getId());
   }
 
-  /* (non-Javadoc)
-   * @see org.apache.mahout.clustering.dirichlet.models.Model#pdf(java.lang.Object)
-   */
   @Override
   public double pdf(VectorWritable vw) {
     Vector x = vw.get();

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/FuzzyKMeansClusterer.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/FuzzyKMeansClusterer.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/FuzzyKMeansClusterer.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/FuzzyKMeansClusterer.java Tue Sep  7 13:54:21 2010
@@ -135,8 +135,8 @@ public class FuzzyKMeansClusterer {
   private void configure(Configuration job) {
     try {
       ClassLoader ccl = Thread.currentThread().getContextClassLoader();
-      Class<?> cl = ccl.loadClass(job.get(FuzzyKMeansConfigKeys.DISTANCE_MEASURE_KEY));
-      measure = (DistanceMeasure) cl.newInstance();
+      measure = ccl.loadClass(job.get(FuzzyKMeansConfigKeys.DISTANCE_MEASURE_KEY))
+          .asSubclass(DistanceMeasure.class).newInstance();
       measure.configure(job);
       convergenceDelta = Double.parseDouble(job.get(FuzzyKMeansConfigKeys.CLUSTER_CONVERGENCE_KEY));
       // nextClusterId = 0;

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/FuzzyKMeansDriver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/FuzzyKMeansDriver.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/FuzzyKMeansDriver.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/FuzzyKMeansDriver.java Tue Sep  7 13:54:21 2010
@@ -167,7 +167,7 @@ public class FuzzyKMeansDriver extends A
     boolean emitMostLikely = Boolean.parseBoolean(getOption(DefaultOptionCreator.EMIT_MOST_LIKELY_OPTION));
     double threshold = Double.parseDouble(getOption(DefaultOptionCreator.THRESHOLD_OPTION));
     ClassLoader ccl = Thread.currentThread().getContextClassLoader();
-    DistanceMeasure measure = (DistanceMeasure) ((Class<?>) ccl.loadClass(measureClass)).newInstance();
+    DistanceMeasure measure = ccl.loadClass(measureClass).asSubclass(DistanceMeasure.class).newInstance();
 
     if (hasOption(DefaultOptionCreator.NUM_CLUSTERS_OPTION)) {
       clusters = RandomSeedGenerator.buildRandom(input, clusters, Integer.parseInt(parseArguments(args)
@@ -388,10 +388,10 @@ public class FuzzyKMeansDriver extends A
         SequenceFile.Reader reader = new SequenceFile.Reader(fs, s.getPath(), conf);
         try {
           Writable key = reader.getKeyClass().asSubclass(Writable.class).newInstance();
-          VectorWritable vw = (VectorWritable) reader.getValueClass().newInstance();
+          VectorWritable vw = reader.getValueClass().asSubclass(VectorWritable.class).newInstance();
           while (reader.next(key, vw)) {
             clusterer.addPointToClusters(clusters, vw.get());
-            vw = (VectorWritable) reader.getValueClass().newInstance();
+            vw = reader.getValueClass().asSubclass(VectorWritable.class).newInstance();
           }
         } finally {
           reader.close();
@@ -517,10 +517,10 @@ public class FuzzyKMeansDriver extends A
                                                            WeightedVectorWritable.class);
       try {
         Writable key = reader.getKeyClass().asSubclass(Writable.class).newInstance();
-        VectorWritable vw = (VectorWritable) reader.getValueClass().newInstance();
+        VectorWritable vw = reader.getValueClass().asSubclass(VectorWritable.class).newInstance();
         while (reader.next(key, vw)) {
           clusterer.emitPointToClusters(vw, clusters, writer);
-          vw = (VectorWritable) reader.getValueClass().newInstance();
+          vw = (VectorWritable) reader.getValueClass().asSubclass(VectorWritable.class).newInstance();
         }
       } finally {
         reader.close();

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/FuzzyKMeansUtil.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/FuzzyKMeansUtil.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/FuzzyKMeansUtil.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/FuzzyKMeansUtil.java Tue Sep  7 13:54:21 2010
@@ -75,7 +75,7 @@ final class FuzzyKMeansUtil {
           Class<?> valueClass = reader.getValueClass();
           Writable key;
           try {
-            key = (Writable) reader.getKeyClass().newInstance();
+            key = reader.getKeyClass().asSubclass(Writable.class).newInstance();
           } catch (InstantiationException e) { // Should not be possible
             log.error("Exception", e);
             throw new IllegalStateException(e);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/SoftCluster.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/SoftCluster.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/SoftCluster.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/fuzzykmeans/SoftCluster.java Tue Sep  7 13:54:21 2010
@@ -49,9 +49,6 @@ public class SoftCluster extends Cluster
     return (isConverged() ? "SV-" : "SC-") + getId();
   }
 
-  /* (non-Javadoc)
-   * @see org.apache.mahout.clustering.DistanceMeasureCluster#pdf(org.apache.mahout.math.VectorWritable)
-   */
   @Override
   public double pdf(VectorWritable vw) {
     // SoftCluster pdf cannot be calculated out of context. See FuzzyKMeansClusterer

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansClusterMapper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansClusterMapper.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansClusterMapper.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansClusterMapper.java Tue Sep  7 13:54:21 2010
@@ -46,8 +46,8 @@ public class KMeansClusterMapper extends
     Configuration conf = context.getConfiguration();
     try {
       ClassLoader ccl = Thread.currentThread().getContextClassLoader();
-      Class<?> cl = ccl.loadClass(conf.get(KMeansConfigKeys.DISTANCE_MEASURE_KEY));
-      DistanceMeasure measure = (DistanceMeasure) cl.newInstance();
+      DistanceMeasure measure = ccl.loadClass(conf.get(KMeansConfigKeys.DISTANCE_MEASURE_KEY))
+          .asSubclass(DistanceMeasure.class).newInstance();
       measure.configure(conf);
       
       String clusterPath = conf.get(KMeansConfigKeys.CLUSTER_PATH_KEY);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansClusterer.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansClusterer.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansClusterer.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansClusterer.java Tue Sep  7 13:54:21 2010
@@ -62,8 +62,8 @@ public class KMeansClusterer {
   public KMeansClusterer(Configuration conf)
       throws ClassNotFoundException, InstantiationException, IllegalAccessException {
     ClassLoader ccl = Thread.currentThread().getContextClassLoader();
-    Class<?> cl = ccl.loadClass(conf.get(KMeansConfigKeys.DISTANCE_MEASURE_KEY));
-    this.measure = (DistanceMeasure) cl.newInstance();
+    this.measure = ccl.loadClass(conf.get(KMeansConfigKeys.DISTANCE_MEASURE_KEY))
+        .asSubclass(DistanceMeasure.class).newInstance();
     this.measure.configure(conf);
 
     this.convergenceDelta = Double.parseDouble(conf.get(KMeansConfigKeys.CLUSTER_CONVERGENCE_KEY));

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansDriver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansDriver.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansDriver.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansDriver.java Tue Sep  7 13:54:21 2010
@@ -28,7 +28,6 @@ import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.SequenceFile;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.io.Writable;
-import org.apache.hadoop.io.WritableComparable;
 import org.apache.hadoop.mapreduce.Job;
 import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
 import org.apache.hadoop.mapreduce.lib.input.SequenceFileInputFormat;
@@ -134,7 +133,7 @@ public class KMeansDriver extends Abstra
       HadoopUtil.overwriteOutput(output);
     }
     ClassLoader ccl = Thread.currentThread().getContextClassLoader();
-    DistanceMeasure measure = (DistanceMeasure) ((Class<?>) ccl.loadClass(measureClass)).newInstance();
+    DistanceMeasure measure = ((Class<?>) ccl.loadClass(measureClass)).asSubclass(DistanceMeasure.class).newInstance();
 
     if (hasOption(DefaultOptionCreator.NUM_CLUSTERS_OPTION)) {
       clusters = RandomSeedGenerator.buildRandom(input, clusters, Integer
@@ -264,10 +263,10 @@ public class KMeansDriver extends Abstra
         SequenceFile.Reader reader = new SequenceFile.Reader(fs, s.getPath(), conf);
         try {
           Writable key = reader.getKeyClass().asSubclass(Writable.class).newInstance();
-          VectorWritable vw = (VectorWritable) reader.getValueClass().newInstance();
+          VectorWritable vw = reader.getValueClass().asSubclass(VectorWritable.class).newInstance();
           while (reader.next(key, vw)) {
             clusterer.addPointToNearestCluster(vw.get(), clusters);
-            vw = (VectorWritable) reader.getValueClass().newInstance();
+            vw = reader.getValueClass().asSubclass(VectorWritable.class).newInstance();
           }
         } finally {
           reader.close();
@@ -394,7 +393,7 @@ public class KMeansDriver extends Abstra
       if (name.startsWith("part") && !name.endsWith(".crc")) {
         SequenceFile.Reader reader = new SequenceFile.Reader(fs, part.getPath(), conf);
         try {
-          Writable key = (Writable) reader.getKeyClass().newInstance();
+          Writable key = reader.getKeyClass().asSubclass(Writable.class).newInstance();
           Cluster value = new Cluster();
           while (reader.next(key, value)) {
             if (!value.isConverged()) {
@@ -478,7 +477,7 @@ public class KMeansDriver extends Abstra
         VectorWritable vw = reader.getValueClass().asSubclass(VectorWritable.class).newInstance();
         while (reader.next(key, vw)) {
           clusterer.emitPointToNearestCluster(vw.get(), clusters, writer);
-          vw = (VectorWritable) reader.getValueClass().newInstance();
+          vw = reader.getValueClass().asSubclass(VectorWritable.class).newInstance();
         }
       } finally {
         reader.close();

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansMapper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansMapper.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansMapper.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansMapper.java Tue Sep  7 13:54:21 2010
@@ -18,6 +18,7 @@ package org.apache.mahout.clustering.kme
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 import org.apache.hadoop.conf.Configuration;
@@ -47,8 +48,8 @@ public class KMeansMapper extends Mapper
     Configuration conf = context.getConfiguration();
     try {
       ClassLoader ccl = Thread.currentThread().getContextClassLoader();
-      Class<?> cl = ccl.loadClass(conf.get(KMeansConfigKeys.DISTANCE_MEASURE_KEY));
-      DistanceMeasure measure = (DistanceMeasure) cl.newInstance();
+      DistanceMeasure measure = ccl.loadClass(conf.get(KMeansConfigKeys.DISTANCE_MEASURE_KEY))
+          .asSubclass(DistanceMeasure.class).newInstance();
       measure.configure(conf);
 
       this.clusterer = new KMeansClusterer(measure);
@@ -76,7 +77,7 @@ public class KMeansMapper extends Mapper
    *          a List<Cluster>
    * @param measure TODO
    */
-  void setup(List<Cluster> clusters, DistanceMeasure measure) {
+  void setup(Collection<Cluster> clusters, DistanceMeasure measure) {
     this.clusters.clear();
     this.clusters.addAll(clusters);
     this.clusterer = new KMeansClusterer(measure);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansUtil.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansUtil.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansUtil.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/KMeansUtil.java Tue Sep  7 13:54:21 2010
@@ -74,7 +74,7 @@ final class KMeansUtil {
           Class<?> valueClass = reader.getValueClass();
           Writable key;
           try {
-            key = (Writable) reader.getKeyClass().newInstance();
+            key = reader.getKeyClass().asSubclass(Writable.class).newInstance();
           } catch (InstantiationException e) { // Should not be possible
             log.error("Exception", e);
             throw new IllegalStateException(e);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/RandomSeedGenerator.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/RandomSeedGenerator.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/RandomSeedGenerator.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/RandomSeedGenerator.java Tue Sep  7 13:54:21 2010
@@ -82,8 +82,8 @@ public final class RandomSeedGenerator {
           continue; // select only the top level files
         }
         SequenceFile.Reader reader = new SequenceFile.Reader(fs, fileStatus.getPath(), conf);
-        Writable key = (Writable) reader.getKeyClass().newInstance();
-        VectorWritable value = (VectorWritable) reader.getValueClass().newInstance();
+        Writable key = reader.getKeyClass().asSubclass(Writable.class).newInstance();
+        VectorWritable value = reader.getValueClass().asSubclass(VectorWritable.class).newInstance();
         while (reader.next(key, value)) {
           Cluster newCluster = new Cluster(value.get(), nextClusterId++, measure);
           newCluster.observe(value.get(), 1);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDADriver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDADriver.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDADriver.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDADriver.java Tue Sep  7 13:54:21 2010
@@ -26,6 +26,7 @@ import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.DoubleWritable;
 import org.apache.hadoop.io.SequenceFile;
+import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.mapreduce.Job;
 import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
 import org.apache.hadoop.mapreduce.lib.input.SequenceFileInputFormat;
@@ -226,7 +227,7 @@ public final class LDADriver extends Abs
     }
   }
 
-  private void writeInitialState(Path statePath, int numTopics, int numWords) throws IOException {
+  private static void writeInitialState(Path statePath, int numTopics, int numWords) throws IOException {
     Configuration job = new Configuration();
     FileSystem fs = statePath.getFileSystem(job);
 
@@ -240,14 +241,14 @@ public final class LDADriver extends Abs
 
       double total = 0.0; // total number of pseudo counts we made
       for (int w = 0; w < numWords; ++w) {
-        IntPairWritable kw = new IntPairWritable(k, w);
+        Writable kw = new IntPairWritable(k, w);
         // A small amount of random noise, minimized by having a floor.
         double pseudocount = random.nextDouble() + 1.0E-8;
         total += pseudocount;
         v.set(Math.log(pseudocount));
         writer.append(kw, v);
       }
-      IntPairWritable kTsk = new IntPairWritable(k, TOPIC_SUM_KEY);
+      Writable kTsk = new IntPairWritable(k, TOPIC_SUM_KEY);
       v.set(Math.log(total));
       writer.append(kTsk, v);
 
@@ -255,7 +256,7 @@ public final class LDADriver extends Abs
     }
   }
 
-  private double findLL(Path statePath, Configuration job) throws IOException {
+  private static double findLL(Path statePath, Configuration job) throws IOException {
     FileSystem fs = statePath.getFileSystem(job);
 
     double ll = 0.0;

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopy.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopy.java?rev=993365&r1=993364&r2=993365&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopy.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopy.java Tue Sep  7 13:54:21 2010
@@ -158,9 +158,6 @@ public class MeanShiftCanopy extends Clu
     return (isConverged() ? "MSV-" : "MSC-") + getId();
   }
 
-  /* (non-Javadoc)
-   * @see org.apache.mahout.clustering.DistanceMeasureCluster#pdf(org.apache.mahout.math.VectorWritable)
-   */
   @Override
   public double pdf(VectorWritable vw) {
     // MSCanopy membership is explicit via membership in boundPoints. Can't compute pdf for Arbitrary point



Mime
View raw message