Graph
In [1]:
Copied!
# plot common activation functions
import numpy as np
import matplotlib.pyplot as plt
# plot common activation functions
import numpy as np
import matplotlib.pyplot as plt
In [7]:
Copied!
# sigmoid function
def sigmoid(x):
return 1 / (1 + np.exp(-x))
# tanh function
def tanh(x):
return np.tanh(x)
# ReLU function
def ReLU(x):
return np.maximum(0, x)
# Leaky ReLU function
def Leaky_ReLU(x):
return np.maximum(0.01 * x, x)
x = np.linspace(-10, 10, 100)
def set_plot(name: str):
plt.figure()
plt.title(name)
plt.xlabel("x")
plt.ylabel("y")
plt.grid()
plt.axhline(y=0, color="k")
plt.axvline(x=0, color="k")
# plot sigmoid
set_plot("sigmoid")
plt.plot(x, sigmoid(x), label="sigmoid")
plt.savefig("imgs/sigmoid.png")
# plot tanh
set_plot("tanh")
plt.plot(x, tanh(x), label="tanh")
plt.savefig("imgs/tanh.png")
# plot ReLU
set_plot("ReLU")
plt.plot(x, ReLU(x), label="ReLU")
plt.savefig("imgs/ReLU.png")
# plot Leaky ReLU
set_plot("Leaky ReLU")
plt.plot(x, Leaky_ReLU(x), label="Leaky ReLU")
plt.savefig("imgs/Leaky_ReLU.png")
# sigmoid function
def sigmoid(x):
return 1 / (1 + np.exp(-x))
# tanh function
def tanh(x):
return np.tanh(x)
# ReLU function
def ReLU(x):
return np.maximum(0, x)
# Leaky ReLU function
def Leaky_ReLU(x):
return np.maximum(0.01 * x, x)
x = np.linspace(-10, 10, 100)
def set_plot(name: str):
plt.figure()
plt.title(name)
plt.xlabel("x")
plt.ylabel("y")
plt.grid()
plt.axhline(y=0, color="k")
plt.axvline(x=0, color="k")
# plot sigmoid
set_plot("sigmoid")
plt.plot(x, sigmoid(x), label="sigmoid")
plt.savefig("imgs/sigmoid.png")
# plot tanh
set_plot("tanh")
plt.plot(x, tanh(x), label="tanh")
plt.savefig("imgs/tanh.png")
# plot ReLU
set_plot("ReLU")
plt.plot(x, ReLU(x), label="ReLU")
plt.savefig("imgs/ReLU.png")
# plot Leaky ReLU
set_plot("Leaky ReLU")
plt.plot(x, Leaky_ReLU(x), label="Leaky ReLU")
plt.savefig("imgs/Leaky_ReLU.png")
In [ ]:
Copied!