# Activation function

In computational networks, the activation function of a node defines the output of that node given an input or set of inputs. A standard computer chip circuit can be seen as a digital network of activation functions that can be "ON" (1) or "OFF" (0), depending on input. This is similar to the behavior of the linear perceptron in neural networks. However, it is the nonlinear activation function that allows such networks to compute nontrivial problems using only a small number of nodes. In artificial neural networks this function is also called the transfer function.

## Functions

In biologically inspired neural networks, the activation function is usually an abstraction representing the rate of action potential firing in the cell. In its simplest form, this function is binary—that is, either the neuron is firing or not. The function looks like ${\displaystyle \phi (v_{i})=U(v_{i})}$, where ${\displaystyle U}$ is the Heaviside step function. In this case a large number of neurons must be used in computation beyond linear separation of categories.

A line of positive slope may also be used to reflect the increase in firing rate that occurs as input current increases. The function would then be of the form ${\displaystyle \phi (v_{i})=\mu v_{i}}$, where ${\displaystyle \mu }$ is the slope. This activation function is linear, and therefore has the same problems as the binary function. In addition, networks constructed using this model have unstable convergence because neuron inputs along favored paths tend to increase without bound, as this function is not normalizable.

All problems mentioned above can be handled by using a normalizable sigmoid activation function. One realistic model stays at zero until input current is received, at which point the firing frequency increases quickly at first, but gradually approaches an asymptote at 100% firing rate. Mathematically, this looks like ${\displaystyle \phi (v_{i})=U(v_{i})\tanh(v_{i})}$, where the hyperbolic tangent function can also be replaced by any sigmoid function. This behavior is realistically reflected in the neuron, as neurons cannot physically fire faster than a certain rate. This model runs into problems, however, in computational networks as it is not differentiable, a requirement in order to calculate backpropagation.

The final model, then, that is used in multilayer perceptrons is a sigmoidal activation function in the form of a hyperbolic tangent. Two forms of this function are commonly used: ${\displaystyle \phi (v_{i})=\tanh(v_{i})}$ whose range is normalized from -1 to 1, and ${\displaystyle \phi (v_{i})=(1+\exp(-v_{i}))^{-1}}$ is vertically translated to normalize from 0 to 1. The latter model is often considered more biologically realistic, but it runs into theoretical and experimental difficulties with certain types of computational problems.

### Alternative structures

A special class of activation functions known as radial basis functions (RBFs) are used in RBF networks, which are extremely efficient as universal function approximators. These activation functions can take many forms, but they are usually found as one of three functions:

• Gaussian: ${\displaystyle \,\phi (v_{i})=\exp \left(-{\frac {\|v_{i}-c_{i}\|^{2}}{2\sigma ^{2}}}\right)}$
• Multiquadratics: ${\displaystyle \,\phi (v_{i})={\sqrt {\|v_{i}-c_{i}\|^{2}+a^{2}}}}$
• Inverse multiquadratics: ${\displaystyle \,\phi (v_{i})=(\|v_{i}-c_{i}\|^{2}+a^{2})^{-1/2}}$

where ${\displaystyle c_{i}}$ is the vector representing the function center and ${\displaystyle a}$ and ${\displaystyle \sigma }$ are parameters affecting the spread of the radius.

Support vector machines (SVMs) can effectively utilize a class of activation functions that includes both sigmoids and RBFs. In this case, the input is transformed to reflect a decision boundary hyperplane based on a few training inputs called support vectors ${\displaystyle x}$. The activation function for the hidden layer of these machines is referred to as the inner product kernel, ${\displaystyle K(v_{i},x)=\phi (v_{i})}$. The support vectors are represented as the centers in RBFs with the kernel equal to the activation function, but they take a unique form in the perceptron as

${\displaystyle \,\phi (v_{i})=\tanh \left(\beta _{1}+\beta _{0}\sum _{j}v_{i,j}x_{j}\right)}$,

where ${\displaystyle \beta _{0}}$ and ${\displaystyle \beta _{1}}$ must satisfy certain conditions for convergence. These machines can also accept arbitrary-order polynomial activation functions where

${\displaystyle \,\phi (v_{i})=\left(1+\sum _{j}v_{i,j}x_{j}\right)^{p}}$.[1]

Activation function having types:

1. Identity function.
2. Binary step function.
3. Bipolar step function.
4. Sigmoidal function.
1. Binary sigmoidal function.
2. Bipolar sigmoidal function.
5. Ramp function.

### Comparison of activation functions

Some desirable properties in an activation function include:

• Nonlinear: When the activation function is non-linear, then a two-layer neural network can be proven to be a universal function approximator.[2] The identity activation function does not satisfy this property. When multiple layers use the identity activation function, the entire network is equivalent to a single-layer model.
• Continuously differentiable: This property is necessary for enabling gradient-based optimization methods. The binary step activation function is not differentiable at 0, and it differentiates to 0 for all other values, so gradient-based methods can make no progress with it.[3]
• Range: When the range of the activation function is finite, gradient-based training methods tend to be more stable, because pattern presentations significantly affect only limited weights. When the range is infinite, training is generally more efficient because pattern presentations significantly affect most of the weights. In the latter case, smaller learning rates are typically necessary.[citation needed]
• Monotonic: When the activation function is monotonic, the error surface associated with a single-layer model is guaranteed to be convex.[4]
• Smooth Functions with a Monotonic derivative have been shown to generalize better in some cases. The argument for these properties suggests that such activation functions are more consistent with Occam's razor.[5]
• Approximates identity near the origin: When activation functions have this property, the neural network will learn efficiently when its weights are initialized with small random values. When the activation function does not approximate identity near the origin, special care must be used when initializing the weights.[6] In the table below, activation functions where ${\displaystyle f(0)=0}$ and ${\displaystyle f'(0)=1}$ and ${\displaystyle f'}$ is continuous at 0 are indicated as having this property.

The following table compares the properties of several activation functions that are functions of one fold x from the previous layer or layers:

Name Plot Equation Derivative (with respect to x) Range Order of continuity Monotonic Derivative Monotonic Approximates identity near the origin
Identity ${\displaystyle f(x)=x}$ ${\displaystyle f'(x)=1}$ ${\displaystyle (-\infty ,\infty )}$ ${\displaystyle C^{\infty }}$ Yes Yes Yes
Binary step ${\displaystyle f(x)=\left\{{\begin{array}{rcl}0&{\mbox{for}}&x<0\\1&{\mbox{for}}&x\geq 0\end{array}}\right.}$ ${\displaystyle f'(x)=\left\{{\begin{array}{rcl}0&{\mbox{for}}&x\neq 0\\?&{\mbox{for}}&x=0\end{array}}\right.}$ ${\displaystyle \{0,1\}}$ ${\displaystyle C^{-1}}$ Yes No No
Logistic (a.k.a. Soft step) ${\displaystyle f(x)={\frac {1}{1+e^{-x}}}}$ ${\displaystyle f'(x)=f(x)(1-f(x))}$ ${\displaystyle (0,1)}$ ${\displaystyle C^{\infty }}$ Yes No No
TanH ${\displaystyle f(x)=\tanh(x)={\frac {2}{1+e^{-2x}}}-1}$ ${\displaystyle f'(x)=1-f(x)^{2}}$ ${\displaystyle (-1,1)}$ ${\displaystyle C^{\infty }}$ Yes No Yes
ArcTan ${\displaystyle f(x)=\tan ^{-1}(x)}$ ${\displaystyle f'(x)={\frac {1}{x^{2}+1}}}$ ${\displaystyle \left(-{\frac {\pi }{2}},{\frac {\pi }{2}}\right)}$ ${\displaystyle C^{\infty }}$ Yes No Yes
Softsign [7][8] ${\displaystyle f(x)={\frac {x}{1+|x|}}}$ ${\displaystyle f'(x)={\frac {1}{(1+|x|)^{2}}}}$ ${\displaystyle (-1,1)}$ ${\displaystyle C^{1}}$ Yes No Yes
Rectified linear unit (ReLU)[9] ${\displaystyle f(x)=\left\{{\begin{array}{rcl}0&{\mbox{for}}&x<0\\x&{\mbox{for}}&x\geq 0\end{array}}\right.}$ ${\displaystyle f'(x)=\left\{{\begin{array}{rcl}0&{\mbox{for}}&x<0\\1&{\mbox{for}}&x\geq 0\end{array}}\right.}$ ${\displaystyle [0,\infty )}$ ${\displaystyle C^{0}}$ Yes Yes No
Leaky rectified linear unit (Leaky ReLU)[10] ${\displaystyle f(x)=\left\{{\begin{array}{rcl}0.01x&{\mbox{for}}&x<0\\x&{\mbox{for}}&x\geq 0\end{array}}\right.}$ ${\displaystyle f'(x)=\left\{{\begin{array}{rcl}0.01&{\mbox{for}}&x<0\\1&{\mbox{for}}&x\geq 0\end{array}}\right.}$ ${\displaystyle (-\infty ,\infty )}$ ${\displaystyle C^{0}}$ Yes Yes No
Parameteric rectified linear unit (PReLU)[11] ${\displaystyle f(\alpha ,x)=\left\{{\begin{array}{rcl}\alpha x&{\mbox{for}}&x<0\\x&{\mbox{for}}&x\geq 0\end{array}}\right.}$ ${\displaystyle f'(\alpha ,x)=\left\{{\begin{array}{rcl}\alpha &{\mbox{for}}&x<0\\1&{\mbox{for}}&x\geq 0\end{array}}\right.}$ ${\displaystyle (-\infty ,\infty )}$ ${\displaystyle C^{0}}$ Yes iff ${\displaystyle \alpha \geq 0}$ Yes Yes iff ${\displaystyle \alpha =1}$
Randomized leaky rectified linear unit (RReLU)[12] ${\displaystyle f(\alpha ,x)=\left\{{\begin{array}{rcl}\alpha x&{\mbox{for}}&x<0\\x&{\mbox{for}}&x\geq 0\end{array}}\right.}$[1] ${\displaystyle f'(\alpha ,x)=\left\{{\begin{array}{rcl}\alpha &{\mbox{for}}&x<0\\1&{\mbox{for}}&x\geq 0\end{array}}\right.}$ ${\displaystyle (-\infty ,\infty )}$ ${\displaystyle C^{0}}$ Yes Yes No
Exponential linear unit (ELU)[13] ${\displaystyle f(\alpha ,x)=\left\{{\begin{array}{rcl}\alpha (e^{x}-1)&{\mbox{for}}&x<0\\x&{\mbox{for}}&x\geq 0\end{array}}\right.}$ ${\displaystyle f'(\alpha ,x)=\left\{{\begin{array}{rcl}f(\alpha ,x)+\alpha &{\mbox{for}}&x<0\\1&{\mbox{for}}&x\geq 0\end{array}}\right.}$ ${\displaystyle (-\alpha ,\infty )}$ ${\displaystyle C^{1}}$ when
${\displaystyle \alpha =1}$, otherwise ${\displaystyle C^{0}}$
Yes iff ${\displaystyle \alpha \geq 0}$ Yes iff ${\displaystyle 0\leq \alpha \leq 1}$ Yes iff ${\displaystyle \alpha =1}$
Scaled exponential linear unit (SELU)[14] ${\displaystyle f(\alpha ,x)=\lambda \left\{{\begin{array}{rcl}\alpha (e^{x}-1)&{\mbox{for}}&x<0\\x&{\mbox{for}}&x\geq 0\end{array}}\right.}$

with ${\displaystyle \lambda =1.0507}$ and ${\displaystyle \alpha =1.67326}$

${\displaystyle f'(\alpha ,x)=\lambda \left\{{\begin{array}{rcl}f(\alpha ,x)+\alpha &{\mbox{for}}&x<0\\1&{\mbox{for}}&x\geq 0\end{array}}\right.}$ ${\displaystyle (-\lambda \alpha ,\infty )}$ ${\displaystyle C^{0}}$ Yes No No
S-shaped rectified linear activation unit (SReLU)[15] ${\displaystyle f_{t_{l},a_{l},t_{r},a_{r}}(x)=\left\{{\begin{array}{rcl}t_{l}+a_{l}(x-t_{l})&{\mbox{for}}&x\leq t_{l}\\x&{\mbox{for}}&t_{l}
${\displaystyle t_{l},a_{l},t_{r},a_{r}}$ are parameters.
${\displaystyle f'_{t_{l},a_{l},t_{r},a_{r}}(x)=\left\{{\begin{array}{rcl}a_{l}&{\mbox{for}}&x\leq t_{l}\\1&{\mbox{for}}&t_{l} ${\displaystyle (-\infty ,\infty )}$ ${\displaystyle C^{0}}$ No No No
Adaptive piecewise linear (APL) [16] ${\displaystyle f(x)=\max(0,x)+\sum _{s=1}^{S}a_{i}^{s}\max(0,-x+b_{i}^{s})}$ ${\displaystyle f'(x)=H(x)-\sum _{s=1}^{S}a_{i}^{s}H(-x+b_{i}^{s})}$[2] ${\displaystyle (-\infty ,\infty )}$ ${\displaystyle C^{0}}$ No No No
SoftPlus[17] ${\displaystyle f(x)=\ln(1+e^{x})}$ ${\displaystyle f'(x)={\frac {1}{1+e^{-x}}}}$ ${\displaystyle (0,\infty )}$ ${\displaystyle C^{\infty }}$ Yes Yes No
Bent identity ${\displaystyle f(x)={\frac {{\sqrt {x^{2}+1}}-1}{2}}+x}$ ${\displaystyle f'(x)={\frac {x}{2{\sqrt {x^{2}+1}}}}+1}$ ${\displaystyle (-\infty ,\infty )}$ ${\displaystyle C^{\infty }}$ Yes Yes Yes
SoftExponential [18] ${\displaystyle f(\alpha ,x)=\left\{{\begin{array}{rcl}-{\frac {\ln(1-\alpha (x+\alpha ))}{\alpha }}&{\mbox{for}}&\alpha <0\\x&{\mbox{for}}&\alpha =0\\{\frac {e^{\alpha x}-1}{\alpha }}+\alpha &{\mbox{for}}&\alpha >0\end{array}}\right.}$ ${\displaystyle f'(\alpha ,x)=\left\{{\begin{array}{rcl}{\frac {1}{1-\alpha (\alpha +x)}}&{\mbox{for}}&\alpha <0\\e^{\alpha x}&{\mbox{for}}&\alpha \geq 0\end{array}}\right.}$ ${\displaystyle (-\infty ,\infty )}$ ${\displaystyle C^{\infty }}$ Yes Yes Yes iff ${\displaystyle \alpha =0}$
Sinusoid ${\displaystyle f(x)=\sin(x)}$ ${\displaystyle f'(x)=\cos(x)}$ ${\displaystyle [-1,1]}$ ${\displaystyle C^{\infty }}$ No No Yes
Sinc ${\displaystyle f(x)=\left\{{\begin{array}{rcl}1&{\mbox{for}}&x=0\\{\frac {\sin(x)}{x}}&{\mbox{for}}&x\neq 0\end{array}}\right.}$ ${\displaystyle f'(x)=\left\{{\begin{array}{rcl}0&{\mbox{for}}&x=0\\{\frac {\cos(x)}{x}}-{\frac {\sin(x)}{x^{2}}}&{\mbox{for}}&x\neq 0\end{array}}\right.}$ ${\displaystyle [\approx -.217234,1]}$ ${\displaystyle C^{\infty }}$ No No No
Gaussian ${\displaystyle f(x)=e^{-x^{2}}}$ ${\displaystyle f'(x)=-2xe^{-x^{2}}}$ ${\displaystyle (0,1]}$ ${\displaystyle C^{\infty }}$ No No No
^ Here, H is the Heaviside step function.
^ ${\displaystyle \alpha }$ is a stochastic variable sampled from a uniform distribution at training time and fixed to the expectation value of the distribution at test time.

The following table lists activation functions that are not functions of a single fold x from the previous layer or layers:

Name Equation Derivatives Range Order of continuity
Softmax ${\displaystyle f({\vec {x}})_{i}={\frac {e^{x_{i}}}{\sum _{k=1}^{K}e^{x_{k}}}}}$    for i = 1, …, K ${\displaystyle {\frac {\partial f({\vec {x}})_{i}}{\partial x_{j}}}=f({\vec {x}})_{i}(\delta _{ij}-f({\vec {x}})_{j})}$[3] ${\displaystyle (0,1)}$ ${\displaystyle C^{\infty }}$
Maxout[19] ${\displaystyle f({\vec {x}})=\max _{i}x_{i}}$ ${\displaystyle {\frac {\partial f}{\partial x_{j}}}=\left\{{\begin{array}{rcl}1&{\mbox{for}}&j={\underset {i}{\operatorname {argmax} }}\,x_{i}\\0&{\mbox{for}}&j\neq {\underset {i}{\operatorname {argmax} }}\,x_{i}\end{array}}\right.}$ ${\displaystyle (-\infty ,\infty )}$ ${\displaystyle C^{0}}$

^ Here, ${\displaystyle \delta }$ is the Kronecker delta.

## References

1. ^ Haykin, Simon (1998). Neural Networks: A Comprehensive Foundation (2 ed.). Prentice Hall. ISBN 0-13-273350-1.
2. ^ Cybenko, George. "Approximation by superpositions of a sigmoidal function." Mathematics of control, signals and systems 2.4 (1989): 303-314.
3. ^ Snyman, Jan. Practical mathematical optimization: an introduction to basic optimization theory and classical and new gradient-based algorithms. Vol. 97. Springer Science & Business Media, 2005.
4. ^ Wu, Huaiqin. "Global stability analysis of a general class of discontinuous neural networks with linear growth activation functions." Information Sciences 179.19 (2009): 3432-3441.
5. ^ Gashler, Michael S., and Stephen C. Ashmore. "Training Deep Fourier Neural Networks to Fit Time-Series Data." Intelligent Computing in Bioinformatics. Springer International Publishing, 2014. 48-55, arXiv:1405.2262
6. ^ Sussillo, David, and L. F. Abbott. "Random walks: Training very deep nonlinear feed-forward networks with smart initialization." CoRR, arXiv:1412.6558 (2014): 286.
7. ^ Bergstra, James and Desjardins, Guillaume and Lamblin, Pascal and Bengio, Yoshua. "Quadratic polynomials learn better image features". Technical Report 1337, Département d’Informatique et de Recherche Opérationnelle, Université de Montréal 2009. http://www.iro.umontreal.ca/~lisa/publications2/index.php/attachments/single/205
8. ^ Glorot, Xavier and Bengio, Yoshua."Understanding the difficulty of training deep feedforward neural networks". In Proceedings of the International Conference on Artificial Intelligence and Statistics (AISTATS’10). Society for Artificial Intelligence and Statistics. 2010. http://jmlr.org/proceedings/papers/v9/glorot10a/glorot10a.pdf
9. ^ Nair, Vinod, and Geoffrey E. Hinton. "Rectified linear units improve restricted boltzmann machines." Proceedings of the 27th International Conference on Machine Learning (ICML-10). 2010.
10. ^ Maas, Andrew L.; Hannun, Awni Y.; Ng, Andrew Y. (June 2013). "Rectifier nonlinearities improve neural network acoustic models" (PDF). Proc. ICML. 30 (1). Retrieved 2 January 2017.
11. ^
12. ^ Xu, Bing; Wang, Naiyan; Chen, Tianqi; Li, Mu (2015). "Empirical Evaluation of Rectified Activations in Convolutional Network." arXiv:1505.00853
13. ^
14. ^
15. ^ Jin, Xiaojie; Xu, Chunyan; Feng, Jiashi; Wei, Yunchao; Xiong, Junjun; Yan, Shuicheng (2015). "Deep Learning with S-shaped Rectified Linear Activation Units." arXiv:1512.07030
16. ^ Forest Agostinelli; Matthew Hoffman; Peter Sadowski; Pierre Baldi (21 Dec 2014). "Learning Activation Functions to Improve Deep Neural Networks". arXiv. Retrieved 2 January 2017.
17. ^ Glorot, Xavier, Antoine Bordes, and Yoshua Bengio. "Deep sparse rectifier neural networks." International Conference on Artificial Intelligence and Statistics. 2011.
18. ^ Luke B. Godfrey and Gashler, Michael S. A Continuum among Logarithmic, Linear, and Exponential Functions, and Its Potential to Improve Generalization in Neural Networks. In Proceedings of the 7th International Joint Conference on Knowledge Discovery, Knowledge Engineering and Knowledge Management: KDIR, pages 481-486. Lisbon, Portugal, November, 2015, arXiv:1602.01321.
19. ^ Ian J. Goodfellow, David Warde-Farley, Mehdi Mirza, Aaron Courville, Yoshua Bengio (2013). "Maxout Networks." arXiv:1302.4389