Backpropagation
There is one algorithm that unites the various algorithms in machine learning: Backpropagation. This is the algorithm that enables Neural Networks to learn!
The Backpropagation algorithm was first applied to Neural
Networks in 1986, when
they were known as multi-layer perceptrons.
Intuition
Consider a graph with many points. Our goal is to find some function that will fit the best
line possible to these points. It will be an approximation, but it will give us the best way
to represent this line.
Think of drawing some curvy line that will connect all of these dots. It is easy to do by
hand, but how do we do it with math? This is called a "Curve Fitting Problem." The goal is to
find some function that most closely represents the dots in this chart.
Polynomials
Polynomials are functions in math that combine terms of different degrees (think exponents!)
with addition and subtraction. Each term has a coefficient that is some number (such as -2,
-1, 0, 1, 2, etc.). This is a basic example of a polynomial:
And a more advanced one that has coefficients other than 1:
Polynomials are useful in finding curves for complicated functions because we can combine the
graph of each term in order to find a line for a more complicated graph.
For example, here are the graphs for each term in a basic polynomial of degree 5, where the
coefficient for each term is 1:
We can generalize this to the following formula, where each is a on the number line:
Finding Coefficients Randomly
The first thing we can try is to find all of the coefficients randomly, tweaking each value manually to try and find the best curve. Let's see how this works
by playing around with each of these values:
Loss Function
One issue is knowing when exactly the best curve has been found, as many curves look about
correct. This is what a Loss Function tells us.
This loss is calculated using Mean Squared Error. This Loss Function sums the squared value of each error (the difference between the actual
point and the predicted point on the curve), and then it divides it by the total number of
points to get the mean.
As the curve gets closer and closer to fitting the points, the Loss gets closer to 0. The goal
is to make this Loss as small as possible! Try to find values that have a
Loss of less than 50.
While it is possible to find good values with low loss when fitting the curve
manually, how can we be sure this is the best possible curve and the lowest possible Loss? What
if we have a complicated five-term polynomial that we are trying to fit a curve to:
This is where our tools like Derivatives and Gradient Descent become very important and
useful!
Finding Minimum Loss in One Dimension
Let's start by focusing only on , and keeping , , and fixed. For every value tried, it's corresponding loss will be plotted.
0.00
Plotted Against Loss
We can see clearly from this example that has the lowest loss when , but only when , , and .
To help us know if we should increase or decrease for our next guess, we
can take the derivative of that point. The slope of this derivative tells us if our next guess
for should be bigger or smaller:
Plotted Against Loss with Derivatives
Now we can make smarter predictions! If the derivative is negative, we want to make our next
guess to the right - a bigger number . If it's positive, we want make
our next guess to the left - a smaller number . Review the derivatives
of the points in the above graph to check your understanding. We know that we have reached the
minimum loss when the derivative is 0, and that is when we stop checking new values !
Minimum Loss with Multiple Dimensions
Putting the Pieces Together
These are all the components of Gradient Descent!. The one
additional piece is to know how much bigger or smaller the guess should
be. This difference between the last guess and the next one is called the Step Size. Step Size is found by multiplying the slope by a value called the Learning Rate, which is chosen by the researcher and
controls how big the steps are. The Learning Rate is usually
denoted by the lowercase Greek letter Eta η.
We want to choose a value that's big enough that our guesses quickly move downhill, but not
too big that they jump past the minimum.
By multiplying the derivative of the output by some fixed Learning Rate η value, we take smaller and smaller steps as we get closer to the minimum.