Depth study on the first day
Our hands have a lot of x and y, find the weight
training is weighted
data samples
x | W | Y |
---|---|---|
height | 0 | |
body weight | 0 | |
blood group | 0.3 | |
Toes | 0.8 |
A group of x to calculate a Y corresponding
calculation is w
following picture is the most basic formula
we know a lot of data x and y are
desired to be obtained by W "Sitar"
Our study has only just begun, you first need to understand that the door
x1 | x2 | Y |
---|---|---|
0 | 0 | 0 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 1 |
Above is a AND gate, where the principle of the brain will be long, so that we directly on the code
def AND(x1, x2):
w1, w2, theta = 0.5, 0.5, 0.7
tmp = x1*w1 + x2*w2
if tmp <= theta:
return 0
elif tmp > theta:
return 1
Here let us consider the NAND and OR gates
NAND gate
x1 | x2 | Y |
---|---|---|
0 | 0 | 1 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
OR
x1 | x2 | Y |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 1 |
Simple implementation of machine perception
After understanding the above gate, we began to implement a simple Perceptron
just with the door code is a fundamental part of the knowledge, let's make some changes to their implementation
Here we used this formula
import numpy as np
x = np.array([0,1])
w = np.array([0.5,0.5])
b = -0.7
print(np.sum(w*x))
print(np.sum(w*x)+b)
#0.5
#-0.19999999999999996
From this we can see that, when two identical numpy array elements, we adding and multiplying them (i.e. -numpy.sum () method)
again and b (offset) added to complete computing the above formula
Then we realized just an AND gate, where we first posted the first AND gate
def AND(x1, x2):
w1, w2, theta = 0.5, 0.5, 0.7
tmp = x1*w1 + x2*w2
if tmp <= theta:
return 0
elif tmp > theta:
return 1
#0 0 0 1
Then we want to achieve with the new door
import numpy as np
def AND(x1,x2):
w = np.array([0.5,0.5])
x = np.array([x1,x2])
b = -0.7
tmp = np.sum(w*x)+b
if tmp <= 0:
return 0
elif tmp > 0:
return 1
#0 0 0 1
Specifically, and W2 is W1 of the parameter control input signal of the importance of , and offset (b) is adjusted neuron is activated easiness (a degree of the output signal) of the parameters .
Then we realize NAND and OR gates
import numpy as np
def NAND(x1,x2):
w = np.array([-0.5,-0.5])#仅权重和偏置改变了
x = np.array([x1,x2])
b = 0.7
tmp = np.sum(w*x)+b
if tmp <=0:
return 0
elif tmp >0:
return 1
def OR(x1, x2):
x = np.array([x1, x2])
w = np.array([0.5, 0.5]) # 仅权重和偏置与AND不同!
b = -0.2
tmp = np.sum(w*x) + b
if tmp <= 0:
return 0
else:
return 1
# 1 1 1 0
# 0 1 1 1
AND gates, NAND gates, OR gates perceptron having the same configuration, except that only the value of the weight parameter. Thus, achieving NAND gate and an OR gate, the values of the weights and bias provided only that the gate and a different implement.
XOR gates are special
def XOR(x1,x2):
s1 = NAND(x1,x2)
s2 = OR(x1,x2)
y = AND(s1,s2)
return y
# 0 1 1 0
But there are digital logic-based, it should not be difficult to understand