mlpack  master
softplus_function.hpp
Go to the documentation of this file.
1 
26 #ifndef MLPACK_METHODS_ANN_ACTIVATION_FUNCTIONS_SOFTPLUS_FUNCTION_HPP
27 #define MLPACK_METHODS_ANN_ACTIVATION_FUNCTIONS_SOFTPLUS_FUNCTION_HPP
28 
29 #include <mlpack/prereqs.hpp>
30 
31 namespace mlpack {
32 namespace ann {
33 
44 {
45  public:
46 
53  static double fn(const double x)
54  {
55  if (x < DBL_MAX)
56  return x > -DBL_MAX ? std::log(1 + std::exp(x)) : 0;
57  return 1.0;
58  }
59 
66  template<typename InputVecType, typename OutputVecType>
67  static void fn(const InputVecType& x, OutputVecType& y)
68  {
69  y = x;
70 
71  for (size_t i = 0; i < x.n_elem; i++)
72  y(i) = fn(x(i));
73  }
74 
81  static double deriv(const double y)
82  {
83  return 1.0 / (1 + std::exp(-y));
84  }
85 
92  template<typename InputVecType, typename OutputVecType>
93  static void deriv(const InputVecType& y, OutputVecType& x)
94  {
95  x = 1.0 / (1 + arma::exp(-y));
96  }
97 
104  static double inv(const double y)
105  {
106  return y > 0 ? arma::trunc_log(arma::trunc_exp(y) - 1) : 0;
107  }
108 
115  template<typename InputVecType, typename OutputVecType>
116  static void inv(const InputVecType& y, OutputVecType& x)
117  {
118  x = y;
119 
120  for (size_t i = 0; i < y.n_elem; i++)
121  x(i) = inv(y(i));
122  }
123 }; // class SoftplusFunction
124 
125 } // namespace ann
126 } // namespace mlpack
127 
128 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
static double fn(const double x)
Computes the softplus function.
The core includes that mlpack expects; standard C++ includes and Armadillo.
static double inv(const double y)
Computes the inverse of the softplus function.
static void fn(const InputVecType &x, OutputVecType &y)
Computes the softplus function.
static double deriv(const double y)
Computes the first derivative of the softplus function.
The softplus function, defined by.
static void inv(const InputVecType &y, OutputVecType &x)
Computes the inverse of the softplus function.
static void deriv(const InputVecType &y, OutputVecType &x)
Computes the first derivatives of the softplus function.