INGOAMPT learning series · Day 24
Activation functions change both a network’s output and the gradients that train it. Compare nine functions, read the complete original lesson, and then follow a checked two-neuron example that separates an activation’s derivative from a parameter’s gradient.
| Activation Function | Formula | Comparison | Why (Problem and Solution) | Mathematical Explanation and Proof |
|---|---|---|---|---|
| Sigmoid | σ(z) = 11 + e−z |
– Non-zero-centered output – Saturates for large values, leading to vanishing gradients |
Problem: Vanishing gradients for large positive or negative inputs, slowing down learning in deep networks. Solution: ReLU was introduced to avoid the saturation issue by having a linear response for positive values. |
The gradient of the sigmoid function is σ′(z) = σ(z)(1 − σ(z)). As z moves far from zero (either positive or negative), σ(z) approaches 1 or 0, causing σ′(z) to approach 0, leading to very small gradients and hence slow learning. |
| ReLU (Rectified Linear Unit) | f(z) = max(0, z) |
– Simple and computationally efficient – Doesn’t saturate for positive values – Suffers from “dying ReLU” problem |
Problem: “Dying ReLU,” where neurons stop learning when their inputs are negative, leading to dead neurons. Solution: Leaky ReLU was introduced to allow a small, non-zero gradient when z < 0, preventing neurons from dying. |
For z < 0, the gradient of ReLU is 0, meaning that neurons receiving negative inputs will not update during backpropagation. If this persists, the neuron is effectively “dead.” |
| Leaky ReLU | Leaky ReLUα(z) = max(αz, z) |
– Solves “dying ReLU” issue by allowing small gradient for negative values – Hyperparameter α determines the slope for z < 0 |
Problem: Choosing α is crucial; a bad choice can lead to suboptimal learning. Solution: Parametric ReLU (PReLU) allows α to be learned during training, optimizing the activation function for the specific dataset. |
By allowing αz (where α is a small positive number) for z < 0, Leaky ReLU ensures that gradients never fully vanish, maintaining some gradient flow even for negative inputs. |
| PReLU (Parametric ReLU) | f(z) = max(αz, z), where α is learned |
– Adaptively adjusts the slope of negative inputs based on data – Can lead to overfitting on small datasets |
Problem: Potential overfitting on smaller datasets due to the added flexibility of learning α. Solution: Use regularization techniques or simpler activation functions like ELU that don’t require learning parameters. |
The parameter α is learned during training, allowing the network to adaptively find the best slope for negative inputs. However, this flexibility can lead to overfitting, particularly on small datasets. |
| ELU (Exponential Linear Unit) | ELUα(z) = {α(ez − 1),if z < 0z,if z ≥ 0 |
– Allows for negative outputs, reducing bias shift – Smooths the gradient across the origin |
Problem: ReLU, Leaky ReLU, and PReLU can result in a bias shift and their derivatives aren’t smooth at z = 0. Solution: ELU allows negative outputs and provides a smooth gradient transition, helping in faster convergence and better learning stability. |
ELU ensures that the gradient remains smooth and non-zero even when z < 0, avoiding the abrupt changes seen in ReLU and its variants. This smoothness aids in better and faster learning. |
| SELU (Scaled Exponential Linear Unit) | SELU(z) = λ × {α(ez − 1),if z < 0z,if z ≥ 0 |
– Scaled version of ELU – Self-normalizing properties ensure stable outputs |
Problem: SELU requires specific conditions for self-normalization, limiting its flexibility to only certain architectures. Solution: Use in plain MLPs with standardized inputs and LeCun normal initialization. For other architectures, alternative activation functions like GELU might be better. |
The scaling factor λ ensures that the output of each layer is normalized, helping to maintain a consistent output distribution. However, the required conditions (e.g., standardized inputs, specific initialization) limit its general applicability. |
| GELU (Gaussian Error Linear Unit) | f(z) = z × Φ(z), where Φ(z) is the Gaussian CDF |
– Smooth variant of ReLU – Non-convex, non-monotonic, which can capture complex patterns better |
Problem: ReLU and its variants may struggle with complex tasks due to their linearity or fixed non-linear behavior. Solution: GELU’s combination of linear and Gaussian distribution provides a more flexible activation, making it better suited for capturing complex patterns. |
GELU leverages the Gaussian CDF to introduce smooth, probabilistic behavior in the activation function. This smoothness helps to handle complex patterns, but at the cost of higher computational complexity. |
| Swish | f(z) = z × σ(βz), where σ is the sigmoid function and β is a trainable parameter |
– Similar to GELU, allows smoother transitions and non-linear behavior – Slightly more computationally expensive than ReLU |
Problem: Even with GELU, the performance may not be optimal for all tasks. Solution: Swish introduces a parameterized smooth curve, which allows for a more adaptive and potentially more effective activation, depending on the task and dataset. |
The smooth transition offered by Swish, combined with the trainable parameter β, allows for dynamic adjustments of the activation behavior, optimizing performance across different tasks. |
| Mish | f(z) = z × tanh(ln(1 + ez)) |
– Non-monotonic, smooth, and self-regularizing – Encourages better gradient flow and faster convergence |
Problem: Swish and GELU, while powerful, may not always capture the most effective gradient dynamics or can be computationally intensive. Solution: Mish enhances gradient flow by ensuring smoother transitions and self-regularization, potentially leading to better convergence and model performance. |
Mish combines the properties of both Swish and GELU, providing a smooth activation function that enhances gradient flow across layers. The tanh(ln(1 + ez)) term ensures that the activation is bounded and non-monotonic, which can lead to better performance in some deep learning tasks. |
Let’s see their graph:


Now let’s continue even deeper:
Understanding the Impact of Activation Functions on Gradient Descent
Activation functions are integral to the learning mechanisms within neural networks, primarily influencing the efficiency and direction of gradient descent during training. This article delves into how activation functions like ReLU and Sigmoid shape the training process through a detailed comparative example.
Example Neural Network Setup
A simple neural network configuration includes:
- Input: x = 0.5
- Weights: w1 = 0.6, w2 = −0.4, wout = 0.3
- Biases: b1 = 0.1, b2 = 0.2, bout = 0.0
- Target Output: ytarget = 1.0
Forward Pass Calculation
First, we calculate the output of the hidden neurons and the final output of the network.
| Activation Function | Neuron 1 Output (h1) | Neuron 2 Output (h2) | Network Output (y) |
|---|---|---|---|
| ReLU | 0.4 | 0.0 | 0.12 |
| Sigmoid | 0.5987 | 0.5 | 0.3296 |
Backward Pass: Gradient Calculation
Next, we calculate the gradients to understand how each activation function influences the learning process:
Loss = 12(ytarget − y)2Gradient = ∂Loss∂y = y − ytarget
| Activation Function | Output Gradient | h1 Gradient | h2 Gradient |
|---|---|---|---|
| ReLU | -0.88 | -0.264 | 0 (ReLU derivative is 0 for h2 = 0) |
| Sigmoid | -0.6704 | −0.6704 · 0.3 · 0.240 = −0.0483 | −0.6704 · 0.3 · 0.25 = −0.0503 |
Analysis
ReLU: Neuron 1 (h1) contributes significantly to the gradient due to the derivative being 1 when positive; Neuron 2 (h2) contributes nothing, leading to “dying” neurons.
Sigmoid: Both neurons contribute, but with smaller gradients, potentially leading to vanishing gradients in deeper networks.
Conclusion
This discussion underscores the importance of choosing the right activation function to optimize neural network training, balancing between avoiding vanishing gradients and preventing neuron death.
View the 12 original TeX expressions
-
\(x = 0.5\) -
\(w_1 = 0.6\) -
\(w_2 = -0.4\) -
\(w_{out} = 0.3\) -
\(b_1 = 0.1\) -
\(b_2 = 0.2\) -
\(b_{out} = 0.0\) -
\(y_{target} = 1.0\) -
\[ \text{Loss} = \frac{1}{2} (y_{target} - y)^2 \] -
\[ \text{Gradient} = \frac{\partial \text{Loss}}{\partial y} = y - y_{target} \] -
\(-0.6704 \cdot 0.3 \cdot 0.240 = -0.0483\) -
\(-0.6704 \cdot 0.3 \cdot 0.25 = -0.0503\)
Corrections and context: shape is not a performance ranking
The original comparison is useful as a map of ideas, but each function is a mathematical choice with tradeoffs. A newer name does not establish better accuracy, faster training or a cure for vanishing gradients. A controlled experiment must hold the task, data split, preprocessing, initialization, optimizer and training budget fixed. Check validation performance, variability across random seeds and actual inference cost before choosing a replacement.
Start with the role of the layer
A hidden-layer activation creates nonlinear features. An output activation also has to fit the target and loss: a sigmoid can express a probability for a binary target, while a linear output is useful for an unrestricted scalar prediction. These are different roles. The numerical example below deliberately has a linear final output for both hidden-activation choices; adding an output sigmoid would create a different computation and different gradients.
Sigmoid’s derivative is σ(z)(1 − σ(z)), at most 14 and close to zero in either saturated tail. ReLU passes a positive input unchanged and gives zero on a negative input. A nonzero slope on the negative-input branch in Leaky ReLU or PReLU preserves a local negative-branch signal, but a full network’s gradient is a chain of many operations. Neither a local nonzero slope nor a smooth curve guarantees useful gradients in every architecture.
PReLU needs the piecewise definition
The general definition is f(z) = z when z ≥ 0, and f(z) = αz when z < 0. Equivalently it is max(z, 0) + α min(z, 0). The original max(αz, z) shortcut agrees with this piecewise function only when α ≤ 1. A learned, unconstrained parameter is not guaranteed to stay in that range. For example, at α = 2 and z = 1, the piecewise definition returns 1, while the shortcut returns 2. Learning a slope adds parameters; whether that helps or overfits is something to measure.
ELU: check the two one-sided slopes at zero
For the original ELU definition, the derivative below zero is αez and the derivative above zero is 1. Their limits at zero match only when α = 1. With that choice the first derivative is continuous, but the second derivative still changes from 1 on the left to 0 on the right at zero. It is therefore misleading to describe every α choice as having a smooth gradient transition. Far into the negative tail, the positive-α derivative also approaches zero, even though it is nonzero at each finite negative input.
SELU’s normalization result has conditions
SELU uses fixed scaling constants in a particular self-normalizing analysis. It is not an instruction that explicitly standardizes each layer’s actual activations. Its statistical result depends on assumptions about inputs, weights and architecture. Follow the original paper and the framework’s guidance on compatible initialization and dropout; LeCun normal and AlphaDropout are common components of that setting. Substituting SELU into an arbitrary residual or normalized architecture is not a proof that its activations will maintain zero mean and unit variance.
GELU, Swish and Mish: distinguish definitions from claims
Exact GELU is zΦ(z), with Φ the standard-normal cumulative distribution function. It is a deterministic calculation; the CDF factor does not mean a random gate is sampled. Some implementations use a tanh approximation. The new chart uses the exact error-function form, so its definition is explicit.
For generalized Swish, β may be a fixed constant or a learned parameter. β = 1 gives the SiLU/Swish-1 curve used in the chart and in a common fixed-form API. Calling a fixed SiLU activation does not automatically create a trainable β. Changing β changes the curve; for example β = 0 gives z2 rather than the plotted β = 1 shape.
Mish is unbounded above. Its tanh gate is bounded, but the activation multiplies that gate by z. At large positive inputs it approaches z; at very negative inputs it approaches zero from below. It has a finite lower bound, approximately −0.30884, rather than being bounded on both sides. “Self-regularized” is the paper’s description, not a guarantee that ordinary regularization, validation or careful optimization can be omitted.
Nine computed curves on the same axes
Each panel below uses inputs from −5 to 5 and the same output scale. Leaky ReLU uses α = 0.1; the PReLU panel is a fixed α = 0.25 slice, not a trained parameter. ELU uses α = 1. SELU uses α = 1.6732632423543772 and scale 1.0507009873554805. Swish uses β = 1, and GELU uses the exact normal CDF. Mish’s softplus is evaluated with a stable formula to avoid an unnecessary large exponential.

The original comparison cards above provide the definitions as selectable text. A curve by itself does not show the loss landscape of an entire network. Negative saturation, positive slopes, parameter choices and the operations surrounding an activation all affect its role.
A checked forward and backward pass
To make the original example unambiguous, use two independent output-edge weights, v1 = v2 = 0.3. Keep x = 0.5, hidden weights 0.6 and −0.4, hidden biases 0.1 and 0.2, final bias zero and target 1. The hidden preactivations are z1 = 0.4 and z2 = 0. The final output is linear, and the loss is half the squared error:
For ReLU, the hidden outputs are 0.4 and 0, giving y = 0.12 and L = 0.3872. For sigmoid, they are approximately 0.5986876601 and 0.5, giving y = 0.3296062980 and L = 0.2247138578. These reproduce the original rounded forward values under the stated assumptions. A lower loss on this one input is not evidence that sigmoid trains better on a dataset.
Trace one input along both paths
Begin at the top of the sketch with the input 0.5. Read the left branch first. Multiplying by 0.6 and adding 0.1 brings the first hidden unit to 0.4 before its activation. On the right branch, multiplying by −0.4 gives −0.2. The bias of 0.2 cancels that value exactly. Each hidden unit now applies the same chosen activation to its own input.

Follow the right branch to see why the predictions differ. ReLU sends zero forward at an input of zero, so this branch adds nothing to the prediction. Sigmoid sends 0.5 forward at the same input. Its outgoing weight converts that into a contribution of 0.15. The left branch also changes because the two functions assign different outputs to 0.4.
| Path or result | ReLU | Sigmoid |
|---|---|---|
| Unit 1 contribution, v1h1 | 0.120000 | 0.179606 |
| Unit 2 contribution, v2h2 | 0.000000 | 0.150000 |
| Prediction, sum of contributions | 0.120000 | 0.329606 |
| Half-squared loss at target 1 | 0.387200 | 0.224714 |
Read down either column to check the arithmetic. Add the two contributions to get the prediction, then subtract it from the target of 1, square the error and divide by two. The table rounds each displayed value to six decimal places after the calculation. To trace a gradient, start at that prediction and follow the same edges in reverse. Each factor you encounter describes the sensitivity of one step along the path.
Two gradients that must not share one label
Let δ = ∂L∂y = y − target. The gradient with respect to a hidden output is δvi. To reach the preactivation, multiply by the activation derivative as well:
The original table’s sigmoid “h1 Gradient” and “h2 Gradient” already include f′(z), so their values describe preactivation gradients, ∂L∂z, rather than hidden-output gradients, ∂L∂h. The original wording and values remain in their table; the labelled table below separates the quantities.
| Quantity | ReLU, selected slope 0 at zero | Sigmoid |
|---|---|---|
| δ = ∂L∂y | −0.88 | −0.6703937020 |
| ∂L∂h1, ∂L∂h2 | −0.264, −0.264 | −0.2011181106, −0.2011181106 |
| ∂L∂z1, ∂L∂z2 | −0.264, 0 | −0.0483207872, −0.0502795276 |
| ∂L∂w1, ∂L∂w2 | −0.132, 0 | −0.0241603936, −0.0251397638 |
| ∂L∂v1, ∂L∂v2 | −0.352, 0 | −0.4013564368, −0.3351968510 |
At ReLU’s kink, state the convention
Here z2 is exactly zero, rather than strictly negative. ReLU has no ordinary two-sided derivative at zero. Selecting a slope of zero there is an explicit convention, often used in automatic differentiation. Under that convention ∂L∂z2 = 0, even though ∂L∂h2 = −0.264. One zero output on one observation does not establish a neuron that remains inactive throughout training.
The two output-edge weights are independent in this calculation. If the original single wout is intended as one tied parameter shared by both edges, its derivative must sum both paths: ∂L∂v = δ(h1 + h2). That would give −0.352 for ReLU and approximately −0.7365532878 for sigmoid. A diagram or implementation should make this parameter-sharing choice explicit.
A small calculation you can reproduce
The following dependency-free Python listing was executed for this revision. It calculates only a scalar forward/backward pass. It does not import a deep-learning framework, fit data, run an optimizer or measure accuracy. Separate independent finite-difference checks tested all seven parameter gradients for sigmoid and for ReLU on each side of the kink; a central difference at the kink was not treated as a classical derivative test.
"""Scalar forward/backward example; no framework, optimizer or training run."""
from math import exp
import json
def evaluate(name):
x, target = 0.5, 1.0
w, b, v = (0.6, -0.4), (0.1, 0.2), (0.3, 0.3)
z = [wi * x + bi for wi, bi in zip(w, b)]
if name == "ReLU":
h = [max(0.0, zi) for zi in z]
# The derivative at exactly zero is selected as 0, not classical.
slope = [1.0 if zi > 0.0 else 0.0 for zi in z]
else:
h = [1.0 / (1.0 + exp(-zi)) for zi in z]
slope = [hi * (1.0 - hi) for hi in h]
prediction = sum(vi * hi for vi, hi in zip(v, h))
delta = prediction - target
dh = [delta * vi for vi in v]
dz = [gi * si for gi, si in zip(dh, slope)]
return {"z": z, "h": h, "prediction": prediction,
"loss": 0.5 * delta**2, "dL_dy": delta,
"dL_dh": dh, "dL_dz": dz,
"dL_dw": [gi * x for gi in dz],
"dL_dv": [delta * hi for hi in h]}
if __name__ == "__main__":
results = {name: evaluate(name) for name in ("ReLU", "Sigmoid")}
assert abs(results["ReLU"]["prediction"] - 0.12) < 1e-12
assert abs(results["Sigmoid"]["prediction"] - 0.3296062980337356) < 1e-12
assert abs(results["Sigmoid"]["dL_dz"][1] + 0.05027952764746983) < 1e-12
print(json.dumps(results, indent=2))
Read the printed dL_dh and dL_dz arrays side by side. Their distinction explains why a hidden unit can have a nonzero upstream gradient while its activation blocks the gradient reaching a weight. That chain-rule interpretation is more informative than labelling an activation universally good or bad.
Questions about activation functions and gradients
Which activation function is best?
There is no universal winner. Match hidden and output roles to the architecture, target and loss, then compare controlled validation results and inference cost. The nine curves in this lesson are not an accuracy ranking.
Is Mish bounded?
Mish is bounded below, approximately by −0.30884, and unbounded above. Its tanh gate is bounded, but multiplying that gate by the input does not bound the full activation above.
Is ELU smooth at zero for every alpha?
No. Its one-sided first derivatives are alpha and 1, so they match only at alpha = 1. Even then the second derivative is discontinuous at zero.
Does Swish always learn beta?
No. Generalized Swish may use a fixed or learned beta. The common SiLU/Swish-1 curve fixes beta at 1; using that function does not automatically create a trainable beta.
Why does the original gradient table need clarification?
Its hidden-gradient labels include the activation derivative and therefore describe preactivation gradients. The revised worked example separately labels gradients with respect to hidden outputs and preactivations, and states the selected ReLU slope at zero.
Were models trained or benchmarked in this revision?
No. Scalar formulas, activation curves and a forward/backward example were computed. The two original images and all original values are retained for context; no training, framework compatibility or model-accuracy result is certified.
Primary sources and further study
- Keras activation API: implemented activation definitions, SELU guidance and parameter choices.
- Keras PReLU layer: the piecewise definition and learnable slopes.
- Clevert and colleagues, Fast and Accurate Deep Network Learning by Exponential Linear Units: the ELU definition and reported experiments.
- Klambauer and colleagues, Self-Normalizing Neural Networks: SELU’s assumptions and analysis.
- Hendrycks and Gimpel, Gaussian Error Linear Units: GELU and its exact/approximate forms.
- Ramachandran and colleagues, Searching for Activation Functions: Swish with fixed or learned beta.
- Misra, Mish: A Self Regularized Non-Monotonic Activation Function: its definition and reported task-specific results.
Expanded and checked 17 November 2026. Original historical wording, all three original tables, twelve TeX sources and two original illustrations remain above. Corrections and newly computed examples are labelled separately. Statistical or optimization claims in the historical text are not certified by preserving them.
