# Activation function

Jump to navigation Jump to search

In artificial neural networks, the activation function of a node defines the output of that node given an input or set of inputs. A standard integrated 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, only nonlinear activation functions allow such networks to compute nontrivial problems using only a small number of nodes, and such activation functions are called nonlinearities.

## Classification of activation functions

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

### Ridge activation functions

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

• Linear activation: $\phi (\mathbf {v} )=a+\mathbf {v} '\mathbf {b}$ ,
• ReLU activation: $\phi (\mathbf {v} )=\max(0,a+\mathbf {v} '\mathbf {b} )$ ,
• Heaviside activation: $\phi (\mathbf {v} )=1_{a+\mathbf {v} '\mathbf {b} >0}$ ,
• Logistic activation: $\phi (\mathbf {v} )=(1+\exp(-a-\mathbf {v} '\mathbf {b} ))^{-1}$ .

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 $\phi (\mathbf {v} )=U(a+\mathbf {v} '\mathbf {b} )$ , where $U$ is the Heaviside step function.

A line of positive slope may be used to 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}$ .

Neurons also cannot fire faster than a certain rate, motivating sigmoid activation functions whose domain is a finite interval.

### Radial activation functions

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 such as:

• Gaussian: $\,\phi (\mathbf {v} )=\exp \left(-{\frac {\|\mathbf {v} -\mathbf {c} \|^{2}}{2\sigma ^{2}}}\right)$ • Multiquadratics: $\,\phi (\mathbf {v} )={\sqrt {\|\mathbf {v} -\mathbf {c} \|^{2}+a^{2}}}$ where $\mathbf {c}$ is the vector representing the function center and $a$ and $\sigma$ 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.

## Comparison of activation functions

There are numerous activation functions. Hinton et al.'s seminal 2012 paper on automatic speech recognition uses a logistic sigmoid activation function. The seminal 2012 AlexNet computer vision architecture uses the ReLU activation function, as did the seminal 2015 computer vision architecture ResNet. The seminal 2018 language processing model BERT uses a smooth version of the ReLU, the GELU.

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.[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.

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.

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, $f(x)$ Derivative of $f$ , $f'(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}}$ ${\begin{cases}0&{\text{if }}x\neq 0\\{\text{undefined}}&{\text{if }}x=0\end{cases}}$ $\{0,1\}$ $C^{-1}$ Logistic, sigmoid, or soft step $\sigma (x)={\frac {1}{1+e^{-x}}}$ $f(x)(1-f(x))$ $(0,1)$ $C^{\infty }$ tanh $\tanh(x)={\frac {e^{x}-e^{-x}}{e^{x}+e^{-x}}}$ $1-f(x)^{2}$ $(-1,1)$ $C^{\infty }$ Rectified linear unit (ReLU) {\begin{aligned}&{\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\\{\text{undefined}}&{\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}} $\Phi (x)+x\phi (x)$ $(-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\\1&{\text{if }}x=0{\text{ and }}\alpha =1\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<0\\x&{\text{if }}x\geq 0\end{cases}}$ ${\begin{cases}0.01&{\text{if }}x<0\\1&{\text{if }}x\geq 0\end{cases}}$ $(-\infty ,\infty )$ $C^{0}$ Parameteric 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}$ 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 }$ Gaussian $e^{-x^{2}}$ $-2xe^{-x^{2}}$ $(0,1]$ $C^{\infty }$ ^ Here, $\sigma$ is the logistic function.
^ $\alpha >0$ for the range to hold true.

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

Name Equation, $f_{i}\left({\vec {x}}\right)$ Derivatives, ${\frac {\partial f_{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 $f_{i}\left({\vec {x}}\right)\left(\delta _{ij}-f_{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.