“This is the sixth day of my participation in the First Challenge 2022. For details: First Challenge 2022”

preface

Before officially enter the machine learning, we need to part of the development of our theory, because the first is for our common machine learning algorithms, such as KNN K – means the bayesian decision tree, random forests and so on algorithm, don’t need too or advanced mathematics foundation, the understanding of the special ability to understand the study can be used. In fact, I’ve written two previous learning posts on Sklearn (in my machine Learning column).

However, for later learning, such as using Pytorch to build a simple CNN neural network model, these theories are still important. Of course, if you only build a CNN, you may only need to understand part of it, that is, the part about CNN, such as building a CIFAR10 model.

You probably only need to know that part of the image convolution to build a neural network like this, and then the training leads to the training model.

But this part is probably not enough, and we need to understand our theoretical basis roughly.

The concept of convolution

OK, so now let’s start with a general understanding of convolution. We’re going to explain convolution in two parts. One part is to analyze from our mathematical point of view where this convolution actually comes from, what is convolution, why is it called convolution? That’s important. Of course it’s not too complicated to get back to this, and I’m sure even if you’re in high school and you know calculus, you can understand it.

So the second part is what about the convolution of CNN, our convolutional neural network? What does this convolution do in our CNN?

Now let’s explore four questions. In station B, there are many similar videos with explanations, and many people give many examples, but they all seem to be almost interesting. It’s a bit off topic, although I know they’re trying to explain convolution as best they can, so without further ado, let’s just get started. With these theoretical foundations in mind, we’ll be able to play pytorch pretty quickly. Of course, we still need to understand neural networks, but this thing itself is not very complicated, so I’m going to focus on convolution.

Convolution linguistic meaning

Yes, before we understand convolution, we have to look at the language, although sometimes things are very abstract. But in terms of convolution, it means something similar in terms of what we actually do.

Convolution: alias: convolution. It just means taking two or more things and turning them into one thing and putting them out, and combining them together, and rolling them up, and the product you can think of here as a kind of operation, which is the product, and we combine these two things by multiplying them. The name convolution comes from mathematics, and it’s actually a mathematical operation. So let’s just define here, convolution is a special kind of operation.

Mathematics performance

We said this is a special operation so the question is, how special is it, you can call it convolution. I can look at the formula for convolution first.

And then let’s look at the picture of the operation of convolution

And just by looking at this picture and the state of the operation, I think you can see why this operation is called a roll, right

So why does it do this, and what are the scenarios?

case

Let me give you a little example

So let’s say that we have an explosion experiment, and we have a device to observe the shock wave from our explosion. First of all, we know that our explosion waves are constantly being generated (we measure them in nanoseconds). And the waves from the explosion also decay over time.

So we now assume that one of the relationships between them is as follows

(Our image-drawing code is assumed as follows).

import matplotlib.pyplot as plt
import matplotlib.pylab as mpl


mpl.rcParams["font.sans-serif"] = ["SimHei"]
mpl.rcParams["axes.unicode_minus"] = False

fig,axes = plt.subplots(nrows=2, ncols=1, figsize=(8.6), dpi=100)

time = [i for i in range(10)]
boomStree = [(i**5) + 10 for i in time ]
boomLess = [(i-20) * *2 for i in time]

axes[0].set_xticks(time)
axes[0].set_yticks([0.100.50])
axes[1].set_xticks(time)
axes[1].set_yticks([0.100.50])

axes[0].plot(time,boomStree,color='r',linestyle="-.",label="Explosion pressure")

axes[1].plot(time,boomLess,color='b',linestyle="-.",label="Explosion attenuation")

axes[0].legend()
axes[1].legend()
plt.show()

Copy the code

Now I want to know what the number of explosions my device is detecting at any given moment. Let’s say I want to know what I detected at time four.

State influence

The first thing we need to know is that we have an explosion wave, which we have for a period of time, that is, the explosion wave at the first moment, the impact at the fourth moment is still there, but it decreases, and it decreases like this.

In the same way, the effects of the explosion at time 0 are still there

So again let’s analyze our first moment

Since we are looking at the pressure at time four, for the blast wave at time one, it goes through three moments of decay to time four!

Let’s assume that the picture is discrete!

So in order to figure out what happens at time four, we do this

operation

Now our actual graph is continuous, so we’re actually integrating and multiplying. But here’s the problem

So if you look at the formula, why is g of x minus t, then this is actually going to be our operation.

And then you integrate

So this is really our mathematical definition of convolution.

Convolution in the field of image processing

So, finally, convolution in the field of image processing, and as we know from the previous mathematical examples, convolution is essentially the conversion of different inputs into one output, which is the hybridization of our key information.

So the same is true for image processing, the reason why we use convolution in image processing, or why we have convolution operations, what is the similarity between their convolution operations and our mathematical convolution operations?

The similarities

First of all, the similarity is that the integral in mathematics is actually the same thing as summing up, okay? And we’re still using the product. So in our image processing, we also have continuous multiplication and accumulation. So this operation is very similar to convolution in mathematics, which is why we call it convolution here, which is also a special operation.

Image convolution

So how does it convolve in our picture?

And this is actually not too hard, but first we need to know the composition of the picture

So for a computer, things are a little bit many, so we have to compress the matrix, but because the matrix has a special meaning, we can’t just compress it, we have to have a rule.

Convolution kernel/convolution layer

In order to compress the matrix well, without losing the features of the matrix, or highlighting one of the features of the matrix, we designed a special matrix. The eigenmatrix is used like this.

Let’s multiply and add. This is going to be the same thing as our new matrix, and our matrix is going to be smaller once.

This operation is called convolution. So let’s go back to our original model

This layer is called the convolution layer. But when WE say we’re going to simplify the matrix, we’re just going to reduce one circle, which is not enough

So we also have the pooling layer

Pooling layer

That’s what compresses it

But that’s not enough, matrices are too abstract for computers so we have one last layer

The connection layer

We’re going to take the matrix and turn it into a one-dimensional array and run it through the neural network

conclusion

And what we can actually see is that the convolution is actually very simple, and all it does is do one thing, and in our case, it’s information extraction but the name of this process sounds very fancy, very cool. Finally, it is about the arrangement of Letcode brush questions, which is to fix the number of questions in a week, then take one or two days to brush, and then summarize. Brush every day, all of a sudden time conflict. And then in a couple of days we’re going to talk about other algorithms for machine learning, or optimization algorithms, like genetic algorithms or EA with an emphasis on EA. After all, THE MO I studied in winter vacation was MOEA. After I got back, I studied MOPSO based on this and then made MOFLINK. (Hey, when was my target backend engineer, the Java distributed, ah, spring source code ah will have to wait until I go back to school to finish the game, and do things with the teacher)