You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@horn.apache.org by zj...@apache.org on 2016/02/03 00:59:04 UTC

[2/3] incubator-horn git commit: Change SmallLayeredNeuralNetworkTrainer#isConverge's type from boolean to AtomicBoolean

Change SmallLayeredNeuralNetworkTrainer#isConverge's type from boolean to AtomicBoolean


Project: http://git-wip-us.apache.org/repos/asf/incubator-horn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-horn/commit/8f412c67
Tree: http://git-wip-us.apache.org/repos/asf/incubator-horn/tree/8f412c67
Diff: http://git-wip-us.apache.org/repos/asf/incubator-horn/diff/8f412c67

Branch: refs/heads/master
Commit: 8f412c6777fdd2434234ad316165cf165d12ffba
Parents: a8e7ff8
Author: Lee Dongjin <do...@gmail.com>
Authored: Mon Feb 1 00:11:45 2016 +0900
Committer: Lee Dongjin <do...@gmail.com>
Committed: Mon Feb 1 00:11:45 2016 +0900

----------------------------------------------------------------------
 .../horn/bsp/SmallLayeredNeuralNetworkTrainer.java     | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-horn/blob/8f412c67/src/main/java/org/apache/horn/bsp/SmallLayeredNeuralNetworkTrainer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/horn/bsp/SmallLayeredNeuralNetworkTrainer.java b/src/main/java/org/apache/horn/bsp/SmallLayeredNeuralNetworkTrainer.java
index 002a9e5..b4657f0 100644
--- a/src/main/java/org/apache/horn/bsp/SmallLayeredNeuralNetworkTrainer.java
+++ b/src/main/java/org/apache/horn/bsp/SmallLayeredNeuralNetworkTrainer.java
@@ -32,6 +32,7 @@ import org.apache.hama.commons.math.DoubleVector;
 import org.mortbay.log.Log;
 
 import java.io.IOException;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
  * The trainer that train the {@link SmallLayeredNeuralNetwork} based on BSP
@@ -53,7 +54,7 @@ public final class SmallLayeredNeuralNetworkTrainer
   private long convergenceCheckInterval;
   private long iterations;
   private long maxIterations;
-  private boolean isConverge;
+  private AtomicBoolean isConverge;
 
   private String modelPath;
 
@@ -79,7 +80,7 @@ public final class SmallLayeredNeuralNetworkTrainer
     if (isMaster(peer)) {
       Log.info("Begin to train");
     }
-    this.isConverge = false;
+    this.isConverge = new AtomicBoolean(false);
     this.conf = peer.getConfiguration();
     this.iterations = 0;
     this.modelPath = conf.get("modelPath");
@@ -128,7 +129,7 @@ public final class SmallLayeredNeuralNetworkTrainer
         mergeUpdates(peer);
       }
       peer.sync();
-      if (this.isConverge) {
+      if (this.isConverge.get()) {
         break;
       }
     }
@@ -150,9 +151,9 @@ public final class SmallLayeredNeuralNetworkTrainer
       DoubleMatrix[] preWeightUpdates = inMessage.getPrevMatrices();
       this.inMemoryModel.setWeightMatrices(newWeights);
       this.inMemoryModel.setPrevWeightMatrices(preWeightUpdates);
-      this.isConverge = inMessage.isConverge();
+      this.isConverge.set(inMessage.isConverge());
       // check converge
-      if (isConverge) {
+      if (isConverge.get()) {
         return;
       }
     }
@@ -205,7 +206,7 @@ public final class SmallLayeredNeuralNetworkTrainer
     int numMessages = peer.getNumCurrentMessages();
     boolean isConverge = false;
     if (numMessages == 0) { // converges
-      this.isConverge = true;
+      this.isConverge.set(true);
       return;
     }