[mlpack-git] master: add pooling rules (340a6d1)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Apr 23 16:02:23 EDT 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/9763c578d44db92496c044bbda812cf1af49b9a8...5d820f8a54290f22e79831ff2f08d5ace0409343
>---------------------------------------------------------------
commit 340a6d18453183fda76b8ff58a7423f3989fb999
Author: HurricaneTong <HurricaneTong at HurricaneTong.local>
Date: Thu Apr 23 09:41:51 2015 +0800
add pooling rules
>---------------------------------------------------------------
340a6d18453183fda76b8ff58a7423f3989fb999
.../methods/ann/pooling_rules/max_pooling.hpp | 40 ++++++++++++++++++++++
.../methods/ann/pooling_rules/mean_pooling.hpp | 36 +++++++++++++++++++
2 files changed, 76 insertions(+)
diff --git a/src/mlpack/methods/ann/pooling_rules/max_pooling.hpp b/src/mlpack/methods/ann/pooling_rules/max_pooling.hpp
new file mode 100644
index 0000000..1e95aa7
--- /dev/null
+++ b/src/mlpack/methods/ann/pooling_rules/max_pooling.hpp
@@ -0,0 +1,40 @@
+/**
+ * @file max_pooling.hpp
+ * @author Shangtong Zhang
+ *
+ * Definition of the MaxPooling class, which implements max pooling.
+ */
+#ifndef __MLPACK_METHODS_ANN_POOLING_MAX_POOLING_HPP
+#define __MLPACK_METHODS_ANN_POOLING_MAX_POOLING_HPP
+
+#include <mlpack/core.hpp>
+
+namespace mlpack {
+namespace ann /** Artificial Neural Network. */ {
+
+class MaxPooling
+{
+ public:
+ template<typename MatType>
+ static void pooling(const MatType& input, double& output)
+ {
+ output = input.max();
+ }
+
+ template<typename MatType>
+ static void unpooling(const MatType& input, const double& value,
+ MatType& output)
+ {
+ arma::uword row = 0;
+ arma::uword col = 0;
+ output = arma::zeros<MatType>(input.n_rows, input.n_cols);
+ input.max(row, col);
+ output(row, col) = value;
+ }
+
+};
+
+}; // namespace ann
+}; // namespace mlpack
+
+#endif
diff --git a/src/mlpack/methods/ann/pooling_rules/mean_pooling.hpp b/src/mlpack/methods/ann/pooling_rules/mean_pooling.hpp
new file mode 100644
index 0000000..0844565
--- /dev/null
+++ b/src/mlpack/methods/ann/pooling_rules/mean_pooling.hpp
@@ -0,0 +1,36 @@
+/**
+ * @file mean_pooling.hpp
+ * @author Shangtong Zhang
+ *
+ * Definition of the MeanPooling class, which implements mean pooling.
+ */
+#ifndef __MLPACK_METHODS_ANN_POOLING_MEAN_POOLING_HPP
+#define __MLPACK_METHODS_ANN_POOLING_MEAN_POOLING_HPP
+
+#include <mlpack/core.hpp>
+
+namespace mlpack {
+namespace ann /** Artificial Neural Network. */ {
+
+class MeanPooling
+{
+ public:
+ template<typename MatType>
+ static void pooling(const MatType& input, double& output)
+ {
+ output = arma::mean(arma::mean(input));
+ }
+
+ template<typename MatType>
+ static void unpooling(const MatType& input, const double& value,
+ MatType& output)
+ {
+ output = MatType(input.n_rows, input.n_cols);
+ output.fill(value / input.n_elem);
+ }
+};
+
+}; // namespace ann
+}; // namespace mlpack
+
+#endif
More information about the mlpack-git
mailing list