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

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Sun Jan 11 11:30:10 EST 2015


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

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/37395966b16172f2ac2c7dbeba5ec13e2e37659d...b584f3434762fdefb8002422752a7b37ca2fd354

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

commit b584f3434762fdefb8002422752a7b37ca2fd354
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()].


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

b584f3434762fdefb8002422752a7b37ca2fd354
 .../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