Activation function

From HandWiki
Revision as of 20:50, 6 February 2024 by Steve2012 (talk | contribs) (fix)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Short description: Artificial neural network node function
Logistic activation function

The activation function of a node in an artificial neural network is a function that calculates the output of the node based on its individual inputs and their weights. Nontrivial problems can be solved using only a few nodes if the activation function is nonlinear.[1] Modern activation functions include the smooth version of the ReLU, the GELU, which was used in the 2018 BERT model,[2] the logistic (sigmoid) function used in the 2012 speech recognition model developed by Hinton et al,[3] the ReLU used in the 2012 AlexNet computer vision model and in the 2015 ResNet model.

Comparison of activation functions

Aside from their empirical performance, activation functions also have different mathematical properties:

Nonlinear
When the activation function is non-linear, then a two-layer neural network can be proven to be a universal function approximator.[4] This is known as the Universal Approximation Theorem. 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.
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]
Continuously differentiable
This property is desirable (ReLU is not continuously differentiable and has some issues with gradient-based optimization, but it is still possible) 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.[5]

These properties do not decisively influence performance, nor are they the only mathematical properties that may be useful. For instance, the strictly positive range of the softplus makes it suitable for predicting variances in variational autoencoders.

Mathematical details

The most common activation functions can be divided into three categories: ridge functions, radial functions and fold functions.

An activation function [math]\displaystyle{ f }[/math] is saturating if [math]\displaystyle{ \lim_{|v|\to \infty} |\nabla f(v)| = 0 }[/math]. It is nonsaturating if it is not saturating. Non-saturating activation functions, such as ReLU, may be better than saturating activation functions, as networks using are less likely to suffer from the vanishing gradient problem.[6]

Ridge activation functions

Main page: Ridge function

Ridge functions are multivariate functions acting on a linear combination of the input variables. Often used examples include:[clarification needed]

  • Linear activation: [math]\displaystyle{ \phi (\mathbf v)=a +\mathbf v'\mathbf b }[/math],
  • ReLU activation: [math]\displaystyle{ \phi (\mathbf v)=\max(0,a +\mathbf v'\mathbf b) }[/math],
  • Heaviside activation: [math]\displaystyle{ \phi (\mathbf v)=1_{a +\mathbf v'\mathbf b\gt 0} }[/math],
  • Logistic activation: [math]\displaystyle{ \phi(\mathbf v) = (1+\exp(-a-\mathbf v'\mathbf b))^{-1} }[/math].

In biologically inspired neural networks, the activation function is usually an abstraction representing the rate of action potential firing in the cell.[7] In its simplest form, this function is binary—that is, either the neuron is firing or not. Neurons also cannot fire faster than a certain rate, motivating sigmoid activation functions whose range is a finite interval.

The function looks like [math]\displaystyle{ \phi(\mathbf v)=U(a + \mathbf v'\mathbf b) }[/math], where [math]\displaystyle{ U }[/math] is the Heaviside step function.

If a line has a positive slope, on the other hand, it may reflect the increase in firing rate that occurs as input current increases. Such a function would be of the form [math]\displaystyle{ \phi(\mathbf v)=a+\mathbf v'\mathbf b }[/math].

Rectified linear unit and Gaussian error linear unit activation functions

Radial activation functions

Main page: Radial function

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 the following functions:

  • Gaussian: [math]\displaystyle{ \,\phi(\mathbf v)=\exp\left(-\frac{\|\mathbf v - \mathbf c\|^2}{2\sigma^2}\right) }[/math]
  • Multiquadratics: [math]\displaystyle{ \,\phi(\mathbf v) = \sqrt{\|\mathbf v - \mathbf c\|^2 + a^2} }[/math]
  • Inverse multiquadratics: [math]\displaystyle{ \,\phi(\mathbf v) = \left(\|\mathbf v-\mathbf c\|^2 + a^2\right)^{-\frac{1}{2}} }[/math]
  • Polyharmonic splines

where [math]\displaystyle{ \mathbf c }[/math] is the vector representing the function center and [math]\displaystyle{ a }[/math] and [math]\displaystyle{ \sigma }[/math] are parameters affecting the spread of the radius.

Folding activation functions

Folding activation functions are extensively used in the pooling layers in convolutional neural networks, and in output layers of multiclass classification networks. These activations perform aggregation over the inputs, such as taking the mean, minimum or maximum. In multiclass classification the softmax activation is often used.

Table of activation functions

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 Function, [math]\displaystyle{ g(x) }[/math] Derivative of [math]\displaystyle{ g }[/math], [math]\displaystyle{ g'(x) }[/math] Range Order of continuity
Identity Activation identity.svg [math]\displaystyle{ x }[/math] [math]\displaystyle{ 1 }[/math] [math]\displaystyle{ (-\infty,\infty) }[/math] [math]\displaystyle{ C^\infty }[/math]
Binary step Activation binary step.svg [math]\displaystyle{ \begin{cases} 0 & \text{if } x \lt 0\\ 1 & \text{if } x \ge 0 \end{cases} }[/math] [math]\displaystyle{ 0 }[/math] [math]\displaystyle{ \{0,1\} }[/math] [math]\displaystyle{ C^{-1} }[/math]
Logistic, sigmoid, or soft step Activation logistic.svg [math]\displaystyle{ \sigma(x) \doteq \frac{1}{1 + e^{-x}} }[/math] [math]\displaystyle{ g(x)(1 - g(x)) }[/math] [math]\displaystyle{ (0,1) }[/math] [math]\displaystyle{ C^\infty }[/math]
Hyperbolic tangent (tanh) Activation tanh.svg [math]\displaystyle{ \tanh(x) \doteq \frac{e^x - e^{-x}}{e^x + e^{-x}} }[/math] [math]\displaystyle{ 1 - g(x)^2 }[/math] [math]\displaystyle{ (-1,1) }[/math] [math]\displaystyle{ C^\infty }[/math]
Soboleva modified hyperbolic tangent (smht) SMHTAF size.png [math]\displaystyle{ \operatorname{smht}(x) \doteq \frac {e^{ax} - e^{-bx}} {e^{cx} + e^{-dx}} }[/math] [math]\displaystyle{ (-1,1) }[/math] [math]\displaystyle{ C^\infty }[/math]
Rectified linear unit (ReLU)[8] Activation rectified linear.svg [math]\displaystyle{ \begin{align} (x)^+ \doteq {} &\begin{cases} 0 & \text{if } x \le 0\\ x & \text{if } x \gt 0 \end{cases} \\ = {} &\max(0,x) = x \textbf{1}_{x\gt 0} \end{align} }[/math] [math]\displaystyle{ \begin{cases} 0 & \text{if } x \lt 0\\ 1 & \text{if } x \gt 0 \end{cases} }[/math] [math]\displaystyle{ [0,\infty) }[/math] [math]\displaystyle{ C^0 }[/math]
Gaussian Error Linear Unit (GELU)[2] Visualization of the Gaussian Error Linear Unit (GELU) [math]\displaystyle{ \begin{align} &\frac{1}{2} x \left(1 + \text{erf}\left(\frac{x}{\sqrt{2}}\right)\right) \\ {}={} &x\Phi(x) \end{align} }[/math] [math]\displaystyle{ \Phi(x) + x\phi(x) }[/math] [math]\displaystyle{ (-0.17\ldots, \infty) }[/math] [math]\displaystyle{ C^\infty }[/math]
Softplus[9] Activation softplus.svg [math]\displaystyle{ \ln\left(1 + e^x\right) }[/math] [math]\displaystyle{ \frac{1}{1 + e^{-x}} }[/math] [math]\displaystyle{ (0,\infty) }[/math] [math]\displaystyle{ C^\infty }[/math]
Exponential linear unit (ELU)[10] Activation elu.svg [math]\displaystyle{ \begin{cases} \alpha\left(e^x - 1\right) & \text{if } x \le 0\\ x & \text{if } x \gt 0 \end{cases} }[/math]
with parameter [math]\displaystyle{ \alpha }[/math]
[math]\displaystyle{ \begin{cases} \alpha e^x & \text{if } x \lt 0 \\ 1 & \text{if } x \gt 0 \end{cases} }[/math] [math]\displaystyle{ (-\alpha,\infty) }[/math] [math]\displaystyle{ \begin{cases} C^1 & \text{if } \alpha = 1 \\ C^0 & \text{otherwise} \end{cases} }[/math]
Scaled exponential linear unit (SELU)[11] Activation selu.png [math]\displaystyle{ \lambda \begin{cases} \alpha(e^x - 1) & \text{if } x \lt 0\\ x & \text{if } x \ge 0 \end{cases} }[/math]
with parameters [math]\displaystyle{ \lambda = 1.0507 }[/math] and [math]\displaystyle{ \alpha = 1.67326 }[/math]
[math]\displaystyle{ \lambda \begin{cases} \alpha e^x & \text{if } x \lt 0\\ 1 & \text{if } x \ge 0 \end{cases} }[/math] [math]\displaystyle{ (-\lambda\alpha,\infty) }[/math] [math]\displaystyle{ C^0 }[/math]
Leaky rectified linear unit (Leaky ReLU)[12] Activation prelu.svg [math]\displaystyle{ \begin{cases} 0.01x & \text{if } x \le 0\\ x & \text{if } x \gt 0 \end{cases} }[/math] [math]\displaystyle{ \begin{cases} 0.01 & \text{if } x \lt 0\\ 1 & \text{if } x \gt 0 \end{cases} }[/math] [math]\displaystyle{ (-\infty,\infty) }[/math] [math]\displaystyle{ C^0 }[/math]
Parametric rectified linear unit (PReLU)[13] Activation prelu.svg [math]\displaystyle{ \begin{cases} \alpha x & \text{if } x \lt 0\\ x & \text{if } x \ge 0 \end{cases} }[/math]
with parameter [math]\displaystyle{ \alpha }[/math]
[math]\displaystyle{ \begin{cases} \alpha & \text{if } x \lt 0\\ 1 & \text{if } x \ge 0 \end{cases} }[/math] [math]\displaystyle{ (-\infty,\infty) }[/math] [math]\displaystyle{ C^0 }[/math]
Sigmoid linear unit (SiLU,[2] Sigmoid shrinkage,[14] SiL,[15] or Swish-‍1[16]) Swish Activation Function [math]\displaystyle{ \frac{x}{1 + e^{-x}} }[/math] [math]\displaystyle{ \frac{1 + e^{-x} + xe^{-x}}{\left(1 + e^{-x}\right)^2} }[/math] [math]\displaystyle{ [-0.278\ldots, \infty) }[/math] [math]\displaystyle{ C^\infty }[/math]
Gaussian Activation gaussian.svg [math]\displaystyle{ e^{-x^2} }[/math] [math]\displaystyle{ -2xe^{-x^2} }[/math] [math]\displaystyle{ (0,1] }[/math] [math]\displaystyle{ C^\infty }[/math]

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

Name Equation, [math]\displaystyle{ g_i\left(\vec{x}\right) }[/math] Derivatives, [math]\displaystyle{ \frac{\partial g_i\left(\vec{x}\right)}{\partial x_j} }[/math] Range Order of continuity
Softmax [math]\displaystyle{ \frac{e^{x_i}}{\sum_{j=1}^J e^{x_j}} }[/math]    for i = 1, …, J [math]\displaystyle{ g_i\left(\vec{x}\right)\left(\delta_{ij} - g_j\left(\vec{x}\right)\right) }[/math][1][2] [math]\displaystyle{ (0,1) }[/math] [math]\displaystyle{ C^\infty }[/math]
Maxout[17] [math]\displaystyle{ \max_i x_i }[/math] [math]\displaystyle{ \begin{cases} 1 & \text{if } j = \underset{i}{\operatorname{argmax}} \, x_i \\ 0 & \text{if } j \ne \underset{i}{\operatorname{argmax}} \, x_i \end{cases} }[/math] [math]\displaystyle{ (-\infty,\infty) }[/math] [math]\displaystyle{ C^0 }[/math]
^ Here, [math]\displaystyle{ \delta_{ij} }[/math] is the Kronecker delta.
^ For instance, [math]\displaystyle{ j }[/math] could be iterating through the number of kernels of the previous neural network layer while [math]\displaystyle{ i }[/math] iterates through the number of kernels of the current layer.

Quantum activation functions

In quantum neural networks programmed on gate-model quantum computers, based on quantum perceptrons instead of variational quantum circuits, the non-linearity of the activation function can be implemented with no need of measuring the output of each perceptron at each layer. The quantum properties loaded within the circuit such as superposition can be preserved by creating the Taylor series of the argument computed by the perceptron itself, with suitable quantum circuits computing the powers up to a wanted approximation degree. Because of the flexibility of such quantum circuits, they can be designed in order to approximate any arbitrary classical activation function.[18]


See also

References

  1. Hinkelmann, Knut. "Neural Networks, p. 7". http://didattica.cs.unicam.it/lib/exe/fetch.php?media=didattica:magistrale:kebi:ay_1718:ke-11_neural_networks.pdf. 
  2. 2.0 2.1 2.2 Hendrycks, Dan; Gimpel, Kevin (2016). "Gaussian Error Linear Units (GELUs)". arXiv:1606.08415 [cs.LG].
  3. Hinton, Geoffrey; Deng, Li; Deng, Li; Yu, Dong; Dahl, George; Mohamed, Abdel-rahman; Jaitly, Navdeep; Senior, Andrew et al. (2012). "Deep Neural Networks for Acoustic Modeling in Speech Recognition". IEEE Signal Processing Magazine 29 (6): 82–97. doi:10.1109/MSP.2012.2205597. 
  4. Cybenko, G. (December 1989). "Approximation by superpositions of a sigmoidal function" (in en). Mathematics of Control, Signals, and Systems 2 (4): 303–314. doi:10.1007/BF02551274. ISSN 0932-4194. https://hal.archives-ouvertes.fr/hal-03753170/file/Cybenko1989.pdf. 
  5. Snyman, Jan (3 March 2005). Practical Mathematical Optimization: An Introduction to Basic Optimization Theory and Classical and New Gradient-Based Algorithms. Springer Science & Business Media. ISBN 978-0-387-24348-1. https://books.google.com/books?id=0tFmf_UKl7oC. 
  6. Krizhevsky, Alex; Sutskever, Ilya; Hinton, Geoffrey E. (2017-05-24). "ImageNet classification with deep convolutional neural networks". Communications of the ACM 60 (6): 84–90. doi:10.1145/3065386. ISSN 0001-0782. 
  7. Hodgkin, A. L.; Huxley, A. F. (1952-08-28). "A quantitative description of membrane current and its application to conduction and excitation in nerve". The Journal of Physiology 117 (4): 500–544. doi:10.1113/jphysiol.1952.sp004764. PMID 12991237. 
  8. Nair, Vinod; Hinton, Geoffrey E. (2010), "Rectified Linear Units Improve Restricted Boltzmann Machines", 27th International Conference on International Conference on Machine Learning, ICML'10, USA: Omnipress, pp. 807–814, ISBN 9781605589077, http://dl.acm.org/citation.cfm?id=3104322.3104425 
  9. Glorot, Xavier; Bordes, Antoine; Bengio, Yoshua (2011). "Deep sparse rectifier neural networks". http://proceedings.mlr.press/v15/glorot11a/glorot11a.pdf. 
  10. Clevert, Djork-Arné; Unterthiner, Thomas; Hochreiter, Sepp (2015-11-23). "Fast and Accurate Deep Network Learning by Exponential Linear Units (ELUs)". arXiv:1511.07289 [cs.LG].
  11. Klambauer, Günter; Unterthiner, Thomas; Mayr, Andreas; Hochreiter, Sepp (2017-06-08). "Self-Normalizing Neural Networks". Advances in Neural Information Processing Systems 30 (2017). 
  12. Maas, Andrew L.; Hannun, Awni Y.; Ng, Andrew Y. (June 2013). "Rectifier nonlinearities improve neural network acoustic models". Proc. ICML 30 (1). 
  13. He, Kaiming; Zhang, Xiangyu; Ren, Shaoqing; Sun, Jian (2015-02-06). "Delving Deep into Rectifiers: Surpassing Human-Level Performance on ImageNet Classification". arXiv:1502.01852 [cs.CV].
  14. Atto, Abdourrahmane M.; Pastor, Dominique; Mercier, Grégoire (2008), "Smooth sigmoid wavelet shrinkage for non-parametric estimation", 2008 IEEE International Conference on Acoustics, Speech and Signal Processing, doi:10.1109/ICASSP.2008.4518347, https://hal.archives-ouvertes.fr/hal-02136546/file/ICASSP_ATTO_2008.pdf 
  15. Elfwing, Stefan; Uchibe, Eiji; Doya, Kenji (2018). "Sigmoid-Weighted Linear Units for Neural Network Function Approximation in Reinforcement Learning". Neural Networks 107: 3–11. doi:10.1016/j.neunet.2017.12.012. PMID 29395652. 
  16. Ramachandran, Prajit; Zoph, Barret; Le, Quoc V (2017). "Searching for Activation Functions". arXiv:1710.05941 [cs.NE].
  17. Goodfellow, Ian J.; Warde-Farley, David; Mirza, Mehdi; Courville, Aaron; Bengio, Yoshua (2013). "Maxout Networks". JMLR Workshop and Conference Proceedings 28 (3): 1319–1327. 
  18. Maronese, Marco; Destri, Claudio; Prati, Enrico (2022). "Quantum activation functions for quantum neural networks". Quantum Information Processing 21 (4): 128. doi:10.1007/s11128-022-03466-0. ISSN 1570-0755.