hard_sigmoid_function.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_ANN_ACTIVATION_FUNCTIONS_HARD_SIGMOID_FUNCTION_HPP
13 #define MLPACK_METHODS_ANN_ACTIVATION_FUNCTIONS_HARD_SIGMOID_FUNCTION_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 #include <algorithm>
17 
18 namespace mlpack {
19 namespace ann {
20 
35 {
36  public:
43  static double Fn(const double x)
44  {
45  return std::min(1.0, std::max(0.0, 0.2 * x + 0.5));
46  }
47 
54  template<typename InputVecType, typename OutputVecType>
55  static void Fn(const InputVecType& x, OutputVecType& y)
56  {
57  y.set_size(size(x));
58 
59  for (size_t i = 0; i < x.n_elem; ++i)
60  y(i) = Fn(x(i));
61  }
62 
69  static double Deriv(const double y)
70  {
71  if (y == 0.0 || y == 1.0)
72  {
73  return 0.0;
74  }
75  return 0.2;
76  }
77 
84  template<typename InputVecType, typename OutputVecType>
85  static void Deriv(const InputVecType& y, OutputVecType& x)
86  {
87  x.set_size(size(y));
88 
89  for (size_t i = 0; i < y.n_elem; ++i)
90  {
91  x(i) = Deriv(y(i));
92  }
93  }
94 }; // class HardSigmoidFunction
95 
96 } // namespace ann
97 } // namespace mlpack
98 
99 #endif
constexpr auto size(Container const &container) noexcept -> decltype(container.size())
Definition: iterator.hpp:29
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes, Armadillo, cereal, and a few basic mlpa...
constexpr T const & max(T const &lhs, T const &rhs)
Definition: algorithm.hpp:79
static void Deriv(const InputVecType &y, OutputVecType &x)
Computes the first derivatives of the hard sigmoid function.
static void Fn(const InputVecType &x, OutputVecType &y)
Computes the hard sigmoid function.
constexpr T const & min(T const &lhs, T const &rhs)
Definition: algorithm.hpp:69
static double Fn(const double x)
Computes the hard sigmoid function.
The hard sigmoid function, defined by.
static double Deriv(const double y)
Computes the first derivatives of hard sigmoid function.