본문 바로가기
Statistics/Bayesian With Python

다양한 사전 분포 _ Prior distribution

by Kanii 2021. 1. 29.
반응형

저번 포스팅에서 Prior distribution에 대해 간략하게 언급했었고, 이번 포스팅에서는 prior distribution의 종류를 정리해 보려고 한다.


1. 사전 분포란 ? What is the prior distribution?

 

 사전 분포란 베이지안 통계분석에서 등장하는 용어로, 데이터의 분포를 결정하는 모수 $\theta$ (parameter)에 대한 사전 정보를 나타내는 분포이다. 데이터를 관찰하기 이전에 이미 알고있는 정보를 나타낸다고 생각하면 된다.

 

예를 들어, 2021년 8월에 남자아이가 태어날 확률을 알고싶다면, 태어날 아이의 성별은 {여자, 남자}로 두 가지 경우만 존재하기 때문에, 남자아이가 태어날 확률이 $\cfrac{1}{2}$라고 생각해도 되지만, 우리가 지난 10년 간 8월에 태어난 남자아이의 비율이 $\cfrac{60}{100}=0.7$이었다면, 이 정보를 올해의 확률을 예측하는데 사용할 수 있을 것이다.

이러한 정보를 사전 정보라고 하고, 그것의 분포를 사전 분포 prior distribution이라고 한다. 또한, 베이지안에서 사후 분포를 계산하기 위해선 반드시 필요한 분포이기도 하다.

 

하지만 사전 분포는 베이지안 접근법의 단점으로 지적되기도 한다..

 

베이지안에서 사후 분포 (posterior)는 다음과 같이 계산된다.

$$p(\theta|y)=\cfrac{p(y|\theta)p(\theta)}{p(y)}$$

$$~~~~~~~~~\propto p(y|\theta)p(\theta)$$

즉, 베이지안 접근법은 모수에 대한 사후 분포를 가능도 함수(likelihood)와 사전 분포(prior)의 결합으로 계산하게 되며 데이터 샘플 수가 적을 수록 posterior는 prior에 영향을 많이 받게된다.

 

따라서 데이터에 맞는 적절한 prior를 설정하는 것이 중요한데,

"000한 데이터에는 ***한 사전분포를 사용해야한다." 같은 명확한 기준이 존재하지 않기 때문에 실험 설계자의 주관적인 판단에 많이 의존하곤 한다.

이러한 이유로 베이지안은 빈도론자들에게 비판을 받아왔고,(옛날에ㅎ)

'주관적'이라는 비판을 극복하기 위해 non-informative prior를 사용하는 등 많은 연구가 이루어져왔다.

 

이번 포스팅에서는 베이지안에서 아주 중요한 일반적으로 많이 알려진 사전분포들의 종류를 정리해보려고 한다.


2. Flat Prior 혹은 Non-Informative Prior (무정보적 사전 분포)

 

무정보적 사전 분포란 사전 분포가 사후 분포에 끼치는 영향을 최소화하기 위해 제안된 사전 분포이다.

$Uniform(0,1)$처럼 flat한 형태를 가지고 있는 분포를 사용하거나, $N(0,100)$처럼 분산이 아주 큰 분포를 사용하는 것이 대표적이다.


3. Proper/ Improper Prior

 

확률 분포에서 전체 확률의 합이 1이 되는 확률 분포는 proper distribution, 그렇지 않은 분포를 improper distribution이라고한다.

 

$$\int_{-\infty}^{\infty}p(\theta)d\theta = 1~~ ~\text{(proper)}$$

$$\int_{-\infty}^{\infty}p(\theta)d\theta \neq 1 ~~\text{(improper)}$$

 

확률 분포란 정의 자체가 합이 1이어야한다는 전제가 있기 때문에, improper distribution은 사전 분포로 아예 사용할 수 없다고 생각 할 수 있다.

하지만, improper prior를 사용해도 proper posterior가 계산될 수 있다. 이와 같은 경우에 한해서 improper distribution을 prior로 사용할 수 있다.

 

예를 들어 $y|\theta \sim N(\theta,1)$이고, $p(theta)=c \text{constant}$일 때, $\int_{-\infty}^{\infty}cd\theta = \infty$인 improper prior distribution을 고려해보자.

이때, $p(\theta|y)$를 계산하면 다음과 같다.

$$p(\theta|y)  \propto p(y|\theta)p(\theta)$$

$$~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\propto exp\{-\cfrac{1}{2}(y-\theta)^2\} \times c$$

$$~~~~~~~~~~~~~~~~~~~~~~~~\propto exp\{-\cfrac{1}{2}(\theta-y)^2\}$$

$$~~~~~~=N(y,1)$$

 

Prorper prior를 사용하면 posterior는 항상 proper이지만,

Improper prior를 사용할 경우, posterior는 proper/improper가 모두 나올 수 있다.

따라서, Improper prior를 사용하게 될 경우 posterior의 형태를 꼭 살펴보아야 한다.


4. Conjugate Prior (켤레/공액 사전분포)

 

Conjugate prior의 사전적 정의는 다음과 같다.

In Bayesian probability theory, if the posterior distribution $p(\theta|x)$ is in the same probability distribution family as the prior probability distribution $p(\theta)$, the prior and posterior are then called conjugate distributions, and the prior is called a conjugate prior for the likelihood function $p(y|\theta)$
- Wikipedia

즉, 우리가 설정한 사전 분포의 분포족(distribution family)와 계산 된 사후 분포의 분포족이 같을 경우,

그 사전 분포를 Likelihood function $p(y|\theta)$에 대한 conjugate prior라고 부른다.

Conjugate prior를 사용할 경우, 사후 분포의 계산이 간편해지기 때문에, 베이지안 접근법에서 가장 많이 사용되는 사전 분포의 형태이다.

 

Conjugate prior로 활용할 수 있는 주요 분포들은 다음과 같다.

Parameter Likelihood Conjugate prior Posterior
$\mu$ $Normal(\mu,\sigma^2)$ $Normal(\mu_0,\sigma_0)$ $Normal$
$\theta$ $Binomial(N,\theta)$ $Beta(a,b)$ $Beta$
$\lambda$ $Poisson(\lambda)$ $Gamma(r,s)$ $Gamma$
$\theta_1,\cdots,\theta_K$ $Multinomial(\theta_1,\cdots,\theta_K)$ $Dirichlet(\alpha_1,\cdots,\alpha_K)$ $Dirichlet$

 

간단한 예를 한번 살펴보자.

 

$y_i|\theta~~ iid \sim Bin(1,\theta), i=1,\cdots,N$ , $p(\theta)=Beta(a,b)$

$$p(\theta|y_1,\cdots,y_N)\propto \prod_{i=1}^{N} p(y_i|\theta) p(\theta)$$

$$~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\propto \left(\prod_{i=1}^N\theta^{y_i}(1-\theta)^{1-y_i}\right) \theta^{a-1}(1-\theta)^{b-1}$$

$$~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\propto \theta^{a+\sum_{i=1}^N y_i}(1-\theta)^{b+n-\sum_{i=1}^N y_i}$$

$$~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\propto Beta(a+\sum_{i=1}^N y_i, b+n-\sum_{i=1}^N y_i)$$

 

더 많은 conjugate prior는 wikipedia에서 살펴 볼 수 있다.

https://en.wikipedia.org/wiki/Conjugate_prior 


5. Jeffreys prior (제프리 사전분포)

 

마지막으로 살펴볼 것은 Jeffreys prior이다.  제프리 사전분포는 Fisher information을 통해 계산된다.

 

$$ p(\theta) \propto \sqrt{det I(\theta)}$$

$$\text{where}~~~ I(\theta) = E\left[-\cfrac{\partial^2}{\partial\theta^2}\log L(\theta|y)\right]$$

 

제프리 사전분포의 가장 큰 장점은 불변성(Invariance)을 만족 한다는 것이다.

사전 분포의 불변성이란, 

모수 $\theta$가 존재하고 $\phi=f(\theta)$라고 정의 되었을 때, $p(\theta)$가 제프리 사전분포라면 변수 변환 기법을 사용하여 $p(\phi)$와 $p(\theta)$가 동일함을 보일 수 있다는 것이다.

 

간단한 예를 살펴보자.

$y \sim N(0,\sigma^2)$일 때, 모수 $\sigma$에 대한 제프리 사전분포를 구해보자.

 

$$\log L(y|\sigma) \propto -\cfrac{1}{2\sigma^2}y^2$$

$$\cfrac{\partial}{\partial \sigma} \log L(y|\sigma) \propto \cfrac{y^2}{\sigma^3}$$

$$\cfrac{\partial^2}{\partial \sigma^2} \log L(y|\sigma) \propto - \cfrac{y^2}{\sigma^4}$$

$$I(\sigma) = \cfrac{3*E[y^2]}{\sigma^4} = \cfrac{3}{\sigma^2}$$

$$p(\sigma)=\sqrt{I(\sigma)}\propto \cfrac{1}{\sigma}$$

 

이때, $\phi = \sigma^2$로 가정하고 변수변환 기법을 사용해 $p(\phi)$를 구해보면,

$$\phi = \sigma^2 ~~~ \Rightarrow ~~~ \cfrac{\partial \sigma}{\partial \phi} = \cfrac{1}{2\sqrt{\phi}}$$

$$p_\phi(\phi) = p_\sigma(\sqrt{\phi})|\cfrac{\partial \sigma}{\partial \phi}|$$

$$ ~~~~~~~~\propto \cfrac{1}{\sqrt{\phi}} | \cfrac{1}{\sqrt{\phi}}|$$

$$\therefore p(\phi)=\cfrac{1}{\phi}$$

 

이렇듯, 제프리 사전분포를 사용할 경우 모수의 형태가 바뀌더라도 사전 분포는 변하지 않는 '불변성'을 만족한다는 것을 확인 할 수 있다. 또한, 제프리 사전분포는 그 자체로 무정보적 사전분포이다.


이번 게시물에선 가장 잘 알려진 사전 분포의 형태들을 살펴보았다.

설명을 할 때는 non-informative/ (im)proper/ conjugate/ Jeffreys를 나눠서 설명하였지만 사실 이것들은 딱딱 나눠지는 개념은 아니다.

Jeffereys prior가 그 자체로 non-informative prior인 것 처럼, 그것은 Likelihood function의 형태에 따라 improper할 수도 있고, conjugate prior가 될 수도 있다.

(실제로 Likelihood가 $Bin(1,\theta)$일 때, Jeffreys prior는 $\beta(\cfrac{1}{2},\cfrac{1}{2})$이며, 베타는 Binomial likelihood의 conjugate prior이다.)

 

요새는 많은 연구에서는 계산하기 쉬운 conjugate prior에 분산을 키워서 non-informative하게 사용하는게 주인것 같지만..

연구에 알맞게 prior를 선택 할 수 있다면 베이지안 연구의 강점이 더 살아날 것이다.

# 본문에 사용된 그래프
import numpy as np
from scipy.stats import uniform
import matplotlib.pyplot as plt

x = np.linspace(0,1,10000)

plt.plot(x,uniform.pdf(x),'r',lw=5,alpha=0.8)
plt.fill_betweenx([0,1],[1,1],alpha=0.4)
plt.grid(alpha=0.3,linestyle='--')
plt.xlabel(r'$\theta$')
plt.ylabel(r'$p(\theta)$')
plt.title(r'Non informative prior distribution , $Uniform(0,1)$')
plt.ylim(0,1.2)
반응형

댓글