mlpack
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
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
static double Fn(const double x)
Computes the softsign function.
Definition: softsign_function.hpp:56
The core includes that mlpack expects; standard C++ includes and Armadillo.
static double Deriv(const double y)
Computes the first derivative of the softsign function.
Definition: softsign_function.hpp:84
static void Inv(const InputVecType &y, OutputVecType &x)
Computes the inverse of the softsign function.
Definition: softsign_function.hpp:122
static void Deriv(const InputVecType &y, OutputVecType &x)
Computes the first derivatives of the softsign function.
Definition: softsign_function.hpp:96
static double Inv(const double y)
Computes the inverse of the softsign function.
Definition: softsign_function.hpp:107
static void Fn(const InputVecType &x, OutputVecType &y)
Computes the softsign function.
Definition: softsign_function.hpp:70
The softsign function, defined by.
Definition: softsign_function.hpp:47