1 /**
2  * @file methods/ann/activation_functions/elliot_function.hpp
3  * @author Bisakh Mondal
4  *
5  * Definition and implementation of the Elliot Activation function as described
6  * by D.L. Elliott.
7  *
8  * For more information, see the following paper.
9  *
10  * @code
11  * @techreport{Elliott1993,
12  *   title = {A better activation function for artificial neural networks},
13  *   author = {Elliott, David L},
14  *   url = {https://drum.lib.umd.edu/bitstream/handle/1903/5355/TR_93-8.pdf}
15  *   year = {1993}
16  * }
17  * @endcode
18  *
19  * mlpack is free software; you may redistribute it and/or modify it under the
20  * terms of the 3-clause BSD license.  You should have received a copy of the
21  * 3-clause BSD license along with mlpack.  If not, see
22  * http://www.opensource.org/licenses/BSD-3-Clause for more information.
23  */
24 #ifndef MLPACK_METHODS_ANN_ACTIVATION_FUNCTIONS_ELLIOT_FUNCTION_HPP
25 #define MLPACK_METHODS_ANN_ACTIVATION_FUNCTIONS_ELLIOT_FUNCTION_HPP
26 
27 #include <mlpack/prereqs.hpp>
28 
29 namespace mlpack {
30 namespace ann /** Artificial Neural Network. */ {
31 
32 /**
33  * The Elliot function, defined by
34  *
35  * @f{eqnarray*}{
36  *  f(x) &=& \frac{x}{1 + |x|} \\
37  *  f'(x) &=& \frac{1}{(1 + |x|)^2}
38  * @f}
39  */
40 class ElliotFunction
41 {
42  public:
43   /**
44    * Computes the Elliot function.
45    *
46    * @param x Input data.
47    * @return f(x).
48    */
Fn(const double x)49   static double Fn(const double x)
50   {
51     return x / (1.0 + std::abs(x));
52   }
53 
54   /**
55    * Computes the Elliot function.
56    *
57    * @param x Input data.
58    * @param y The resulting output activation.
59    */
60   template <typename InputVecType, typename OutputVecType>
Fn(const InputVecType & x,OutputVecType & y)61   static void Fn(const InputVecType &x, OutputVecType &y)
62   {
63     y = x / (1.0 + arma::abs(x));
64   }
65 
66   /**
67    * Computes the first derivative of the Elliot function.
68    *
69    * @param y Input data.
70    * @return f'(x).
71    */
Deriv(const double y)72   static double Deriv(const double y)
73   {
74     return 1.0 / std::pow(1.0 + std::abs(y), 2);
75   }
76 
77   /**
78    * Computes the first derivatives of the Elliot function.
79    *
80    * @param y Input activations.
81    * @param x The resulting derivatives.
82    */
83   template <typename InputVecType, typename OutputVecType>
Deriv(const InputVecType & y,OutputVecType & x)84   static void Deriv(const InputVecType &y, OutputVecType &x)
85   {
86     x = 1.0 / arma::pow(1.0 + arma::abs(y), 2);
87   }
88 }; // class ElliotFunction
89 
90 } // namespace ann
91 } // namespace mlpack
92 
93 #endif
94