이름 그대로 위의 perceptron을 multi-layer 쌓아서 적층한 구조. 각 layer에서 다음 layer로 넘어가는 과정에서 non-linear function을 통과하니, 이때 점차 model에 non-linearity가 생김. 따라서 이러한 구조가 3층이상으로 깊게 쌓이면 Deep-Neural-Network이라 함.
SIMD(Single Instruction Multiple Data)
—
여러 개의 data를 vector 형식으로 묶어서 처리하자!
**
파이썬으로 구현해보기!
Perceptron
class Perceptron(): def __init__(self, num_features): self.num_features = num_features self.weights = np.zeros((num_features, 1), dtype=float) self.bias = np.zeros(1, dtype=float) def forward(self, x): # $\hat{y} = xw + b$ linear = np.dot(x, self.weights) + self.bias # comp. net input # train에서 보면, y[i] 차원으로 데이터가 들어오니, vec * vec 연산. # linear = x @ self.weights + self.bias predictions = np.where(linear > 0., 1, 0) # step function - threshold return predictions # 'ppp' exercise def backward(self, x, y): # pred랑 ground_truth 값 비교. return y - self.forward(x) # 중간 중간 reshape이 과연 필요할까? def train(self, x, y, epochs): for e in range(epochs): for i in range(y.shape[0]): errors = self.backward(x[i].reshape(1, self.num_features), y[i]).reshape(-1) self.weights += (errors * x[i]).reshape(self.num_features, 1) self.bias += errors def evaluate(self, x, y): predictions = self.forward(x).reshape(-1) accuracy = np.sum(predictions == y) / y.shape[0] return accuracy