[mlpack-git] master: Return a number in the interval [0, 1] instead of [0, std::numeric_limits<eT>::max()]. (4a676a0)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:11:36 EST 2015


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

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

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

commit 4a676a0eb0c59f5d854d7249506f4e3366825b9d
Author: Marcus Edel <marcus.edel at fu-berlin.de>
Date:   Sun Jan 11 17:30:00 2015 +0100

    Return a number in the interval [0, 1] instead of [0, std::numeric_limits<eT>::max()].


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

4a676a0eb0c59f5d854d7249506f4e3366825b9d
 .../ann/activation_functions/logistic_function.hpp      | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/mlpack/methods/ann/activation_functions/logistic_function.hpp b/src/mlpack/methods/ann/activation_functions/logistic_function.hpp
index 728a2c5..a728a05 100644
--- a/src/mlpack/methods/ann/activation_functions/logistic_function.hpp
+++ b/src/mlpack/methods/ann/activation_functions/logistic_function.hpp
@@ -30,9 +30,19 @@ class LogisticFunction
    * @param x Input data.
    * @return f(x).
    */
-  static double fn(const double x)
+  template<typename eT>
+  static double fn(const eT x)
   {
-    return 1.0 /  (1.0 + arma::trunc_exp(-x));
+    if(x < arma::Math<eT>::log_max())
+    {
+      if (x > -arma::Math<eT>::log_max()) {
+        return 1.0 /  (1.0 + std::exp(-x));
+      }
+
+      return 0.0;
+    }
+
+    return 1.0;
   }
 
   /**
@@ -44,7 +54,8 @@ class LogisticFunction
   template<typename InputVecType, typename OutputVecType>
   static void fn(const InputVecType& x, OutputVecType& y)
   {
-    y = 1.0 / (1.0 + arma::trunc_exp(-x));
+    y = x;
+    y.transform( [](double x) { return fn(x); } );
   }
 
   /**



More information about the mlpack-git mailing list