最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python實現(xiàn)簡單神經(jīng)網(wǎng)絡(luò)算法

 更新時間:2018年03月10日 12:37:19   作者:由硬到軟  
這篇文章主要為大家詳細介紹了python實現(xiàn)簡單神經(jīng)網(wǎng)絡(luò)算法,具有一定的參考價值,感興趣的小伙伴們可以參考一下

python實現(xiàn)簡單神經(jīng)網(wǎng)絡(luò)算法,供大家參考,具體內(nèi)容如下

python實現(xiàn)二層神經(jīng)網(wǎng)絡(luò)

包括輸入層和輸出層

import numpy as np 
 
#sigmoid function 
def nonlin(x, deriv = False): 
  if(deriv == True): 
    return x*(1-x) 
  return 1/(1+np.exp(-x)) 
 
#input dataset 
x = np.array([[0,0,1], 
       [0,1,1], 
       [1,0,1], 
       [1,1,1]]) 
 
#output dataset 
y = np.array([[0,0,1,1]]).T 
 
np.random.seed(1) 
 
#init weight value 
syn0 = 2*np.random.random((3,1))-1 
 
for iter in xrange(100000): 
  l0 = x             #the first layer,and the input layer  
  l1 = nonlin(np.dot(l0,syn0))  #the second layer,and the output layer 
 
 
  l1_error = y-l1 
 
  l1_delta = l1_error*nonlin(l1,True) 
 
  syn0 += np.dot(l0.T, l1_delta) 
print "outout after Training:" 
print l1 
import numpy as np 
 
#sigmoid function 
def nonlin(x, deriv = False): 
  if(deriv == True): 
    return x*(1-x) 
  return 1/(1+np.exp(-x)) 
 
#input dataset 
x = np.array([[0,0,1], 
       [0,1,1], 
       [1,0,1], 
       [1,1,1]]) 
 
#output dataset 
y = np.array([[0,0,1,1]]).T 
 
np.random.seed(1) 
 
#init weight value 
syn0 = 2*np.random.random((3,1))-1 
 
for iter in xrange(100000): 
  l0 = x             #the first layer,and the input layer  
  l1 = nonlin(np.dot(l0,syn0))  #the second layer,and the output layer 
 
 
  l1_error = y-l1 
 
  l1_delta = l1_error*nonlin(l1,True) 
 
  syn0 += np.dot(l0.T, l1_delta) 
print "outout after Training:" 
print l1 

這里,
l0:輸入層

l1:輸出層

syn0:初始權(quán)值

l1_error:誤差

l1_delta:誤差校正系數(shù)

func nonlin:sigmoid函數(shù)

可見迭代次數(shù)越多,預(yù)測結(jié)果越接近理想值,當(dāng)時耗時也越長。

python實現(xiàn)三層神經(jīng)網(wǎng)絡(luò)

包括輸入層、隱含層和輸出層

import numpy as np 
 
def nonlin(x, deriv = False): 
  if(deriv == True): 
    return x*(1-x) 
  else: 
    return 1/(1+np.exp(-x)) 
 
#input dataset 
X = np.array([[0,0,1], 
       [0,1,1], 
       [1,0,1], 
       [1,1,1]]) 
 
#output dataset 
y = np.array([[0,1,1,0]]).T 
 
syn0 = 2*np.random.random((3,4)) - 1 #the first-hidden layer weight value 
syn1 = 2*np.random.random((4,1)) - 1 #the hidden-output layer weight value 
 
for j in range(60000): 
  l0 = X            #the first layer,and the input layer  
  l1 = nonlin(np.dot(l0,syn0)) #the second layer,and the hidden layer 
  l2 = nonlin(np.dot(l1,syn1)) #the third layer,and the output layer 
 
 
  l2_error = y-l2    #the hidden-output layer error 
 
  if(j%10000) == 0: 
    print "Error:"+str(np.mean(l2_error)) 
 
  l2_delta = l2_error*nonlin(l2,deriv = True) 
 
  l1_error = l2_delta.dot(syn1.T)   #the first-hidden layer error 
 
  l1_delta = l1_error*nonlin(l1,deriv = True) 
 
  syn1 += l1.T.dot(l2_delta) 
  syn0 += l0.T.dot(l1_delta) 
print "outout after Training:" 
print l2 
import numpy as np 
 
def nonlin(x, deriv = False): 
  if(deriv == True): 
    return x*(1-x) 
  else: 
    return 1/(1+np.exp(-x)) 
 
#input dataset 
X = np.array([[0,0,1], 
       [0,1,1], 
       [1,0,1], 
       [1,1,1]]) 
 
#output dataset 
y = np.array([[0,1,1,0]]).T 
 
syn0 = 2*np.random.random((3,4)) - 1 #the first-hidden layer weight value 
syn1 = 2*np.random.random((4,1)) - 1 #the hidden-output layer weight value 
 
for j in range(60000): 
  l0 = X            #the first layer,and the input layer  
  l1 = nonlin(np.dot(l0,syn0)) #the second layer,and the hidden layer 
  l2 = nonlin(np.dot(l1,syn1)) #the third layer,and the output layer 
 
 
  l2_error = y-l2    #the hidden-output layer error 
 
  if(j%10000) == 0: 
    print "Error:"+str(np.mean(l2_error)) 
 
  l2_delta = l2_error*nonlin(l2,deriv = True) 
 
  l1_error = l2_delta.dot(syn1.T)   #the first-hidden layer error 
 
  l1_delta = l1_error*nonlin(l1,deriv = True) 
 
  syn1 += l1.T.dot(l2_delta) 
  syn0 += l0.T.dot(l1_delta) 
print "outout after Training:" 
print l2 

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • python讀取和保存視頻文件

    python讀取和保存視頻文件

    這篇文章主要為大家詳細介紹了python讀取顯示和保存視頻文件,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • Python中xml.etree.ElementTree的使用示例

    Python中xml.etree.ElementTree的使用示例

    ElementTree是Python標(biāo)準(zhǔn)庫中的一個模塊,專門用于處理XML文件,它提供了解析、創(chuàng)建、修改和遍歷XML文檔的API,非常適合處理配置文件、數(shù)據(jù)交換格式和Web服務(wù)響應(yīng)等場景,本文就來介紹一下,感興趣的可以了解一下
    2024-09-09
  • OpenCV 邊緣檢測

    OpenCV 邊緣檢測

    OpenCV提供了許多邊緣檢測濾波函數(shù),這些濾波函數(shù)都會將非邊緣區(qū)域轉(zhuǎn)為黑色,將邊緣區(qū)域轉(zhuǎn)為白色或其他飽和的顏色。這篇文章主要介紹了OpenCV 邊緣檢測,需要的朋友可以參考下
    2019-07-07
  • python讀取ini配置的類封裝代碼實例

    python讀取ini配置的類封裝代碼實例

    這篇文章主要介紹了python讀取ini配置的類封裝代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-01-01
  • python中的屬性管理機制詳解

    python中的屬性管理機制詳解

    這篇文章主要介紹了python中的屬性管理機制,主要包括私有屬性和屬性限制-__slots__方法,文中詳細介紹了python中如何去聲明變量的相關(guān)知識,需要的朋友可以參考下
    2022-06-06
  • java直接調(diào)用python腳本的例子

    java直接調(diào)用python腳本的例子

    有時需求使用JAVA直接調(diào)用python腳本,執(zhí)行一些服務(wù)器監(jiān)控的事情。 本文給出一個java直接調(diào)用python腳本的例子
    2014-02-02
  • 一起來學(xué)習(xí)一下python的數(shù)據(jù)類型

    一起來學(xué)習(xí)一下python的數(shù)據(jù)類型

    這篇文章主要為大家詳細介紹了python的數(shù)據(jù)類型,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下希望能夠給你帶來幫助
    2022-01-01
  • python基礎(chǔ)教程之簡單入門說明(變量和控制語言使用方法)

    python基礎(chǔ)教程之簡單入門說明(變量和控制語言使用方法)

    這篇文章主要介紹了開始學(xué)習(xí)python的第一步需要知道的知識(變量和控制語言使用方法),需要的朋友可以參考下
    2014-03-03
  • Django 使用easy_thumbnails壓縮上傳的圖片方法

    Django 使用easy_thumbnails壓縮上傳的圖片方法

    今天小編就為大家分享一篇Django 使用easy_thumbnails壓縮上傳的圖片方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-07-07
  • Python面向?qū)ο蟪绦蛟O(shè)計之類的定義與繼承簡單示例

    Python面向?qū)ο蟪绦蛟O(shè)計之類的定義與繼承簡單示例

    這篇文章主要介紹了Python面向?qū)ο蟪绦蛟O(shè)計之類的定義與繼承,結(jié)合完整實例形式分析了Python面向?qū)ο蟪绦蛟O(shè)計中類的定義、調(diào)用、繼承及相關(guān)操作注意事項,需要的朋友可以參考下
    2019-03-03

最新評論

营口市| 灌阳县| 都匀市| 巴里| 杨浦区| 淮滨县| 大姚县| 吉隆县| 小金县| 浠水县| 郁南县| 华蓥市| 延津县| 化德县| 达尔| 兴安县| 胶州市| 中超| 封开县| 青冈县| 扎囊县| 怀宁县| 天柱县| 灵丘县| 防城港市| 淳安县| 碌曲县| 阜阳市| 綦江县| 乌拉特后旗| 普兰县| 永吉县| 新安县| 旅游| 荥阳市| 开阳县| 买车| 张家港市| 泸溪县| 赤水市| 布尔津县|