赞
踩
s t e p ( x ) = { 1 i f x > 0 0 i f x ≤ 0 step(x) = {1ifx>00ifx≤0 step(x)={1ifx>00ifx≤0
import numpy as np
def step_function(x):
return np.array(x > 0, dtype=np.int)
s i g m o i d ( x ) = 1 1 + e − x sigmoid(x) = \frac{1}{1 + e^{-x}} sigmoid(x)=1+e−x1
y的取值范围 ( 0 , 1 ) (0, 1) (0,1)
import numpy as np
def sigmoid(x):
return 1. / (1 + np.exp(-x))
t a n h ( x ) = e x − e − x e x + e − x tanh(x)=\frac{e^x-e^{-x}}{e^x+e^{-x}} tanh(x)=ex+e−xex−e−x
import numpy as np
def tanh(x):
return (np.exp(x) - np.exp(-x)) / (np.exp(x) + np.exp(-x))
sigmoid和tanh具有共同的缺陷,即:在x很大或者很小时,梯度几乎为0,因此使用梯度下降的优化算法更新网络会很慢。
也正因为这个缺陷,ReLu成为目前大多数神经网络的默认选择。
R e L u ( x ) = { x i f x > 0 0 i f x ≤ 0 ReLu(x) = {xifx>00ifx≤0 ReLu(x)={xifx>00ifx≤0
import numpy as np
def relu(x):
return np.maximum(0, x)
ReLu的缺点:当 x < 0 x<0 x<0时,斜率即导数为0,因此引申出leaky relu函数,但是实际上leaky relu使用的并不多。
L R e L u ( x ) = { 0.01 x i f x < 0 x i f x ≤ 0 LReLu(x)={0.01xifx<0xifx≤0 LReLu(x)={0.01xifx<0xifx≤0
import numpy as np
def LReLu(x):
return maximum(0.01 * x, x)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。