$ y = \begin{cases}0 \;if\;b + w_1x_1 + w_2x_2 <= 0\\ 1 \;if\; b + w_1x_1 + w_2x_2 > 0\end{cases} $
$ y = h(b + w_1x_1 + w_2x_2) $
$ h(x) = \begin{cases}0 \;if\;x <= 0\\ 1 \;if\; x > 0\end{cases} $
$h(x) = \frac{1}{1 + exp(-x)}$
import numpy as np
x = np.array([-1.0, 1.0, 2.0])
print(x)
y = x > 0
y = y.astype(np.int64)
print(y)
[-1. 1. 2.] [0 1 1]
import numpy as np
import matplotlib.pylab as plt
def step_function(x):
return np.array(x > 0, dtype=np.int64)
x = np.arange(-5.0, 5.0, 0.1)
y = step_function(x)
plt.plot(x, y)
plt.ylim(-0.1, 1.1)
plt.show()
# sigmoid function
def sigmoid(x):
return 1 / (1 + np.exp(-x))
x = np.array([-1.0, 1.0, 2.0])
print(sigmoid(x))
[0.26894142 0.73105858 0.88079708]
🔽 Sigmoid function graph
x = np.arange(-5.0, 5.0, 0.1)
y = sigmoid(x)
plt.plot(x, y)
plt.ylim(-0.1, 1.1)
plt.show()
🔽 step function과 sigmoid function의 차이
🔽 step function과 sigmoid function의 공통점
def relu(x):
return np.maximum(0, x)