3.4 参数展开-机器学习笔记-斯坦福吴恩达教授
生活随笔
收集整理的這篇文章主要介紹了
3.4 参数展开-机器学习笔记-斯坦福吴恩达教授
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
參數(shù)展開(Unrolling Parameters)
在神經(jīng)網(wǎng)絡(luò)的學(xué)習(xí)過程中,我們的工作對象面臨的是一些矩陣:
Θ(1),Θ(2),Θ(3),...Θ^{(1)},Θ^{(2)},Θ^{(3)},...Θ(1),Θ(2),Θ(3),...D(1),D(2),D(3),...D^{(1)},D^{(2)},D^{(3)},...D(1),D(2),D(3),...
這對于編程里面一些的 API 是不友善的,例如 matlab 或者 octave 的 fminunc() 方法,scipy 中的 minimize 方法等,這些方法都支持傳遞代價函數(shù) costFunctioncostFunctioncostFunction ,但是代價函數(shù)只支持傳遞向量作為參數(shù),因此,我們需要先將矩陣元素平鋪開為一個長向量:
matlab 中展開:
thetaVector = [ Theta1(:); Theta2(:); Theta3(:); ] deltaVector = [ D1(:); D2(:); D3(:) ]python 中展開:
import numpy as np # ... thetaVector = np.r_[Theta1.reshape(-1,1), Theta2.reshape(-1,1), Theta3.reshape(-1,1)] deltaVector = np.r_[ D1.reshape(-1,1), D2.reshape(-1,1), D3.reshape(-1,1) ]假定:
Θ(1)∈R10×11,Θ(2)∈R10×11,Θ(3)∈R1×11Θ^{(1)}∈R^{10×11},Θ^{(2)}∈R^{10×11},Θ^{(3)}∈R^{1×11}Θ(1)∈R10×11,Θ(2)∈R10×11,Θ(3)∈R1×11
matlab 中還原:
Theta1 = reshape(thetaVec(1:110),10,11) Theta2 = reshape(thetaVec(111:220),10,11) Theta3 = reshape(thetaVec(221:231),1,11)python 中還原:
import numpy as np # ... Theta1 = thetaVec[0:110].reshape(10,11) Theta2 = thetaVec[110:220].reshape(10,11) Theta3 = thetaVec[220:231].reshape(1,11)總結(jié)
以上是生活随笔為你收集整理的3.4 参数展开-机器学习笔记-斯坦福吴恩达教授的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 3.3 前向传播与反向传播-机器学习笔记
- 下一篇: 3.5 梯度校验-机器学习笔记-斯坦福吴