[mlpack-svn] r16436 - mlpack/trunk/src/mlpack/methods/sparse_autoencoder

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Apr 16 14:53:25 EDT 2014


Author: rcurtin
Date: Wed Apr 16 14:53:24 2014
New Revision: 16436

Log:
Syntax cleanup; just some spacing.  No functionality change.


Modified:
   mlpack/trunk/src/mlpack/methods/sparse_autoencoder/sparse_autoencoder_function.cpp
   mlpack/trunk/src/mlpack/methods/sparse_autoencoder/sparse_autoencoder_impl.hpp

Modified: mlpack/trunk/src/mlpack/methods/sparse_autoencoder/sparse_autoencoder_function.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/sparse_autoencoder/sparse_autoencoder_function.cpp	(original)
+++ mlpack/trunk/src/mlpack/methods/sparse_autoencoder/sparse_autoencoder_function.cpp	Wed Apr 16 14:53:24 2014
@@ -49,18 +49,18 @@
   // operations without making the code too ugly.
 
   arma::mat parameters;
-  parameters.zeros(2*hiddenSize + 1, visibleSize + 1);
+  parameters.zeros(2 * hiddenSize + 1, visibleSize + 1);
 
   // Initialize w1 and w2 to random values in the range [0, 1].
-  parameters.submat(0, 0, 2*hiddenSize - 1, visibleSize - 1).randu();
+  parameters.submat(0, 0, 2 * hiddenSize - 1, visibleSize - 1).randu();
 
   // Decide the parameter 'r' depending on the size of the visible and hidden
   // layers. The formula used is r = sqrt(6) / sqrt(vSize + hSize + 1).
   const double range = sqrt(6) / sqrt(visibleSize + hiddenSize + 1);
 
   //Shift range of w1 and w2 values from [0, 1] to [-r, r].
-  parameters.submat(0, 0, 2*hiddenSize - 1, visibleSize - 1) = 2 * range *
-      (parameters.submat(0, 0, 2*hiddenSize - 1, visibleSize - 1) - 0.5);
+  parameters.submat(0, 0, 2 * hiddenSize - 1, visibleSize - 1) = 2 * range *
+      (parameters.submat(0, 0, 2 * hiddenSize - 1, visibleSize - 1) - 0.5);
 
   return parameters;
 }
@@ -80,7 +80,7 @@
   // Compute the limits for the parameters w1, w2, b1 and b2.
   const size_t l1 = hiddenSize;
   const size_t l2 = visibleSize;
-  const size_t l3 = 2*hiddenSize;
+  const size_t l3 = 2 * hiddenSize;
 
   // w1, w2, b1 and b2 are not extracted separately, 'parameters' is directly
   // used in their place to avoid copying data. The following representations
@@ -93,11 +93,12 @@
   arma::mat hiddenLayer, outputLayer;
 
   // Compute activations of the hidden and output layers.
-  hiddenLayer = Sigmoid(parameters.submat(0, 0, l1-1, l2-1) * data +
-      arma::repmat(parameters.submat(0, l2, l1-1, l2), 1, data.n_cols));
+  hiddenLayer = Sigmoid(parameters.submat(0, 0, l1 - 1, l2 - 1) * data +
+      arma::repmat(parameters.submat(0, l2, l1 - 1, l2), 1, data.n_cols));
 
-  outputLayer = Sigmoid(parameters.submat(l1, 0, l3-1, l2-1).t() * hiddenLayer +
-      arma::repmat(parameters.submat(l3, 0, l3, l2-1).t(), 1, data.n_cols));
+  outputLayer = Sigmoid(
+      parameters.submat(l1, 0, l3 - 1, l2 - 1).t() * hiddenLayer +
+      arma::repmat(parameters.submat(l3, 0, l3, l2 - 1).t(), 1, data.n_cols));
 
   arma::mat rhoCap, diff;
 
@@ -109,8 +110,8 @@
   double wL2SquaredNorm;
 
   // Calculate squared L2-norms of w1 and w2.
-  wL2SquaredNorm = arma::accu(parameters.submat(0, 0, l3-1, l2-1) %
-      parameters.submat(0, 0, l3-1, l2-1));
+  wL2SquaredNorm = arma::accu(parameters.submat(0, 0, l3 - 1, l2 - 1) %
+      parameters.submat(0, 0, l3 - 1, l2 - 1));
 
   double sumOfSquaresError, weightDecay, klDivergence, cost;
 
@@ -145,7 +146,7 @@
   // Compute the limits for the parameters w1, w2, b1 and b2.
   const size_t l1 = hiddenSize;
   const size_t l2 = visibleSize;
-  const size_t l3 = 2*hiddenSize;
+  const size_t l3 = 2 * hiddenSize;
 
   // w1, w2, b1 and b2 are not extracted separately, 'parameters' is directly
   // used in their place to avoid copying data. The following representations
@@ -158,11 +159,12 @@
   arma::mat hiddenLayer, outputLayer;
 
   // Compute activations of the hidden and output layers.
-  hiddenLayer = Sigmoid(parameters.submat(0, 0, l1-1, l2-1) * data +
-      arma::repmat(parameters.submat(0, l2, l1-1, l2), 1, data.n_cols));
+  hiddenLayer = Sigmoid(parameters.submat(0, 0, l1 - 1, l2 - 1) * data +
+      arma::repmat(parameters.submat(0, l2, l1 - 1, l2), 1, data.n_cols));
 
-  outputLayer = Sigmoid(parameters.submat(l1, 0, l3-1, l2-1).t() * hiddenLayer +
-      arma::repmat(parameters.submat(l3, 0, l3, l2-1).t(), 1, data.n_cols));
+  outputLayer = Sigmoid(
+      parameters.submat(l1, 0, l3 - 1, l2 - 1).t() * hiddenLayer +
+      arma::repmat(parameters.submat(l3, 0, l3, l2 - 1).t(), 1, data.n_cols));
 
   arma::mat rhoCap, diff;
 
@@ -181,18 +183,20 @@
   // includes the KL divergence term, we adjust for that in the formula below.
   klDivGrad = beta * (-(rho / rhoCap) + (1 - rho) / (1 - rhoCap));
   delOut = diff % outputLayer % (1 - outputLayer);
-  delHid = (parameters.submat(l1, 0, l3-1, l2-1) * delOut +
-      arma::repmat(klDivGrad, 1, data.n_cols)) % hiddenLayer % (1-hiddenLayer);
+  delHid = (parameters.submat(l1, 0, l3 - 1, l2 - 1) * delOut +
+      arma::repmat(klDivGrad, 1, data.n_cols)) % hiddenLayer %
+      (1 - hiddenLayer);
 
-  gradient.zeros(2*hiddenSize + 1, visibleSize + 1);
+  gradient.zeros(2 * hiddenSize + 1, visibleSize + 1);
 
   // Compute the gradient values using the activations and the delta values. The
   // formula also accounts for the regularization terms in the objective.
   // function.
-  gradient.submat(0, 0, l1-1, l2-1) = delHid * data.t() / data.n_cols + lambda *
-      parameters.submat(0, 0, l1-1, l2-1);
-  gradient.submat(l1, 0, l3-1, l2-1) = (delOut * hiddenLayer.t() / data.n_cols +
-      lambda * parameters.submat(l1, 0, l3-1, l2-1).t()).t();
-  gradient.submat(0, l2, l1-1, l2) = arma::sum(delHid, 1) / data.n_cols;
-  gradient.submat(l3, 0, l3, l2-1) = (arma::sum(delOut, 1) / data.n_cols).t();
+  gradient.submat(0, 0, l1 - 1, l2 - 1) = delHid * data.t() / data.n_cols +
+      lambda * parameters.submat(0, 0, l1 - 1, l2 - 1);
+  gradient.submat(l1, 0, l3 - 1, l2 - 1) =
+      (delOut * hiddenLayer.t() / data.n_cols +
+      lambda * parameters.submat(l1, 0, l3 - 1, l2 - 1).t()).t();
+  gradient.submat(0, l2, l1 - 1, l2) = arma::sum(delHid, 1) / data.n_cols;
+  gradient.submat(l3, 0, l3, l2 - 1) = (arma::sum(delOut, 1) / data.n_cols).t();
 }

Modified: mlpack/trunk/src/mlpack/methods/sparse_autoencoder/sparse_autoencoder_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/sparse_autoencoder/sparse_autoencoder_impl.hpp	(original)
+++ mlpack/trunk/src/mlpack/methods/sparse_autoencoder/sparse_autoencoder_impl.hpp	Wed Apr 16 14:53:24 2014
@@ -66,8 +66,8 @@
   const size_t l1 = hiddenSize;
   const size_t l2 = visibleSize;
 
-  features = Sigmoid(parameters.submat(0, 0, l1-1, l2-1) * data +
-      arma::repmat(parameters.submat(0, l2, l1-1, l2), 1, data.n_cols));
+  features = Sigmoid(parameters.submat(0, 0, l1 - 1, l2 - 1) * data +
+      arma::repmat(parameters.submat(0, l2, l1 - 1, l2), 1, data.n_cols));
 }
 
 }; // namespace nn



More information about the mlpack-svn mailing list