Sources grouped here: in3050_lecture_07_ffnn_2025.pdf and 03-4-5.feedforward-nets.pdf.
A feedforward network maps inputs to outputs through weighted layers. Training chooses weights that minimise a loss: forward propagation computes predictions, backpropagation computes gradients efficiently, and an optimiser updates the parameters.
1. Feedforward neural network (FFNN)
A feedforward neural network is a directed acyclic network: information moves only from input toward output. It has no feedback/recurrent connections.
- Input layer: receives feature vector .
- Hidden layer(s): transform the representation.
- Output layer: produces the prediction .
- Weights and biases: trainable parameters on connections and units.
For layer :
Here . The activation function is applied elementwise in hidden layers.
Output layers by task
| Task | Output units | Typical output activation | Meaning |
|---|---|---|---|
| Regression | 1 or more | Identity | Predict real number(s). |
| Binary classification | 1 | Sigmoid | Predict . |
| Multi-label classification | One per label | Independent sigmoid | Several labels may simultaneously be true. |
| Multi-class classification | One per class | Softmax | Class probabilities sum to 1. |
If every activation is linear, multiple layers collapse into one matrix multiplication and the network is still linear. Nonlinear activations allow nonlinear decision boundaries.
2. Risk minimisation and loss functions
Given training data and model parameters , learning minimises the empirical risk:
The loss measures one prediction’s error; is the average training loss.
| Problem | Loss | Key point |
|---|---|---|
| Regression | MSE: | Penalises large errors strongly; sensitive to outliers. |
| Regression | MAE: | More robust to outliers; not smooth at zero. |
| Binary classification | Matches a sigmoid probability output. | |
| Multi-class classification | Cross-entropy with one-hot target and softmax output. |
Entropy and cross-entropy
Entropy measures uncertainty of a probability distribution:
-
Entropy is low when one outcome is almost certain and high when probability is spread evenly.
-
Cross-entropy compares the true distribution with model prediction :
For a one-hot target, cross-entropy is simply the negative log probability assigned to the correct class. A confident correct prediction has low loss; a confident wrong prediction has very high loss.
3. Optimisation with gradient descent
The gradient tells how the loss changes when parameters change. Gradient descent takes a small step opposite the gradient:
where is the learning rate.
- Very small : training is slow.
- Very large : loss can oscillate or diverge.
- Neural-network losses are non-convex, so training is not guaranteed to find a global minimum.
Batch, stochastic, and mini-batch updates
| Method | Gradient uses | Trade-off |
|---|---|---|
| Batch gradient descent | Entire training set | Stable but expensive per update. |
| Stochastic gradient descent (SGD) | One example | Cheap/noisy updates; noise can help escape poor regions. |
| Mini-batch gradient descent | A small subset | Standard practical choice: efficient parallel computation with useful gradient noise. |
4. Backpropagation I: the idea
The output layer can be trained like linear/logistic regression. The challenge is calculating gradients for earlier hidden-layer weights, since their desired intermediate outputs are not known.
Backpropagation solves this using:
- the chain rule to relate each parameter to the final loss;
- a backward pass from output to input;
- cached intermediate values so shared calculations are not repeated.
For a computational chain :
The gradient arriving from later computation is the upstream gradient. At a layer, it is multiplied by that layer’s local derivative to produce the gradient passed farther back.
Forward propagation asks, “What prediction does these weights give?” Backpropagation asks, “How much did each weight contribute to this error?”
5. Backpropagation II: equations and algorithm
For one layer, with
define the layer error signal
Then:
For a hidden layer:
where is elementwise multiplication.
Training loop
- Initialise weights and biases.
- Take a mini-batch.
- Forward pass: compute all , , predictions, and loss.
- Backward pass: compute output error, then propagate error signals backward layer by layer.
- Compute gradients for each weight/bias.
- Update parameters with the optimiser.
- Repeat for many batches/epochs; evaluate on validation data.
Caching forward values makes both the forward and backward computations scale linearly with the number of layers, rather than repeatedly recomputing long chain-rule products.
Explain backpropagation for a multilayer perceptron with mathematical notation. First compute and forward. For the output calculate . Propagate backwards by . Then and ; subtract the learning rate times each gradient. Choose the output delta appropriate to the particular loss and activation.
6. Initialisation and stable training
Weight initialisation
Do not initialise all weights to zero or the same constant. Units in the same layer then receive identical gradients and remain identical; they cannot learn different features.
- Use small random values to break symmetry.
- Xavier/Glorot and Kaiming/He initialisation choose random scales based on layer width and activation type.
- Run several seeds when results are unstable; compare average and variation, not one lucky run.
Input scaling and normalisation
Scale input features so that no feature dominates merely because of its unit. Normalisation also stabilises activation ranges and often speeds optimisation.
Vanishing and exploding gradients
Backpropagation multiplies many derivatives/Jacobians.
- Repeated small factors can make gradients approach 0: vanishing gradients.
- Repeated large factors can make gradients huge/NaN: exploding gradients.
Helpful choices include suitable initialisation, ReLU-like activations, normalisation, learning-rate control, gradient clipping (for explosion), and residual/skip connections in deep networks.
| Activation | Training behaviour |
|---|---|
| Sigmoid | Can saturate near 0/1; gradients become very small. |
| Tanh | Zero-centred but also saturates. |
| ReLU | Efficient and non-saturating for positive inputs; may produce dead units for persistent negative inputs. |
| Leaky ReLU | Keeps a small negative-side slope, reducing dead-unit risk. |
7. Validation, regularisation, and model selection
Split data by role:
| Split | Purpose |
|---|---|
| Training set | Fit learnable weights. |
| Validation set | Choose hyperparameters and detect overfitting. |
| Test set | Final unbiased estimate after choices are fixed. |
Regularisation and overfitting control
- L2 weight decay: add to the objective; discourages overly large weights.
- L1 regularisation: add ; encourages sparse weights.
- Dropout: randomly set a fraction of hidden activations to zero during training. This prevents reliance on one narrow set of units and acts like an implicit ensemble. Disable it at evaluation/inference with the framework’s proper scaling.
- Early stopping: periodically measure validation loss. Save the best validation model and stop when validation loss stops improving while training loss continues falling.
Model selection
Hyperparameters are settings not learned directly from gradient updates: learning rate, batch size, number of layers, layer width, activation, dropout rate, regularisation strength, and epoch limit.
Choose them using validation performance, not test performance. The test set is used once only after selection; repeatedly tuning on test results turns it into another validation set and gives an optimistic estimate.
First try to overfit a very small sample. If training loss cannot fall near zero on a handful of examples, suspect an implementation, gradient, learning-rate, or initialisation error before tuning the full model.
8. Evaluation for classification
For binary classification:
For multi-class problems, calculate per-class metrics in one-vs-rest form and use a softmax output layer when classes are mutually exclusive.
FFNN: weighted layers moving forward only.
Training: minimise empirical risk with a task-appropriate loss.
Backprop: chain rule + cached activations gives all gradients efficiently.
Generalisation: validate hyperparameters, regularise, and test only once at the end.
