You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hama.apache.org by to...@apache.org on 2012/10/12 14:27:59 UTC

svn commit: r1397538 - /hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/GradientDescentBSP.java

Author: tommaso
Date: Fri Oct 12 12:27:58 2012
New Revision: 1397538

URL: http://svn.apache.org/viewvc?rev=1397538&view=rev
Log:
[HAMA-651] - fixing log and Strings

Modified:
    hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/GradientDescentBSP.java

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=1397538&r1=1397537&r2=1397538&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 Fri Oct 12 12:27:58 2012
@@ -36,10 +36,10 @@ import java.io.IOException;
 public class GradientDescentBSP extends BSP<VectorWritable, DoubleWritable, VectorWritable, DoubleWritable, VectorWritable> {
 
   private static final Logger log = LoggerFactory.getLogger(GradientDescentBSP.class);
-  static final String INITIAL_THETA_VALUES = "initial.theta.values";
-  static final String ALPHA = "alpha";
-  static final String THRESHOLD = "threshold";
-  static final String REGRESSION_MODEL_CLASS = "regression.model.class";
+  public static final String INITIAL_THETA_VALUES = "gd.initial.theta";
+  public static final String ALPHA = "gd.alpha";
+  public static final String THRESHOLD = "gd.threshold";
+  public static final String REGRESSION_MODEL_CLASS = "gd.regression.model";
 
   private boolean master;
   private DoubleVector theta;
@@ -107,15 +107,15 @@ public class GradientDescentBSP extends 
 
       // cost check
       if (cost - totalCost < 0) {
-        throw new RuntimeException("gradient descent failed to converge with alpha " + alpha);
+        throw new RuntimeException(new StringBuilder("gradient descent failed to converge with alpha ").
+                append(alpha).toString());
       } else if (totalCost == 0 || totalCost < threshold) {
-        log.info(peer.getPeerName()+": finishing!");
         cost = totalCost;
         break;
       } else {
         cost = totalCost;
-        if (log.isInfoEnabled()) {
-          log.info(peer.getPeerName()+": cost is " + cost);
+        if (log.isDebugEnabled()) {
+          log.debug(peer.getPeerName()+": cost is " + cost);
         }
       }
 
@@ -156,8 +156,9 @@ public class GradientDescentBSP extends 
       }
       theta = new DenseDoubleVector(newTheta);
 
-      if (log.isInfoEnabled()) {
-        log.info(peer.getPeerName()+": new theta for cost " + cost + " is " + theta.toString());
+      if (log.isDebugEnabled()) {
+        log.debug(new StringBuilder(peer.getPeerName()).append(": new theta for cost ").
+                append(cost).append(" is ").append(theta.toString()).toString());
       }
       // master writes down the output
       if (master) {
@@ -173,12 +174,13 @@ public class GradientDescentBSP extends 
 
   @Override
   public void cleanup(BSPPeer<VectorWritable, DoubleWritable, VectorWritable, DoubleWritable, VectorWritable> peer) throws IOException {
-    if (log.isInfoEnabled()) {
-        log.info(peer.getPeerName()+":computation finished with cost " + cost + " for theta " + theta);
-    }
     // master writes down the final output
     if (master) {
         peer.write(new VectorWritable(theta), new DoubleWritable(cost));
+        if (log.isInfoEnabled()) {
+            log.info(new StringBuilder(peer.getPeerName()).append(":computation finished with cost ").
+                    append(cost).append(" for theta ").append(theta).toString());
+        }
     }
   }
 
@@ -190,10 +192,14 @@ public class GradientDescentBSP extends 
             for (String peerName : peer.getAllPeerNames()) {
                 peer.send(peerName, new VectorWritable(theta));
             }
-            log.info(peer.getPeerName() + ": sending theta");
+            if (log.isDebugEnabled()) {
+              log.debug(new StringBuilder(peer.getPeerName()).append(": sending theta").toString());
+            }
             peer.sync();
         } else {
-            log.info(peer.getPeerName() + ": getting theta");
+            if (log.isDebugEnabled()) {
+              log.debug(new StringBuilder(peer.getPeerName()).append(": getting theta").toString());
+            }
             peer.sync();
             VectorWritable vectorWritable = peer.getCurrentMessage();
             theta = vectorWritable.getVector();