#relu激活函数
from matplotlib import pyplot
import numpy as np
def relu(x):
if x > 0:
return x
else:
return 0
def func():
x = np.arange(-5,5,0.02)
y = []
for i in x:
yi = relu(i)
y.append(yi)
pyplot.xlabel("x")
pyplot.ylabel("y")
pyplot.title("relu")
pyplot.plot(x,y)
pyplot.show()
func()
#leakyrelu
from matplotlib import pyplot
import numpy as np
def leakyrelu(x):
if x > 0:
return x
else:
return x*0.1
def func():
x = np.arange(-5,5,0.02)
y = []
for i in x:
yi = leakyrelu(i)
y.append(yi)
pyplot.xlabel("x")
pyplot.ylabel("y")
pyplot.title("leakyrelu")
pyplot.plot(x,y)
pyplot.show()
func()
#tanh
from matplotlib import pyplot
import numpy as np
x = np.arange(-5,5,0.02)
y = (np.exp(x) - np.exp(-x)) / (np.exp(x) + np.exp(-x))
pyplot.xlabel("x")
pyplot.ylabel("y")
pyplot.title("tanh")
pyplot.plot(x,y)
pyplot.show()
from matplotlib import pyplot as plt
import numpy as np
x = np.arange(-5,5,0.02)
y = 1 / (1 + np.exp(-x))
plt.xlabel("x")
plt.ylabel("y")
plt.title("sigmoid")
plt.plot(x,y)
plt.show()