激活函数及其导函数图像

import matplotlib.pyplot as plt 
import numpy as np
plt.rcParams["font.family"] = "SimHei"
plt.rcParams['axes.unicode_minus'] = False

sigmoid 函数

x=np.linspace(-10,10,100)
y=1/(1+np.exp(-x))
plt.xlabel("x")
plt.ylabel("y")
plt.title("sigmoid function and its derivative image")
plt.plot(x,y,color='r',label="sigmoid")
y=np.exp(-x)/pow((1+np.exp(-x)),2)
plt.plot(x,y,color='b',label="derivative")
plt.legend()
plt.show()

激活函数及其导函数图像_第1张图片

tanh函数

x=np.linspace(-10,10,100)
y=(1-np.exp(-2*x))/(1+np.exp(-2*x))
plt.xlabel('x')
plt.ylabel('y')
plt.title("Tanh function and its derivative image")
plt.plot(x,y,color='r',label='Tanh')
y=1-pow((1-np.exp(-2*x))/(1+np.exp(-2*x)),2)
plt.plot(x,y,color='b',label='derivative')
plt.legend()
plt.show()

激活函数及其导函数图像_第2张图片

Relu 函数 (分段函数的绘图)

x=np.linspace(-2,2,100)
y=x*(x>0)
plt.xlabel('x')
plt.ylabel('y')
plt.title("Relu function")
plt.plot(x,y,color='r',label="Relu")
plt.legend()

激活函数及其导函数图像_第3张图片

x=np.linspace(-2,0)
y=np.linspace(0,0)
plt.plot(x,y,color='b')

plt.vlines(0, 0, 1, colors = "b")
    
x=np.linspace(0,2)
y=np.linspace(1,1)
plt.title("Relu's derivative image")
plt.plot(x,y,color='b',label="derivative")

plt.legend()
plt.show()

激活函数及其导函数图像_第4张图片

绘制横竖线段

可以使用:
vlines(x, ymin, ymax)
hlines(y, xmin, xmax)
画竖横线段

def Laplacian_Prior(x, u, b):    
    return 1.0/(2*b)*np.exp(-abs(x - u)/b)
 
if __name__ == "__main__":    
    x = np.arange(-10, 10, 0.01)
    y_1 = Laplacian_Prior(x, 0, 1)
    y_2 = Laplacian_Prior(x, 0, 2)
    y_3 = Laplacian_Prior(x, 0, 4)
    y_4 = Laplacian_Prior(x, -5, 4)
    plt.plot(x, y_1, "r-")
    plt.plot(x, y_2, "k-")
    plt.plot(x, y_3, "b-")
    plt.plot(x, y_4, "g-")
    plt.vlines(0, 0, 0.5, colors = "c", linestyles = "dashed")

激活函数及其导函数图像_第5张图片

你可能感兴趣的:(tensorflow与图像处理)