当前位置:网站首页>Self learning neural network sequence -- 2 perceptron
Self learning neural network sequence -- 2 perceptron
2022-06-26 09:09:00 【ML_ python_ get√】
perceptron
2.1 What is a perceptron
- Accept multiple input signals , Output a signal
- Neuron : Weighting the input signal , If the weighted number meets a certain condition, enter 1, Otherwise output 0
- The weight represents the importance of the signal
2.2 And or not
- And gate : Only two inputs are 1 When the output 1, Other situation output 0
- NAND gate : Invert the and gate output , Only two inputs are 1 When the output 0, Otherwise output 1
- Or gate : As long as one input is 1, Then output 1, Only all inputs are 0, Just output 0
- As long as the parameters of the sensor are adjusted, the switch between different doors can be realized
- Parameter adjustment is left to the computer , Let the computer decide what kind of door
- Exclusive OR gate : Only one input is 1 when , Will enter 1, The two inputs are 1 when , Output 0
# python Implement and gate
def AND(x1,x2):
''' Implementation of and gate '''
w1,w2,theta = 0.5,0.5,0.7
tmp = x1*w1+x2*w2
if tmp<=theta:
return 0
elif tmp>theta:
return 1
# Test functions
AND(1,1)
AND(0,0)
AND(1,0)
AND(0,1)
# Use offset and numpy Realization
def AND(x1,x2):
import numpy as np
x = np.array([x1,x2])
w = np.array([0.5,0.5])
b = -0.7 # threshold , Adjust how easily neurons are activated
tmp = np.sum(w*x) +b
if tmp<=0:
return 0
elif tmp>0:
return 1
# test
AND(1,1)
AND(1,0)
AND(0,1)
AND(0,0)
# NAND gate
# The output is just the opposite , The weights and offsets are opposite to each other
def NAND(x1,x2):
''' NAND gate '''
import numpy as np
x = np.array([x1,x2])
w = np.array([-0.5,-0.5])
b = 0.7
tmp = np.sum(w*x)+b
if tmp <=0:
return 0
elif tmp>0:
return 1
# test
NAND(1,1)
NAND(1,0)
NAND(0,1)
NAND(0,0)
# Or gate : The absolute value of the offset is less than 0.5 that will do
def OR(x1,x2):
import numpy as np
x = np.array([x1,x2])
w = np.array([0.5,0.5]) # As long as not both inputs go 0, It outputs 1
b = -0.2
tmp = np.sum(w*x)+b
if tmp<=0:
return 0
else:
return 1
OR(1,1)
OR(0,1)
OR(1,0)
OR(1,1)
# Exclusive OR gate : Cannot be separated by a straight line
# Introduce nonlinearity : Overlay layer perceptron
# Through the NAND gate, we get S1 Or door access S2 You can see the result of the XOR gate that can be reached through the and gate
# Multilayer perceptron , There are multiple linear classifiers , The nonlinear fitting can be realized through and gate
def XOR(x1,x2):
s1 = NAND(x1,x2)
s2 = OR(x1,x2)
y = AND(s1,s2)
return y
# test
XOR(1,1)
XOR(0,0)
XOR(1,0)
XOR(0,1)
边栏推荐
猜你喜欢
随机推荐
1.27 pytorch learning
phpcms小程序插件教程网站正式上线
Fast construction of neural network
Isinstance() function usage
phpcms小程序插件api接口升级到4.3(新增批量获取接口、搜索接口等)
XSS cross site scripting attack
Pytorch build progression
1.20 study univariate linear regression
In automated testing, there are three commonly used waiting methods: sleep, implicitly\wait, and expected\u conditions
【微积分】拉格朗日乘子法
Efficiency thesis Reading 1
Games104 Lecture 12 游戏引擎中的粒子和声效系统
phpcms手机站模块实现自定义伪静态设置
教程1:Hello Behaviac
Fix the problem that the rich text component of the applet does not support the properties of video cover, autoplay, controls, etc
PD快充磁吸移动电源方案
HDU - 6225 little boxes (\u int128)
[program compilation and pretreatment]
直播回顾 | smardaten李鸿飞解读中国低/无代码行业研究报告:风向变了
docker安装redis









