mlpack 3.4.2
logistic_function.hpp
Go to the documentation of this file.
1
12#ifndef MLPACK_METHODS_ANN_ACTIVATION_FUNCTIONS_LOGISTIC_FUNCTION_HPP
13#define MLPACK_METHODS_ANN_ACTIVATION_FUNCTIONS_LOGISTIC_FUNCTION_HPP
14
15#include <mlpack/prereqs.hpp>
16
17namespace mlpack {
18namespace ann {
19
30{
31 public:
38 template<typename eT>
39 static double Fn(const eT x)
40 {
41 if (x < arma::Datum<eT>::log_max)
42 {
43 if (x > -arma::Datum<eT>::log_max)
44 return 1.0 / (1.0 + std::exp(-x));
45
46 return 0.0;
47 }
48
49 return 1.0;
50 }
51
58 template<typename InputVecType, typename OutputVecType>
59 static void Fn(const InputVecType& x, OutputVecType& y)
60 {
61 y = (1.0 / (1 + arma::exp(-x)));
62 }
63
70 static double Deriv(const double x)
71 {
72 return x * (1.0 - x);
73 }
74
81 template<typename InputVecType, typename OutputVecType>
82 static void Deriv(const InputVecType& y, OutputVecType& x)
83 {
84 x = y % (1.0 - y);
85 }
86
93 static double Inv(const double y)
94 {
95 return arma::trunc_log(y / (1 - y));
96 }
97
104 template<typename InputVecType, typename OutputVecType>
105 static void Inv(const InputVecType& y, OutputVecType& x)
106 {
107 x = arma::trunc_log(y / (1 - y));
108 }
109}; // class LogisticFunction
110
111} // namespace ann
112} // namespace mlpack
113
114#endif
The logistic function, defined by.
static double Inv(const double y)
Computes the inverse of the logistic function.
static double Fn(const eT x)
Computes the logistic function.
static double Deriv(const double x)
Computes the first derivative of the logistic function.
static void Deriv(const InputVecType &y, OutputVecType &x)
Computes the first derivatives of the logistic function.
static void Inv(const InputVecType &y, OutputVecType &x)
Computes the inverse of the logistic function.
static void Fn(const InputVecType &x, OutputVecType &y)
Computes the logistic function.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.