Recommended resources
The freely available resources this lesson will direct you to.
Introduction
In our previous lesson, we established the foundational concept of the perceptron. We explored its function as a linear classifier and proved its convergence for linearly separable data. However, we concluded by identifying its critical limitation: the inability to solve non-linearly separable problems, epitomized by the XOR gate. This limitation historically stalled progress in neural network research.
This lesson directly addresses that fundamental weakness. We will explore the solution that unlocked the potential of neural networks: the introduction of non-linear activation functions. You will learn why stacking linear functions is futile and how non-linearity is the essential ingredient that allows networks of neurons to approximate arbitrarily complex patterns. We will survey the most significant activation functions—Sigmoid, Tanh, and ReLU—analyzing their mathematical properties, their historical context, and the practical trade-offs, such as the infamous vanishing gradient problem, that guide their use in modern deep learning.
The Necessity of Non-Linearity
In the last lesson, the perceptron used a simple step function. You might wonder: what if we simply stack layers of these linear units to gain more power? Let's investigate why this approach is fundamentally flawed.
A single neuron without an activation function, or with a simple linear activation , computes a linear transformation of its input: . If we feed the output of this neuron, , into a second linear neuron, the final output would be:
Expanding this expression gives:
If we define and , the equation simplifies to . This is just another linear transformation. No matter how many layers you stack, a network of purely linear units is mathematically equivalent to a single linear layer. It can only learn linear functions and is no more powerful than the simple perceptron we've already studied.
The following videos provide a concise mathematical and visual demonstration of this crucial concept.
Why Non-linear Activation Functions (C1W3L07)
First, watch this explanation by Andrew Ng from the DeepLearning.AI course. He provides a clear, step-by-step derivation showing how a multi-layer linear network collapses into a single linear function.
Watch from the beginning to the end of the main argument. Pay close attention to the algebraic substitution that proves the point. He also notes an important exception we'll revisit: using a linear activation in the output layer for regression tasks.
Activation Functions - EXPLAINED!
Next, this video from CodeEmporium offers a more visual take. It starts by showing a linear model failing on a non-linear dataset and then provides a complementary mathematical breakdown.
First, watch the introductory segment demonstrating the problem and solution. Then, jump to the section "Case 1", which walks through the math of why a network with no activation function reduces to logistic regression, a linear model.
By introducing a non-linear function after each linear transformation, we break this chain of linearity. The output of a layer becomes . When this is fed into the next layer, the composition is no longer a simple linear function. It is this non-linearity, applied layer after layer, that allows neural networks to construct highly complex, non-linear decision boundaries.
The theoretical underpinning for this is the Universal Approximation Theorem, which states that a feedforward network with a single hidden layer containing a finite number of neurons can approximate any continuous function on compact subsets of , under mild assumptions on the activation function. Non-linearity is the key that makes this possible.

A Tour of Activation Functions
Now that we've established the why, let's explore the what. Numerous activation functions have been proposed, each with distinct characteristics and trade-offs.

The "S"-Shaped Classics: Sigmoid and Tanh
Historically, the most popular activation functions were smooth, "S"-shaped (sigmoidal) functions. They were seen as a natural choice because their output can be interpreted as a neuron's "firing rate," smoothly transitioning from 0 (not firing) to 1 (firing at maximum rate).
[PDF] Review and Comparison of Commonly Used Activation Functions for ...
This research paper provides a detailed survey of various activation functions. We'll start with the "S"-shaped family.
In the section "S"-shaped Activation Functions, read the subsections on the Sigmoid Function and the Hyperbolic Tangent Activation Function. Focus on their mathematical forms, their output ranges (0 to 1 for Sigmoid, -1 to 1 for Tanh), and their respective pros and cons. Pay special attention to the two major problems introduced: the vanishing gradient problem and the non-zero centrality issue of the sigmoid.
As the paper discusses, both Sigmoid and Tanh have a critical flaw: their gradients become extremely small in the saturated regions (where the input is large positive or large negative). The derivative of the sigmoid function, , has a maximum value of only 0.25 at and approaches zero as .
During backpropagation (which we will detail in a future lesson), the gradient of the loss is multiplied by the gradient of the activation function at each layer. If these gradients are consistently small numbers (less than 1), their product across many layers will shrink exponentially, "vanishing" to near zero. This means the neurons in the early layers of a deep network receive almost no update signal, and learning grinds to a halt.
Activation Functions - EXPLAINED!
This video provides an excellent visual intuition for the vanishing gradient problem.
Watch the segment from the initial explanation and then the more detailed breakdown in "Case 3" from the cause of the problem. The key idea is the "squeezing" nature of the function, which causes gradients to diminish as they propagate backward.
The Modern Workhorse: Rectified Linear Unit (ReLU)
The vanishing gradient problem severely limited the depth of networks that could be effectively trained. The solution came from a surprisingly simple function: the Rectified Linear Unit, or ReLU.
ReLU is defined as:
Its derivative is also simple: 1 for and 0 for .
This function has several key advantages:
- Combats Vanishing Gradients: For positive inputs, the gradient is a constant 1. This means gradients can pass backward through active neurons without shrinking, allowing for much deeper networks to be trained effectively.
- Computational Efficiency: Both the function and its derivative are trivial to compute, unlike the exponentials in Sigmoid and Tanh.
- Sparsity: For any given input, many ReLU neurons will have a negative pre-activation value and thus an output of 0. This "sparsity" in activations can make the network more efficient and has been argued to be beneficial for learning disentangled representations.
However, ReLU is not without its own problems.
[PDF] Review and Comparison of Commonly Used Activation Functions for ...
Let's return to the review paper to analyze ReLU and its own specific failure mode.
Read the section titled "Rectified Linear Unit Activation Functions". Start with the Basic Rectified Linear Unit (ReLU) and understand its advantages. Then, carefully read the subsection on the Dying ReLU Problem. The paper provides a clear explanation and then a concrete example using the XOR gate to show how a neuron can become permanently inactive.
The "dying ReLU" problem occurs when a neuron's weights are updated in such a way that its pre-activation value becomes consistently negative for all data points in the training set. Since the gradient is 0 for negative inputs, the neuron's weights will never be updated again. It becomes "dead," contributing nothing to the network's output.
To address this, several variants have been proposed:
- Leaky ReLU: , where is a small constant like 0.01. This introduces a small, non-zero gradient for negative inputs, preventing neurons from dying completely.
- Parametric ReLU (PReLU): The slope is treated as a learnable parameter for each neuron.
- Exponential Linear Unit (ELU): Uses a curved function for negative values, which can help push mean activations closer to zero, similar to Tanh.
These variants ensure that there is always some gradient flow, making the network more robust.
Practical Considerations and Recommendations
The choice of activation function is a key element of neural network design. The transition from Sigmoid/Tanh to ReLU and its variants was a major catalyst for the deep learning revolution.
The review paper you've been reading concludes with a practical comparison and a set of useful heuristics.
[PDF] Review and Comparison of Commonly Used Activation Functions for ...
Let's conclude with the practical summary from the paper, which compares performance and offers guidelines.
Read the final two sections, "Comparisons and Results Analysis" and "Conclusions". The experimental results in Figure 12 and 13 show ReLU and Leaky ReLU outperforming the others in both accuracy and training time on a sample task. The final summary table provides an excellent set of rules-of-thumb for when to use each function.
The general consensus in modern practice is:
- Start with ReLU as your default choice for hidden layers. It is fast and generally works very well.
- If you observe a large number of "dead" neurons in your network, switch to Leaky ReLU or another variant like ELU.
- Sigmoid is still commonly used in the output layer for binary classification problems, as its (0, 1) range is perfect for representing a probability.
- Tanh can sometimes be effective in recurrent neural networks (RNNs) due to its zero-centered nature, but has largely been superseded by more advanced architectures.
Conclusion
In this lesson, we have uncovered the critical role of non-linearity in empowering neural networks. We have seen how it breaks the limitations of linear models, enabling the approximation of complex, real-world functions.
Here are the key takeaways from our exploration:
- Non-Linearity is Essential: A neural network with purely linear activation functions is no more powerful than a single linear model, regardless of its depth. Non-linearity is the key to learning complex patterns.
- Sigmoid and Tanh: These "S"-shaped functions were historical mainstays but suffer from the vanishing gradient problem, which limits their effectiveness in deep networks.
- ReLU: The modern default activation for hidden layers. It is computationally efficient and solves the vanishing gradient issue for positive inputs but can suffer from the "dying ReLU" problem.
- ReLU Variants: Leaky ReLU and other variants provide a small, non-zero gradient for negative inputs, making them more robust against dying neurons.
- A Practical Choice: The selection of an activation function is a design trade-off. ReLU is a strong starting point, with its variants offering a solution to its primary weakness.
We have now defined a neuron model—a linear transformation followed by a non-linear activation—that can serve as a powerful building block. In the next lesson, we will assemble these blocks to construct a full feedforward neural network and define its forward propagation mechanism mathematically, laying the groundwork for understanding how these models make predictions.