인공지능 확률통계

베이즈 이론 - 인공지능 확률 통계

인공지능 대학생 2023. 9. 17. 23:08

(* 참고: https://allendowney.github.io/ThinkBayes2/chap02.html )

 

베이즈 정리(Bayes rule)는 어떤 데이터 조건이 주어졌을 때의 조건부확률을 구하는 공식이다.

 

베이즈 정리 (Bayes rule) (= Inverse probability)

\[P(Y|X) = \frac{P(X|Y)P(Y)}{P(X)}\]

 

베이즈 이론 (Bayes theorem)

  • 추론 대상의 사전확률(prior)과 추가적인 정보인 가능성 정보(=가능도, likelihood)를 통해, 해당 대상의 사후확률(posterior)을 추론하는 방법
  • 추론하는 대상을 확률변수(X)로 보아 그 변수의 확률분포(P(X))를 추정
  • (✏️) prior과 likelihood가 주어졌을 때, posterior는 likelihood 조건부 확률 접근의 반대 접근이 된다. (아래 수식 참고)
  • (✏️) posterior를 구하기 위해 prior와 likelihood를 곱한 결합확률(joint probability, = unnorm)을 구하게 된다. (아래 수식 참고)
  • (✏️) 구하고자 하는 값은 posterior 이다.

prior : \[P(X)\]

likelihood : \[P(Y|X) = \frac{P(X,Y)}{P(X)} = \frac{P(X|Y)P(Y)}{P(X)}\]

unnorm : \[P(X,Y) =P(Y,X) = P(Y|X)P(X)\]

posterior : \[P(X|Y) = \frac{P(Y|X)P(X)}{P(Y)}\]

 

만약 샘플 X가 여러항(k개)일 경우엔 다음과 같이 표현 할 수 있다.

 

prior : (i, j = index) \[P(Xi)\]

likelihood : \[P(Y|Xi) = \frac{P(Xi,Y)}{P(Xi)} = \frac{P(Xi|Y)P(Y)}{P(Xi)}\]

unnorm : \[P(Xi,Y) =P(Y,Xi) = P(Y|Xi)P(Xi)\]

posterior : \[P(Xi|Y) = \frac{P(Y|Xi)P(Xi)}{P(Y)}=\frac{P(Y|Xi)P(Xi)}{\sum_{j=1}^kP(Y|Xj)P(Xj)}\]

(* 여기서 i는 현재 구하고자 하는 값의 index이고, j는 k개의 항을 가리키기 위한 index)

 

실제 문제를 풀 때 prior와 posterior의 정의를 잘 구분해야 한다.


Q1. Suppose you have two coins in a box. One is a normal coin with heads on one side and tails on the other, and one is a trick coin with heads on both sides. You choose a coin at random and see that one of the sides is heads. What is the probability that you chose the trick coin?

  • prior: 2개의 코인, X1 = normal coin, X2 = trick coin, X ∈ {X1, X2}
    (* X의 값의 분포가 2개일 때, Binomial distribution 혹은 Bernoulli distribution 이라 한다.)
  • posterior: trick 코인을 선택하게 될 확률 P(X2|Y)  ,Y ∈ {head, tail}
    (* posterior 중 우리가 찾고자 하는 값을 MAP solution이라 한다.)
coin prior likelihood unnorm posterior
Normal (X1) 1/2 1/2 1/2 * 1/2 = 1/4 1/3
Trick (X2) 1/2 1 1/2 * 1 = 1/2 2/3 (MAP solution)
X P(Xi) P(Yhead|Xi) P(Xi,Y)
= P(Y|Xi)P(Xi)
P(Xi|Y)

A1) posterior X=2, Y=h \[P(X2|Yh) = \frac{P(Yh|X2)P(X2)}{P(Yh)} = \frac{P(Yh|X2)P(X2)}{\sum_{i=1}^2P(Yh|Xi)P(Xi)}\]

\[\frac{1\times1/2}{1/4+1/2} = \frac{1}{2}\times\frac{4}{3}=\frac{2}{3}\]


Q2. Suppose you meet someone and learn that they have two children. You ask if either child is a girl and they say yes. What is the probability that both children are girls?

Hint: Start with four equally likely hypotheses.

  • prior: 2명의 children, X ∈ {gg, gb, bg, bb}
  • posterior: 두 자녀가 모두 gg일 확률 P(Xgg|Yg) ,Y ∈ {g, b}
children prior likelihood unnorm posterior
gg 1/4 1 1/4 1/3
gb 1/4 1 1/4 1/3
bg 1/4 1 1/4 1/3
bb 1/4 0 0 0
X P(Xi) P(Yg|Xi) P(Xi,Yg)
= P(Yg|Xi)P(Xi)
P(Xi|Yg)

A2) posterior X=gg, Y=g (* 앞으로 확률변수 표기는 값을 표현하지 않고 변수만 표기하도록 한다)
\[P(X|Y) = \frac{P(Y|X)P(X)}{P(Y)}=\frac{1\times1/4}{1/4+1/4+1/4}=\frac{1}{4}\cdot\frac{4}{3}\]

 

반응형