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  const double val = std::log(1 + std::exp(x));
55  if (std::isfinite(val))
56  return val;
57  return x;
58  }
59 
66  template<typename InputType, typename OutputType>
67  static void Fn(const InputType& x, OutputType& y)
68  {
69  y.set_size(arma::size(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 InputType, typename OutputType>
93  static void Deriv(const InputType& y, OutputType& x)
94  {
95  x = 1.0 / (1 + arma::exp(-y));
96  }
97 
104  static double Inv(const double y)
105  {
106  const double val = std::log(std::exp(y) - 1);
107  if (std::isfinite(val))
108  return val;
109  return y;
110  }
111 
118  template<typename InputType, typename OutputType>
119  static void Inv(const InputType& y, OutputType& x)
120  {
121  x.set_size(arma::size(y));
122 
123  for (size_t i = 0; i < y.n_elem; ++i)
124  x(i) = Inv(y(i));
125  }
126 }; // class SoftplusFunction
127 
128 } // namespace ann
129 } // namespace mlpack
130 
131 #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.
constexpr auto size(Container const &container) noexcept -> decltype(container.size())
Definition: iterator.hpp:29
Linear algebra utility functions, generally performed on matrices or vectors.
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.