機器學習中常見的邏輯回歸和線性回歸,都是線性的,它們簡單高效。 但也有明細缺陷,表達能力弱,無法描述非線性問題。為了擴展它們的表達能力, 通常可以通過非線性地改變輸入φ(x),比如:添加核函數。 設計選擇φ(x)的方法:
使用一個通用的 φ,例如無限維的 φ。 總是有足夠的能力 來擬合訓練集,但是對于測試集的泛化往往不佳。
手動地設計 φ。在深度學習出現以前,這一直是主流的方法, 通常是根據各個領域的問題,設計不同的φ
深度學習的策略是去學習 φ。此時,我們定義函數族 φ(x; θ), 并且使用優化算法來尋找 θ。這種方法可以同時獲得上面兩張方法的好處。
實例:學習 XOR(異或)
線性模型是無法擬合XOR函數的,但是可以通過多層非線性模型來擬合。實例中使用ReLU激活函數來實現非線性變換。基于梯度的學習
神經網絡的非線性導致大多數損失函都變得非凸。但是,用于非凸損失函數的隨機梯度下降不保證收斂性,并且對參數的初始值很敏感。因而對于前饋神經網絡,將所有的權重值初始化為小隨機數是很重要的。偏置則可以初始化為零或者小的正值。
2.1 代價函數
大多數現代的神經網絡使用最大似然來訓練。這意味著代價函數就是負的對數似然,它與訓練數據和模型分布間的交叉熵等價。這個代價函數表示為:
對輸出分布的最大似然估計和對線性模型均方誤差的最小化是等價的
代價函數的梯度必須足夠的大和具有足夠的預測性。飽和(變得非常平)的函數破壞了這一目標,因為它們把梯度變得非常小。這在很多情況下都會發生,因為用于產生隱藏單元或者輸出單元的輸出的激活函數會飽和。很多輸出單元都會包含一個指數函數,這在它的變量取絕對值非常大的負值時會造成飽和。負對數似然代價函數中的對數函數消除某些輸 出單元中的指數效果。
學習條件統計量
使用最小化均方誤差代價函數(L2)將得到一個函數, 它可以用來對每個 x 的值預測出 y 的均值
使用L1的代價函數將得到一個函數可以對每個 x 預測 y 取值的中位數
2.2 輸出單元
2.2.1 用于高斯輸出分布的線性單元
給定特征 h,線性輸出單元層產生一個向量 y? = W?h + b,線性輸出層經常被用來產生條件高斯分布的均值
2.2.2 用于 Bernoulli 輸出分布的 sigmoid 單元:
σ(x) = 1/(1+ e ^-x)
當我們使用其他的損失函數,例如均方誤差之類的,損失函數會在 σ(z) 飽和時飽和。sigmoid 激活函數在 z 取非常小的負值時會飽和到 0,當 z 取非常大的正值時 會飽和到 1。這種情況一旦發生,梯度會變得非常小以至于不能用來學習,無論此模型給出的是正確還是錯誤的答案。因此,最大似然幾乎總是訓練 sigmoid 輸出單元的優選方法。
2.2.3 用于 Multinoulli 輸出分布的 softmax 單元
負對數似然代價函數總是強烈地懲罰最活躍的不正確預測。如果正確答案已經具有了 softmax 的最大輸入,那么 ?zi 項和 log ∑ exp(zj ) ≈ maxj zj = zi j項將大致抵消。這個樣本對于整體訓練代價貢獻很小,這個代價主要由其他未被正確分類的樣本產生。
- 隱藏單元
大多數的隱藏單元都可以描述為接受輸入向量 x,計算仿射變 換 z = W?x + b,然后使用一個逐元素的非線性函數 g(z)。大多數隱藏單元的區別 僅僅在于激活函數 g(z) 的形式。
激活函數:
整流線性單元激活函數: g(z) = max{0, z},優點:計算簡單,梯度不消失,缺點:在 z = 0 處不可微, 不能通過基于梯度的方法學習那些使它們激活為零的樣本。
絕對值整流(absolute value rectification): g(z) = |z|
滲漏整流線性單元:g(z, α)= max(0, z) + αmin(0, z), a是個很小的數,如:0.01
參數化整流線性單元(parametric ReLU)或者 PReLU: g(z, α)= max(0, z) + αmin(0, z),將 α 作為學習的參數。
maxout 單元(maxout unit)
sigmod: σ(x) : x很大或很小的時候梯度飽和, 取值范圍不是0對稱。
雙曲正切函數:g(z)=tanh(z)=2σ(2x)-1 , 取值范圍0對稱
- 架構設計
在這些鏈式架構中,主要的架構考慮是選擇網絡的深度和每一層的寬度。即使只有一個隱藏層的網絡也足夠適應訓練集。更深層的網絡通常能夠 對每一層使用更少的單元數和更少的參數,并且經常容易泛化到測試集,但是通常也更難以優化。
萬能近似定理(universal approximation theorem):一個前饋神經網絡如果具有線性輸出層和至少一層具有任何一種 “擠壓” 性質的激活函數(例如logistic sigmoid激活函數)的隱藏層,只要給予網絡足夠數量的隱藏單元,它可以以任意的精度來近似任何從一個有限維空間到另一個有限維空間的 Borel 可測函數。在 Rn 的有界閉集上的任意連續函數是 Borel 可測的, 因此可以用神經網絡來近似。
總之,具有單層的前饋網絡足以表示任何函數,但是網絡層可能大得不可實現, 并且可能無法正確地學習和泛化。在很多情況下,使用更深的模型能夠減少表示期 望函數所需的單元的數量,并且可以減少泛化誤差。
- 反向傳播和其他的微分算法
反向傳播(back propagation)算法,經常簡稱為backprop,允許來自代價函數的信息通過網絡向后流動, 以便計算梯度。
The chain rule of derivatives tells us how two small effects (that of a small change of x on y, and that of y on z) are composed. A small change Δx in x gets transformed first into a small change Δy in y by getting multiplied by ?y/?x (that is, the definition of partial derivative). Similarly, the change Δy creates a change Δz in z. Substituting one equation into the other gives the chain rule of derivatives — how Δx gets turned into Δz through multiplication by the product of ?y/?x and ?z/?x. It also works when x, y and z are vectors (and the derivatives are Jacobian matrices).
c: The equations used for computing the forward pass in a neural net with two hidden layers and one output layer, each constituting a module through which one can backpropagate gradients. At each layer, we first compute the total input z to each unit, which is a weighted sum of the outputs of the units in the layer below. Then a non-linear function f(.) is applied to z to get the output of the unit. For simplicity, we have omitted bias terms. The non-linear functions used in neural networks include the rectified linear unit (ReLU) f(z) = max(0,z), commonly used in recent years, as well as the more conventional sigmoids, such as the hyberbolic tangent, f(z) = (exp(z) ? exp(?z))/(exp(z) + exp(?z)) and logistic function logistic, f(z) = 1/(1 + exp(?z)).
d: The equations used for computing the backward pass. At each hidden layer we compute the error derivative with respect to the output of each unit, which is a weighted sum of the error derivatives with respect to the total inputs to the units in the layer above. We then convert the error derivative with respect to the output into the error derivative with respect to the input by multiplying it by the gradient of f(z). At the output layer, the error derivative with respect to the output of a unit is computed by differentiating the cost function. This gives yl ? tl if the cost function for unit l is 0.5(yl ? tl) , where tl is the target value. Once the ?E/?zk is known, the error-derivative for the weight wjk on the connection from unit j in the layer below is just yj ?E/?zk