0 目录
便于看着回想
-
Loss Function
cross entropy -
激活函数
sigmoid -
其他
softmax
softmax + cross entropy
1 各种Loss Function及其性质
1.1 cross entropy (交叉熵)
- 注意 y y y和 y ^ \hat{y} y^是向量, y y y是one-hot编码的lable(one-hot label vector), y ^ \hat{y} y^是预测的每个类别的可能性(the predicted probability vector for all classes), y i y_i yi和 y ^ i \hat{y}_i y^i 是向量中的第i个元素。
- 下面交叉熵函数中的log就是ln,有些资料写法不同,但一般没写底数的log就是ln。
对 y ^ i \hat{y}_i y^i 的偏导数:
∂ C E ( y , y ^ ) y ^ i = − y i y ^ i \frac{\partial{CE(y, \hat{y})}}{\hat{y}_i} = - \frac{y_i}{\hat{y}_i} y^i∂CE(y,y^)=−y^iyi
2 激活函数及其性质和导数
2.1 sigmoid
σ ( x ) = 1 1 + e − x \sigma(x) = \frac{1}{1+e^{-x}} σ(x)=1+e−x1
导数(求导非常容易):
σ ′ ( x ) = e − x ( 1 + e − x ) 2 = σ ( x ) ( 1 − σ ( x ) ) \sigma'(x) = \frac{e^{-x}}{(1+e^{-x})^2} = \sigma(x)(1-\sigma(x)) σ′(x)=(1+e−x)2e−x=σ(x)(1−σ(x))
3 其他
3.1 softmax
s o f t m a x ( x i ) = e x i ∑ j e x j softmax(x_i) =\frac{ e^{x_i} }{\sum_j{e^{x_j}}} softmax(xi)=∑jexjexi
导数:softmax和sigmoid其实很像,分子分母同除以 e x i e^{x_i} exi,得到 s o f t m a x ( x i ) = 1 1 + e − x i ∑ j ̸ = i e x j softmax(x_i) =\frac{1}{ 1+ e^{-x_i}\sum_{j \not= i}{e^{x_j}}} softmax(xi)=1+e−xi∑j̸=iexj1 ,这样就很容易看出和sigmoid很像了,所以其对 x i x_i xi的偏导数和sigmoid的导数很像。
∂ s o f t m a x ( x i ) ∂ x i = e − x i ∑ j ̸ = i e x j ( 1 + e − x i ∑ j ̸ = i e x j ) 2 = s o f t m a x ( x i ) ( 1 − s o f t m a x ( x i ) ) \frac{\partial softmax(x_i)}{\partial x_i} =\frac{e^{-x_i}\sum_{j \not= i}{e^{x_j}}}{( 1+ e^{-x_i}\sum_{j \not= i}{e^{x_j}})^2} = softmax(x_i)(1 - softmax(x_i)) ∂xi∂softmax(xi)=(1+e−xi∑j̸=iexj)