brunch

You can make anything
by writing

C.S.Lewis

by 라인하트 Oct 25. 2020

앤드류 응의 머신러닝(8-5):신경망의 논리 연산 I

   온라인 강의 플랫폼 코세라의 창립자인 앤드류 응 (Andrew Ng) 교수는 인공지능 업계의 거장입니다. 그가 스탠퍼드 대학에서 머신 러닝 입문자에게 한 강의를 그대로 코세라 온라인 강의 (Coursera.org)에서 무료로 배울 수 있습니다. 이 강의는 머신러닝 입문자들의 필수코스입니다. 인공지능과 머신러닝을 혼자 공부하면서 자연스럽게 만나게 되는 강의입니다. 


Neural Networks : Representation

인공 신경망 : 표현


Application (응용)


Examples and Intuitions I (예제와 이해 I)    


   In this and the next video I want to work through a detailed example showing how a neural network can compute a complex non linear function of the input. And hopefully this will give you a good sense of why neural networks can be used to learn complex non linear hypotheses. 


   이번 강의와 다음 강의에서 인공 신경망이 복잡한 비선형 함수를 계산하는 방법을 보여주기 위해 몇 가지 예제를 살펴봅니다. 여러분이 신경망이 복잡한 비선형 가설을 학습하기에 좋은 이유를 이해할 수 있기를 바랍니다.  



   Consider the following problem where we have features X1 and X2 that are binary values. So, either 0 or 1. So, X1 and X2 can each take on only one of two possible values. In this example, I've drawn only two positive examples and two negative examples.


   여기 0과 1의 이진 값인 x1과 x2 피처(Feature)를 학습 문제가 있습니다. 피처 x1과 x2는 두 개의 값 중 하나만을 선택합니다. 그림에는 두 개의 파지티브 예제와 두 개의 네거티브 예제가 있습니다. 



    That you can think of this as a simplified version of a more complex learning problem where we may have a bunch of positive examples in the upper right and lower left and a bunch of negative examples denoted by the circles. And what we'd like to do is learn a non-linear division of boundary that may need to separate the positive and negative examples.   So, how can a neural network do this and rather than using the example and the variable to use this maybe easier to examine example on the left. 


   왼쪽 그림은 복잡한 학습 문제를 단순화한 버전입니다. 왼쪽 상단과 오른쪽 하단에 파지티브 예제가 많고 왼쪽 하단과 오른쪽 상단에 네거티브 예제가 많습니다. 파지티브 예제와 네거티브 예제를 분리하기 위해 비선형 결정 경계를 학습합니다. 신경망의 동작 방식을 이해하기 위해 학습 데이터 셋 예제가 많은 오른쪽 그림보다 적은 왼쪽 그림을 중심으로 설명합니다.   



  Concretely what this is, is really computing the type of label y equals x 1 x or x 2. Or actually this is actually the x 1 x nor x 2 function where x nor is the alternative notation for not x 1 or x 2. So, x 1 x or x 2 that's true only if exactly 1 of x 1 or x 2 is equal to 1. It turns out that these specific examples in the works out a little bit better if we use the XNOR example instead. These two are the same of course. This means not x1 or x2 and so, we're going to have positive examples of either both are true or both are false and what have as y equals 1, y equals 1. And we're going to have y equals 0 if only one of them is true and we're going to figure out if we can get a neural network to fit to this sort of training set. In order to build up to a network that fits the XNOR example we're going to start with a slightly simpler one and show a network that fits the AND function. 


   예를 들어, 레이블 y의 유형이 x1과 x2와 논리 연산과 같습니다. 


   XOR 논리 연산의 반대가 XNOR입니다. XOR는 x1 = 1 또는 x2 = 1 인 경우에만 즉, 값이 같으면 0, 값이 다르면 1입니다.  XNOR가 XOR보다 월씬 더 잘 동직 하지만 두 논리 연산 모두 동일합니다. XNOR x1과 x 2가 둘 다 0 이거나 둘 다 1일 때 참(1)입니다. X표를 한 (1,1)과 (0,0) 은 파지티브 예제입니다. XNOR는 x1과 x2 중에 하나만 참이면 거짓())입니다. O표를 한 (0,1)과 (1,0)은 네거티브 예제입니다. NXOR 논리 연산에 맞는 신경망을 구현할 수 있는 지를 알아봅니다. 복잡한 NXOR 논리 연산을 구현하기 전에 간단한 AND 논리 연산을 수행하는 신경망부터 구현합니다. 

   


   Concretely, let's say we have input x1 and x2 that are again binaries so, it's either 0 or 1 and let's say our target labels y = x1 AND x2. This is a logical AND. So, can we get a one-unit network to compute this logical AND function? In order to do so, I'm going to actually draw in the bias unit as well the plus one unit. Now let me just assign some values to the weights or parameters of this network. I'm gonna write down the parameters on this diagram here, -30 here. +20 and + 20. And what this mean is just that I'm assigning a value of -30 to the value associated with X0 this +1 going into this unit and a parameter value of +20 that multiplies to X1 a value of +20 for the parameter that multiplies into x 2. So, concretely it's the same that the hypothesis h(x)=g(-30+20 X1 plus 20 X2. So, sometimes it's just convenient to draw these weights. Draw these parameters up here in the diagram within and of course this- 30. This is actually theta 1 of 1 0. This is theta 1 of 1 1 and that's theta 1 of 1 2 but it's just easier to think about it as associating these parameters with the edges of the network.


   여기 피처 x1과 x2에 AND 연산을 수행하는 신경망이 있습니다. 

   입력 x1 및 x2는 0 또는 1의 이진수입니다. 레이블 y = x1 AND x2 함수입니다. AND 논리 연산을 계산하기 위한 단일 유닛 네트워크가 필요합니다. 먼저 항상 1의 값을 가지는 바이어스 유닛 x0를 그립니다. 신경망에 가중치 또는 파라미터 θ이 값을 할당합니다. 최적의 파라미터 값은 -30, +20, +20입니다. 


   x0에 가중치를 부여하는 θ^(1)10은 -30입니다.  

   x1에 가중치를 부여하는 θ^(1)11은 +20입니다.

   x2에 가중치를 부여하는 θ^(1)12는 + 20입니다. 

   따라서 가설 hθ(x) = g(-30 +20x1 + 20x2)입니다. 때때로 파라미터 θ를 가중치로 표현하는 것이 더 편리할 수 있습니다. 파라미터 θ를 신경망의 맨 끝과 연관시키는 것이 훨씬 더 쉽습니다.  





   Let's look at what this little single neuron network will compute. Just to remind you the sigmoid activation function g(z) looks like this. It starts from 0 rises smoothly crosses 0.5 and then it asymptotic as 1 and to give you some landmarks, if the horizontal axis value z is equal to 4.6 then the sigmoid function is equal to 0.99. This is very close to 1 and kind of symmetrically, if it's -4.6 then the sigmoid function there is 0.01 which is very close to 0. 


   Let's look at the four possible input values for x1 and x2 and look at what the hypotheses will output in that case. If x1 and x2 are both equal to 0. If you look at this, if x1 x2 are both equal to 0 then the hypothesis of g of -30. So, this is a very far to the left of this diagram so it will be very close to 0. If x 1 equals 0 and x equals 1, then this formula here evaluates the g that is the sigma function applied to -10, and again that's you know to the far left of this plot and so, that's again very close to 0. This is also g of minus 10 that is f x 1 is equal to 1 and x 2 0, this minus 30 plus 20 which is minus 10 and finally if x 1 equals 1 x 2 equals 1 then you have g of minus 30 plus 20 plus 20. So, that's g of positive 10 which is there for very close to 1.   And if you look in this column this is exactly the logical and function. So, this is computing h of x is approximately x 1 and x 2. In other words it outputs one If and only if x2, x1 and x2, are both equal to 1. So, by writing out our little truth table like this we manage to figure what's the logical function that our neural network computes.


   이 작은 단일 신경망이 무엇을 계산하는 지를 설명합니다. 시그모이드 활성화 함수 g(z)는 다음과 같습니다. 


    0에서 시작해서 0.5를 부드럽게 교차한 다음 1에 근접합니다. 기준점을 표시하기 위해 수평축 z가 4.6이면 시그모이드 함수 g(z)의 값은 0.99의 값이고, z가 -4.6일 때 시그모이드 함수 g(z)의 값은 0.01입니다.  x1과 x2에 0과 1을 입력하여 결과를 확인합니다. 

   x1과 x2에 대해 네 가지 입력 값을 살펴보고 가설  hθ(x) = g(-30 +20x1 + 20x2)가 출력할 값을 살펴봅시다. x1 = 0, x2 = 0 일 때 g(-30+0+0) = g(-30)이므로 0에 가깝습니다. x1 = 0, x2 = 1 일 때 g(-30+0+20) = g(-10)이므로 0에 가깝습니다. x1 = 1, x2 = 0 일 때 g(-30+20+0) = g(-10)이므로 0에 가깝습니다. x1 = 1, x2 = 1 일 때 g(-30+0+0) = g(+10)이므로 1에 가깝습니다.  분홍색 박스로 표시한 0, 0, 0, 1의 값은 정확히 논리적입니다. x1과 x2에 대한 hθ(x)를 계산한 것입니다. 즉, x1과 x 2가 모두 1일 때만 1을 출력합니다. 그래서 인공 신경망이 계산하는 논리 함수가 무엇인지를 알아낼 수 있습니다. 

   



   This network showed here computes the OR function. Just to show you how I worked that out. If you are write out the hypothesis that this confusing g of -10 + 20 x 1 + 20 x 2 and so you fill in these values. You find that's g of minus 10 which is approximately 0. g of 10 which is approximately 1 and so on and these are approximately 1 and approximately 1 and these numbers are essentially the logical OR function.


     여기 신경망은 논리 연산 OR 함수입니다. 

   OR 연산이 어떻게 동작하는 지를 계산합니다.   가설 함수 hθ(x) = g(-10 +20x1 + 20x2)입니다. x1 = 0, x2 = 0 일 때 hθ(x) = g(-10 +0 + 0) = g(-10)이므로 0입니다.   x1 = 0, x2 = 1 일 때 hθ(x) = g(-10 +0 + 20) = g(10)이므로 1입니다.  x1 = 1, x2 = 0 일 때 hθ(x) = g(-10 +20 + 0) = g(10)이므로 1입니다. x1 = 1, x2 = 1 일 때 hθ(x) = g(-10 +20 + 20) = g(30)이므로 1입니다. 이것이 시그모이드 함수의 그래프를 이용한 논리 연산 OR입니다. 


   So, hopefully with this you now understand how single neurons in a neural network can be used to compute logical functions like AND and OR and so on. In the next video we'll continue building on these examples and work through a more complex example. We'll get to show you how a neural network now with multiple layers of units can be used to compute more complex functions like the XOR function or the XNOR function.


   신경망의 단일 뉴런을 사용하여 AND 연산과 OR 연산과 같은 논리 함수를 계산하는 법을 공부했습니다. 다음 강의에서는 이런 예제를 계속 보면서 더 복잡한 예제를 공부할 것입니다. 이제 여러 층의 단위가 있는 신경망을 상요하여 XOR 함수 또는 XNOR 함수를 계산하는 방법을 공부할 것입니다.  


앤드류 응의 머신러닝 동영상 강의



정리하며


   논리 연산은 다음과 같습니다.

        x1 XOR x2는 같은 같이면 0, 다른 값이면 1입니다. 

      x1 XNOR x2는 값이 같으면 1, 다른 값이면 0입니다.


  논리 연산 AND는 둘 다 참일 때만 1입니다.  이를 인공 신경망에서 구현합니다. 


   시그모이드  함수를 보면,  hθ(x)가-4 작으면 0이고, hθ(x)가 4보다 크면 1이기 때문입니다.


     논리 연산 OR에 대한 신경망은 다음과 같습니다.


매거진의 이전글 앤드류 응의 머신러닝(8-4): 신경망 모델표현 II
작품 선택
키워드 선택 0 / 3 0
댓글여부
afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari