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

python里反向傳播算法詳解

 更新時(shí)間:2020年11月22日 11:24:41   作者:十一  
在本篇文章了小編給大家整理的是一篇關(guān)于python里反向傳播算法詳解內(nèi)容,有興趣的朋友們可以學(xué)習(xí)下。

反向傳播的目的是計(jì)算成本函數(shù)C對(duì)網(wǎng)絡(luò)中任意w或b的偏導(dǎo)數(shù)。一旦我們有了這些偏導(dǎo)數(shù),我們將通過一些常數(shù) α的乘積和該數(shù)量相對(duì)于成本函數(shù)的偏導(dǎo)數(shù)來更新網(wǎng)絡(luò)中的權(quán)重和偏差。這是流行的梯度下降算法。而偏導(dǎo)數(shù)給出了最大上升的方向。因此,關(guān)于反向傳播算法,我們繼續(xù)查看下文。

我們向相反的方向邁出了一小步——最大下降的方向,也就是將我們帶到成本函數(shù)的局部最小值的方向。

圖示演示:

反向傳播算法中Sigmoid函數(shù)代碼演示:

# 實(shí)現(xiàn) sigmoid 函數(shù)
return 1 / (1 + np.exp(-x))
def sigmoid_derivative(x):
# sigmoid 導(dǎo)數(shù)的計(jì)算
return sigmoid(x)*(1-sigmoid(x))

反向傳播算法中ReLU 函數(shù)導(dǎo)數(shù)函數(shù)代碼演示:

def relu_derivative(x): # ReLU 函數(shù)的導(dǎo)數(shù)
d = np.array(x, copy=True) # 用于保存梯度的張量
d[x < 0] = 0 # 元素為負(fù)的導(dǎo)數(shù)為 0
d[x >= 0] = 1 # 元素為正的導(dǎo)數(shù)為 1
return d

實(shí)例擴(kuò)展:

BP反向傳播算法Python簡單實(shí)現(xiàn)

import numpy as np

# "pd" 偏導(dǎo)
def sigmoid(x):
  return 1 / (1 + np.exp(-x))

def sigmoidDerivationx(y):
  return y * (1 - y)


if __name__ == "__main__":
  #初始化
  bias = [0.35, 0.60]
  weight = [0.15, 0.2, 0.25, 0.3, 0.4, 0.45, 0.5, 0.55]
  output_layer_weights = [0.4, 0.45, 0.5, 0.55]
  i1 = 0.05
  i2 = 0.10
  target1 = 0.01
  target2 = 0.99
  alpha = 0.5 #學(xué)習(xí)速率
  numIter = 10000 #迭代次數(shù)
  for i in range(numIter):
    #正向傳播
    neth1 = i1*weight[1-1] + i2*weight[2-1] + bias[0]
    neth2 = i1*weight[3-1] + i2*weight[4-1] + bias[0]
    outh1 = sigmoid(neth1)
    outh2 = sigmoid(neth2)
    neto1 = outh1*weight[5-1] + outh2*weight[6-1] + bias[1]
    neto2 = outh2*weight[7-1] + outh2*weight[8-1] + bias[1]
    outo1 = sigmoid(neto1)
    outo2 = sigmoid(neto2)
    print(str(i) + ", target1 : " + str(target1-outo1) + ", target2 : " + str(target2-outo2))
    if i == numIter-1:
      print("lastst result : " + str(outo1) + " " + str(outo2))
    #反向傳播
    #計(jì)算w5-w8(輸出層權(quán)重)的誤差
    pdEOuto1 = - (target1 - outo1)
    pdOuto1Neto1 = sigmoidDerivationx(outo1)
    pdNeto1W5 = outh1
    pdEW5 = pdEOuto1 * pdOuto1Neto1 * pdNeto1W5
    pdNeto1W6 = outh2
    pdEW6 = pdEOuto1 * pdOuto1Neto1 * pdNeto1W6
    pdEOuto2 = - (target2 - outo2)
    pdOuto2Neto2 = sigmoidDerivationx(outo2)
    pdNeto1W7 = outh1
    pdEW7 = pdEOuto2 * pdOuto2Neto2 * pdNeto1W7
    pdNeto1W8 = outh2
    pdEW8 = pdEOuto2 * pdOuto2Neto2 * pdNeto1W8

    # 計(jì)算w1-w4(輸出層權(quán)重)的誤差
    pdEOuto1 = - (target1 - outo1) #之前算過
    pdEOuto2 = - (target2 - outo2) #之前算過
    pdOuto1Neto1 = sigmoidDerivationx(outo1)  #之前算過
    pdOuto2Neto2 = sigmoidDerivationx(outo2)  #之前算過
    pdNeto1Outh1 = weight[5-1]
    pdNeto2Outh2 = weight[7-1]

    pdEOuth1 = pdEOuto1 * pdOuto1Neto1 * pdNeto1Outh1 + pdEOuto2 * pdOuto2Neto2 * pdNeto1Outh1
    pdOuth1Neth1 = sigmoidDerivationx(outh1)
    pdNeth1W1 = i1
    pdNeth1W2 = i2
    pdEW1 = pdEOuth1 * pdOuth1Neth1 * pdNeth1W1
    pdEW2 = pdEOuth1 * pdOuth1Neth1 * pdNeth1W2
    pdNeto1Outh2 = weight[6-1]
    pdNeto2Outh2 = weight[8-1]
    pdOuth2Neth2 = sigmoidDerivationx(outh2)
    pdNeth2W3 = i1
    pdNeth2W4 = i2
    pdEOuth2 = pdEOuto1 * pdOuto1Neto1 * pdNeto1Outh2 + pdEOuto2 * pdOuto2Neto2 * pdNeto2Outh2
    pdEW3 = pdEOuth2 * pdOuth2Neth2 * pdNeth2W3
    pdEW4 = pdEOuth2 * pdOuth2Neth2 * pdNeth2W4
    #權(quán)重更新
    weight[1-1] = weight[1-1] - alpha * pdEW1
    weight[2-1] = weight[2-1] - alpha * pdEW2
    weight[3-1] = weight[3-1] - alpha * pdEW3
    weight[4-1] = weight[4-1] - alpha * pdEW4
    weight[5-1] = weight[5-1] - alpha * pdEW5
    weight[6-1] = weight[6-1] - alpha * pdEW6
    weight[7-1] = weight[7-1] - alpha * pdEW7
    weight[8-1] = weight[8-1] - alpha * pdEW8
    # print(weight[1-1])
    # print(weight[2-1])
    # print(weight[3-1])
    # print(weight[4-1])
    # print(weight[5-1])
    # print(weight[6-1])
    # print(weight[7-1])
    # print(weight[8-1])

到此這篇關(guān)于python里反向傳播算法詳解的文章就介紹到這了,更多相關(guān)python里反向傳播算法是什么內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 新一代Python包管理工具

    新一代Python包管理工具

    這篇文章主要介紹了新一代Python包管理工具,Python包管理工具,一般就會(huì)想到想到pip、conda等經(jīng)典工具,本篇文章要介紹的是一款新穎的Python包管理工具pdm,需要的小伙伴可以參考一下
    2022-02-02
  • 利用python腳本提取Abaqus場(chǎng)輸出數(shù)據(jù)的代碼

    利用python腳本提取Abaqus場(chǎng)輸出數(shù)據(jù)的代碼

    這篇文章主要介紹了利用python腳本提取Abaqus場(chǎng)輸出數(shù)據(jù),利用python腳本對(duì)Abaqus進(jìn)行數(shù)據(jù)提取時(shí),要對(duì)python腳本做前步的導(dǎo)入處理,本文通過實(shí)例代碼詳細(xì)講解需要的朋友可以參考下
    2022-11-11
  • python之dlib包安裝失敗問題及解決

    python之dlib包安裝失敗問題及解決

    這篇文章主要介紹了python之dlib包安裝失敗問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • PyCharm打代碼時(shí)出現(xiàn)白色光標(biāo)問題(筆記本的解決方案)

    PyCharm打代碼時(shí)出現(xiàn)白色光標(biāo)問題(筆記本的解決方案)

    PyCharm中白色光標(biāo)通常是虛擬空格功能導(dǎo)致的,可以通過按下Insert鍵或在設(shè)置中取消勾選“Show virtual space at line end”選項(xiàng)來解決
    2025-02-02
  • Python+Turtle繪制一個(gè)可愛的生日蛋糕

    Python+Turtle繪制一個(gè)可愛的生日蛋糕

    每當(dāng)有朋友過生日時(shí),生日蛋糕自然是必不可少的。本文將利用Python中的turtle、math和random繪制一個(gè)可愛的生日蛋糕,需要的可以參考一下
    2022-05-05
  • PyG搭建GCN需要準(zhǔn)備的數(shù)據(jù)格式

    PyG搭建GCN需要準(zhǔn)備的數(shù)據(jù)格式

    這篇文章主要為大家介紹了PyG搭建GCN前需要準(zhǔn)備的PyG數(shù)據(jù)格式,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-05-05
  • Python+OpenCV實(shí)現(xiàn)車牌字符分割和識(shí)別

    Python+OpenCV實(shí)現(xiàn)車牌字符分割和識(shí)別

    這篇文章主要為大家詳細(xì)介紹了Python+OpenCV實(shí)現(xiàn)車牌字符分割和識(shí)別,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-03-03
  • Python虛擬環(huán)境庫virtualenvwrapper安裝及使用

    Python虛擬環(huán)境庫virtualenvwrapper安裝及使用

    這篇文章主要介紹了Python虛擬環(huán)境庫virtualenvwrapper安裝及使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-06-06
  • python之lambda表達(dá)式與sort函數(shù)中的key用法

    python之lambda表達(dá)式與sort函數(shù)中的key用法

    這篇文章主要介紹了python之lambda表達(dá)式與sort函數(shù)中的key用法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • python中not not x 與bool(x) 的區(qū)別

    python中not not x 與bool(x) 的區(qū)別

    這篇文章主要介紹了python中not not x 與 bool(x) 的區(qū)別,我們就來做一個(gè)選擇,就是 not not x 和 bool(x) 用哪個(gè)比較好?下面一起進(jìn)入文章看看吧

    2021-12-12

最新評(píng)論

汝阳县| 清远市| 绥棱县| 甘德县| 阳东县| 梁平县| 长乐市| 三穗县| 时尚| 浏阳市| 安塞县| 定州市| 通道| 凤城市| 永修县| 隆昌县| 澄城县| 米泉市| 汾西县| 延寿县| 宝应县| 龙南县| 四平市| 阿尔山市| 临颍县| 泸溪县| 分宜县| 台东市| 若尔盖县| 高州市| 颍上县| 建宁县| 六盘水市| 兰州市| 和顺县| 汶川县| 金溪县| 石景山区| 正安县| 达尔| 博野县|