From fe0db815c790029623a3327417893ee6c9d0fb84 Mon Sep 17 00:00:00 2001 From: akhandait Date: Fri, 1 Jun 2018 17:43:45 +0530 Subject: [PATCH 1/2] add support for all types --- .../softplus_function.hpp | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/mlpack/methods/ann/activation_functions/softplus_function.hpp b/src/mlpack/methods/ann/activation_functions/softplus_function.hpp index dd5875ff83..c8dbeb35b9 100644 --- a/src/mlpack/methods/ann/activation_functions/softplus_function.hpp +++ b/src/mlpack/methods/ann/activation_functions/softplus_function.hpp @@ -62,13 +62,11 @@ class SoftplusFunction * @param x Input data. * @param y The resulting output activation. */ - template - static void Fn(const InputVecType& x, OutputVecType& y) + template + static void Fn(const InputType& x, OutputType& y) { y = x; - - for (size_t i = 0; i < x.n_elem; i++) - y(i) = Fn(x(i)); + y.for_each([](OutputType::elem_type& val) {val = Fn(val);}) } /** @@ -88,8 +86,8 @@ class SoftplusFunction * @param y Input activations. * @param x The resulting derivatives. */ - template - static void Deriv(const InputVecType& y, OutputVecType& x) + template + static void Deriv(const InputType& y, OutputType& x) { x = 1.0 / (1 + arma::exp(-y)); } @@ -111,13 +109,11 @@ class SoftplusFunction * @param y Input data. * @param x The resulting inverse of the input data. */ - template - static void Inv(const InputVecType& y, OutputVecType& x) + template + static void Inv(const InputType& y, OutputType& x) { x = y; - - for (size_t i = 0; i < y.n_elem; i++) - x(i) = Inv(y(i)); + x.for_each([](OutputType::elem_type& val) {val = Inv(val);}) } }; // class SoftplusFunction From 3adc0c206a72ac1009f76f98792bf7e65e740852 Mon Sep 17 00:00:00 2001 From: akhandait Date: Fri, 1 Jun 2018 18:09:29 +0530 Subject: [PATCH 2/2] used transform instead of for_each --- .../methods/ann/activation_functions/softplus_function.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mlpack/methods/ann/activation_functions/softplus_function.hpp b/src/mlpack/methods/ann/activation_functions/softplus_function.hpp index c8dbeb35b9..395e99db99 100644 --- a/src/mlpack/methods/ann/activation_functions/softplus_function.hpp +++ b/src/mlpack/methods/ann/activation_functions/softplus_function.hpp @@ -66,7 +66,7 @@ class SoftplusFunction static void Fn(const InputType& x, OutputType& y) { y = x; - y.for_each([](OutputType::elem_type& val) {val = Fn(val);}) + y.transform([](double val) {return (Fn(val));} ); } /** @@ -113,7 +113,7 @@ class SoftplusFunction static void Inv(const InputType& y, OutputType& x) { x = y; - x.for_each([](OutputType::elem_type& val) {val = Inv(val);}) + x.transform([](double val) {return (Inv(val));} ); } }; // class SoftplusFunction