Reference articles on history, science, culture and more
Encyclopedia

Activation function

Artificial neural network node function

Image credit is listed at the end of this article.

In artificial neural networks, the activation function of a node 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.

Modern activation functions include the logistic (sigmoid) function used in the 2012 speech recognition model developed by Hinton et al; the ReLU used in the 2012 AlexNet computer vision model and in the 2015 ResNet model; and the smooth version of the ReLU, the GELU, which was used in the 2018 BERT model.

01Comparison 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. 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.
Continuously differentiable
This property is desirable for enabling gradient-based optimization methods (ReLU is not continuously differentiable and has some issues with gradient-based optimization, but it is still possible). 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.

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.

Rectified linear unit and Gaussian error linear unit activation functions
Rectified linear unit and Gaussian error linear unit activation functions

02Mathematical details

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

An activation function f is saturating if \lim _{|v|\to \infty }|\nabla f(v)|=0. It is nonsaturating if \lim _{|v|\to \infty }|\nabla f(v)|\neq 0. Non-saturating activation functions, such as ReLU, may be better than saturating activation functions, because they are less likely to suffer from the vanishing gradient problem.

Ridge activation functions

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

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.

Neurons also cannot fire faster than a certain rate. This biological limitation motivates the use of sigmoid activation functions, whose output range is confined to a finite interval.

The function looks like \phi (\mathbf {v} )=U(a+\mathbf {v} '\mathbf {b} ), where U 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 \phi (\mathbf {v} )=a+\mathbf {v} '\mathbf {b}.

Radial activation functions

A special class of activation functions known as radial basis functions (RBFs) are used in RBF networks. These activation functions can take many forms, but they are usually found as one of the following functions:

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

Other examples

Periodic functions can serve as activation functions. Usually the sinusoid is used, as any periodic function is decomposable into sinusoids by the Fourier transform.

Quadratic activation maps x\mapsto x^{2}.

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, g(x) Derivative of g, g'(x) Range Order of continuity
Identity x 1 (-\infty ,\infty ) C^{\infty }
Binary step {\begin{cases}0&{\text{if }}x<0\\1&{\text{if }}x\geq 0\end{cases}} 0 \{0,1\} C^{-1}
Logistic, sigmoid, or soft step \sigma (x)\doteq {\frac {1}{1+e^{-x}}} g(x)(1-g(x)) (0,1) C^{\infty }
Hyperbolic tangent (tanh) \tanh(x)\doteq {\frac {e^{x}-e^{-x}}{e^{x}+e^{-x}}} 1-g(x)^{2} (-1,1) C^{\infty }
Soboleva modified hyperbolic tangent (smht) \operatorname {smht} (x)\doteq {\frac {e^{ax}-e^{-bx}}{e^{cx}+e^{-dx}}} (-1,1) C^{\infty }
Softsign {\frac {x}{1+|x|}} {\frac {1}{(1+|x|)^{2}}} (-1,1) C^{1}
Rectified linear unit (ReLU) {\begin{aligned}(x)^{+}\doteq {}&{\begin{cases}0&{\text{if }}x\leq 0\\x&{\text{if }}x>0\end{cases}}\\={}&\max(0,x)=x{\textbf {1}}_{x>0}\end{aligned}} {\begin{cases}0&{\text{if }}x<0\\1&{\text{if }}x>0\end{cases}} [0,\infty ) C^{0}
Gaussian Error Linear Unit (GELU) {\begin{aligned}&{\frac {1}{2}}x\left(1+{\text{erf}}\left({\frac {x}{\sqrt {2}}}\right)\right)\\{}={}&x\Phi (x)\end{aligned}} where \mathrm {erf} is the gaussian error function. \Phi (x)+{\frac {1}{2}}x\phi (x) where \phi (x)={\frac {1}{\sqrt {2\pi }}}e^{-{\frac {1}{2}}x^{2}} is the probability density function of standard gaussian distribution. (-0.17\ldots ,\infty ) C^{\infty }
Softplus \ln \left(1+e^{x}\right) {\frac {1}{1+e^{-x}}} (0,\infty ) C^{\infty }
Exponential linear unit (ELU) {\begin{cases}\alpha \left(e^{x}-1\right)&{\text{if }}x\leq 0\\x&{\text{if }}x>0\end{cases}}
with parameter \alpha
{\begin{cases}\alpha e^{x}&{\text{if }}x<0\\1&{\text{if }}x>0\end{cases}} (-\alpha ,\infty ) {\begin{cases}C^{1}&{\text{if }}\alpha =1\\C^{0}&{\text{otherwise}}\end{cases}}
Scaled exponential linear unit (SELU) \lambda {\begin{cases}\alpha (e^{x}-1)&{\text{if }}x<0\\x&{\text{if }}x\geq 0\end{cases}}
with parameters \lambda =1.0507 and \alpha =1.67326
\lambda {\begin{cases}\alpha e^{x}&{\text{if }}x<0\\1&{\text{if }}x\geq 0\end{cases}} (-\lambda \alpha ,\infty ) C^{0}
Leaky rectified linear unit (Leaky ReLU) {\begin{cases}0.01x&{\text{if }}x\leq 0\\x&{\text{if }}x>0\end{cases}} {\begin{cases}0.01&{\text{if }}x<0\\1&{\text{if }}x>0\end{cases}} (-\infty ,\infty ) C^{0}
Parametric rectified linear unit (PReLU) {\begin{cases}\alpha x&{\text{if }}x<0\\x&{\text{if }}x\geq 0\end{cases}}
with parameter \alpha
{\begin{cases}\alpha &{\text{if }}x<0\\1&{\text{if }}x\geq 0\end{cases}} (-\infty ,\infty ) C^{0}
Rectified Parametric Sigmoid Units (flexible, 5 parameters) \alpha (2x{1}_{\{x\geqslant \lambda \}}-g_{\lambda ,\sigma ,\mu ,\beta }(x))+(1-\alpha )g_{\lambda ,\sigma ,\mu ,\beta }(x)

where g_{\lambda ,\sigma ,\mu ,\beta }(x)={\frac {(x-\lambda ){1}_{\{x\geqslant \lambda \}}}{1+e^{-\operatorname {sgn} (x-\mu )\left({\frac {\vert x-\mu \vert }{\sigma }}\right)^{\beta }}}}

- (-\infty ,\infty ) C^{0}
Sigmoid linear unit (SiLU, Sigmoid shrinkage, SiL, or Swish-1) {\frac {x}{1+e^{-x}}} {\frac {1+e^{-x}+xe^{-x}}{\left(1+e^{-x}\right)^{2}}} [-0.278\ldots ,\infty ) C^{\infty }
Exponential Linear Sigmoid SquasHing (ELiSH) {\begin{cases}{\frac {e^{x}-1}{1+e^{-x}}}&{\text{if }}x<0\\{\frac {x}{1+e^{-x}}}&{\text{if }}x\geq 0\end{cases}} {\begin{cases}{\frac {2e^{2x}+e^{3x}-e^{x}}{e^{2x}+2e^{x}+1}}&{\text{if }}x<0\\{\frac {xe^{x}+e^{2x}+e^{x}}{e^{2x}+2e^{x}+1}}&{\text{if }}x\geq 0\end{cases}} [-0.881\ldots ,\infty ) C^{1}
Gaussian e^{-x^{2}} -2xe^{-x^{2}} (0,1] C^{\infty }
Sinusoid \sin x \cos x [-1,1] C^{\infty }

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

Name Equation, g_{i}\left({\vec {x}}\right) Derivatives, {\frac {\partial g_{i}\left({\vec {x}}\right)}{\partial x_{j}}} Range Order of continuity
Softmax {\frac {e^{x_{i}}}{\sum _{j=1}^{J}e^{x_{j}}}}    for i = 1, ..., J g_{i}\left({\vec {x}}\right)\left(\delta _{ij}-g_{j}\left({\vec {x}}\right)\right) (0,1) C^{\infty }
Maxout \max _{i}x_{i} {\begin{cases}1&{\text{if }}j={\underset {i}{\operatorname {argmax} }}\,x_{i}\\0&{\text{if }}j\neq {\underset {i}{\operatorname {argmax} }}\,x_{i}\end{cases}} (-\infty ,\infty ) C^{0}
^ Here, \delta _{ij} is the Kronecker delta.
^ For instance, j could be iterating through the number of kernels of the previous neural network layer while i 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.

Watch videos about Activation functionExplainers and documentaries on YouTube (opens in a new tab)

Sources and credits

This article is adapted from the Wikipedia article Activation function, written by its contributors and licensed under CC BY-SA 4.0. Fathomly has changed the layout, removed citation markers, navigation and maintenance notices, and adjusted punctuation. This adapted version is shared under the same license. For references, see the original article.

Images, from Wikimedia Commons:

Fathomly is not affiliated with or endorsed by the Wikimedia Foundation. Spotted a problem? Tell us.

Continue exploring

Related topics

Logistic function

A logistic function or logistic curve is a common S-shaped curve with the equation f ( x ) = L 1 + e − k ( x − x 0 ) {\displaystyle f(x)={\frac {L}{1+e^{-k(x-x_{0})}}}} where L {\displaystyle L} is the carrying capacity, the supremum of the values of the function; k {\displaystyle k} is the logistic growth rate, the steepness of the curve; and x 0 {\displaystyle x_{0}} is the x {\displaystyle x} value of the function's midpoint. The logistic function has domain the real numbers, the limit as x {\displaystyle x} tends to − ∞ {\displaystyle -\infty } is 0, and the limit as x {\displaystyle x} tends to + ∞ {\displaystyle +\infty } is L {\displaystyle L} .

Rectified linear unit

In the context of artificial neural networks, the rectifier or ReLU activation function is an activation function defined as the non-negative part of its argument, i.e., the ramp function: ReLU ⁡ ( x ) = x + = max ( 0 , x ) = x + | x | 2 = { x if x > 0 , 0 x ≤ 0 {\displaystyle \operatorname {ReLU} (x)=x^{+}=\max(0,x)={\frac {x+|x|}{2}}={\begin{cases}x&{\text{if }}x>0,\\0&x\leq 0\end{cases}}} where x {\displaystyle x} is the input to a neuron. This is analogous to half-wave rectification in electrical engineering.

Stability (learning theory)

Stability, also known as algorithmic stability, is a notion in computational learning theory of how a machine learning algorithm output is changed with small perturbations to its inputs. A stable learning algorithm is one for which the prediction does not change much when the training data is modified slightly.