상태: deep learning
참고 서적: https://wikidocs.net/book/2155
Basic of Deep Learning
- Perceptron
- 초기 형태의 인공신경망이다. 다수의 입력으로 하나의 결과를 보내는 알고리즘이다. 실제 뇌를 구성하는 신경세포의 뉴런과 유사한 동작을 보인다. 뉴런은 가지돌기를 통해서 신호를 받고 이 신호가 일정치 이상의 크기를 가지면 축삭돌기를 통해서 신호를 다른 뉴런으로 전달한다. 신호를 받는 것을 입력 값, 일정 신호를 받아 신호를 보내는 것을 가중치(W), 출력값이라고 표현한다. 밑에 그림에서 각각의 인공 뉴런에서 보내진 입력값 x는 가중치와 함께 y로 보내진다. 각각의 입력값은 각각의 가중치가 존재하는데 이때 가중치가 크면 클수록 해당 입력값이 중요한 값이라는 것을 의미한다. 입력값은 가중치와 함께 곱해져서 인공뉴런으로 보내지고 가중치의 곱의 전체 합이 threshold(임계치)를 넘으면 종착지의 인공 뉴련은 출력 신호로 1일 출력, 그렇지 않으면 0을 출력한다. 이때 뉴런에서 출력값을 변경시키는 함수를 활성화 함수라고 한다. sigmoid나 softmax도 활성함수 중 하나이다.
- logistic regression은 하나의 인공 뉴런으로 볼 수 있다.
- Single-Layer Perceptrn
- 위에서 살펴본 perceptron이 single-layer perceptron이다. 이는 값을 보내는 단계와 값을 출력하는 단계로 이루워져 있다. 이때 단계를 layer라고 한다.
- 단층으로는 AND, OR, NAND gate는 구현할 수 있지만, XOR gate는 구현할 수 없다. 단층은 직선 하나로 두 영역을 나눌 수 있을 때에만 가능하기 때문이다. XOR의 경우 선형영역에서만 분리하여 구현이 가능하다.
- MultiLayer Perceptron, MLP
- XOR은 AND, OR, NAND를 조합해서 구현할 수 있다. 즉, 층을 더 쌓으면 구현할 수 있다. 다층 퍼셉트론의 경우 입력층과 출력층 사이에 층을 더 추가한 것인데 이를 은닉층(hidden layer)라고 부른다. XOR보다 더 복잡한 문제를 해결하기 위해서는 hidden layer를 더 추가할 수 있다. 이때 은닉층이 2개 이상인 경우를 심층 신경망(Deep Neural Network, DNN)이라고 부른다.
- 기계가 가중치를 스스로 찾아내도록 자동화 시키는데 이를 학습(training)이라고 부른다. 학습을 시키는 인공신경망이 심층 신경망일 경우에는 이를 심층 신경망을 학습시킨다고 하여, Deep Learning이라고 부른다.
- 입력층에서 출력층으로 연산이 전개되는 것을 Feed- Forward Neural Network라고 부른다. 별도로 이름을 가지는 이유는 feed forward가 아닌 신경망이 있기 때문이다.
Explore Artificial Neural Network
- Fully-connected layer, FC, Dense layer
- 어떤 층의 모든 뉴런들이 이전 층의 모든 뉴런들과 연결되어 있는 것을 의미한다. 전결합층으로만 이루어진 feed forward 신경망이 있다면 이를 Fully-connected FFNN)이라고 부른다.
- Activation Function
- 앞서 예시에서는 step function을 통해 출력값이 0이 될지 1이 될지 결정하였다.
- 이러한 매커니즘은 실제 뇌를 구성하는 신경 세포 뉴런이 전위가 일정치 이상이 되면 시냅스가 서로 화학적으로 연결되는 모습을 모방한 것이다. 이렇게 은닉층과 출력층의 뉴런에서 출력값을 결정하는 함수를 활성화 함수(Activation function)라고 하는데 계단 함수는 이러한 활성화 함수의 하나의 예제에 불과하다.
- Nonlinear Function
- Activation funtion은 Nonlinear(비선형)여야 한다. 이는 그래프를 그릴 때 직선 하나로 그릴 수 없는 함수를 의미한다. 인공 신경망의 능력을 높이기 위해서는 hidden layer을 계속해서 추가해야 하며 이때비선형 함수를 사용해야 한다. 선형함수로는 hidden layer를 추가할 수 없다.
- Sigmoid Function위 이미지는 인공 신경망은 입력에 대해서 순전파(forward propagation) 연산을 하고, 그리고 순전파 연산을 통해 나온 예측값과 실제값의 오차를 손실 함수(loss function)을 통해 계산하고, 그리고 이 손실(loss)을 미분을 통해서 기울기(gradient)를 구하고, 이를 통해 역전파(back propagation)를 수행한다. 이때 sigmoid 함수를 사용하는데 미분을 해서 기울기를 구할 때 sigmoid 함수의 경우 기울기 소실 문제가 발생한다. 주황색 부분의 경우 기울기가 0에 가까운 수이고 이 기울기가 back propagation 과정에서 이 기울기가 곱해진다면 0에 가깝기 때문에 앞단에 제대로 전달이 안될 수 있다.
- Hyperbolic tangent function-1 ~ 1에 가까운 값을 출력하는데 이는 앞에 나온 sigmoid와 비슷한 문제를 가진다. sigmoid와의 차이점은 0을 중심으로 하고 있으며 이로 인해 sigmoid에 비해 반환값의 변화폭이 더 크다. 그래서 시그모이드 함수보다는 기울기 소실 증상이 적은 편이다. 은닉층에서 시그모이드 함수보다는 많이 사용된다.
- ReLU이는 음수이면 0을, 양수이면 입력값을 그대로 반환한다. 특정 양수값에 수렴하지 않기에 sigmoid보다 더 잘 작동하고, 단순 임계값이기 때문에 빠르다. 문제는 입력값이 음수이면 기울기도 0이 되기에 이 뉴런을 회생하는 것은 어렵다. 이러한 문제를 해결하기 위해 다양한 변형 함수가 나왔으며 그 중 하나가 leaky ReLU이다. 이는 음수일 경우에 0이 아니라, 0.01과 같이 매우 작은 수를 반환한다. 입력값이 음수여도 기울기가 0이 되지 않는다. a는 하이퍼파라미터로 입력값의 음수일 때의 기울기를 결정한다.
- $$f(x) = max(ax, x)$$
- $$f(x) = max(0, x)$$
- Softmax @주환 김softmax는 분류해야 하는 정답지(class)의 총 개수를 k라고 할 때 k차원의 백터를 입력받아 각 class에 대한 확률을 구한다. 위에 식에서 p1은 첫번째 class가 정답일 확률, p2는 두번째 class가 정답일 확률이다. 각각은 0~1사이 값을 가지며 총 합은 1이 된다.
- $$softmax(z)=[\frac{e^{z_{1}}}{\sum_{j=1}^{3} e^{z_{j}}}\ \frac{e^{z_{2}}}{\sum_{j=1}^{3} e^{z_{j}}}\ \frac{e^{z_{3}}}{\sum_{j=1}^{3} e^{z_{j}}}] = [p_{1}, p_{2}, p_{3}] = \hat{y} = \text{예측값}$$