반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 IT 프로젝트에서 사용되는 툴들에 대해 많은 분들과 정보를 공유하고 싶습니다.
솔웅

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리

Elements of AI - The Bayes Rule

2018. 6. 12. 05:00 | Posted by 솔웅


반응형

Elements of AI



II.The Bayes Rule




We will not go too far into the details of probability calculus and all the ways in which it can be used in various AI applications. But we will discuss one very important formula.


확률 계산과 관련해서 너무 깊게 들어가지는 않을 겁니다. 그리고 많은 인공지능 제품 들에 사용될 수 있는 다양한 방법들에 대해서도 너무 깊게 들어가지는 않을 겁니다. 단지 한가지 굉장히 중요한 공식에 대해 논의 해 보겠습니다.




We will do this because this particular formula is both simple and elegant as well as incredibly powerful. It can be used to weigh conflicting pieces of evidence in medicine, in a court of law, and in many (if not all) scientific disciplines. The formula is called the Bayes rule (or the Bayes formula).



이 특정 공식을 다루는 이유는 인공지능과 관련 이 공식은 아주 간단하면서도 우아하고 수퍼 파워풀 한 공식이기 때문입니다. 이 공식은 의학분야, 법정 그리고 많은 과학 연구 분야에서 서로 상충되는 증거들을 비교 평가 하는데 사용될 수 있습니다. 이 공식은 Bayes rule (or the Bayes formula)이라고 부릅니다.



We will start by demonstrating the power of the Bayes rule by means of a simple medical diagnosis problem where it highlights how poorly our intuition is suited for combining conflicting evidence. We will then show how the Bayes rule can be used to build AI methods that can cope with conflicting and noisy observations.



우리는 단순한 의학적 진단 문제를 통해 Bayes rule이 얼마나 강력한 지를 보여 드리겠습니다. 이것을 통해 우리의 직감이 상충되는 증거의 결합에 얼마나 적합하지 않음을 알 수 있습니다. 그리고 나서 이 Bayes rule이 상충되는 상황과 noisy observations 들에 대처할 수 있는 인공지능 방법론을 만드는데 어떻게 사용되어질 수 있는지 보여드리겠습니다. 




Key terminology

Prior and posterior odds


The Bayes rule can be expressed in many forms. The simplest one is in terms of odds. The idea is to take the odds for something happening (against it not happening), which we´ll write as prior odds. The word prior refers to our assessment of the odds before obtaining some new information that may be relevant. The purpose of the formula is to update the prior odds when new information becomes available, to obtain the posterior odds, or the odds after obtaining the information. (The dictionary meaning of posterior is “something that comes after, later.“)


Bayes rule 규칙은 여러 형태로 표현 될 수 있습니다. 가장 간단한 방법은 odds 확률입니다. 그 아이디어는 바로 일어나는 것입니다. (반대는 일어나지 않는 것이겠죠),  우리는 이것을 prior odds 라고 할 겁니다. prior라는 단어는 관련됐을 수 있는 어떤 새로운 정보를 취득하기 이전의 odds에 대한 평가를 말하는 겁니다. 이 공식의 목적은 새로운 정보가 가능한 상황일 때 이 prior odds를 업데이트해서 posterior odds나 정보를 취득한 이후의 odds를 얻기 위함입니다.   새로운 정보를 얻기 전에 확률에 대한 평가를 나타냅니다. 공식의 목적은 새로운 정보가 이용 가능해질 때 이전 확률을 업데이트하고, 정보를 얻은 후 posterior 확률 또는 확률을 얻는 것입니다. (posterior의 사전적 의미는 "나중에 오는 어떤 것"입니다.)





How odds change


In order to weigh the new information, and decide how the odds change when it becomes available, we need to consider how likely we would be to encounter this information in alternative situations. Let’s take as an example, the odds that it will rain later today. Imagine getting up in the morning in Finland. The chances of rain are 206 in 365. (Including rain, snow, and hail. Brrr!) The number of days without rain is therefore 159. This converts to prior odds of 206:159 for rain, so the cards are stacked against you already before you open your eyes.




새로운 정보를 평가하고 그것이 가능한 상황이 될 때 odds가 어떻게 변하는지 결정하려면 다른 상황에서 이 정보를 접하게 되면 어떻게 될지에 대해 고려해야 합니다. 오늘 늦게 비가올 것이라는 odds를 가지고 예를 들어 보죠. 핀란드에서 아침에 잠에서 깼다고 생각해 보세요. 핀란드에서 비가 오는 날은 365일 중 206일입니다. (비, 눈, 우박 뭐 그런것들 다 합해서요) 비가 오지 않는 날은 159일 입니다. 비가 오는 날과 오지 않을 날을 odds로 표현하면  206:159 가 됩니다. 당신이 눈을 뜨기 전에 이미 이 카드는 존재해 있는 겁니다.



However, after opening your eyes and taking a look outside, you notice it’s cloudy. Suppose the chances of having a cloudy morning on a rainy day are 9 out of 10 — that means that only one out of 10 rainy days start out with blue skies. But sometimes there are also clouds without rain: the chances of having clouds on a rainless day are 1 in 10. Now how much higher are the chances of clouds on a rainy day compared to a rainless day? Think about this carefully as it will be important to be able to comprehend the question and obtain the answer in what follows.



아침에 눈을 떴을 때 창밖을 바라보니까 구름이 끼어 있네요. 비가 오는 날 중 아침에 구름이 끼어 있는 날은 10일 중 9일 입니다. 즉 10일 중 하루는 아침에 구름이 안 끼었는데도 비가 온다는 말입니다. 어떤 날은 아침에 구름이 끼었는데 비는 안오고 계속 구름만 끼어 있는 날도 있습니다. 아침에 구름이 끼어 있는데 비가 안오는 날은 10일중 하루이지요. 비가 오는 날 구름이 끼어있을 가능성은 비가 오지 않는 날 구름이 끼어있을 가능성과 비교해서 얼마나 높을까요? 잘 한번 생각해 보세요. 질문을 잘 이해하시는게 중요합니다. 그래야 아래 나오는 문제에 대해 잘 대답할 수 있습니다.



The answer is that the chances of clouds are nine times higher on a rainy day than on a rainless day: on a rainy day the chances are 9 out of 10, whereas on a rainless day the chances of clouds are 1 out of 10, and that makes nine times higher.



정답은 비가 오는 날 아침에 구름이 끼어있을 가능성은 비가 오지 않는 날 아침에 구름이 끼어있을 가능성의 9배 입니다. 비가 오는 날의 가능성은 10일 중 9일 입니다. 비가 오지 않을날 아침에 구름이 낄 가능성은 10일 중 하루이구요. 그렇기 때문에 9배 인 것입니다.



Key terminology

Likelihood ratio


The above ratio (nine times higher chance of clouds on a rainy day than on a rainless day) is called the likelihood ratio. More generally, the likelihood ratio is the probability of the observation in case the event of interest (in the above, rain), divided by the probability of the observation in case of no event (in the above, no rain). Please read the previous sentence a few times. It may look a little intimidating, but it´s not impossible to digest if you just focus carefully. We will walk you through the steps in detail, just don´t lose your nerve. We´re almost there.


위의 비율을 우도비율 likelihood ratio라고 부릅니다. (비가 오는 날 아침에 구름이 끼어 있을 가능성이 비가 오지 않는 날 아침에 구름이 낄 가능성의 9배이다 라는 비율) 보다 일반적으로 이 likelihood ratio는 interest 이벤트 (위의 경우는 비) 의 확률을 no event (비가 안오는 경우)의 확률로 나눈 값을 말합니다. 이 문장들을 여러번 잘 읽어 보세요. 집중해서 잘 읽어보면 충분히 이해하실 수 있을 겁니다. 이에 대해 스텝별로 자세하게 안내하겠습니다. 긴장을 늦추지 마세요. 이제 거의 다 왔습니다.




So we concluded that on a cloudy morning, we have: likelihood ratio = (9/10) / (1/10) = 9



이제 구름낀 아침에 대해 결론을 내릴 수 있게 됐습니다. 우리는 우도비율 likelihood ratio = (9/10) / (1/10) = 9 라고 답을 낼 수 있습니다.



The mighty Bayes rule for converting prior odds into posterior odds is — ta-daa! — as follows: posterior odds = likelihood ratio × prior odds



prior odds를 posterior odds로 변환할 전능한 Bayes rule 은 바로 이것입니다. (짜잔~~~~~)


 posterior odds = likelihood ratio × prior odds



Now you are probably thinking: Hold on, that’s the formula? It’s a frigging multiplication! That is the formula — we said it’s simple, didn’t we? You wouldn’t imagine that a simple multiplication can be used for all kinds of incredibly useful applications, but it can. We’ll study a couple examples which will demonstrate this.



당신은 '이게 그 공식 맞아? 그냥 간단한 곱셈이잖아!' 라고 아마 생각 하실 수도 있을 겁니다. 위 글에서 아주 간단하다고 말하자 않았나요? 아마 당신은 이렇게 간단한 곱셈으로 모든 종류의 유용한 응용품들에 적용할 수 있을 거리고는 상상하지 못했을 겁니다. 그런데 그게 가능합니다. 그것을 입증할 몇가지 예를 들어 드리겠습니다.




Note

Many forms of Bayes

In case you have any trouble with the following exercises, you may need to read the above material a few times and give it some time, and if that doesn´t do it, you can look for more material online. Just a word of advice: there are many different forms in which the Bayes rule can be written, and the odds form that we use isn´t the most common one. Here are a couple links that you may find useful.


이어질 연습 문제를 푸는데 어려움이 있다면 시간을 조금 투자해서 위에 설명된 내용을 읽어 보실 필요가 있습니다. 그래도 잘 모르겠으면 온라인에 있는 관련된 정보들을 검색해 보세요. 그래도 어려움이있을 경우 온라인 자료를 더 찾아야 할 수도 있습니다. 조언을 하자면 Bayes rule에 대해 많은 설명들이 다른 방식으로 돼 있을 겁니다. 우리가 사용하는 odds 관련된 예는 이  Bayes rule을 설명하는 가장 일반적인 예는 아닙니다. 아마 아래 두개의 링크를 따라가 보시면 도움이 될 만한 내용을 보실 수 있을 겁니다. 








Exercise 10: Bayes rule (part 1 of 2)


Apply the Bayes rule to calculate the posterior odds for rain having observed clouds in the morning in Helsinki.



Bayes rule을 적용해 헬싱키에서 아침에 구름이 끼었을 때 비가 내릴 posterior odds를 계산해 보세요.



As we calculated above, the prior odds for rain having observed clouds is 206:159 and the likelihood ratio is 9



위에 서 계산한 대로 아침에 구름이 끼었을 때 비가 오는 것에 대한 prior odds는 206:159 였고 likelihood ratio는 9였습니다.



Give your result in the form of odds, xx:yy, where xx and yy are numbers. Remember that when multiplying odds, you should only multiply the numerator (the xx part). Give the answer without simplifying the expression even if both sides have a common denominator.



여러분의 답을 odds 형식 (xx:yy)으로 답하세요. xx 와 yy는 숫자입니다. odds를 곱할 때 주의하세요. 분자 (xx part)를 곱해야 합니다. 양쪽에 공통 분모가 있더라도 식을 단순화하지 말고 (약분하지 말고) 답을 제공하십시오.




The Bayes rule in practice: breast cancer screening



Our first realistic application is a classical example of using the Bayes rule, namely medical diagnosis. This example also illustrates a common bias in dealing with uncertain information called the base-rate fallacy.



우리의 첫 번째 현실적인 응용 프로그램은 Bayes rule을 사용한 아주 고전적인 예 입니다. 이름하여 medical diagnosis라고 합니다. 이 예제는 또한 base-rate fallacy라고 불리는 불확실한 정보를 다루는데 있어서의 일반적인 편견을 보여줍니다.







Consider mammographic screening for breast cancer. Using made up percentages for the sake of simplifying the numbers, let’s assume that five in 100 women have breast cancer. Suppose that if a person has breast cancer, then the mammograph test will find it 80 times out of 100. When the test comes out suggesting that breast cancer is present, we say that the result is positive, although of course there is nothing positive about this for the person being tested. (A technical way of saying this is that the sensitivity of the test is 80%.)



유방암에 대한 유방 X 선 mammographic 검사를 고려하십시오. 숫자를 단순화하기 위해 백분율을 사용하여 100 명의 여성 중 5 명이 유방암을 앓고 있다고 가정 해 봅시다. 어떤 사람이 유방암이 있다고 가정합시다. 그리고 유방 조영술 mammographic 검사를 하면 100번 중 80번 이것을 찾아 낸다고 가정해 봅시다. (기술적으로 이와 같은 상황은 해당 검사의 sensitivity는 80%라고 말합니다.). 검사 해서 유방암이 있다고 결론이 나오는 것을 양성 positive이라고 합니다. - 물론 검사 받는 사람에게는 긍정적 positive인 상황은 아니지만 말이죠- 



The test may also fail in the other direction, namely to indicate breast cancer when none exists. This is called a false positive finding. Suppose that if the person being tested actually doesn’t have breast cancer, the chances that the test nevertheless comes out positive are 10 in 100.



유방암에 걸렸을 경우 80% 는 유방암을 발견한다는 것은 20%는 발견 못 한다는 것이죠. 그리고 또 다른 각도에서 검사의 실패 가능성을 염두에 두어야 합니다. 즉 유방암에 걸리지 않았는데 유방암에 걸렸다고 검사결과가 잘 못 나올 경우도 있는거죠.  이를 false positive finding이라고합니다. 어느 검사를 받는 사람이 실제로는 유방암이 없다고 합시다, 그럼에도 불구하고 검사가 양성으로 나올 확률은 100 명당 10 명입니다.



Based on the above probabilities, you are be able to calculate the likelihood ratio. You'll find use for it in the next exercise. If you forgot how the likelihood ratio is calculated, you may wish to check the terminology box earlier in this section and revisit the rain example.



위의 확률에 근거해 likelihood ratio을 계산할 수 있습니다. 다음 연습 문제에서 한번 사용 해 보세요. likelihood ratio 계산 방법을 잊어 버린 경우 이 섹션의 앞부분에있는 용어 상자를 확인하고 비가 오는 예제를 다시 참조 하세요.





Exercise 11: Bayes rule (part 2 of 2)

Consider the above breast cancer scenario. An average woman takes the mammograph test and gets a positive test result suggesting breast cancer. What do you think are the odds that she has breast cancer?



위의 유방암 시나리오를 참조하세요. 한 평범하 여성이 mammograph 검사를 받고 유방암을 암시하는 양성인 검사 결과를 받았습니다.  이 여성이 유방암에 걸렸을 확률 odds 는 얼마입니까?



Use your intuition without applying the Bayes rule, and write down on a piece of paper (not in the answer box below) what you think the chances of having breast cancer are after a positive test result. After this, calculate the posterior odds for her having breast cancer using the Bayes rule.



Bayes rule을 적용하지 말고 직관을 사용해서 풀어보세요, 그리고 양성 검사 결과를 받았을 경우 유방암에 걸렸을 확률을 종이에 적어 보세요. (아래 빈칸에 넣지 마시구요). 그리고 난 다음에 Bayes rule을 사용해서 그녀가 암에 걸렸을 확률에 대한 posterior odds를 계산해 보세요.



(Hint:) Start by calculating the prior odds and then multiply it by the likelihood ratio.


Hint : 우선 prior odd를 먼저 계산 한 다음 likelihood ratio을 이용해 그것을 곱하세요.



Enter the posterior odds as your solution below. Give the answer in the form xx:yy where xx and yy are numbers, without simplifying the expression even if both sides have a common denominator.



당신이 계산한 posterior odds를 아래에 입력하세요. 답은 xx:yy 형식으로 입력하세요. xx와 yy는 숫자입니다. 양쪽에 공통 분모 common denominator가 있어도 이를 간단하게 고치지 말고 (약분하지 말고) 그냥 입력하세요. 





반응형