softsign_function.hpp
Go to the documentation of this file.
1 
25 #ifndef MLPACK_METHODS_ANN_ACTIVATION_FUNCTIONS_SOFTSIGN_FUNCTION_HPP
26 #define MLPACK_METHODS_ANN_ACTIVATION_FUNCTIONS_SOFTSIGN_FUNCTION_HPP
27 
28 #include <mlpack/prereqs.hpp>
29 
30 namespace mlpack {
31 namespace ann {
32 
48 {
49  public:
56  static double Fn(const double x)
57  {
58  if (x < DBL_MAX)
59  return x > -DBL_MAX ? x / (1.0 + std::abs(x)) : -1.0;
60  return 1.0;
61  }
62 
69  template<typename InputVecType, typename OutputVecType>
70  static void Fn(const InputVecType& x, OutputVecType& y)
71  {
72  y.set_size(arma::size(x));
73 
74  for (size_t i = 0; i < x.n_elem; ++i)
75  y(i) = Fn(x(i));
76  }
77 
84  static double Deriv(const double y)
85  {
86  return std::pow(1.0 - std::abs(y), 2);
87  }
88 
95  template<typename InputVecType, typename OutputVecType>
96  static void Deriv(const InputVecType& y, OutputVecType& x)
97  {
98  x = arma::pow(1.0 - arma::abs(y), 2);
99  }
100 
107  static double Inv(const double y)
108  {
109  if (y > 0)
110  return y < 1 ? -y / (y - 1) : DBL_MAX;
111  else
112  return y > -1 ? y / (1 + y) : -DBL_MAX;
113  }
114 
121  template<typename InputVecType, typename OutputVecType>
122  static void Inv(const InputVecType& y, OutputVecType& x)
123  {
124  x.set_size(arma::size(y));
125 
126  for (size_t i = 0; i < y.n_elem; ++i)
127  x(i) = Inv(y(i));
128  }
129 }; // class SoftsignFunction
130 
131 } // namespace ann
132 } // namespace mlpack
133 
134 #endif
static double Inv(const double y)
Computes the inverse of the softsign function.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
static void Fn(const InputVecType &x, OutputVecType &y)
Computes the softsign function.
static void Deriv(const InputVecType &y, OutputVecType &x)
Computes the first derivatives of the softsign function.
static void Inv(const InputVecType &y, OutputVecType &x)
Computes the inverse of the softsign function.
static double Fn(const double x)
Computes the softsign function.
static double Deriv(const double y)
Computes the first derivative of the softsign function.
The softsign function, defined by.