在神經網絡中,sigmoid和tanh分別是兩個激活函數,用在每個layer輸出的時候。
這里對這個兩個激活函數做出比較,首先,將兩個函數圖像畫到一張圖上面來:

sigmod函數: sigmod(a)=1/(1+exp(-a))
tanh函數(正切三角函數),可寫成是sigmod函數的一種變形:tanh(a)=2sigmod(2a)-1,因此tanh函數的一般線性組合可寫成sigmod函數的一般線性組合。
比較這兩個函數:
相較於tanh函數,sigmod有一點缺陷,觀察兩條曲線,可以看出在sigmod函數處於[-1,1]之間的時候,隨着x的變化,函數的變化敏感,但是一旦接近或者超出這個區間,sigmod函數就失去了敏感性,處於一種飽和狀態,影響神經網絡預測的精度值。
而tanh的輸入和輸出能夠保持非線性單調上升和下降關系,符合BP網絡的梯度求解,容錯性好,有界,漸進與0,1,符合人腦神經飽和的規律,但比sigmod函數延遲了飽和期。
在這方面看來tanh函數比sigmod具有優越性。
參考文獻:李曦,《神經網絡信息傳輸函數sigmoid與tanh比較論證》,武漢理工大學學報,2004.
Sigmoid
說到sigmoid函數,下面就來談一談sigmoid函數對gradient vanishing(梯度消失)的影響。
假設損失函數為C, 那么根據參數的梯度算法,前面層的梯度值等於后面層上面梯度的乘積,舉例說假如有三個隱藏層,那么第一個隱藏層的梯度就等於C對output層的梯度乘以之前每一層的后一層對這一層的梯度。
這里可以參考這個總結:http://blog.csdn.net/cppjava_/article/details/68941436
然后我們發現,由於:
1.通常來說層跟層之前的參數w小於1.
2.sigmod函數的梯度的最大絕對值不超過0.25.
下圖為sigmoid 函數與其梯度函數,可以看出其梯度的最大值為0.25

所以,一步步的梯度傳輸,會使得越靠近input層的神經元上參數的梯度越小,也就是對於越靠近輸入層的參數,more knowledge from the data will be ‘lost’. 即使我們在輸出層得到了big errors, 也無法對內層的參數造成很大的影響。------這便稱為gradient vanishing,也就是說,使用sigmoid做激活函數會引起梯度消失。
Rectified Linear Units
在深度學習結構中,ReLUs 被經常用於中間隱藏層。(我認為是因為,根據它的梯度ReLUs不會像sigmoid函數那樣出現梯度消失的情況)
ReLUs的表達式如下,當小於0時候為0,大於0時候為本身不變(注意它仍舊是一個非線性函數):

可以看出它是一個非常簡單的激活函數,當input大於0時候,其梯度為1,故它不會對靠近input層的參數造成梯度消失。並且研究表明,ReLUs激活函數對結構龐大的神經網絡訓練速度很快。
不過,任何事物都有它的兩面性,ReLUs也有其不好的地方:
Unfortunately, ReLU units can be fragile during training and can "die". For example, a large gradient flowing through a ReLU neuron could cause the weights to update in such a way that the neuron will never activate on any datapoint again. If this happens, then the gradient flowing through the unit will forever be zero from that point on. That is, the ReLU units can irreversibly die during training since they can get knocked off the data manifold. For example, you may find that as much as 40% of your network can be "dead" (i.e. neurons that never activate across the entire training dataset) if the learning rate is set too high. With a proper setting of the learning rate this is less frequently an issue.
轉自:https://github.com/Kulbear/deep-learning-nano-foundation/wiki/ReLU-and-Softmax-Activation-Functions
Softmax
所以對於一個observation來說,哪一個類別的概率最大相當於它激活了這個類別。故softmax多用於分類問題(多至上百成千類別)。
轉自:https://github.com/Kulbear/deep-learning-nano-foundation/wiki/ReLU-and-Softmax-Activation-Functions
