Commit e89d468b authored by Davis King's avatar Davis King

Added log1pexp()

parent 5e92f10f
...@@ -14,11 +14,29 @@ ...@@ -14,11 +14,29 @@
#include "../algs.h" #include "../algs.h"
#include <utility> #include <utility>
#include <tuple> #include <tuple>
#include <cmath>
namespace dlib namespace dlib
{ {
// ----------------------------------------------------------------------------------------
inline double log1pexp(double x)
{
using std::exp;
using namespace std; // Do this instead of using std::log1p because some compilers
// error out otherwise (E.g. gcc 4.9 in cygwin)
if (x <= -37)
return exp(x);
else if (-37 < x && x <= 18)
return log1p(exp(x));
else if (18 < x && x <= 33.3)
return x + exp(-x);
else
return x;
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// Tell us if T is one of the special layer types (i.e. add_layer, add_tag_layer, or // Tell us if T is one of the special layer types (i.e. add_layer, add_tag_layer, or
......
...@@ -45,6 +45,15 @@ namespace dlib ...@@ -45,6 +45,15 @@ namespace dlib
So it basically returns make_tuple(get<1>(item),get<2>(item),get<3>(item), and so on). So it basically returns make_tuple(get<1>(item),get<2>(item),get<3>(item), and so on).
!*/ !*/
double log1pexp(
double x
);
/*!
ensures
- returns log(1+exp(x))
(except computes it using a numerically accurate method)
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < template <
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment