Feedforward Neural Networks — Layers, Notation and Parameters
5 min read
On this page 7 headingsBUILD INTUITION WITH NUMBERS
Track shapes through one layer
Input has two features. This layer has two sigmoid neurons. We use column vectors.
Check the dimensions before multiplying.
xWb=[12]=[1002]=[−11]
Multiply and add the bias. A 2×2 matrix times a 2×1 vector gives a 2×1 vector.
a=Wx+b=[14]+[−11]=[05]
Apply sigmoid separately to each entry.
h=[σ(0)σ(5)]≈[0.50.9933]
What changed? Each row of W belongs to one neuron. The activation keeps the same vector shape as the pre-activation.
Quick check: If this layer had three neurons and two input features, what shape would W have?
3×2: three rows for neurons, two columns for input features.
Swipe long formulas, tables or code sideways to see the rest.
Start here A feedforward neural network is just many
sigmoid-type neurons arranged in layers, where information flows
one way: from the input, through hidden layers, to the output. This page fixes the notation (ai,hi,Wi,bi) that the whole of backpropagation uses — learn it well and the rest becomes much easier.
Information flows upward: x → h₁ → h₂ → ŷ. Each layer has its own
weights W and biases b.
Input: an n-dimensional vector x=(x1,…,xn). Call it layer 0(h0=x).
Hidden layers:L−1 of them (2 in the picture), each with n neurons.
Output layer:k neurons (for
example, one per class). Call it layer L (here L=3).
Between layer i−1 and layer i: a weight matrix Wi
and a bias vector bi.
Parameter
Shape
Between
Wi(0<i<L)
n×n
layer i−1 and hidden layer i
bi(0<i<L)
n
WL
k×n
last hidden layer and output
bL
k
(One later slide writes ∇WL∈Rn×k; the correct shape, matching WL, is k×n.)
Everyday example A factory line: raw material
(input) passes through station 1, station 2 (hidden layers), and comes
out as the finished product (output). Nothing goes backwards while
making the product.
a is the “raw score”; h is what the neuron passes on after squashing
it.
Pre-activation (the weighted sum):
ai=bi+Wihi−1
Activation (apply the activation function g):
hi=g(ai)g= logistic (sigmoid), tanh, linear, …
Output layer uses an output activation
function O:
y^=f(x)=hL=O(aL)O=softmax, linear, …
ai and hi are vectors (one number per neuron in the layer). We write ai instead of ai(x) to keep things short.
Lecture example — sizes with numbers Say x has n=3 values, each hidden layer has 3 neurons, and there are k=2 outputs. W1:3×3,b1:3→a1=b1+W1x is a 3-vector, h1=g(a1) is a 3-vector. W2:3×3,b2:3→a2,h2 are 3-vectors. W3:2×3,b3:2→a3 is a 2-vector, y^=O(a3) is a 2-vector. Total parameters =(9+3)+(9+3)+(6+2)=32.
t ← 0; max_iterations ← 1000
initialise θ₀ = [W₁, …, W_L, b₁, …, b_L]
while t++ < max_iterations:
θ_{t+1} ← θ_t − η ∇θ_t
Except now ∇θ is huge: it contains ∂L/∂(every single weight and bias) — ∂L/∂W111,∂L/∂W112,…,∂L/∂WL,nk,∂L/∂b11,…. It is made of:
∇W1,…,∇WL−1∈Rn×n,∇WL∈Rk×n
∇b1,…,∇bL−1∈Rn,∇bL∈Rk
So we must answer two questions:
How do we choose the loss function L(θ)? → next
page.
How do we compute ∇θ efficiently? → backpropagation
(pages 3 and 4).
In one line: A feedforward network computes ai=bi+Wihi−1 and hi=g(ai) layer by layer, ending with y^=O(aL); its parameters are all the Wi and bi, learned by gradient descent.
Exam words: feedforward neural network, input layer (layer 0), hidden layer, output layer (layer L), pre-activation ai, activation hi, activation function g, output function O, weight matrix Wi, bias bi,θ.