[mlpack-svn] master: Add implementation of the random weight initialization method. (84c5f2c)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Wed Dec 31 16:05:49 EST 2014


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/5c67a7f75ba446321f794b63b861dc35f37dcd11...97351b828f14779109b3cca9bd37b39336d7ec5a

>---------------------------------------------------------------

commit 84c5f2c214a6fa7c106d7ab71996150ec8374338
Author: Marcus Edel <marcus.edel at fu-berlin.de>
Date:   Wed Dec 31 22:01:06 2014 +0100

    Add implementation of the random weight initialization method.


>---------------------------------------------------------------

84c5f2c214a6fa7c106d7ab71996150ec8374338
 src/mlpack/methods/ann/init_rules/random_init.hpp | 70 +++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/src/mlpack/methods/ann/init_rules/random_init.hpp b/src/mlpack/methods/ann/init_rules/random_init.hpp
new file mode 100644
index 0000000..6811e8e
--- /dev/null
+++ b/src/mlpack/methods/ann/init_rules/random_init.hpp
@@ -0,0 +1,70 @@
+/**
+ * @file random_init.hpp
+ * @author Marcus Edel
+ *
+ * Intialization rule for the neural networks. This simple initialization is
+ * performed by assigning a random matrix to the weight matrix.
+ */
+#ifndef __MLPACK_METHOS_ANN_INIT_RULES_RANDOM_INIT_HPP
+#define __MLPACK_METHOS_ANN_INIT_RULES_RANDOM_INIT_HPP
+
+#include <mlpack/core.hpp>
+
+namespace mlpack {
+namespace ann /** Artificial Neural Network. */ {
+
+/**
+ * This class is used to initialize randomly the weight matrix.
+ *
+ * @tparam MatType Type of matrix (should be arma::mat or arma::spmat).
+ */
+template<typename MatType = arma::mat>
+class RandomInitialization
+{
+ public:
+  /**
+   * Initialize the random initialization rule with the given lower bound and
+   * upper bound.
+   *
+   * @param lowerBound The number used as lower bound.
+   * @param upperBound The number used as upper bound.
+   */
+  RandomInitialization(const double lowerBound = -0.05,
+                       const double upperBound = 0.05) :
+      lowerBound(lowerBound), upperBound(upperBound) { }
+
+  /**
+   * Initialize the random initialization rule with the given bound.
+   * Using the negative of the bound as lower bound and the postive bound as
+   * upper bound.
+   *
+   * @param bound The number used as lower bound
+   */
+  RandomInitialization(const double bound) :
+      lowerBound(-std::abs(bound)), upperBound(std::abs(bound)) { }
+
+  /**
+   * Initialize randomly the elements of the specified weight matrix.
+   *
+   * @param W Weight matrix to initialize.
+   * @param n_rows Number of rows.
+   * @param n_cols Number of columns.
+   */
+  void Initialize(MatType& W, const size_t n_rows, const size_t n_cols)
+  {
+    W = lowerBound + arma::randu<MatType>(n_rows, n_cols) *
+        (upperBound - lowerBound);
+  }
+
+ private:
+  //! The number used as lower bound.
+  const double lowerBound;
+
+  //! The number used as upper bound.
+  const double upperBound;
+}; // class RandomInitialization
+
+}; // namespace ann
+}; // namespace mlpack
+
+#endif




More information about the mlpack-svn mailing list