Backpropagation - Fixing blunders.
Experience is the name everyone gives to their mistakes. – Oscar Wilde
Index
- Neural Networks
- Backpropagation (You are here)
- Machine Learning
- MNIST Number Classification
In the last part we saw what a neural network is and how it learns. Now, we need to fix its mistakes since it's common to mess up while learning. If we recall what alters the activation, It's mainly the change in 3 things:
- Bias
- Weights
- Activation of the previous layer
Backpropagation is an algorithm to calculate the negative gradient to nudge your weights or biases.
That's a long sentence, but to understand that, we need to understand the calculus behind it. But first let us see what affects the output of our neural network.
For the sake of convention we shall we shall superscript the layer. For example, the activation of the L layer will be represented as .
Take a look at this flowchart:
As we can see from the above flow, The weights of the layer, the activation of the previous layer and our bias affects our pre-squished function which we represent as some . This value affects our activation for the layer which inturn affects our cost function. To write all this mathematically:
where is 1 only at expected activation. To propagate backwards, we need to find out what change in the affecting factors lead to how much change in the cost function . This function is then optimized to achieve ideal results.
Alright let's talk math, we'll be needing or the change in cost function with respect to the weights. From the flowchart above, we can say that the resultant is influenced by:
Now this is just for one case, and we have neurons. Let us assume the below structure for the network
Let the first layer have k neurons and the last one have j. For readability and convention, we shall subscript the neuron number and superscript the layer.
Our new cost function is now defined as:
When we measure it with respect to the change in activation, our function now becomes
The above math might require pen and paper to work out and understand properly so take your time for it. But that's what backpropagation is, just a bunch of calculus to write an algorithm to determine how to minimize your cost function.
In the next part of the series we shall look at what are machine learning models and it's classification.