Lecture 19: Back propogation equations
Overview
Burton Ma derives backpropagation for fully connected neural networks, showing how the layer error propagates through transposed weight matrices and how each layer's weight gradient is formed from its activations and errors. He then walks through a two-pass MATLAB implementation and a small XOR classification example, highlighting the roles of bias weights, random initialization, and network architecture.
Key takeaways
- A hidden-layer error is computed by multiplying the next layer's error vector by the transpose of its weight matrix, excluding the bias column, then applying the current layer's activation derivative elementwise.
- For each layer, the weight gradient is the Kronecker product of the layer's error vector and the preceding layer's activation vector, including the augmented constant activation used for bias gradients.
- Backpropagation requires a forward pass to compute activations and a reverse pass to compute errors; an optimizer such as gradient descent must then use those gradients to update weights.
- In the XOR demonstration, two sigmoid hidden neurons and a scalar Heaviside output may produce different boundaries across runs because of random weight initialization, and the limited architecture can classify poorly.
- MATLAB cell arrays are used to store layer-specific weight matrices, activation functions, derivatives, and error vectors because their dimensions can vary between layers.
Chapters
- The layer error δᶫ is the gradient of the cost with respect to that layer's transfer values zᶫ.
- Changing one activation affects every neuron in the next layer, so the chain rule sums contributions across those connections.
- Each next-layer contribution uses its error δ, the connection weight, and the activation derivative φ′(z).
- Collecting the neuron-level sums gives δᶫ = φ′(zᶫ) ⊙ ((Wᶫ⁺¹ without its bias column)ᵀ δᶫ⁺¹).
- For a single neuron, the derivative with respect to each incoming weight is the corresponding input activation multiplied by that neuron's error δ.
- The bias is treated as an extra activation of 1, so its gradient is also covered by the activation-error product.
- For a layer with multiple neurons, the individual neuron contributions form the layer's full weight-gradient matrix.
- The Kronecker product compactly represents the repeated scalar-times-activation-vector structure.
- Each layer's gradient pairs its error vector with the activations from the preceding layer using a Kronecker product.
- The output-layer contribution uses the final-layer error from backpropagation equation 1 and the previous layer's activations.
- Applying the same construction to every layer yields the complete gradient over all network weights.
- Ma notes that modern networks can have thousands or millions of neurons per layer, making their parameter-gradient vectors very large.
- A forward pass feeds one training pair (x, y) through the network, computing each layer's z values and activations.
- After calculating the final-layer error, a backward pass applies equation 2 from the second-last layer to the first.
- With all layer errors available, equation 4 computes the weight gradient contributed by that training sample.
- Backpropagation computes gradients, not updated weights; gradient descent or another optimizer performs the training updates.
- The XOR-style target labels vectors in quadrants I and III as 1, and vectors in quadrants II and IV as 0.
- The example network has a two-dimensional input, one hidden layer with two neurons, and one scalar output.
- Hidden neurons use sigmoid activation, while the output uses a Heaviside function to produce 0 or 1.
- Ma notes that the example treats the Heaviside derivative as 1 for the gradient calculation.
- The two-neuron hidden layer produces linear decision boundaries, which can fail to classify large portions of the XOR quadrants correctly.
- Repeated runs can yield different boundaries because the network weights are initialized randomly.
- The displayed MATLAB runs include both poor classifications and different learned boundary shapes.
- Adding neurons or layers can increase the network's ability to represent nonlinear classification boundaries.
- The example stores each layer's weights separately, including two input weights and one bias weight per neuron in the first layer.
- MATLAB cell arrays hold layer matrices of different sizes, activation functions, and their derivatives.
- A neural-network object organizes the weights and functions and provides methods to pack or unpack weights as one vector.
- The network uses sigmoid derivatives for the hidden layer and a derivative function for the output layer's Heaviside activation.
- The gradient routine first assigns the optimizer's flat weight vector back to the appropriate layer matrices.
- For each layer, the forward pass computes z from the weight matrix and previous activations, then applies the layer's activation function.
- The backward pass stores each δ vector in a cell array because different layers can have different neuron counts.
- The routine removes the bias column when propagating errors, then uses the Kronecker product to assemble equation 4's gradient.
- The XOR demonstration loads its examples as training data and displays results on those same samples, with no separate test set shown.
- Changing or randomizing the data, or dividing it into different training batches, can change the learned result.
- Ma distinguishes the gradient computation from the broader practical work of training, which involves additional choices and techniques.
- The MATLAB implementation's complexity comes largely from managing layer-specific dimensions and repeatedly unpacking and repacking weights.
- Each neuron receiving the two-dimensional input has three weights: one for x₁, one for x₂, and one for the bias.
- The bias connection supplies a constant activation of 1, which is multiplied by the neuron's third weight.
- The constant-one input is represented by augmenting the activation vector, explaining why the weight matrices include a bias column.
Transcript excerpt
0:00 All right, good morning everybody. Um, so picking up where we left off from last lecture. Um, so we were talking about the back propagation equations uh for a fully connected neural network. Uh, and so at the end of the last lecture we had managed to derive an expression for this thing here back propagation equation number one. Um and so its value is given the symbol delta uh with a superscript big L. So it's something uh related to the last layer of the neural network. Right? That's what that capital L there is indicating. Uh and this term delta is called the error in the layer. Um or uh but really what it is it's the gradient
0:50 of the overall cost with respect to the transfer function. um in that layer. So delta of big L is the gradient of the cost with respect to the transfer function in uh the last layer. So we're in the last layer. So we can actually calculate this quantity um because there's only that one layer of neurons that we have to consider. Uh and so when you crunch through all the math uh you end up uh with a simple relatively simple expression um for uh back propagation equation number one. This is for the least squares loss. Uh now we need to do the same thing for the all of the preceding layers. And so that's what propagation equation number two is. It's going to do the same thing. So it's going to compute the gradient of
1:37 the cost uh with respect to the transfer function in uh in a layer. Uh but it's going to do it for a layer that's not the last layer. Um okay. Okay, so this picture here will hopefully uh well, it contains all the
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Burton Ma.