In this lecture, we are going to continue our discussion of convolution by looking at a totally different
perspective on how it works.
This is very helpful for understanding convolution, but it doesn't teach you anything new mechanically.
So this lecture is optional.
If you want to move on and just learn about how to make CNN's.
Something I mentioned very often is factorization.
We like to victories operations and code because using Nampai functions is a lot more efficient than
writing your own python for loops.
The pattern you're looking for when you want to victories in operation is usually of the form of a product.
A dot product is an element y's multiplication and then the summation of those results.
So whenever you see the sum over I of items by, that's a dot product.
This also applies to matrix multiplication, since if amber matrices, then the matrix multiplication
of AB is just B.
You'll notice that for convolution, we yet again have something similar.
The only difference is that there are two summations.
However, this is not really a relevant detail, since the outcome is the same instead of summing over
one axis or something over two axes.
But it's still an element y some an ad.
The question is, why is the DOT products important?
One definition of the DOT product other than that element, why some an ad is that it's the magnitude
of a multiplied by the magnitude of B multiplied by the cosine of the angle between A and B.
We sometimes call this the cosine similarity or cosine distance, depending on the sign that you use.
So how does this work geometrically consider just the angle for a moment, if the angle between the
two vectors is zero, then the cosine of that angle is one that's the maximum value of the cosine.
Now, imagine that the angle between two vectors is 90 degrees, then the cosine of that angle is zero.
Finally, imagine that the angle between the two vectors is 180 degrees.
This is basically as far apart as possible, then the cosine of that angle is minus one, which is the
minimum value of the cosine.
So if you're just using raw cosine, then it's a similarity.
The larger the number, the closer the two vectors are, the smaller the number, the further away they
are, the maximum value.
When amber parallel is one, the minimum value when and B are A. Parallel is minus one.
And if A and B are orthogonal, then the cosine similarity is just zero.
OK, so why is that important?
Consider now how you would find it the cosine of the angle between two vectors.
That's just 8b divided by the magnitude of a in the magnitude of B.
So I just rearrange the equation that we had before.
Now, let's compare this to another popular measurement, the Pearson correlation, the Pearson correlation
is defined as what you see here.
But notice how similar this is to cosine similarity.
The only difference is that the Pearson correlation uses mean subtraction.
And so now you have two hints that convolution is really correlation.
The first one from before it was that we were actually doing what is called the cross correlation.
And second, now you have that the DOT product is actually very similar to the Pearson correlation.
So I hope that by this point, you are convinced that the dog products, while that seems like an abstract
concept, can be thought of as a correlation measure, it tells me how correlated is the first thing
with the second thing.
If they are highly, positively correlated, then the dog products should be large and positive.
That means two vectors pointing in nearly the same direction.
If they are highly negatively correlated, then the dot product should be large and negative.
That means the two vectors are pointing in nearly opposite direction.
Finally, if the two vectors are orthogonal or at right angles, then the DOT product should be zero.
The reason why this is important is you don't have to think of a filter as an abstract concepts.
In fact, it's just a pattern finder.
This actually makes the term filter make a lot more sense.
It filters out everything not related to the pattern contained in the filter by sending them to zero
and keeps everything that is related to the pattern.
So what convolution is doing is it's passing this filter along each point on the original input image
and sliding it along at each point.
It asks, Is the pattern here is the pattern, here is the pattern here and so forth.
Then it gives us a high number in the positions where the pattern is found.
And then a small number where the pattern is not found.
And thus, this is your first alternative perspective on convolution.
It's just a sliding pattern finder that passes through an entire image looking for a particular pattern.