hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1554532 - in /hama/trunk/ml/src/main/java/org/apache/hama/ml: ann/ kmeans/ perception/ regression/ semiclustering/
Date Tue, 31 Dec 2013 15:08:08 GMT
Author: tommaso
Date: Tue Dec 31 15:08:07 2013
New Revision: 1554532

URL: http://svn.apache.org/r1554532
Log:
HAMA-835 - findbugs fixes applied to ML

Modified:
    hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/AbstractLayeredNeuralNetwork.java
    hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/AutoEncoder.java
    hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/NeuralNetwork.java
    hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/SmallLayeredNeuralNetwork.java
    hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/SmallLayeredNeuralNetworkTrainer.java
    hama/trunk/ml/src/main/java/org/apache/hama/ml/kmeans/KMeansBSP.java
    hama/trunk/ml/src/main/java/org/apache/hama/ml/perception/SmallMLPTrainer.java
    hama/trunk/ml/src/main/java/org/apache/hama/ml/perception/SmallMultiLayerPerceptron.java
    hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/GradientDescentBSP.java
    hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/LinearRegression.java
    hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/LogisticRegression.java
    hama/trunk/ml/src/main/java/org/apache/hama/ml/semiclustering/SemiClusterDetails.java
    hama/trunk/ml/src/main/java/org/apache/hama/ml/semiclustering/SemiClusterMessage.java
    hama/trunk/ml/src/main/java/org/apache/hama/ml/semiclustering/SemiClusteringVertex.java

Modified: hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/AbstractLayeredNeuralNetwork.java
URL: http://svn.apache.org/viewvc/hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/AbstractLayeredNeuralNetwork.java?rev=1554532&r1=1554531&r2=1554532&view=diff
==============================================================================
--- hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/AbstractLayeredNeuralNetwork.java (original)
+++ hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/AbstractLayeredNeuralNetwork.java Tue
Dec 31 15:08:07 2013
@@ -20,7 +20,6 @@ package org.apache.hama.ml.ann;
 import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.hadoop.io.WritableUtils;
@@ -252,8 +251,8 @@ abstract class AbstractLayeredNeuralNetw
 
     // write layer size list
     output.writeInt(this.layerSizeList.size());
-    for (int i = 0; i < this.layerSizeList.size(); ++i) {
-      output.writeInt(this.layerSizeList.get(i));
+    for (Integer aLayerSizeList : this.layerSizeList) {
+      output.writeInt(aLayerSizeList);
     }
 
     WritableUtils.writeEnum(output, this.trainingMethod);

Modified: hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/AutoEncoder.java
URL: http://svn.apache.org/viewvc/hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/AutoEncoder.java?rev=1554532&r1=1554531&r2=1554532&view=diff
==============================================================================
--- hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/AutoEncoder.java (original)
+++ hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/AutoEncoder.java Tue Dec 31 15:08:07
2013
@@ -40,7 +40,7 @@ import com.google.common.base.Preconditi
  */
 public class AutoEncoder {
 
-  private SmallLayeredNeuralNetwork model;
+  private final SmallLayeredNeuralNetwork model;
 
   /**
    * Initialize the autoencoder.

Modified: hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/NeuralNetwork.java
URL: http://svn.apache.org/viewvc/hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/NeuralNetwork.java?rev=1554532&r1=1554531&r2=1554532&view=diff
==============================================================================
--- hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/NeuralNetwork.java (original)
+++ hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/NeuralNetwork.java Tue Dec 31 15:08:07
2013
@@ -17,16 +17,8 @@
  */
 package org.apache.hama.ml.ann;
 
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Map;
-
+import com.google.common.base.Preconditions;
+import com.google.common.io.Closeables;
 import org.apache.commons.lang.SerializationUtils;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FSDataInputStream;
@@ -38,8 +30,14 @@ import org.apache.hadoop.io.WritableUtil
 import org.apache.hama.ml.util.DefaultFeatureTransformer;
 import org.apache.hama.ml.util.FeatureTransformer;
 
-import com.google.common.base.Preconditions;
-import com.google.common.io.Closeables;
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Map;
 
 /**
  * NeuralNetwork defines the general operations for all the derivative models.

Modified: hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/SmallLayeredNeuralNetwork.java
URL: http://svn.apache.org/viewvc/hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/SmallLayeredNeuralNetwork.java?rev=1554532&r1=1554531&r2=1554532&view=diff
==============================================================================
--- hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/SmallLayeredNeuralNetwork.java (original)
+++ hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/SmallLayeredNeuralNetwork.java Tue
Dec 31 15:08:07 2013
@@ -21,6 +21,7 @@ import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
@@ -145,9 +146,7 @@ public class SmallLayeredNeuralNetwork e
    */
   void setPrevWeightMatrices(DoubleMatrix[] prevUpdates) {
     this.prevWeightUpdatesList.clear();
-    for (DoubleMatrix prevUpdate : prevUpdates) {
-      this.prevWeightUpdatesList.add(prevUpdate);
-    }
+    Collections.addAll(this.prevWeightUpdatesList, prevUpdates);
   }
 
   /**
@@ -181,9 +180,7 @@ public class SmallLayeredNeuralNetwork e
    */
   public void setWeightMatrices(DoubleMatrix[] matrices) {
     this.weightMatrixList = new ArrayList<DoubleMatrix>();
-    for (DoubleMatrix matrix : matrices) {
-      this.weightMatrixList.add(matrix);
-    }
+    Collections.addAll(this.weightMatrixList, matrices);
   }
 
   /**
@@ -239,15 +236,15 @@ public class SmallLayeredNeuralNetwork e
 
     // write squashing functions
     output.writeInt(this.squashingFunctionList.size());
-    for (int i = 0; i < this.squashingFunctionList.size(); ++i) {
-      WritableUtils.writeString(output, this.squashingFunctionList.get(i)
-          .getFunctionName());
+    for (DoubleFunction aSquashingFunctionList : this.squashingFunctionList) {
+      WritableUtils.writeString(output, aSquashingFunctionList
+              .getFunctionName());
     }
 
     // write weight matrices
     output.writeInt(this.weightMatrixList.size());
-    for (int i = 0; i < this.weightMatrixList.size(); ++i) {
-      MatrixWritable.write(this.weightMatrixList.get(i), output);
+    for (DoubleMatrix aWeightMatrixList : this.weightMatrixList) {
+      MatrixWritable.write(aWeightMatrixList, output);
     }
 
     // DO NOT WRITE WEIGHT UPDATE

Modified: hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/SmallLayeredNeuralNetworkTrainer.java
URL: http://svn.apache.org/viewvc/hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/SmallLayeredNeuralNetworkTrainer.java?rev=1554532&r1=1554531&r2=1554532&view=diff
==============================================================================
--- hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/SmallLayeredNeuralNetworkTrainer.java
(original)
+++ hama/trunk/ml/src/main/java/org/apache/hama/ml/ann/SmallLayeredNeuralNetworkTrainer.java
Tue Dec 31 15:08:07 2013
@@ -153,7 +153,7 @@ public final class SmallLayeredNeuralNet
     LongWritable key = new LongWritable();
     VectorWritable value = new VectorWritable();
     for (int recordsRead = 0; recordsRead < batchSize; ++recordsRead) {
-      if (peer.readNext(key, value) == false) {
+      if (!peer.readNext(key, value)) {
         peer.reopenInput();
         peer.readNext(key, value);
       }

Modified: hama/trunk/ml/src/main/java/org/apache/hama/ml/kmeans/KMeansBSP.java
URL: http://svn.apache.org/viewvc/hama/trunk/ml/src/main/java/org/apache/hama/ml/kmeans/KMeansBSP.java?rev=1554532&r1=1554531&r2=1554532&view=diff
==============================================================================
--- hama/trunk/ml/src/main/java/org/apache/hama/ml/kmeans/KMeansBSP.java (original)
+++ hama/trunk/ml/src/main/java/org/apache/hama/ml/kmeans/KMeansBSP.java Tue Dec 31 15:08:07
2013
@@ -112,9 +112,7 @@ public final class KMeansBSP
       try {
         distanceMeasurer = ReflectionUtils.newInstance(distanceClass);
       } catch (ClassNotFoundException e) {
-        throw new RuntimeException(new StringBuilder(
-            "Wrong DistanceMeasurer implementation ").append(distanceClass)
-            .append(" provided").toString());
+        throw new RuntimeException("Wrong DistanceMeasurer implementation " + distanceClass
+ " provided");
       }
     } else {
       distanceMeasurer = new EuclidianDistance();

Modified: hama/trunk/ml/src/main/java/org/apache/hama/ml/perception/SmallMLPTrainer.java
URL: http://svn.apache.org/viewvc/hama/trunk/ml/src/main/java/org/apache/hama/ml/perception/SmallMLPTrainer.java?rev=1554532&r1=1554531&r2=1554532&view=diff
==============================================================================
--- hama/trunk/ml/src/main/java/org/apache/hama/ml/perception/SmallMLPTrainer.java (original)
+++ hama/trunk/ml/src/main/java/org/apache/hama/ml/perception/SmallMLPTrainer.java Tue Dec
31 15:08:07 2013
@@ -315,8 +315,8 @@ class SmallMLPTrainer extends NeuralNetw
     for (int i = 0; i < mat.length; ++i) {
       sb.append(String.format("Matrix [%d]\n", i));
       double[][] values = mat[i].getValues();
-      for (int d = 0; d < values.length; ++d) {
-        sb.append(Arrays.toString(values[d]));
+      for (double[] value : values) {
+        sb.append(Arrays.toString(value));
         sb.append('\n');
       }
       sb.append('\n');

Modified: hama/trunk/ml/src/main/java/org/apache/hama/ml/perception/SmallMultiLayerPerceptron.java
URL: http://svn.apache.org/viewvc/hama/trunk/ml/src/main/java/org/apache/hama/ml/perception/SmallMultiLayerPerceptron.java?rev=1554532&r1=1554531&r2=1554532&view=diff
==============================================================================
--- hama/trunk/ml/src/main/java/org/apache/hama/ml/perception/SmallMultiLayerPerceptron.java
(original)
+++ hama/trunk/ml/src/main/java/org/apache/hama/ml/perception/SmallMultiLayerPerceptron.java
Tue Dec 31 15:08:07 2013
@@ -115,7 +115,7 @@ public final class SmallMultiLayerPercep
 
       this.weightMatrice[i].applyToElements(new DoubleFunction() {
 
-        private Random rnd = new Random();
+        private final Random rnd = new Random();
 
         @Override
         public double apply(double value) {
@@ -556,8 +556,8 @@ public final class SmallMultiLayerPercep
     for (int i = 0; i < mat.length; ++i) {
       sb.append(String.format("Matrix [%d]\n", i));
       double[][] values = mat[i].getValues();
-      for (int d = 0; d < values.length; ++d) {
-        sb.append(Arrays.toString(values[d]));
+      for (double[] value : values) {
+        sb.append(Arrays.toString(value));
         sb.append('\n');
       }
       sb.append('\n');

Modified: hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/GradientDescentBSP.java
URL: http://svn.apache.org/viewvc/hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/GradientDescentBSP.java?rev=1554532&r1=1554531&r2=1554532&view=diff
==============================================================================
--- hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/GradientDescentBSP.java (original)
+++ hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/GradientDescentBSP.java Tue
Dec 31 15:08:07 2013
@@ -17,10 +17,6 @@
  */
 package org.apache.hama.ml.regression;
 
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.util.Arrays;
-
 import org.apache.hadoop.io.DoubleWritable;
 import org.apache.hama.bsp.BSP;
 import org.apache.hama.bsp.BSPPeer;
@@ -32,6 +28,10 @@ import org.apache.hama.commons.util.KeyV
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.Arrays;
+
 /**
  * A gradient descent (see
  * <code>http://en.wikipedia.org/wiki/Gradient_descent</code>) BSP based
@@ -195,9 +195,7 @@ public class GradientDescentBSP
       BSPPeer<VectorWritable, DoubleWritable, VectorWritable, DoubleWritable, VectorWritable>
peer,
       int iterations, double totalCost) {
     if (iterations > 0 && cost < totalCost) {
-      throw new RuntimeException(new StringBuilder(
-          "gradient descent failed to converge with alpha ").append(alpha)
-          .toString());
+      throw new RuntimeException("gradient descent failed to converge with alpha " + alpha);
     } else if (totalCost == 0 || totalCost < costThreshold
         || iterations >= iterationsThreshold) {
       cost = totalCost;

Modified: hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/LinearRegression.java
URL: http://svn.apache.org/viewvc/hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/LinearRegression.java?rev=1554532&r1=1554531&r2=1554532&view=diff
==============================================================================
--- hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/LinearRegression.java (original)
+++ hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/LinearRegression.java Tue Dec
31 15:08:07 2013
@@ -35,7 +35,7 @@ import org.apache.hama.ml.util.FeatureTr
 public class LinearRegression {
 
   /* Internal model */
-  private SmallLayeredNeuralNetwork ann;
+  private final SmallLayeredNeuralNetwork ann;
 
   public LinearRegression(int dimension) {
     ann = new SmallLayeredNeuralNetwork();

Modified: hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/LogisticRegression.java
URL: http://svn.apache.org/viewvc/hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/LogisticRegression.java?rev=1554532&r1=1554531&r2=1554532&view=diff
==============================================================================
--- hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/LogisticRegression.java (original)
+++ hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/LogisticRegression.java Tue
Dec 31 15:08:07 2013
@@ -18,15 +18,15 @@
 
 package org.apache.hama.ml.regression;
 
-import java.io.IOException;
-import java.util.Map;
-
 import org.apache.hadoop.fs.Path;
 import org.apache.hama.commons.math.DoubleVector;
 import org.apache.hama.commons.math.FunctionFactory;
 import org.apache.hama.ml.ann.SmallLayeredNeuralNetwork;
 import org.apache.hama.ml.util.FeatureTransformer;
 
+import java.io.IOException;
+import java.util.Map;
+
 /**
  * The logistic regression model. It can be used to conduct 2-class
  * classification.
@@ -34,7 +34,7 @@ import org.apache.hama.ml.util.FeatureTr
  */
 public class LogisticRegression {
   
-  private SmallLayeredNeuralNetwork ann;
+  private final SmallLayeredNeuralNetwork ann;
   
   public LogisticRegression(int dimension) {
     this.ann = new SmallLayeredNeuralNetwork();

Modified: hama/trunk/ml/src/main/java/org/apache/hama/ml/semiclustering/SemiClusterDetails.java
URL: http://svn.apache.org/viewvc/hama/trunk/ml/src/main/java/org/apache/hama/ml/semiclustering/SemiClusterDetails.java?rev=1554532&r1=1554531&r2=1554532&view=diff
==============================================================================
--- hama/trunk/ml/src/main/java/org/apache/hama/ml/semiclustering/SemiClusterDetails.java
(original)
+++ hama/trunk/ml/src/main/java/org/apache/hama/ml/semiclustering/SemiClusterDetails.java
Tue Dec 31 15:08:07 2013
@@ -89,10 +89,8 @@ public class SemiClusterDetails implemen
         return false;
     } else if (!semiClusterId.equals(other.semiClusterId))
       return false;
-    if (Double.doubleToLongBits(semiClusterScore) != Double
-        .doubleToLongBits(other.semiClusterScore))
-      return false;
-    return true;
+    return Double.doubleToLongBits(semiClusterScore) == Double
+            .doubleToLongBits(other.semiClusterScore);
   }
 
   @Override

Modified: hama/trunk/ml/src/main/java/org/apache/hama/ml/semiclustering/SemiClusterMessage.java
URL: http://svn.apache.org/viewvc/hama/trunk/ml/src/main/java/org/apache/hama/ml/semiclustering/SemiClusterMessage.java?rev=1554532&r1=1554531&r2=1554532&view=diff
==============================================================================
--- hama/trunk/ml/src/main/java/org/apache/hama/ml/semiclustering/SemiClusterMessage.java
(original)
+++ hama/trunk/ml/src/main/java/org/apache/hama/ml/semiclustering/SemiClusterMessage.java
Tue Dec 31 15:08:07 2013
@@ -138,9 +138,7 @@ public class SemiClusterMessage implemen
       }
     }
     out.writeInt(semiClusterContainThis.size());
-    Iterator<SemiClusterDetails> itr = semiClusterContainThis.iterator();
-    while (itr.hasNext())
-      itr.next().write(out);
+    for (SemiClusterDetails semiClusterContainThi : semiClusterContainThis) semiClusterContainThi.write(out);
   }
 
   public Set<SemiClusterDetails> getSemiClusterContainThis() {

Modified: hama/trunk/ml/src/main/java/org/apache/hama/ml/semiclustering/SemiClusteringVertex.java
URL: http://svn.apache.org/viewvc/hama/trunk/ml/src/main/java/org/apache/hama/ml/semiclustering/SemiClusteringVertex.java?rev=1554532&r1=1554531&r2=1554532&view=diff
==============================================================================
--- hama/trunk/ml/src/main/java/org/apache/hama/ml/semiclustering/SemiClusteringVertex.java
(original)
+++ hama/trunk/ml/src/main/java/org/apache/hama/ml/semiclustering/SemiClusteringVertex.java
Tue Dec 31 15:08:07 2013
@@ -18,21 +18,15 @@
 
 package org.apache.hama.ml.semiclustering;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-
 import org.apache.hadoop.io.DoubleWritable;
 import org.apache.hadoop.io.Text;
 import org.apache.hama.HamaConfiguration;
 import org.apache.hama.graph.Edge;
 import org.apache.hama.graph.Vertex;
 
+import java.io.IOException;
+import java.util.*;
+
 /**
  * SemiClusteringVertex Class defines each vertex in a Graph job and the
  * compute() method is the function which is applied on each Vertex in the graph
@@ -207,11 +201,8 @@ public class SemiClusteringVertex extend
    */
   public boolean isVertexInSc(SemiClusterMessage msg) {
     List<String> vertexId = getSemiClusterVerticesIdList(msg.getVertexList());
-    if (vertexId.contains(this.getVertexID().toString())
-        && vertexId.size() < semiClusterMaximumVertexCount)
-      return true;
-    else
-      return false;
+    return vertexId.contains(this.getVertexID().toString())
+            && vertexId.size() < semiClusterMaximumVertexCount;
   }
 
   /**



Mime
View raw message