[MINOR] Fix minor typos and formatting issues in rbm dml script

Project: http://git-wip-us.apache.org/repos/asf/systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/a918d577
Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/a918d577
Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/a918d577

Branch: refs/heads/master
Commit: a918d57788c004921d012b086bbf311f69f82656
Parents: 92f3b7f
Author: Matthias Boehm <[email protected]>
Authored: Thu Dec 28 21:48:04 2017 -0800
Committer: Matthias Boehm <[email protected]>
Committed: Thu Dec 28 21:48:04 2017 -0800

----------------------------------------------------------------------
 scripts/staging/rbm_minibatch.dml | 47 +++++++++++++++++-----------------
 1 file changed, 23 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/a918d577/scripts/staging/rbm_minibatch.dml
----------------------------------------------------------------------
diff --git a/scripts/staging/rbm_minibatch.dml 
b/scripts/staging/rbm_minibatch.dml
index d7e45bb..73a8235 100644
--- a/scripts/staging/rbm_minibatch.dml
+++ b/scripts/staging/rbm_minibatch.dml
@@ -23,7 +23,7 @@
 #
 # The training algorithm uses one-step Contrastive Divergence as suggested in 
[Bengio, Y., Learning Deep 
 # Architectures for AI, Foundations and Trends in Machine Learning, Volume 2 
Issue 1, January 2009, p. 1–127]. 
-# This implemention is slightly modified and uses mini-batches to speed up the 
learning process.
+# This implementation is slightly modified and uses mini-batches to speed up 
the learning process.
 #
 # INPUT PARAMETERS:
 # 
--------------------------------------------------------------------------------------------
@@ -35,18 +35,18 @@
 # B         String  ---- Location to store the hidden units bias vector
 # batchsize  Int     100  Number of observations in a single batch    
 # vis        Int     ---- Number of units in the visible layer. If not 
specified this will be set 
-#                        to the number of features in X
+#                         to the number of features in X
 # hid        Int     2    Number of units in the hidden layer
 # epochs     Int     10   Number of training epochs 
 # alpha      Double  0.1  Learning rate
-# fmt       String  text Matrix output format for W,A, and B, usually "text" 
or "csv"
+# fmt        String  text Matrix output format for W,A, and B, usually "text" 
or "csv"
 # 
--------------------------------------------------------------------------------------------
 # OUTPUT: Matrices containing weights and biases for the trained network
 #
-#      OUTPUT SIZE:   OUTPUT CONTENTS:
-# W    vis x hid      RBM weights
-# A    1   x vis      Visible units biases
-# B    1   x hid      Hidden units biases
+# OUTPUT SIZE:      OUTPUT CONTENTS:
+#   W  vis x hid      RBM weights
+#   A  1   x vis      Visible units biases
+#   B  1   x hid      Hidden units biases
 #
 # To run an observation through the trained network use the rbm_run.dml 
script. 
 # Alternatively, you can simply compute P(h=1|v) using 1.0 / (1 + exp(-(X %*% 
W + B)) and 
@@ -60,18 +60,18 @@
 # -------------------------------------------- START OF RBM_MINIBATCH.DML 
--------------------------------------------
 
 # Default values
-learning_rate      = ifdef($alpha, 0.1)
-hidden_units_count  = ifdef($hid, 2)
-epoch_count        = ifdef($epochs, 10)
-batch_size         = ifdef($batchsize, 100)
-output_format      = ifdef($fmt, "text")
+learning_rate      = ifdef($alpha, 0.1)
+hidden_units_count = ifdef($hid, 2)
+epoch_count        = ifdef($epochs, 10)
+batch_size         = ifdef($batchsize, 100)
+output_format      = ifdef($fmt, "text")
 
 print("BEGIN RBM MINIBATCH TRAINING SCRIPT")
 
 print("Reading X...")
 X = read($X)
 
-# If number of visible units is not set, 
+# If number of visible units is not set,
 # set it to the number of features in X
 visible_units_count = ifdef ($vis, ncol(X))
 
@@ -86,10 +86,10 @@ if (minX < 0.0 | maxX > 1.0) {
   X = (X-minX)/(maxX-minX)
 }
 
-# Initialise a weight matrix (visible_units_count x hidden_units_count)
+# Initialize a weight matrix (visible_units_count x hidden_units_count)
 w = 0.1 * rand(rows = visible_units_count, cols = hidden_units_count, pdf = 
"uniform")
 
-# Setup biases and initialise with 0
+# Setup biases and initialize with 0
 a = matrix(0, rows = 1, cols = visible_units_count)    # Visible units bias
 b = matrix(0, rows = 1, cols = hidden_units_count)     # Hidden units bias
 
@@ -121,31 +121,30 @@ for (epoch in 1:epoch_count) {
     # POSITIVE PHASE
 
     # Compute the probabilities P(h=1|v)
-    p_h1_given_v = 1.0 / (1 + exp(-(v_1 %*% w + b)))   
+    p_h1_given_v = 1.0 / (1 + exp(-(v_1 %*% w + b)))
 
     # Sample from P(h=1|v)
     h1 = p_h1_given_v > rand(rows = batch_N, cols = hidden_units_count)
 
-    # NEGATIVE PHASE         
+    # NEGATIVE PHASE
         
     # Compute the probabilities P(v2=1|h1)
     p_v2_given_h1  = 1.0 / (1 + exp(-(h1 %*% t(w) + a)))
 
-    # Compute the probabilities P(h2=1|v2)          
-    p_h2_given_v2 = 1.0 / (1 + exp(-(p_v2_given_h1 %*% w + b)))         
+    # Compute the probabilities P(h2=1|v2)
+    p_h2_given_v2 = 1.0 / (1 + exp(-(p_v2_given_h1 %*% w + b)))
 
     # UPDATE WEIGHTS AND BIASES
-    w = w + learning_rate * ((t(v_1) %*% p_h1_given_v - t(p_v2_given_h1) %*% 
p_h2_given_v2) / batch_N)        
+    w = w + learning_rate * ((t(v_1) %*% p_h1_given_v - t(p_v2_given_h1) %*% 
p_h2_given_v2) / batch_N)
     a = a + (learning_rate / batch_N) * (colSums(v_1) - colSums(p_v2_given_h1))
-    b = b + (learning_rate / batch_N) * (colSums(p_h1_given_v) - 
colSums(p_h2_given_v2))          
+    b = b + (learning_rate / batch_N) * (colSums(p_h1_given_v) - 
colSums(p_h2_given_v2))
 
-    # COMPUTE ERROR    
+    # COMPUTE ERROR
     minibatch_err = sum((v_1 - p_v2_given_h1) ^ 2) / batch_N
     epoch_err = epoch_err + minibatch_err
   }
-  
-  print("Epoch " + epoch + " completed. Cummulative error is " + epoch_err)
 
+  print("Epoch " + epoch + " completed. Cumulative error is " + epoch_err)
 }
 
 # Save the RBM model

Reply via email to