Jump to content

Activation function: Difference between revisions

From Wikibase
What σ is, why nonlinearity is required, common choices, and the derivative that backpropagation consumes — AI-assisted (RonzzWikiCowriter) (via create-page on MediaWiki MCP Server)
 
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Activation function]]
[[Category:Artificial neural network]][[Category:Special function]]
[[Category:Artificial neural network]]
An '''activation function''' is a mathematical [[function]].
An '''activation function''' is the elementwise nonlinearity applied to the pre-activation of a layer in an [[artificial neural network (ANN)]].<ref>{{#cite:Q3074}}</ref> It is written $\sigma$ throughout this wiki, and it is the only nonlinear component of a plain layer, hence the reason that stacking layers buys more than stacking matrices.


== Why nonlinearity is needed ==
It is part of layer-to-layer '''feedforward mechanisms''' of an [[artificial neural network (ANN)]].


Compose 2 affine layers with no $\sigma$ between them and the composition collapses to a single affine map,
* For a simple [[ANN]],the [[feedforward algorithm]]
* For a [[Transformer]], the [[feed-Forward Network (FFN) Sub-Layer (Transformer)|Feed-Forward Network (FFN)]]


$$
== Formal definition ==
\mathbf{W}_2\left(\mathbf{W}_1\vec x+\vec b_1\right)+\vec b_2
=
\mathbf{W}\vec x+\vec b,
\qquad
\mathbf{W}=\mathbf{W}_2\mathbf{W}_1,
\quad
\vec b=\mathbf{W}_2\vec b_1+\vec b_2,
$$
 
so an arbitrary depth would be no more expressive than 1 layer. Inserting a nonlinear $\sigma$ between them breaks the collapse, which is what makes depth useful.


== Definition ==
An activation function is any component-wise real-vector map
 
An activation function is any scalar map


$$
$$
\sigma:\mathbb{R}\to\mathbb{R}
\sigma:\mathbb{R}^n\to\mathbb{R}^n
$$
$$


applied to a pre-activation vector $\vec z$ componentwise,
so for any '''pre-activation vector''' $\vec z = (z_1,z_2,\dots,z_n)$ of [[artificial neuron#Layer_composition|a layer of artificial neurons]]:


$$
$$
a_j=\sigma\left(z_j\right),
\text{Activation vector}:\sigma(\vec z)=(\sigma(z_1),\sigma(z_2),\dots,\sigma(z_n))
$$
$$


so that $\vec a=\sigma(\vec z)$. The layer that applies it is described at [[feedforward algorithm]], and the weights and biases it acts between at [[model parameters]].
== Importance ==


== Common choices ==
'''Without''' an activation function:
 
* the [[sigmoid function]], bounded in $(0,1)$ and strictly increasing, whose derivative is $\dot\sigma=\sigma(1-\sigma)$.
* the hyperbolic tangent $\tanh(z)=2\sigma(2z)-1$, bounded in $(-1,1)$ and centred at $0$.
* the rectifier $\operatorname{ReLU}(z)=\max(0,z)$, unbounded above and exactly $0$ on negative inputs.
 
== Derivative ==
 
Training needs the derivative, because [[backpropagation]] multiplies each local gradient by it,


$$
$$
\frac{\partial a_j}{\partial z_j}=\dot\sigma\left(z_j\right).
\mathbf{W}_2\left(\mathbf{W}_1\vec x+\vec b_1\right)+\vec b_2
=
\mathbf{W}\vec x+\vec b,
\qquad
\mathbf{W}=\mathbf{W}_2\mathbf{W}_1,
\quad
\vec b=\mathbf{W}_2\vec b_1+\vec b_2,
$$
$$


A saturating activation makes those factors small. The sigmoid is the standard case: its derivative peaks at
Hence, any number of layers of [[artificial neuron]]s is strictly equivalent to 1 larger layer, a phenomenon known as '''depth collapse'''.


$$
The activation function, which introduces '''non-linearity''', enables the preservation of depth of an [[ANN]].
\max_z\dot\sigma(z)=\dot\sigma(0)=\frac{1}{4},
$$
 
so the factor through $L$ layers is at most $4^{-L}$, which is the vanishing-gradient problem. The rectifier avoids the saturation, its derivative being $0$ or $1$ everywhere, at the cost of units that stop responding entirely when their input stays negative.
 
== Not an activation function ==


[[Softmax]] occupies the same position at the output head but does not belong in this class: it couples the components rather than acting on each separately,
== Common variants ==


$$
* [[(leaky) rectified/exponential linear units (ReLU, LeakyReLU, ELU)]]
\operatorname{softmax}(\vec z)_i\ \text{depends on all } z_j,
* [[sigmoid function]]
\qquad\text{whereas}\qquad
* [[sigmoid linear unit (SLU)]]
\sigma(z_i)\ \text{depends on } z_i\ \text{alone}.
* [[gated linear unit (GLU)]]
$$
* [[hyperbolic tangent]]
* [[Gaussian error linear unit (GeLU)]]

Latest revision as of 15:46, 16 November 2026

Languages: English · français · Esperanto

An activation function is a mathematical function.

It is part of layer-to-layer feedforward mechanisms of an artificial neural network (ANN).

Formal definition

An activation function is any component-wise real-vector map

$$ \sigma:\mathbb{R}^n\to\mathbb{R}^n $$

so for any pre-activation vector $\vec z = (z_1,z_2,\dots,z_n)$ of a layer of artificial neurons:

$$ \text{Activation vector}:\sigma(\vec z)=(\sigma(z_1),\sigma(z_2),\dots,\sigma(z_n)) $$

Importance

Without an activation function:

$$ \mathbf{W}_2\left(\mathbf{W}_1\vec x+\vec b_1\right)+\vec b_2 = \mathbf{W}\vec x+\vec b, \qquad \mathbf{W}=\mathbf{W}_2\mathbf{W}_1, \quad \vec b=\mathbf{W}_2\vec b_1+\vec b_2, $$

Hence, any number of layers of artificial neurons is strictly equivalent to 1 larger layer, a phenomenon known as depth collapse.

The activation function, which introduces non-linearity, enables the preservation of depth of an ANN.

Common variants