Artificial Intelligence---Deep Learning From Perceptron to Neural Network

Series Article Directory

What is deep learning



Preface

In the previous chapter, we introduced you to what deep learning is and the relationship between deep learning and machine learning. At the same time, we introduced the concept of neural network in deep learning. At the same time, neural network will also be our next deep learning. The important content of learning. From the beginning of this chapter, I will lead you to really start learning deep learning.


One, the composition of the neural network

       Neural networks are actually derived from the model structure established by the abstraction of human brain neurons in biology. He used mathematical logic to imitate the structure and interaction mode of neurons in the human brain, that is, the way information is received, processed, transmitted, and stored in the brain. So that the computer can learn, think and solve problems like a human.
       Therefore, the most important step in the field of neural networks is the transformation and realization from biological neurons to machine neurons.
Insert picture description here
This brings up the concept of perceptron, our first stop of deep learning.

Second, what is a perceptron

1. The concept of perceptron

        The algorithm of Perceptron was first proposed by American scholar Frank Rosenblatt in 1957. But the reason why we still need to mention such an old algorithm today is that the perceptron is also the origin algorithm of deep learning neural networks. Therefore, learning perceptrons can smoothly allow people without foundation to understand the concept of neural networks, and can also Let a certain basic understanding of the principles of the team network one step closer.
       The perceptron describes a structure that can receive multiple signals and output one signal. The signal here can be a data stream or a current. The sensor can process and rectify such a stream signal into a 1/0 signal, which also symbolizes the operating habits of our computer.

Insert picture description here

2. The mathematical expression of the perceptron

Insert picture description here
        wi are the weights on different nodes. The larger the value of w, the greater the weight of this node. It can also be said that the greater the importance. The output of y depends on the sum of all input nodes. If the sum is If it is greater than θ, 1 will be output, otherwise 0 will be output.

The code is as follows (example):

3. Simple application realization of perceptron

       The simplest application of perceptrons is in the field of logic circuits, such as the realization of their respective gate circuits (AND gate, NOT gate, NAND gate, etc.).

For example, the simplest AND gate:
Insert picture description here
how to use a perceptron to realize such an AND gate?
We can set the parameters of the perceptron as (w1, w2, θ) = (0.5, 0.5, 0.9) and
substitute different X into the available
Insert picture description here
output as we expected. In fact, this is a simple realization of an AND gate. So the nature of a perceptron depends on its Wi and θ.
       Maybe everyone is still not sure what is the use of implementing such a thing? But in fact, as an electrical object, a computer's internal logic is all dependent on the realization of such logic, rather than the natural language communication of our humans, so the reproduction of this logic is the first for us to implement a complex model on the computer. step.
You can also try to implement more gate circuits (not gates, OR gates...) by adjusting W and θ.

4. Code implementation of simple perceptron


def AND_G(x1,x2):
	#	w1,w2,θ
    w1,w2,theta = 0.5,0.5,0.9
    tmp = x1*w1+x2*w2
    return 1 if tmp>theta else 0

Output result:

print(AND_G(0,0))
print(AND_G(1,0))
print(AND_G(0,1))
print(AND_G(1,1))

'''
0
0
0
1

Process finished with exit code 0

'''

5. Introducing the concept of bias to make the perceptron more flexible

Insert picture description here

           Students with a certain neural network foundation must be familiar with the term bias. It is generally described as b. We usually acquiesce to his existence for granted, but why do we need such a configuration amount?
           Just look at the formula for analysis, the introduction of the b value can determine how easily the neuron is activated. From a graphical point of view, because both the perceptron and the complex neural network behind it can actually be converted into a linear representation in the coordinate system. Take the simplest one-variable linear equation as an example. If there is no bias b, then This restricts the line must pass the origin, which makes many classification problems extremely difficult. Facing an extremely simple problem may require extremely complex weight settings, such as the following figure:
Insert picture description here

6. Bias realization

def AND_G(x1,x2):
    w1,w2,b,theta = 0.5,0.5,0.2,0.9
    tmp = x1*w1+x2*w2+b
    return 1 if tmp>theta else 0
print(AND_G(0,0))
print(AND_G(1,0))
print(AND_G(0,1))
print(AND_G(1,1))

operation result:

0
0
0
1

Process finished with exit code 0

3. Establishment of complex perceptron system

           Through the above examples, everyone has mastered the realization of simple logic circuits, but is the application of a perceptron to logic circuits omnipotent? You can take a look at the following logic circuit.
Insert picture description here
This is an XOR gate. In fact, it can be proved by the coordinate system that it is impossible to divide the 0/1 case through a straight line, so that means that this XOR gate cannot be realized with a perceptron. , Which leads to our multilayer perceptron system.

           There are three perceptron circuits that we are currently implementing, namely AND gate, NOT gate and OR gate. How do we put together such an exclusive OR gate?

Insert picture description here

Let us theoretically prove whether this circuit is feasible!
Insert picture description here
        It seems that our experiment is okay. We have indeed realized such a complex logic circuit through the combination of multiple perceptrons, but our deep learning will ultimately be applied to the computer, so we have to consider the feasibility of an algorithm.

Next, let us implement this perceptron system.

#与门的方法我们前面已经实现,非门和或门是留给大家的任务,我这边就不给出答案了
#有问题的同学可以私信我讨论
def XOR_G(x1,x2):
    return AND_G(NAND_G(x1,x2),OR_G(x1,x2))

Run the program:

print(XOR_G(0,0))
print(XOR_G(1,0))
print(XOR_G(0,1))
print(XOR_G(1,1))

come to conclusion

0
1
1
0

Process finished with exit code 0

Then make a certain deformation of our perceptron diagram:
Insert picture description here
Does it suddenly feel very similar to the neural network model we mentioned earlier, this is the simplest neural network model.

        You can also try more collocations and combinations to generate more interesting judgment networks and solve some simple logical problems in life.


to sum up

        So far our first neural network has been successfully built. We start with the most primitive perceptron, and use the example of logic circuit to complete it step by step to a preliminary neural network, but he only matched the shape. In fact, the perceptron has evolved through so many years, and people have more and more The more optimization, the more and more it has both computer science and biological characteristics, making the machine truly possess artificial intelligence.

Guess you like

Origin blog.csdn.net/weixin_44494790/article/details/109777254
Recommended