常用的激活函数
1.階躍函數(shù)
,值域{0,1}
1 def step_function(x): 2 return np.array(x>0,dtype=np.int)2.sigmoid函數(shù)
,值域(0,1)
1 def sigmoid(x): 2 return 1/(1+np.exp(-x))3.relu函數(shù)
,值域[0,+∞)
1 def relu(x): 2 return np.maximum(0,x)4.leaky relu函數(shù)
,值域R
1 def leaky_relu(x): 2 value = [i if i >= 0 else 0.01*i for i in x] 3 return np.array(value)5.tanh函數(shù)
,值域(-1,1)
1 def tanh(x): 2 e_a = np.exp(-2*x) 3 y=(1-e_a)/(1+e_a) 4 return y?
6.softmax函數(shù)
,值域[0,1]
1 def softmax(x): 2 e_a = np.exp(x) 3 sum_e_a = np.sum(e_a) 4 y=e_a/sum_e_a 5 return y 6 #或者,考慮可能出現(xiàn)內(nèi)存溢出問題,減去一個常數(shù) 7 def softmax(x): 8 c=np.max(x) 9 e_a = np.exp(x-c) 10 sum_e_a = np.sum(e_a) 11 y=e_a/sum_e_a 12 return y7.畫圖程序
1 x=np.arange(-5,5,0.1) 2 y=softmax(x)#可替換為其它函數(shù) 3 plt.plot(x, y) 4 plt.ylim(-1.1, 1.1) 5 plt.show()?
轉(zhuǎn)載于:https://www.cnblogs.com/little-horse/p/11241508.html
總結(jié)
- 上一篇: 用了农行信用卡消费备用金影响提额吗?备用
- 下一篇: 今天刚查到的宏,学习