深度学习:激活函数

sigmoid函数

绘制sigmoid函数图像

import numpy as np
import matplotlib.pylab as plt

def sigmoid(x):
    return 1 / (1 + np.exp(-x))
x = np.arange(-5.0,5.0,0.1)
y = sigmoid(x)
plt.plot(x,y)
plt.ylim(-0.1,1.1)
plt.show()

Relu函数

import numpy as np
import matplotlib.pylab as plt

def sigmoid(x):
    return 1 / (1 + np.exp(-x))
def relu(x):
    return np.maximum(0,x)

x = np.arange(-5.0,5.0,0.1)
y1 = sigmoid(x)
y2 = relu(x)
plt.plot(x,y1,label = "sigmoid")
plt.plot(x,y2,label = "relu")
plt.xlabel("x")
plt.ylabel("y")
plt.ylim(-0.1,1.1)
plt.legend()
plt.show()

Relu函数图像:

 

 

posted @ 2022-05-11 19:19  破忒头头  阅读(36)  评论(0)    收藏  举报