[mlpack] 205/207: Re-add random_init.hpp since it is used by PCA.
Barak A. Pearlmutter
barak+git at pearlmutter.net
Thu Mar 23 17:53:55 UTC 2017
This is an automated email from the git hooks/post-receive script.
bap pushed a commit to branch master
in repository mlpack.
commit 40bf68253818176b7f9ba7846c94436a359d3263
Author: Ryan Curtin <ryan at ratml.org>
Date: Tue Mar 21 16:10:19 2017 -0400
Re-add random_init.hpp since it is used by PCA.
---
src/mlpack/methods/ann/CMakeLists.txt | 14 ++++
src/mlpack/methods/ann/init_rules/random_init.hpp | 92 +++++++++++++++++++++++
2 files changed, 106 insertions(+)
diff --git a/src/mlpack/methods/ann/CMakeLists.txt b/src/mlpack/methods/ann/CMakeLists.txt
new file mode 100644
index 0000000..44572c4
--- /dev/null
+++ b/src/mlpack/methods/ann/CMakeLists.txt
@@ -0,0 +1,14 @@
+# Define the files we need to compile
+# Anything not in this list will not be compiled into mlpack.
+set(SOURCES
+ init_rules/random_init.hpp
+)
+
+# Add directory name to sources.
+set(DIR_SRCS)
+foreach(file ${SOURCES})
+ set(DIR_SRCS ${DIR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/${file})
+endforeach()
+# Append sources (with directory name) to list of all mlpack sources (used at
+# the parent scope).
+set(MLPACK_SRCS ${MLPACK_SRCS} ${DIR_SRCS} PARENT_SCOPE)
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..4d720db
--- /dev/null
+++ b/src/mlpack/methods/ann/init_rules/random_init.hpp
@@ -0,0 +1,92 @@
+/**
+ * @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.
+ *
+ * mlpack is free software; you may redistribute it and/or modify it under the
+ * terms of the 3-clause BSD license. You should have received a copy of the
+ * 3-clause BSD license along with mlpack. If not, see
+ * http://www.opensource.org/licenses/BSD-3-Clause for more information.
+ */
+#ifndef MLPACK_METHODS_ANN_INIT_RULES_RANDOM_INIT_HPP
+#define MLPACK_METHODS_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.
+ */
+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 = -1,
+ const double upperBound = 1) :
+ lowerBound(lowerBound), upperBound(upperBound) { }
+
+ /**
+ * Initialize the random initialization rule with the given bound.
+ * Using the negative of the bound as lower bound and the positive 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 rows Number of rows.
+ * @param cols Number of columns.
+ */
+ template<typename eT>
+ void Initialize(arma::Mat<eT>& W, const size_t rows, const size_t cols)
+ {
+ W = lowerBound + arma::randu<arma::Mat<eT>>(rows, cols) *
+ (upperBound - lowerBound);
+ }
+
+ /**
+ * Initialize randomly the elements of the specified weight 3rd order tensor.
+ *
+ * @param W Weight matrix to initialize.
+ * @param rows Number of rows.
+ * @param cols Number of columns.
+ */
+ template<typename eT>
+ void Initialize(arma::Cube<eT>& W,
+ const size_t rows,
+ const size_t cols,
+ const size_t slices)
+ {
+ W = arma::Cube<eT>(rows, cols, slices);
+
+ for (size_t i = 0; i < slices; i++)
+ Initialize(W.slice(i), rows, cols);
+ }
+
+ 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
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git
More information about the debian-science-commits
mailing list