Neural Networks

Neural networks are parameterized function approximators composed of alternating linear transformations and element-wise nonlinearities. This article develops the feedforward architecture from the single-neuron perceptron through deep multilayer networks, with emphasis on the representational consequences of depth and activation choice.


The Perceptron

The perceptron computes a linear function of the input followed by a threshold:

y=σ(wx+b)y = \sigma(\mathbf{w}^\top \mathbf{x} + b)

where σ\sigma is a step function: σ(z)=I[z>0]\sigma(z) = \mathbb{I}[z > 0]. The weight vector wRD\mathbf{w} \in \mathbb{R}^D and bias bRb \in \mathbb{R} define a hyperplane in input space. The perceptron classifies inputs by which side of this hyperplane they fall on.

Geometric interpretation. The decision boundary {x:wx+b=0}\{\mathbf{x} : \mathbf{w}^\top \mathbf{x} + b = 0\} is a (D1)(D-1)-dimensional hyperplane with normal vector w\mathbf{w}. The bias bb controls the offset from the origin. The perceptron can represent any linearly separable function, and only linearly separable functions.

The XOR problem. The function XOR(x1,x2)=x1x2\text{XOR}(x_1, x_2) = x_1 \oplus x_2 is not linearly separable: no single hyperplane in R2\mathbb{R}^2 can separate the positive examples {(0,1),(1,0)}\{(0,1), (1,0)\} from the negative examples {(0,0),(1,1)}\{(0,0), (1,1)\}. Minsky and Papert (1969) formalized this limitation, demonstrating that single-layer perceptrons cannot compute parity functions. This motivated the development of multilayer architectures.


Multilayer Perceptrons

A multilayer perceptron (MLP) composes multiple layers of linear transformations with nonlinear activations. For a network with LL hidden layers:

h(0)=x\mathbf{h}^{(0)} = \mathbf{x} z(l)=W(l)h(l1)+b(l),l=1,,L\mathbf{z}^{(l)} = \mathbf{W}^{(l)} \mathbf{h}^{(l-1)} + \mathbf{b}^{(l)}, \quad l = 1, \ldots, L h(l)=ϕ(z(l)),l=1,,L\mathbf{h}^{(l)} = \phi(\mathbf{z}^{(l)}), \quad l = 1, \ldots, L y^=W(L+1)h(L)+b(L+1)\hat{y} = \mathbf{W}^{(L+1)} \mathbf{h}^{(L)} + \mathbf{b}^{(L+1)}

where W(l)Rdl×dl1\mathbf{W}^{(l)} \in \mathbb{R}^{d_l \times d_{l-1}} are weight matrices, b(l)Rdl\mathbf{b}^{(l)} \in \mathbb{R}^{d_l} are bias vectors, and ϕ\phi is a nonlinear activation function applied element-wise. The pre-activation values z(l)\mathbf{z}^{(l)} and post-activation values h(l)\mathbf{h}^{(l)} are cached during the forward pass for use in backpropagation.

Why nonlinearity is essential. Without activation functions, a composition of linear maps is itself linear: W(2)(W(1)x+b(1))+b(2)=Wx+b\mathbf{W}^{(2)}(\mathbf{W}^{(1)}\mathbf{x} + \mathbf{b}^{(1)}) + \mathbf{b}^{(2)} = \mathbf{W}'\mathbf{x} + \mathbf{b}'. The network collapses to a single linear transformation regardless of depth. Nonlinear activations break this degeneracy and enable the network to represent nonlinear decision boundaries.


Activation Functions

The choice of activation function has significant consequences for optimization dynamics, gradient flow, and representational capacity.

Sigmoid

σ(z)=11+ez,σ(z)=σ(z)(1σ(z))\sigma(z) = \frac{1}{1 + e^{-z}}, \quad \sigma'(z) = \sigma(z)(1 - \sigma(z))

The sigmoid squashes inputs to (0,1)(0, 1). Its derivative has maximum value 1/41/4 at z=0z = 0 and decays exponentially for z0|z| \gg 0. This causes the vanishing gradient problem: in deep networks, gradients flowing through many sigmoid layers shrink exponentially, making early layers nearly untrainable. Additionally, sigmoid outputs are not zero-centered, which introduces systematic bias in gradient updates for downstream weights.

Tanh

tanh(z)=ezezez+ez,tanh(z)=1tanh2(z)\tanh(z) = \frac{e^z - e^{-z}}{e^z + e^{-z}}, \quad \tanh'(z) = 1 - \tanh^2(z)

Tanh maps to (1,1)(-1, 1) and is zero-centered, resolving the bias issue. However, it still saturates for large z|z|, producing vanishing gradients in deep networks. Related to sigmoid by tanh(z)=2σ(2z)1\tanh(z) = 2\sigma(2z) - 1.

ReLU

ReLU(z)=max(0,z),ReLU(z)=I[z>0]\text{ReLU}(z) = \max(0, z), \quad \text{ReLU}'(z) = \mathbb{I}[z > 0]

The Rectified Linear Unit is the default activation in modern deep learning. Its gradient is exactly 1 for positive inputs, eliminating vanishing gradients in the active regime. Computation is a single comparison, making it significantly faster than exponential-based activations.

Dying ReLU problem. If a neuron’s pre-activation is negative for all training examples (e.g., due to a large negative bias update), its gradient is permanently zero and the neuron stops learning. This can affect a significant fraction of neurons in wide networks with aggressive learning rates.

Variants

Leaky ReLU: f(z)=max(αz,z)f(z) = \max(\alpha z, z) with small α>0\alpha > 0 (typically 0.01). Provides a non-zero gradient for negative inputs, preventing dead neurons.

GELU (Gaussian Error Linear Unit): f(z)=zΦ(z)f(z) = z \cdot \Phi(z) where Φ\Phi is the standard Gaussian CDF. Used in BERT, GPT, and most modern transformer architectures. GELU smoothly gates the input by its own magnitude, combining the benefits of ReLU (sparse activation) with a smooth, non-zero gradient everywhere. Approximated as 0.5z(1+tanh[2/π(z+0.044715z3)])0.5z(1 + \tanh[\sqrt{2/\pi}(z + 0.044715z^3)]).

SiLU / Swish: f(z)=zσ(z)f(z) = z \cdot \sigma(z). Discovered through automated activation function search (Ramachandran et al., 2017). Closely related to GELU, used in EfficientNet and many vision architectures.


Forward Propagation

The forward pass computes the network’s output for a given input by sequentially applying each layer’s transformation. For a two-hidden-layer network with ReLU activations and a regression output:

h(1)=ReLU(W(1)x+b(1))\mathbf{h}^{(1)} = \text{ReLU}(\mathbf{W}^{(1)} \mathbf{x} + \mathbf{b}^{(1)}) h(2)=ReLU(W(2)h(1)+b(2))\mathbf{h}^{(2)} = \text{ReLU}(\mathbf{W}^{(2)} \mathbf{h}^{(1)} + \mathbf{b}^{(2)}) y^=w(3)h(2)+b(3)\hat{y} = \mathbf{w}^{(3)\top} \mathbf{h}^{(2)} + b^{(3)}

The intermediate representations h(1),h(2)\mathbf{h}^{(1)}, \mathbf{h}^{(2)} are learned features. Unlike hand-crafted feature engineering, the network discovers useful representations automatically through gradient-based optimization. Each hidden layer computes a progressively more abstract representation of the input.

Parameter count. For a network with layer widths [d0,d1,,dL+1][d_0, d_1, \ldots, d_{L+1}], the total parameter count is l=1L+1(dl1dl+dl)\sum_{l=1}^{L+1}(d_{l-1} \cdot d_l + d_l). A network with input dimension 784, two hidden layers of 256 and 128 units, and 10 output classes has 784256+256+256128+128+12810+10=235,146784 \cdot 256 + 256 + 256 \cdot 128 + 128 + 128 \cdot 10 + 10 = 235,146 parameters.


Output Layers and Loss Functions

The output layer and loss function are chosen jointly based on the prediction task.

Regression

Output: linear (no activation). Loss: mean squared error.

L=1Ni=1N(y^(i)y(i))2\mathcal{L} = \frac{1}{N}\sum_{i=1}^N (\hat{y}^{(i)} - y^{(i)})^2

For heteroscedastic targets or zero-inflated distributions, alternative losses such as Tweedie, Huber, or quantile regression losses may be more appropriate. The tracker cost estimation model uses Tweedie loss for exactly this reason: the zero-inflated transfer size distribution renders MSE suboptimal.

Binary Classification

Output: sigmoid activation producing p^=σ(wh(L))\hat{p} = \sigma(\mathbf{w}^\top \mathbf{h}^{(L)}). Loss: binary cross-entropy.

L=1Ni=1N[y(i)logp^(i)+(1y(i))log(1p^(i))]\mathcal{L} = -\frac{1}{N}\sum_{i=1}^N \left[y^{(i)} \log \hat{p}^{(i)} + (1 - y^{(i)}) \log(1 - \hat{p}^{(i)})\right]

Cross-entropy is the negative log-likelihood under a Bernoulli model, making it the maximum likelihood objective for binary classification. It produces stronger gradients than MSE when the prediction is confident but wrong.

Multi-class Classification

Output: softmax activation producing a probability distribution over KK classes.

p^k=softmax(z)k=ezkj=1Kezj\hat{p}_k = \text{softmax}(\mathbf{z})_k = \frac{e^{z_k}}{\sum_{j=1}^K e^{z_j}}

Loss: categorical cross-entropy (negative log-likelihood of the multinomial).

L=1Ni=1Nk=1Kyk(i)logp^k(i)\mathcal{L} = -\frac{1}{N}\sum_{i=1}^N \sum_{k=1}^K y_k^{(i)} \log \hat{p}_k^{(i)}

The softmax function is invariant to additive constants (softmax(z)=softmax(z+c)\text{softmax}(\mathbf{z}) = \text{softmax}(\mathbf{z} + c)), so the logits z\mathbf{z} encode relative, not absolute, class scores. In practice, the maximum logit is subtracted for numerical stability before exponentiation.


The Universal Approximation Theorem

Theorem (Cybenko, 1989; Hornik, 1991). A feedforward network with a single hidden layer of finite width and a non-polynomial activation function can approximate any continuous function on a compact subset of RD\mathbb{R}^D to arbitrary precision.

Formally: for any continuous f:[0,1]DRf: [0,1]^D \to \mathbb{R}, any ε>0\varepsilon > 0, and any non-polynomial continuous activation ϕ\phi, there exist nNn \in \mathbb{N}, WRn×D\mathbf{W} \in \mathbb{R}^{n \times D}, vRn\mathbf{v} \in \mathbb{R}^n, bRn\mathbf{b} \in \mathbb{R}^n such that:

supx[0,1]Df(x)j=1nvjϕ(wjx+bj)<ε\sup_{\mathbf{x} \in [0,1]^D} \left| f(\mathbf{x}) - \sum_{j=1}^n v_j \phi(\mathbf{w}_j^\top \mathbf{x} + b_j) \right| < \varepsilon

What this means. Neural networks have sufficient representational capacity to approximate any reasonable target function. The theorem is existential: it guarantees the existence of suitable weights but says nothing about whether gradient descent can find them, or how many neurons are required. In practice, the required width for a single hidden layer may be exponentially large in the input dimension.

What this does not mean. The theorem does not guarantee:

  • That the required width is tractable
  • That gradient-based optimization will converge to the approximating solution
  • That the learned function will generalize to unseen data
  • Anything about the sample complexity of learning

The gap between approximation theory (what networks can represent) and learning theory (what networks will learn from finite data) is a central theme in deep learning theory.


Depth vs. Width

The universal approximation theorem shows that a single hidden layer suffices in principle, but deeper networks achieve the same approximation with exponentially fewer parameters in many cases.

Depth efficiency. Telgarsky (2016) proved that there exist functions computable by networks of depth kk that require exponential width to approximate with depth k1k-1. Intuitively, depth enables hierarchical composition: a deep network can build complex features by composing simple ones, while a shallow network must represent the same complexity in a single layer.

Practical implications. Modern architectures are deep (tens to hundreds of layers) rather than wide. ResNets, transformers, and most production models achieve their performance through depth. The key enablers of training deep networks are residual connections (He et al., 2016), batch/layer normalization, and careful initialization schemes. These are covered in the backpropagation article.


Expressiveness of ReLU Networks

ReLU networks compute piecewise linear functions. Each neuron partitions the input space with a hyperplane (where wx+b=0\mathbf{w}^\top \mathbf{x} + b = 0), and the network output is a different linear function in each region of the resulting partition.

A single hidden layer with nn ReLU neurons can produce at most (nD)\binom{n}{D} linear regions in RD\mathbb{R}^D (though this bound is rarely tight). A deep ReLU network with LL layers of width nn can produce up to O((n/D)(L1)DnD)O((n/D)^{(L-1)D} \cdot n^D) linear regions, growing exponentially in depth. This is the formal basis for depth efficiency: deeper networks can carve the input space into exponentially more decision regions.


Summary

ConceptKey Idea
PerceptronSingle linear classifier, limited to linearly separable functions
MLPComposition of linear layers + nonlinearities, can approximate any continuous function
Activation functionsEnable nonlinearity; ReLU is default, GELU for transformers
Universal approximationWidth suffices in theory; depth is more efficient in practice
Forward passSequential layer-by-layer computation; intermediate activations are learned features
Output/loss pairingSigmoid + BCE for binary, softmax + cross-entropy for multi-class, linear + MSE for regression

The forward pass computes predictions; the next article covers backpropagation, which computes the gradients needed to train these networks via gradient descent.