BP神經網路 如何進行權值的初始化
阿新 • • 發佈:2018-11-08
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow
也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!
如果以面向物件(OOP)的方式進行BP神經網路系統的設計與實踐的話,因為權值的初始化以及類的構造都只進行一次(而且發生在整個流程的開始階段)
np.random.randn(shape)
)進行初始化,也即:
class Network(object): # topology:表示神經網路拓撲結構,用list或者tuple來實現, # 比如[784, 30, 10],表示784個神經元的輸入層,30個neuron的隱層,以及十個neuron的輸出層 def __init__(self, topology): self.topology = topology self.num_layers = len(topology) self.biases = [np.random.randn(y, 1) for y in topology[1:]] self.weights = [np.random.randn(y, x) for x, y in zip(self.weights[:-1], self.weights[1:])]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
我們不妨以一個簡單的具體例子,分析這種初始化方法可能存在的缺陷,如下圖所示:
為了簡化問題,我們只以最左一層向中間一層的第一個神經元(neuron)進行前向(forward)傳遞為例進行分析,假設一個輸入樣本(特徵向量, ,其形式如下:
相關程式碼:
def default_weight_init(self): self.biases = [np.random.randn(y, 1)/y for y in self.topology[1:]] self.weights = [np.random.rand(y, x)/np.sqrt(x) for x, y in zip(self.topology[:-1], self.topology[1:])]def large_weight_init(self): self.biases = [np.random.randn(y, 1) for y in self.topoloy[1:]] self.weights = [np.random.randn(y, x)/np.sqrt(x) for x, y in zip(self.topology[:-1], self.topology[1:])]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
我們看到正是這樣一種np.random.randn(y, x)
向np.random.randn(y, x)/np.sqrt(x)
小小的改變,卻暗含著豐富的概率論與數理統計的知識,可見無時無刻無處不體現著數學工具的強大。