基本信息
源码名称:numpy实现BP神经网络
源码大小:1.38KB
文件格式:.py
开发语言:Python
更新时间:2020-10-13
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
手写函数构建神经网络结构和模拟神经网络向前向后传播和迭代过程
def sigmoid(z):
    return 1.0/(1 np.exp(-z))
def bp(w,b,l):
    # 1.向前传播计算预测值和误差
    h1=sigmoid(w[1]*l[1] w[2]*l[2] b[1])
    h2=sigmoid(w[3]*l[1] w[4]*l[2] b[1])
    h3=sigmoid(w[5]*l[1] w[6]*l[2] b[1])
    o1=sigmoid(w[7]*h1 w[9]*h2 w[11]*h3 b[2])
    o2=sigmoid(w[8]*h1 w[10]*h2 w[12]*h3 b[2])
    e=np.square(o1-0.01)/2 np.square(o2-0.99)/2
    
    
    #2.向后传播误差,跟新权值、偏置
    #t1=-(target-outo1)*outo1*(1-outo1)
    t1=-(0.01-o1)*o1*(1-o1)
    #t2=-(target-outo2)*outo2*(1-outo2)
    t2=-(0.99-o2)*o2*(1-o2)
    
    w[7]=w[7]-0.25*(t1*h1)
    w[9]=w[9]-0.25*(t1*h2)
    w[11]=w[11]-0.25*(t1*h3)
    w[8]=w[8]-0.25*(t2*h1)
    w[10]=w[10]-0.25*(t2*h2)
    w[12]=w[12]-0.25*(t2*h3)
    
    w[1]=w[1]-0.25*(t1*w[7] t2*w[8])*h1*(1-h1)*l[1]
    w[2]=w[2]-0.25*(t1*w[7] t2*w[8])*h1*(1-h1)*l[2]
    w[3]=w[3]-0.25*(t1*w[9] t2*w[10])*h2*(1-h2)*l[1]
    w[4]=w[4]-0.25*(t1*w[9] t2*w[10])*h2*(1-h2)*l[2]
    w[5]=w[5]-0.25*(t1*w[11] t2*w[12])*h3*(1-h3)*l[1]
    w[6]=w[6]-0.25*(t1*w[11] t2*w[12])*h3*(1-h3)*l[2]
    return o1,o2,w,e