From the perceptron to neural networks

One artificial neuron is a simple formula. Connect many, stack them in layers, and you get the most flexible function-approximators ever built. This chapter builds a neural network piece by piece — and tells the story of how it was invented.

⏱ 40 minNeeds: Chapters 1, 2, 48 interactive simulations
In plain words

A neuron takes some numbers, multiplies each by a weight (how important it is), adds them up with a bias (a threshold), and passes the result through a simple function — the activation. That is all. A perceptron is one such neuron that answers yes/no. A neural network is many neurons arranged in layers, where the outputs of one layer are the inputs of the next. "Deep" simply means many layers.

How do the weights change?

This chapter builds networks. How they learn — the slope, the minus sign, the update — is explained from scratch with an apple price in Chapter 10, and the backward pass in Chapter 14.

You will learn
Level 1 · basicA neuron; the perceptron; history Level 2 · standardInside a network; layers; activation functions Level 3 · advancedWhy depth helps
Simplest example first · a neuron that decides "pass" or "fail"

A student passes if their marks $x$ are at least 40. One neuron does this: weight $w = 1$, bias $b = -40$, step activation. It computes $z = 1\cdot x - 40$ and outputs $1$ ("pass") if $z \ge 0$, else $0$. With two inputs — say admission needs Maths + Physics $\ge 100$ — use $w_1 = w_2 = 1$, $b = -100$: the neuron now draws a line $x_1 + x_2 = 100$ in the plane and says "yes" on one side. The weights decide what matters; the bias sets the threshold. Every network in this chapter is built from neurons like this one.

1. A short history, in 20 milestones

Click a milestone. Dashed buttons are milestones of scientific machine learning.

To see where neural networks sit among artificial intelligence (AI), machine learning, deep learning, ChatGPT-style language models and scientific machine learning, explore the interactive map of AI in Chapter 9 or on the book home page.

The pattern to notice: the core ideas — weighted sums, learning rules, the chain rule — are old. What changed after 2006 was data, computing power (GPUs (Graphics Processing Units)), and engineering tricks that made deep networks trainable. SciML (from 2017) asks: what if the "data" is a differential equation?

2. Anatomy of an artificial neuron

The biological picture — dendrites collect signals, the cell body adds them, the axon fires if the total exceeds a threshold — inspired the model, but an artificial neuron is simply this formula:

Definition · Artificial neuron

For inputs $x_1, \dots, x_n$, weights $w_1, \dots, w_n$ and bias $b$: $$\underbrace{z = w_1x_1 + w_2x_2 + \dots + w_nx_n + b = \mathbf w\cdot\mathbf x + b}_{\text{weighted sum (pre-activation)}}, \qquad \underbrace{a = \sigma(z)}_{\text{activation (output)}}.$$ $\sigma$ is the activation function. The weights and bias are the neuron's parameters: they are learned from data.

McCulloch & Pitts, "A logical calculus of the ideas immanent in nervous activity", Bull. Math. Biophys. 5 (1943) 115–133; Goodfellow, Bengio & Courville, Deep Learning, MIT Press (2016), chapter 6.
A neuron, term by termchange inputs and weights; click a term below

3. The perceptron: the first learning machine

Animation: a separating line moves step by step as misclassified points are used to update the perceptron weights.
Watch: Rosenblatt's rule: pick a misclassified point (green ring) and nudge the line towards it. Repeat until no mistakes remain.

Frank Rosenblatt's perceptron (1958) is a single neuron with a step activation: it outputs 1 ("yes") if $z \ge 0$ and 0 ("no") otherwise. With two inputs, the set where $w_1x_1 + w_2x_2 + b = 0$ is a straight line — the decision boundary. The perceptron says "yes" on one side and "no" on the other. Its novelty was a rule to learn $\mathbf w$ and $b$ from examples.

Definition · Perceptron and its learning rule

Prediction: $\hat y = \operatorname{step}(\mathbf w\cdot\mathbf x + b) \in \{0, 1\}$. For each training example $(\mathbf x, y)$ in turn, update $$\mathbf w \leftarrow \mathbf w + \eta\,(y - \hat y)\,\mathbf x, \qquad b \leftarrow b + \eta\,(y - \hat y),$$ with learning rate $\eta > 0$. If the prediction is right, $y - \hat y = 0$ and nothing changes; if it is wrong, the boundary is pushed towards classifying that example correctly. One pass through all examples is an epoch.

Rosenblatt, "The perceptron: a probabilistic model for information storage and organization in the brain", Psychological Review 65(6) (1958) 386–408.
Theorem · Perceptron convergence (Novikoff)

Use labels $y_i \in \{-1, +1\}$ and suppose the data are linearly separable with margin: there is a unit vector $\mathbf u$ (bias absorbed as an extra input fixed to 1) with $y_i\,\mathbf u\cdot\mathbf x_i \ge \gamma > 0$ for all $i$, and $\|\mathbf x_i\| \le R$. Then the perceptron algorithm makes at most $(R/\gamma)^2$ mistakes, whatever the order of the examples — so it stops after finitely many updates with a separating line.

Novikoff, "On convergence proofs on perceptrons", Proc. Symposium on the Mathematical Theory of Automata 12 (1962) 615–622; Shalev-Shwartz & Ben-David, Understanding Machine Learning, Cambridge University Press (2014), chapter 9.
Watch a perceptron learnblue = class 1, orange = class 0; click the plot to add points
The ringed point is the example being examined. The shaded side is where the perceptron currently answers "class 1". On separable data, mistakes stop after a few epochs (Novikoff's theorem). On XOR they never stop: no straight line can separate the classes.

4. The XOR problem — and the idea of a hidden layer

XOR ("exclusive or") outputs 1 when exactly one input is 1: $(0,0)\mapsto0$, $(0,1)\mapsto1$, $(1,0)\mapsto1$, $(1,1)\mapsto0$. The two blue points sit on one diagonal, the orange on the other; no single line separates them. Minsky and Papert's book Perceptrons (MIT Press, 1969) made such limitations precise, and funding and interest in neural networks collapsed for over a decade — the first "AI winter".

The way out was already known: combine neurons. XOR = "OR, but not AND". One hidden neuron computes OR, another computes AND, and an output neuron combines them: $$h_1 = \operatorname{step}(x_1 + x_2 - 0.5)\ (\text{OR}),\quad h_2 = \operatorname{step}(x_1 + x_2 - 1.5)\ (\text{AND}),\quad y = \operatorname{step}(h_1 - h_2 - 0.5).$$ The hidden layer re-describes the input in new coordinates $(h_1, h_2)$ in which the problem is linearly separable. That is the essential idea of every neural network: layers learn useful representations.

XOR with one hidden layerpick an input and follow the signal
The plot shows the OR line (blue) and the AND line (violet); points between the two lines are XOR = 1. The diagram shows the network with the weights written on the connections (blue positive, orange negative); filled circles are neurons that fire.

5. From neurons to layers to networks

Put $m$ neurons side by side, all reading the same inputs, and you have a layer. Writing each neuron's weights as a row of a matrix $W$ (Chapter 4), the whole layer is one line: $$\mathbf a = \sigma(W\mathbf x + \mathbf b), \qquad W \in \mathbb R^{m\times n},\ \mathbf b \in \mathbb R^m,$$ with $\sigma$ applied to each entry. Stack layers — the output of one is the input of the next — and you have a multilayer perceptron (MLP), also called a fully connected feed-forward network:

Definition · Feed-forward neural network

With $\mathbf a^{(0)} = \mathbf x$, for $\ell = 1, \dots, L$: $$\mathbf z^{(\ell)} = W^{(\ell)}\mathbf a^{(\ell-1)} + \mathbf b^{(\ell)}, \qquad \mathbf a^{(\ell)} = \sigma\big(\mathbf z^{(\ell)}\big),$$ except that the last layer usually has no activation (regression) or a sigmoid (yes/no probability). Layers $1, \dots, L-1$ are hidden. The network is the composition $u_\theta = f^{(L)}\circ\dots\circ f^{(1)}$ with parameters $\theta = \{W^{(\ell)}, \mathbf b^{(\ell)}\}$.

Goodfellow, Bengio & Courville (2016), chapter 6; Higham & Higham, "Deep learning: an introduction for applied mathematicians", SIAM Review 61(4) (2019) 860–891.
Design a networkcount its parameters
Each line is one weight; each hidden or output neuron also has one bias. A PINN (Physics-Informed Neural Network) for $u(x,t)$ might use 2 inputs, 4 hidden layers of 50 neurons and 1 output: $150 + 3\times2550 + 51 = 7851$ parameters.

The forward pass, one neuron at a time

Evaluating a network — the forward pass — is nothing more than computing $z$ and $a$ for each neuron, layer by layer, left to right. Step through it:

Forward pass, step by stepa 2–3–2–1 network with fixed weights, tanh hidden layers

6. Inside a network: what each neuron does

A network with one hidden layer computes $u(x) = c + \sum_{i=1}^{N} a_i\,\sigma(w_i x + b_i)$. Read it slowly: each hidden neuron makes one S-shaped piece $a_i\sigma(w_ix+b_i)$ — the weight $w_i$ sets how steep it is, the bias $b_i$ where it switches, and the output weight $a_i$ how tall it is and which way up. The network's answer is simply the sum of the pieces. Training moves, stretches and flips the pieces until their sum matches the target.

Animation: six S-shaped pieces from six neurons are added one at a time; their sum approaches a wavy target curve.
Watch: a trained 6-neuron network taken apart. Switching on one neuron at a time, the sum of the S-shaped pieces (right) builds up the target.
Lab · inside the networkchange neurons, activation, target — then train
Thin coloured curves are the individual neurons' pieces (shifted to average zero so they are easy to see); the thick orange curve is their sum, the network output. The diagram shows, for the probe input, how strongly each neuron fires (blue positive, orange negative) and the weights (line thickness).
Experiments
  1. Neurons = 1. One piece can only make one S-shape: the network underfits.
  2. Neurons = 2, 3, 6. Each extra neuron adds one more bend. Count the bends in the target — you need roughly that many neurons.
  3. Activation = ReLU. Pieces become ramps, and the output becomes a broken line (piecewise linear). Its second derivative is zero almost everywhere — why ReLU is a poor choice for PINNs that need $u''$.
  4. Target = step or |x|. Smooth tanh pieces struggle with corners; you need steep pieces (large $w_i$) and patience.
  5. Target = fast wiggle. High frequencies are learned last — spectral bias. Try the sine activation.
Animation: networks with 1, 2, 3, 4, 6, 8, 12 and 20 neurons trained on the same target; the fit improves as neurons are added.
Watch: the same target fitted with more and more neurons. Each one is a little extra flexibility — this is universal approximation in action.

A one-hidden-layer tanh network has 10 hidden neurons and one input. How many S-shaped pieces does its output add up?

Right: one piece per hidden neuron. (31 is the number of parameters: 10 weights $w_i$, 10 biases $b_i$, 10 output weights $a_i$ and one output bias $c$.)

7. Why activation functions — and which?

Without activations, every layer is a matrix, and a product of matrices is just another matrix: $$W^{(2)}\big(W^{(1)}\mathbf x + \mathbf b^{(1)}\big) + \mathbf b^{(2)} = \underbrace{W^{(2)}W^{(1)}}_{W}\mathbf x + \underbrace{W^{(2)}\mathbf b^{(1)} + \mathbf b^{(2)}}_{\mathbf b}.$$ A hundred linear layers are no more powerful than one: they can only draw straight lines and flat planes. The nonlinearity $\sigma$ is what lets networks bend.

Activation functions and their derivativesthe derivative matters for training and for PINNs
σ(z)σ′(z)σ″(z)
ActivationFormulaGood forWatch out
step$1$ if $z\ge0$, else $0$the original perceptron; logicderivative is 0: cannot be trained by gradients
sigmoid$1/(1+e^{-z})$output probabilitiessaturates: $\sigma' \le 1/4$, gradients vanish in deep nets
tanh$\tanh z$PINNs and smooth regressionalso saturates for large $|z|$
ReLU (Rectified Linear Unit)$\max(0,z)$deep networks in vision and language$\sigma''= 0$: useless when the loss contains $u''$
softplus$\ln(1+e^z)$a smooth ReLUslower to compute
sine$\sin z$oscillatory signals (SIREN (Sinusoidal Representation Network))needs careful initialisation
Nair & Hinton, "Rectified linear units improve restricted Boltzmann machines", ICML 2010; Sitzmann et al., "Implicit neural representations with periodic activation functions", NeurIPS 2020.

8. Why go deep?

One hidden layer can already approximate any continuous function (Chapter 13) — so why use many? Because depth lets a network reuse computations. Composing a simple "tent" function with itself $k$ times creates $2^k$ linear pieces, using only two ReLU neurons per layer; a single hidden layer needs about $2^k$ neurons to do the same. Some functions are exponentially cheaper to represent with depth.

Result · Benefits of depth (informal)

For every $k$ there are functions computed by ReLU networks with $O(k^3)$ layers and $O(1)$ neurons per layer that cannot be approximated by networks with $O(k)$ layers unless they have $\Omega(2^k)$ neurons.

Telgarsky, "Benefits of depth in neural networks", Proc. COLT 2016, PMLR 49, 1517–1539.
Depth multiplies the number of piecest(x) = 2·ReLU(x) − 4·ReLU(x − ½) on [0, 1], composed k times

Depth brings its own difficulty: gradients are products of many factors (chain rule), which can shrink to zero or blow up — the vanishing and exploding gradient problem (Hochreiter 1991; Glorot & Bengio, AISTATS 2010). Three engineering ideas tamed it: ReLU activations, careful initialisation, and residual connections $\mathbf a^{(\ell+1)} = \mathbf a^{(\ell)} + f(\mathbf a^{(\ell)})$ (He, Zhang, Ren & Sun, CVPR 2016). A residual layer is one Euler step of an ODE (Ordinary Differential Equation) — Chapter 6 meets deep learning.

9. Every term, in one table

TermSymbolMeaning
input / feature$\mathbf x$the numbers fed in: coordinates $(x,t)$ in a PINN, pixels in an image
weight$w_{ij}$, $W$strength of the connection from neuron $j$ to neuron $i$; learned
bias$b_i$, $\mathbf b$shift of the threshold; lets a neuron fire even when inputs are 0; learned
pre-activation$z = \mathbf w\cdot\mathbf x + b$the weighted sum, before the activation
activation function$\sigma$the nonlinear function applied to $z$ (tanh, ReLU, …)
activation / output$a = \sigma(z)$what the neuron sends on
neuron (unit)one weighted sum + activation
layer$\sigma(W\mathbf a + \mathbf b)$neurons reading the same inputs; input, hidden and output layers
width / depthneurons per layer / number of layers
parameters$\theta$all weights and biases — what training changes
hyperparameterschoices made before training: width, depth, activation, learning rate, epochs
forward passcomputing the output from the input, layer by layer
prediction / target$\hat y$ / $y$what the network outputs / the correct answer
loss$L(\theta)$a number measuring how wrong the predictions are (Chapter 13)
gradient$\nabla_\theta L$direction in parameter space that increases the loss fastest
backpropagationthe chain rule, applied from output to input, to compute the gradient
learning rate$\eta$step size of each parameter update
epoch / batch / iterationone pass over all data / a subset used for one update / one update
training / validation / test setdata to fit / data to tune and stop / data kept for the final honest check
overfitting / underfittingmemorising noise / too simple to capture the pattern
generalisationperforming well on data not seen during training

A neuron has $\mathbf w = (2, -1)$, $b = 0.5$ and ReLU activation. What is its output for $\mathbf x = (1, 3)$?

Right: $z = 2\cdot1 - 1\cdot3 + 0.5 = -0.5$ and $\operatorname{ReLU}(-0.5) = 0$.

Why can a single perceptron not learn XOR?

Right. A hidden layer creates new features ($h_1$ = OR, $h_2$ = AND) in which a line does separate the classes.

How many parameters has a network with layer sizes 1 → 10 → 10 → 1?

Right: $(1\cdot10+10) + (10\cdot10+10) + (10\cdot1+1) = 20 + 110 + 11 = 141$.

Key takeaways

Further reading