日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CS231n 学习笔记(4)——神经网络 part4 :BP算法与链式法则

發布時間:2025/5/22 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CS231n 学习笔记(4)——神经网络 part4 :BP算法与链式法则 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這一部分主要是關于用BP算法來計算梯度,在這一章中,主要解決下面三個問題:
1.梯度的意義(what the gradients mean?)
2.在網絡中梯度如何通過反向傳播(how they flow backwards in the circuit?)
3.如何調整?( how they communicate which part of the circuit should increase or decrease and with what force to make the final output higher.)

  • 梯度的意義

    梯度的意義與在向量代數中曾經給出,它表示一個函數在某一點變化最快的方向(即方向導數最大值),梯度是一個向量。例如:


    再如,sigmoid函數的梯度:

w = [2,-3,-3] # assume some random weights and data x = [-1, -2]# forward pass dot = w[0]*x[0] + w[1]*x[1] + w[2] f = 1.0 / (1 + math.exp(-dot)) # sigmoid function# backward pass through the neuron (backpropagation) ddot = (1 - f) * f # gradient on dot variable, using the sigmoid gradient derivation dx = [w[0] * ddot, w[1] * ddot] # backprop into x dw = [x[0] * ddot, x[1] * ddot, 1.0 * ddot] # backprop into w # we're done! we have the gradientr circuit
  • 在網絡中梯度如何通過反向傳播

在神經網絡中常用的計算有三種即加法、乘法、取最大(add,mul,max),每一種計算稱為一個gate,經過不同的gate梯度發生的變化如下:

加法:梯度不變
乘法:按照鏈式法則相乘
取最大:對于最大值,乘以1.0,其余乘以0.0

  • 矩陣與矩陣相乘后的梯度求算
import numpy as np W = np.random.randn(5, 10) X = np.random.randn(10, 3) D = W.dot(X)# now suppose we had the gradient on D from above in the circuit dD = np.random.randn(*D.shape) # same shape as D dW = dD.dot(X.T) #.T gives the transpose of the matrix dX = W.T.dot(dD) print W print "#############################" print X print "#############################" print D print "#############################" print dD print "#############################" print dW print "#############################" print dX

總結

以上是生活随笔為你收集整理的CS231n 学习笔记(4)——神经网络 part4 :BP算法与链式法则的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。