Linearity requires additivity and scaling, but neural networks need nonlinearity to break free from simple affine transformations. While affine layers only stretch and rotate data without changing its topology, activation functions enable complex reshaping—allowing networks to untangle data manifolds and learn intricate patterns effectively.
Linear Combinations
The concept of linearity runs through mathematics, physics, engineering, and many other fields. Simply put, linearity describes two fundamental operational properties: additivity and homogeneity.
A relationship, function, or system is said to be linear if it satisfies the following two conditions simultaneously.
Consider a transformation or function acting on inputs and .
Additivity
The sum of parts equals the whole. That is, processing two inputs separately and then adding the results is the same as adding the inputs first and then processing the sum.
Example: Multiplication satisfies additivity.
- Left: , Right: , equal.
Counterexample: The square function does not satisfy additivity.
- Left: , Right: , not equal.
Homogeneity
Scaling the input scales the output by the same factor. That is, multiplying an input by a constant (scalar) yields the original output multiplied by the same constant.
Example: satisfies homogeneity.
- Left: , Right: , equal.
Counterexample: Adding a constant does not satisfy homogeneity.
- Left: , Right: , not equal.
In the definition above, satisfying both additivity and homogeneity is sufficient and necessary for linearity.
Many people mistakenly think that "linear" simply means "the graph is a straight line." This understanding is inaccurate.
Truly linear: A straight line that must pass through the origin. For example, . It satisfies both additivity and homogeneity. If the input is 0, the output must also be 0.
Strictly speaking, if a bias term is added, it becomes affine. It is a straight line, but not necessarily passing through the origin. For example, . It does not satisfy homogeneity (since ). Although it is often called a "linear function," in the strict definition it is not linear, but "linear + translation," also known as affine.
Now we can understand why it's called a "linear" combination. This combination allows only two types of "linear" operations:
- Scalar multiplication (corresponding to homogeneity): Stretching or compressing a vector by a factor .
- Addition (corresponding to additivity): Adding the processed vectors together.
Nonlinear operations like squaring, taking absolute values, or logarithms are not allowed. Therefore, expressions like or are not called linear combinations.
It can be said that "linear" is the simplest and most core relationship in mathematics and science because it allows us to decompose complex problems into a superposition of simple parts.
Affine
An affine function is defined as:
where is a matrix and is a constant vector. It is a linear function plus a bias.
If you take a weighted linear combination (coefficients can be scalars) of affine functions:
where each .
Expanding:
This is still an affine function. Thus, weighted combinations do not destroy affinity.
If you combine affine functions using nonlinear polynomial operations, such as squaring or higher powers:
Note: is element-wise squaring, is element-wise multiplication or dot product.
These operations introduce quadratic or higher-order terms and no longer maintain the form. Therefore, nonlinear polynomial combinations are generally not affine functions.
Affine Composition
This question is very important and key to understanding the nature of neural networks. Let's carefully analyze whether the composition of affine functions remains affine.
Suppose you have two affine functions:
Composition is:
Expanding to see the form:
The result is still an affine function.
Thus, the composition of affine functions remains affine. This can be generalized: composing any number of affine functions:
can always be written as:
This is also why: if each layer of a neural network is affine without activation functions, no matter how many layers are stacked, the network's expressive power is the same as a single layer. We can think of an affine layer as an operation of stretching, rotating, or translating, or a combination of these. Composing multiple affine transformations is equivalent to continuous stretching + rotation + translation → ultimately, a single overall stretching + rotation + translation. Therefore, composing affine transformations does not increase nonlinear degrees of freedom and cannot represent curves or complex functions.
Each layer of a neural network is an affine mapping:
- If is invertible (i.e., ), then is bijective and continuous.
- The inverse mapping is:
which is also affine and continuous → a homeomorphism. However, there is a core condition: must be invertible.
Composing multiple affine transformations is equivalent to composing multiple homeomorphisms. Suppose you have multiple consecutive invertible affine maps:
Each is a homeomorphism, and the composition of homeomorphisms remains a homeomorphism. Hence, the final mapping is also a homeomorphism.
Thus, we have the following conclusion: Let be the original manifold:
- An affine mapping that is continuous and bijective → the manifold structure is preserved (homeomorphic).
- Composing multiple such affine maps continuously → the resulting manifold is homeomorphic to .
In other words: "Continuous linear + bias transformations do not change the topology of the manifold; they only stretch/rotate/translate/shear it."
This is why using only linear layers cannot "bend" the data manifold: the data retains its "original shape" (topologically invariant) under nested linear layers. If a decision boundary needs to cut a complex manifold, nonlinearity (activation functions) must be introduced.
This is also the goal in deep learning. If the original manifold's structure is inseparable for a given task, but separability is required for a learning objective, then the original manifold and the target manifold must not be homeomorphic.
In the transformation from the original manifold to the target manifold, losing homeomorphism requires breaking away from linear, affine transformations. Because affine transformations (or more generally, homeomorphic transformations) alone are usually insufficient for disentangling classes. Deep networks often need to reconstruct the data manifold through non-homeomorphic nonlinear operations to make it ultimately linearly separable.
We need to consider how to make the composition of affine transformations nonlinear. This insight is the core of the geometric interpretation of neural networks:
Linear layers can only perform topology-preserving affine transformations; nonlinear layers allow topological changes, enabling neural networks to represent complex functions.
Activation for Affine Layers
Each layer of a neural network is an affine mapping:
where denotes the -th layer. The nested composition of affine mappings across layers is:
If no activation function is introduced, the result above is still an affine function.
Proof is simple:
which remains in the form .
By induction:
Therefore, network depth loses its meaning entirely.
To introduce nonlinearity, we can add activation functions to each layer:
where
Expanded, this is:
This is the standard form of a neural network.
With activation functions added:
cannot be simplified to
because generally:
The activation function breaks the closure property of affine mappings under composition. In other words, it breaks the two key characteristics of additivity and homogeneity. This is essentially the source of the nonlinear expressive power of neural networks.
From the manifold perspective discussed earlier, this can be further written as:
where: affine layers are responsible for stretching, rotating, translating, shearing; activation layers are responsible for folding, cropping, compressing, and restructuring the manifold.
If all are invertible, then the affine layers themselves are only homeomorphic transformations and do not change the topology of the manifold. What gradually makes the manifold separable is often precisely the nonlinear deformation introduced by activation functions.
Therefore, from a geometric perspective, a neural network can be understood as an alternating combination of affine transformations and nonlinear manifold operations acting on the data manifold. This perspective aligns with many interpretations of modern manifold learning and geometric deep learning.
Activations
There is no "single best" choice for an activation function. However, from the perspective of trainability and expressive power of neural networks, a good activation function generally should satisfy several core characteristics:
Nonlinearity
As discussed earlier, nonlinearity is needed to break the linear closure of stacked affine layers, allowing multi-layer networks to approximate arbitrary functions.
Mathematical requirement: It must not satisfy linear combination closure:
Examples: ReLU, Tanh, Sigmoid, GELU.
Linear functions are not suitable because the composition of multiple linear layers remains linear, which would degenerate back to affine composition and limit expressive power.
Differentiability
Because the core of neural networks relies on backpropagation to determine weights, the activation function must be differentiable over most of its domain to facilitate gradient calculation during backpropagation. For non-differentiable points (e.g., ReLU at 0), subgradients are typically used. Moreover, the derivative properties affect gradient flow: gradients that are too small can cause vanishing gradients (Sigmoid), while gradients that are too large can cause exploding gradients.
Continuity
Ensures that the network output changes continuously with the input; otherwise, training becomes unstable. Having few and controllable discontinuities is usually acceptable (e.g., ReLU has only one point of discontinuity, which has little practical impact).
Among the properties above, meeting the conditions is merely an "entry ticket," not a "guarantee of success."