日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

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

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

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

  • 梯度的意義

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


    再如,sigmoid函數(shù)的梯度:

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
  • 在網(wǎng)絡中梯度如何通過反向傳播

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

加法:梯度不變
乘法:按照鏈式法則相乘
取最大:對于最大值,乘以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算法与链式法则的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。