mlpack
tanh_function.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_ANN_ACTIVATION_FUNCTIONS_TANH_FUNCTION_HPP
13 #define MLPACK_METHODS_ANN_ACTIVATION_FUNCTIONS_TANH_FUNCTION_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace ann {
19 
30 {
31  public:
38  static double Fn(const double x)
39  {
40  return std::tanh(x);
41  }
42 
49  template<typename InputVecType, typename OutputVecType>
50  static void Fn(const InputVecType& x, OutputVecType& y)
51  {
52  y = arma::tanh(x);
53  }
54 
61  static double Deriv(const double y)
62  {
63  return 1 - std::pow(y, 2);
64  }
65 
72  template<typename InputVecType, typename OutputVecType>
73  static void Deriv(const InputVecType& y, OutputVecType& x)
74  {
75  x = 1 - arma::pow(y, 2);
76  }
77 
84  static double Inv(const double y)
85  {
86  return std::atanh(y);
87  }
88 
95  template<typename InputVecType, typename OutputVecType>
96  static void Inv(const InputVecType& y, OutputVecType& x)
97  {
98  x = arma::atanh(y);
99  }
100 }; // class TanhFunction
101 
102 } // namespace ann
103 } // namespace mlpack
104 
105 #endif
The tanh function, defined by.
Definition: tanh_function.hpp:29
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
static double Deriv(const double y)
Computes the first derivative of the tanh function.
Definition: tanh_function.hpp:61
static double Inv(const double y)
Computes the inverse of the tanh function.
Definition: tanh_function.hpp:84
The core includes that mlpack expects; standard C++ includes and Armadillo.
static void Deriv(const InputVecType &y, OutputVecType &x)
Computes the first derivatives of the tanh function.
Definition: tanh_function.hpp:73
static void Fn(const InputVecType &x, OutputVecType &y)
Computes the tanh function.
Definition: tanh_function.hpp:50
static void Inv(const InputVecType &y, OutputVecType &x)
Computes the inverse of the tanh function.
Definition: tanh_function.hpp:96
static double Fn(const double x)
Computes the tanh function.
Definition: tanh_function.hpp:38