From One Neuron to a Network
The Limitation of a Single Perceptron
In Section 6.1 we built a single perceptron - a small machine that draws one straight line through the data. That's enough to decide "tension or compression?", but the world rarely cooperates with a single line. Real engineering relationships - soil settlement, traffic congestion, concrete creep - are non-linear and multi-modal.
The fix is brilliantly simple: stack neurons in layers, and feed the output of one layer as the input to the next. The result is the Multi-Layer Perceptron (MLP) - the workhorse of modern deep learning.
Anatomy of an MLP
Every MLP has three kinds of layers:
- Input layer - one neuron per feature. No computation; just holds the raw inputs (e.g. beam length, load, modulus).
- Hidden layer(s) - the "brain". Each neuron takes a weighted sum of all previous-layer outputs and applies a non-linear activation. You can have one or many.
- Output layer - produces the final prediction. One neuron for regression (e.g. predicted deflection in mm), several for classification (e.g. failure mode probabilities).
CE Analogy — The Neural Network as a Truss
Picture a steel truss. Load (signal) enters at the supports (input layer), propagates through interconnected members (hidden layers), and exits as reactions and forces at the far end (output layer). Each joint redistributes the load according to the stiffness of its members — exactly like how each neuron redistributes signal according to its weights.
A taller, deeper truss can carry more complex load patterns. Likewise, a deeper network can capture more complex input-output relationships.
3–4–3–2
has 3 input neurons, two hidden layers (4 then 3 neurons), and 2 output neurons.
We will use this notation throughout the chapter.
Why Depth Matters
Each Layer Learns a Higher Abstraction
The magic of deep networks is that each successive layer learns increasingly abstract features built from the previous layer's outputs.
Consider a network predicting whether a building plan is structurally sound:
- Layer 1 might detect basic patterns: "is the span very long?", "is the load very high?"
- Layer 2 combines those: "long span + heavy load" → "high bending moment risk"
- Layer 3 combines further: "high bending risk + low steel ratio" → "likely failure mode"
- Output: probability of safe / unsafe
You never tell the network this hierarchy — it discovers it on its own during training. That's the breakthrough.
Width vs Depth
For a fixed parameter budget, you can spend it two ways:
Wide & Shallow
Few layers, many neurons each (e.g. 10–200–1).
- Easier to train (fewer vanishing-gradient issues)
- Memorises well, generalises less
- Captures broad patterns but not deep hierarchies
Narrow & Deep
Many layers, fewer neurons each (e.g. 10–16–16–16–16–1).
- Captures hierarchical features beautifully
- Harder to train (needs careful initialisation)
- State-of-the-art for images, language, structural patterns
Modern practice (post-2015) overwhelmingly favours deep architectures, with techniques like residual connections and batch normalisation to keep training stable.
Forward Propagation, Step by Step
The Signal Flows Left to Right
Forward propagation (the "forward pass") is the process of pushing an input through the network to get a prediction. It happens in three steps per layer:
- Weighted sum — each neuron multiplies every incoming activation by its weight and adds them up.
- Add bias — a per-neuron offset, like the intercept in a linear regression.
- Apply activation — pass through a non-linear function (ReLU, sigmoid, tanh — see 6.3).
The output of one layer becomes the input of the next, until we reach the final output. No randomness, no learning — just deterministic arithmetic.
Matrix Notation
Writing it out neuron-by-neuron is exhausting. Linear algebra makes it elegant:
Where:
a(L)— the vector of activations at layer LW(L)— the weight matrix connecting layer L−1 to L. Its shape is(neurons in L) × (neurons in L−1)b(L)— the bias vector for layer Lσ— the activation function (applied element-wise)
To run the entire forward pass, you simply repeat this equation for each layer. That's it. The whole network — potentially billions of parameters — is just a chain of matrix multiplications interleaved with non-linearities.
Why Matrices? Parallelism.
Computing 128 weighted sums one-at-a-time in a Python loop is slow. Computing them as a single matrix-vector product is massively parallel on a GPU — thousands of multiplications happen in the same clock cycle.
This is why frameworks like PyTorch and TensorFlow store everything as tensors: the math is identical to what we wrote above, but the hardware executes it at terabytes-per-second.
def forward(x, weights, biases, activation):
a = x
for W, b in zip(weights, biases):
a = activation(W @ a + b)
return a
CE Analogy — Hydraulic Network
Forward propagation is like water flowing through a pipe network. At each junction (neuron), the inflows are summed (weighted by pipe diameter), a small head loss (bias) is added, and a valve (activation) decides how much flows onward. The final reservoir level is the network's prediction.
Demo 1 — Forward Propagation Visualizer
Watch a signal travel through a 3–4–3–2 network.
Click Inject Signal to release activations from the input layer
and see them light up neurons sequentially. Hover over any neuron to inspect its
weighted sum and final activation. The right panel shows the matrix multiplication
unfolding.
3–4–3–2 Network
Demo 2 — Network Architecture Builder
Drag the sliders to add hidden layers and change neuron counts. The canvas redraws instantly. Watch how the parameter count (weights + biases) explodes as you go wider or deeper — this is why training cost grows so fast.
Build Your MLP
The Universal Approximation Theorem
The Big Promise
In 1989, Cybenko (and later Hornik) proved an astonishing result, informally:
A feed-forward network with a single hidden layer of sufficient width and a non-linear activation function can approximate any continuous function on a closed interval to arbitrary precision.
In other words: there is no continuous engineering relationship — beam deflection, soil consolidation curves, traffic flow — that an MLP cannot, in principle, represent.
The Fine Print
The theorem says "can", not "will easily". In practice:
- "Sufficient width" can mean enormously wide. Often impractical.
- The theorem says nothing about how to find the right weights.
- Going deep instead of wide tends to be exponentially more efficient.
- Generalisation (performing well on unseen data) is a separate, harder problem.
Still, the theorem is the philosophical foundation: it tells us the architecture is not the bottleneck — training is.
CE Analogy — Universal Cross-Section
It's like saying: "Given enough steel, you can build a beam to span any distance." True — but the cost, deflection, and constructability eventually become absurd. Engineering is about finding the elegant solution, not the theoretically possible one. Same with neural networks.
CE Application — Predicting Beam Deflection
The Problem
You want to predict the maximum deflection δ of a simply
supported beam given:
- span
L(m) - uniform load
w(kN/m) - moment of inertia
I(m4) - Young's modulus
E(GPa)
For a simple case, you'd use δ = 5wL4 / (384EI).
But for tapered sections, partial loads, end restraints, and composite
materials — closed-form solutions vanish quickly. Enter the MLP.
The Architecture
A reasonable starting design:
- Input layer (4 neurons):
L, w, I, E(normalised) - Hidden layer 1 (16 neurons, ReLU): learns combinations like
wL,wL4,EI - Hidden layer 2 (8 neurons, ReLU): learns ratios like
wL4/(EI) - Output layer (1 neuron, linear): predicted δ in mm
Train it on a synthetic dataset of 10 000 finite-element simulations. After training, you have a millisecond surrogate model for what would otherwise be a multi-second FEA call — perfect for design optimisation loops.
import torch.nn as nn
class BeamDeflectionMLP(nn.Module):
def __init__(self):
super().__init__()
self.net = nn.Sequential(
nn.Linear(4, 16), nn.ReLU(),
nn.Linear(16, 8), nn.ReLU(),
nn.Linear(8, 1),
)
def forward(self, x):
return self.net(x) # one matrix multiply per layer
Civil Engineering Application
Concrete Strength Prediction
An MLP with inputs [cement, water, fly ash, coarse aggregate, fine aggregate, superplasticizer, age] can predict 28-day f'c within ±3 MPa. Each hidden layer captures interactions the individual inputs can't — like how w/c ratio and fly ash percentage combine nonlinearly.
Sensor Fusion for SHM
Bridge structural health monitoring systems fuse data from accelerometers, strain gauges, and temperature sensors. The forward pass through an MLP combines these heterogeneous signals into a single damage index — something no single sensor type can provide alone.
Check Your Understanding
Q1. In the equation a(L) = σ(W(L) a(L-1) + b(L)), what is W(L)?
Q2. Why do we use matrix notation in forward propagation?
Q3. The Universal Approximation Theorem says, informally:
Q4. What primarily distinguishes deep narrow networks from wide shallow ones?
Add hidden layers and watch the decision boundary bend
Slide hidden units and hidden layers on a moons / circles / XOR / spiral dataset and see exactly when an MLP gains the capacity to separate them.