文章目录
- 1. Sigmod 函数
- 2. 取值
- 3. 图像
- 4. 导数
1. Sigmod 函数
Sigmod 函数是神经网络中最常用的激活函数之一,其形式如下:
sigmod
(
x
)
=
f
(
x
)
=
1
1
+
e
−
x
.
\text{sigmod}(x) = f(x) = \frac{1}{1 + e^{-x}}.
sigmod(x)=f(x)=1+e−x1.
2. 取值
分析:
(1)当
x
=
0
x=0
x=0 时,
f
(
x
)
=
f
(
0
)
=
1
1
+
e
−
0
=
1
2
.
f(x) = f(0) = \frac{1}{1+e^{-0}} = \frac{1}{2}.
f(x)=f(0)=1+e−01=21.
(2)当
x
→
+
∞
x \to +\infty
x→+∞ 时,
e
−
x
→
0
e^{-x} \to 0
e−x→0,由此
f
(
x
)
→
1
f(x) \to 1
f(x)→1。
(3)当
x
→
−
∞
x \to -\infty
x→−∞ 时,
e
−
x
→
+
∞
e^{-x} \to +\infty
e−x→+∞,由此
f
(
x
)
→
0
f(x) \to 0
f(x)→0。
由此,sigmod 函数的取值范围是 [ 0 , 1 ] [0, 1] [0,1],且单调递增。
3. 图像
我们用 Python 画一画它的图像出来:
实现的 Python 代码如下:
import numpy as np
from matplotlib import pyplot as plt
x = np.linspace(-100, 100, 10000)
y = 1 / (1 + np.exp(-x))
plt.plot(x, y, linestyle='-', color='blue', linewidth=6)
plt.show()
4. 导数
f ′ ( x ) = ( 1 1 + e − x ) ′ = − 1 ( 1 + e − x ) 2 ( 1 + e − x ) ′ = − 1 ( 1 + e − x ) 2 e − x ( − x ) ′ = − 1 ( 1 + e − x ) 2 e − x ( − 1 ) = e − x ( 1 + e − x ) 2 = ( 1 − 1 ) + e − x ( 1 + e − x ) 2 = ( 1 + e − x ) − 1 ( 1 + e − x ) 2 = 1 1 + e − x − 1 ( 1 + e − x ) 2 = f ( x ) − f 2 ( x ) = f ( x ) ( 1 − f ( x ) ) . \begin{aligned} f'(x) &= \left(\frac{1}{1+e^{-x}} \right)' \\ &= - \frac{1}{\left(1+e^{-x}\right)^2} \left(1+e^{-x} \right)' \\ &= - \frac{1}{\left(1+e^{-x}\right)^2} e^{-x} (-x)' \\ &= - \frac{1}{\left(1+e^{-x}\right)^2} e^{-x} (-1) \\ &= \frac{e^{-x}}{\left(1+e^{-x}\right)^2} = \frac{(1-1) + e^{-x}}{\left(1+e^{-x}\right)^2} = \frac{(1 + e^{-x}) -1}{\left(1+e^{-x}\right)^2} \\ &= \frac{1}{1 + e^{-x}} - \frac{1}{\left(1 + e^{-x}\right)^2} \\ &= f(x) - f^2(x) \\ &= f(x) \left(1-f(x) \right). \end{aligned} f′(x)=(1+e−x1)′=−(1+e−x)21(1+e−x)′=−(1+e−x)21e−x(−x)′=−(1+e−x)21e−x(−1)=(1+e−x)2e−x=(1+e−x)2(1−1)+e−x=(1+e−x)2(1+e−x)−1=1+e−x1−(1+e−x)21=f(x)−f2(x)=f(x)(1−f(x)).
即: f ′ ( x ) = f ( x ) ( 1 − f ( x ) ) f'(x) = f(x) \left(1-f(x) \right) f′(x)=f(x)(1−f(x))。