[mlpack-svn] master: Add implementation of the rectifier activation function. (a11761e)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Wed Dec 31 15:53:25 EST 2014
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/a1f50fc5189e3d29de559c3c7c34011571dfc354...8316fefddb7b2e23679babf77c90647e529988eb
>---------------------------------------------------------------
commit a11761eec2382f6c349f29a439dc37a0d536d7ae
Author: Marcus Edel <marcus.edel at fu-berlin.de>
Date: Wed Dec 31 21:52:19 2014 +0100
Add implementation of the rectifier activation function.
>---------------------------------------------------------------
a11761eec2382f6c349f29a439dc37a0d536d7ae
.../activation_functions/rectifier_function.hpp | 95 ++++++++++++++++++++++
1 file changed, 95 insertions(+)
diff --git a/src/mlpack/methods/ann/activation_functions/rectifier_function.hpp b/src/mlpack/methods/ann/activation_functions/rectifier_function.hpp
new file mode 100644
index 0000000..3eaa2de
--- /dev/null
+++ b/src/mlpack/methods/ann/activation_functions/rectifier_function.hpp
@@ -0,0 +1,95 @@
+/**
+ * @file rectifier_function.hpp
+ * @author Marcus Edel
+ *
+ * Definition and implementation of the rectifier function as described by
+ * V. Nair and G. E. Hinton.
+ *
+ * For more information, see the following paper.
+ *
+ * @code
+ * @misc{NairHinton2010,
+ * author = {Vinod Nair, Geoffrey E. Hinton},
+ * title = {Rectified Linear Units Improve Restricted Boltzmann Machines},
+ * year = {2010}
+ * }
+ * @endcode
+ */
+#ifndef __MLPACK_METHODS_ANN_ACTIVATION_FUNCTIONS_RECTIFIER_FUNCTION_HPP
+#define __MLPACK_METHODS_ANN_ACTIVATION_FUNCTIONS_RECTIFIER_FUNCTION_HPP
+
+#include <mlpack/core.hpp>
+#include <algorithm>
+
+namespace mlpack {
+namespace ann /** Artificial Neural Network. */ {
+
+/**
+ * The rectifier function, defined by
+ *
+ * @f[
+ * f(x) &=& \max(0, x) \\
+ * f'(x) &=& \left\{
+ * \begin{array}{lr}
+ * 1 & : x > 0 \\
+ * 0 & : x \le 0
+ * \end{array}
+ * \right
+ * @f]
+ */
+class RectifierFunction
+{
+ public:
+ /**
+ * Computes the rectifier function.
+ *
+ * @param x Input data.
+ * @return f(x).
+ */
+ static double fn(const double x)
+ {
+ return std::max(0.0, x);
+ }
+
+ /**
+ * Computes the rectifier function.
+ *
+ * @param x Input data.
+ * @param y The resulting output activation.
+ */
+ template<typename InputVecType, typename OutputVecType>
+ static void fn(const InputVecType& x, OutputVecType& y)
+ {
+ y = x;
+ y = arma::max(arma::zeros<OutputVecType>(x.n_elem), x);
+ }
+
+ /**
+ * Computes the first derivative of the rectifier function.
+ *
+ * @param x Input data.
+ * @return f'(x)
+ */
+ static double deriv(const double y)
+ {
+ return y > 0 ? 1 : 0;
+ }
+
+ /**
+ * Computes the first derivatives of the rectifier function.
+ *
+ * @param y Input activations.
+ * @param x The resulting derivatives.
+ */
+ template<typename InputVecType, typename OutputVecType>
+ static void deriv(const InputVecType& y, OutputVecType& x)
+ {
+ x = y;
+ x.transform( [](double y) { return deriv(y); } );
+ }
+}; // class RectifierFunction
+
+}; // namespace ann
+}; // namespace mlpack
+
+#endif
More information about the mlpack-svn
mailing list