zoukankan      html  css  js  c++  java
  • 简单的神经元算法实现(python)

    image

    image

    image

    参考python代码如下

    #perceptron
    x=[[1 ,0, 0],[1,0,1],[1, 1, 0],[1, 1, 1],[0,0,1],[0,1,0],[0,1,1],[0,0,0]]
    y=[-1,1,1,1,-1,-1,1,-1]#真值
    y_pre=[0,0,0,0,0,0,0,0]#初始化
    _DEBUG=True
    
    
    w=[0 ,0 ,0 ,0.0]
    
    lamu=0.1#学习因子
    
    
    while 1:
        sum=0
        for i in range(len(y)):
            y_pre[i]=((x[i][1]*w[1]+x[i][2]*w[2]+x[i][0]*w[0]+w[3])>=0)*2-1
            for j in range(len(x[1])):
    
    
                w[j]=w[j]+lamu*(y[i]-y_pre[i])*x[i][j]
    
            w[3]=w[3]+lamu*(y[i]-y_pre[i])
        
        for i in range(len(y)):
     
            sum=sum+abs(y[i]-(((x[i][1]*w[1]+x[i][2]*w[2]+x[i][0]*w[0]+w[3])>=0)*2-1))
    
    
    
        
        if sum<0.01:
        
            break
    
    print(w)
  • 相关阅读:
    node
    ionic
    关于websocket和ajax无刷新
    HTML图片热区
    npm -D -S -g -i 以及安装技巧
    es6 webpack转es5
    es6
    es6
    ssh tunnel
    vim上次和下次光标位置
  • 原文地址:https://www.cnblogs.com/Dzhouqi/p/3442297.html
Copyright © 2011-2022 走看看