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:
52  static double Fn(const double x)
53  {
54  if (x < DBL_MAX)
55  return x > -DBL_MAX ? std::log(1 + std::exp(x)) : 0;
56  return 1.0;
57  }
58 
65  template<typename InputType, typename OutputType>
66  static void Fn(const InputType& x, OutputType& y)
67  {
68  y.set_size(arma::size(x));
69 
70  for (size_t i = 0; i < x.n_elem; i++)
71  y(i) = Fn(x(i));
72  }
73 
80  static double Deriv(const double y)
81  {
82  return 1.0 / (1 + std::exp(-y));
83  }
84 
91  template<typename InputType, typename OutputType>
92  static void Deriv(const InputType& y, OutputType& x)
93  {
94  x = 1.0 / (1 + arma::exp(-y));
95  }
96 
103  static double Inv(const double y)
104  {
105  return y > 0 ? arma::trunc_log(arma::trunc_exp(y) - 1) : 0;
106  }
107 
114  template<typename InputType, typename OutputType>
115  static void Inv(const InputType& y, OutputType& x)
116  {
117  x.set_size(arma::size(y));
118 
119  for (size_t i = 0; i < y.n_elem; i++)
120  x(i) = Inv(y(i));
121  }
122 }; // class SoftplusFunction
123 
124 } // namespace ann
125 } // namespace mlpack
126 
127 #endif
static void Deriv(const InputType &y, OutputType &x)
Computes the first derivatives of the softplus function.
static void Fn(const InputType &x, OutputType &y)
Computes the softplus function.
static void Inv(const InputType &y, OutputType &x)
Computes the inverse of the softplus function.
.hpp
Definition: add_to_po.hpp:21
static double Deriv(const double y)
Computes the first derivative of the softplus function.
The core includes that mlpack expects; standard C++ includes and Armadillo.
static double Fn(const double x)
Computes the softplus function.
The softplus function, defined by.
static double Inv(const double y)
Computes the inverse of the softplus function.