본문 바로가기

Machine Learning

Bias term의 필요성

반응형

Q
I'm aware of the Gradient Descent and the Back-propagation Theorem. What I don't get is: When is using a bias important and how do you use it?
For example, when mapping the AND function, when I use 2 inputs and 1 output, it does not give the correct weights, however, when I use 3 inputs (1 of which is a bias), it gives the correct weights.

A
I think that biases are almost always helpful. In effect, a bias value allows you to shift the activation function to the left or right, which may be critical for successful learning.
It might help to look at a simple example. Consider this 1-input, 1-output network that has no bias:

The output of the network is computed by multiplying the input (x) by the weight (w0) and passing the result through some kind of activation function (e.g. a sigmoid function.)
Here is the function that this network computes, for various values of w0:

Changing the weight w0 essentially changes the "steepness" of the sigmoid. That's useful, but what if you wanted the network to output 0 when x is 2? Just changing the steepness of the sigmoid won't really work -- you want to be able to shift the entire curve to the right.
That's exactly what the bias allows you to do. If we add a bias to that network, like so:    

...then the output of the network becomes sig(w0*x + w1*1.0). Here is what the output of the network looks like for various values of w1:

Having a weight of -5 for w1 shifts the curve to the right, which allows us to have a network that outputs 0 when x is 2.






번외
bias가 w_0를 의미하시는 것이지요?

활성화 함수가 ReLU인 경우(그러니까 입력이 0이면 출력이 0인 활성화 함수의 경우)의 예를 들어서 설명 드리자면, 만약 bias가 없다면 y=3x+7 같은 함수를 근사시키는 것이 불가능해집니다.

조금 더 나아가자면 입력 vector가 모두 0으로 구성되어 있다면 출력 vector는 무조건 전부 0이 될 수 밖에 없게 됩니다. 

그래서 (... 이것을 좀 더 일반화 해서 생각해 보면) bias가 꼭 필요합니다.




정리
bias가 없을때 critical문제가 발생하는 구간은 크게 2가지를 생각할 수 있다.
input이 0인경우, output이 0인 경우이다.
bias가 없는 신경망을 구성할 때를 가정한다. ReLU나 Sigmoid의 activation function을 가지고, input이 0이 아닌 값을 주면서, 0인 값을 출력하는(근사하는) weight을 찾으려면, 어려움이 있다. 고작 0이란 값하나때문에, weight을 매우 가파르게 해야 하는 등 0에 값에 의해 model이 크게 영향을 받고 비효율적이다. 반면에, bias를 추가한다면, 조금의 절편이동으로 0을 효율적으로 표현할 수 있다.
반대로, input값을 0이 들어가게되면, 반드시 y값은 원점을지나, 유연성이 떨어지게된다. 가령 model이 y = a1x1+a2x2+...라고 하면, data (0,5)나 (0,32) 같은 값을 근사해서 나타낼 방법이 없다.


반응형

'Machine Learning' 카테고리의 다른 글

Linear Model  (0) 2019.01.22
KNN Classifier, Regression  (0) 2019.01.21
Restricted Boltzmann Machine  (0) 2019.01.19
Optimization 방법론  (0) 2019.01.12
Overfitting을 막는 Regularization  (0) 2019.01.09