Advanced Gradient Descent Method (고급 경사 하강 법)

https://t1.daumcdn.net/cfile/tistory/250F1F3C562B96BD27

출처 : http://imgur.com/a/Hqolp

위에서 소개된 그림은 특정한 landscape에서의 각각의 optimizer들의 학습 속도를 표현 한 것이다. 보기에는 Adadelta가 최고인가하고 생각 할 수 있겠지만, 문제 상황에 따라 잘하는 경우도 있고, 못하는 경우도 있으므로 문제 상황에 맞게 잘 선택해야한다.

https://t1.daumcdn.net/cfile/tistory/222B4F4F562BD0330E

출처 : http://imgur.com/a/Hqolp

위의 이미지는 특히 Rmsprop와 Adagrad가 좋은 성능을 보인다. 뉴럴넷의 W와 같은 고차원의 공간에서는 이러한 saddle point가 매우 많아 문제가 되는 것으로 알려져있다. 따라서 이 두가지 옵티마이저를 선택하는 것은 좋은 방법이다.

요즘에는 Adam이라는 optimizer가 기본으로 쓰는 경우가 많고, 경우에 따라 non-stationary가 심한 문제(강화학습 등)에서 RMSprop를 선택하는 경우가 많다.

GD (Gradient Descent): GD는 가장 기본적은 뉴럴넷의 학습 방법으로, 전체 데이터에 대한 Error함수를 Weight로 미분하여 계산한 각 W 파라미터에 대한 gradient를 이용하여 Weight를 업데이트한다. 이 때 얼만큼의 gradient를 사용할지 결정하는 값을 learning rate라고 하는데, 이 값에 따라 local minima에 빠지거나 발산하는 경우가 있다. 또한 전체 데이터에 대한 계산을 한 뒤에 W를 업데이트하기 때문에, 계산량이 너무커 W가 optimal을 찾아가는 속도가 느려 현재는 거의 쓰이지 않고 있다. Batch Learning이라고도 부른다. 또한 gradient descent는 기울기가 양수(+)이면 w를 음수(-)방향으로 이동시켜야 하므로, 기울기의 반대 부호로 움직인다고 볼 수 있다.

W' = W − λ f'(W)     ( λ 는 learning rate이다.)

SGD (Stochastic Gradeint Descent): SGD는 위에서 GD가 갖는 너무 큰 계산량 문제를 해결하기 위해 전체 데이터중에서 랜덤하게 추출한 1/N의 데이터만을 사용해 훨씬 더 빠르게, 자주 업데이트하는 방법이다. 이 때 추출한 1/N의 데이터를 Minibatch라고 부르며, 이 데이터가 전체 데이터의 분포를 따라야만 제대로 된 학습이 가능하다. 만약 이 데이터가 전체 데이터의 분포를 따르지 않고, 계속 분포가 바뀌는 non-stationary한 경우를 online learning이라고도 부른다.

전체 데이터를 잘 섞어서, 너무 작지 않은 크기로 N 등분하면, 계산량이 1/N 배가되어, 빠르게 Weight를 업데이트할 수 있어, 이론상 N배 더 빠른 학습이 가능하다.

추후 SGD에서 각 Minibatch 분포가 매번 약간씩 달라지는 noise를 internal covariate shift라고 부르며, 이를 해결하기 위한 방법으로 batch-normalization이 등장한다.

Downpour SGD: Downpour SGD는 DistBelif라는 구글의 모델, 데이터 병렬화 학습 모델에서 소개된 방법이다. 간단히 말하면 여러개로 모델을 쪼개어, 여러개의 머신에서 동시에 학습을 하는데 이 때 여러 모델들에서 계산된 gradient를 평균내서 각각의 모델에 적용하는 방법이다. 이렇게 해도 충분히 전체 데이터와 모델에 대한 근사적인 학습이 가능하다고 하다.

http://static.googleusercontent.com/media/research.google.com/ko//archive/large_deep_networks_nips2012.pdf

Per-dimension learning rate: 이 원리는 Momentum 및 기타 여러 advanced optimizer들의 핵심을 관통하는 개념이다. 짧게 설명하자면 각각의 차원마다 서로 다른 learning rate를 사용해야만 더 빠르게 saddle point를 벗어날 수 있다는 것이다. 예를 saddle point에서 long narrow valley 방향으로의 gradient값은 매우 작지만, 이쪽 방향으로 빨리, 많이 학습해야만 이 saddle point를 벗어날 수가 있다. 따라서 이쪽 방향으로의 learning rate는 커야한다. 이러한 개념은 아래 소개되는 advanced method에서 공통적으로 통하는 개념이다.

자세한 내용은 아래 글 참고하기 바란다.

The heuristic annealing procedure discussed above modifies a single global learning rate that applies to all dimensions of the parameters. Since each dimension of the parameter vector can relate to the overall cost in completely different ways, a per-dimension learning rate that can compensate for these differences is often advantageous. When gradient descent nears a minima in the cost surface, the parameter values can oscillate back and forth around the minima. One method to prevent this is to slow down the parameter updates by decreasing the learning rate. This can be done manually when the validation accuracy appears to plateau. This gives a nice intuitive improvement over SGD when optimizing difficult cost surfaces such as a long narrow valley. The gradients along the valley, despite being much smaller than the gradients across the valley, are typically in the same direction and thus the momentum term accumulates to speed up progress. In SGD the progress along the valley would be slow since the gradient magnitude is small and the fixed global learning rate shared by all dimensions cannot speed up progress. These oscillations are mitigated when using momentum because the sign of the gradient changes and thus the momentum term damps down these updates to slow progress across the valley.

Momentum: 모멘텀은 저렴한 2차 최적화방법(cheap second order optimizer)라고도 불리우는 방법으로 구현과 원리가 매우 간단하면서 어느정도 좋은 성능을 내는 것으로 알려져 있다. 원리는 sgd에서 새로 계산된 gradient를 바로 사용하는 대신, 한 스텝 전의 gradient를 일정한 %만큼 반영하여 새로 계산된 gradient와 합해서 사용하는 것이다. 즉 원래의 gradient를 일정 부분 유지하면서 새로운 gradient를 적용하여, 관성 모멘트같은 효과(속도가 존재)를 주는 방식이다. 이를 통해 local minima를 더 빨리 빠져나올 수 있다. 그리고 결국 이 모멘텀에는 과거의 모든 gradient가 계속해서 일정한 %씩 누적되어 있게 된다.