Mathematics/Statistics

[Statisctics] Maximum Likelihood Estimate

언킴 2021. 6. 29. 00:03
반응형

MLE란?


Maximun Likelihood method라고도 불리며, 최대우도법이라고 한다. 어떤 사건이 일어날 가장 높은 확률 값을 찾는 것이라고 볼 수 있다. 어떤 모수 $\theta$로 결정되는 확률변수의 모임 $D_{\theta} = (X_{1},X_{2},...,X_{n})$이 있고, $D_{\theta}$ 의 확률변수가 $f$라고하면 $f$에 대해서 가능도 $\mathcal{L}_{\theta}$는 다음과 같이 표현할 수 있다.

 

$\mathcal{L}_{\theta} = f_{\theta}(x_{1},x_{2},...,x_{n}) $

$\hat{\theta} = \underset{\theta}{\text{argmax} \mathcal{L(\theta)}} $

 

만약 $X_{1},X_{2},...,X_{n}$이 모두 independent 하고 같은 확률분포를 가진다면 $\mathcal{L}(\theta) ={\underset{i=1}{\overset{N}{\prod}}} {f_{\theta}(x_i)} $ 로 표현이 가능하다. 그리고 위 값을 계산하기 편하게 하기 위하여 log값을 취하게 된다. ( log를 취해주게 되면 곱 형태가 덧셈형태로 변형되기 때문에 계산하기 용이하다 )

 

Deep Learning 에서는 MLE를 가지고 Cross Entropy를 계산하거나 -1 을 곱해주어서 최소값을 찾는 Loss function으로도 사용한다. ( input value 가 이산형일 경우 사용을 한다. 연속형일 경우는 GD )

- cross Entropy, Gradient Descent 는 다음에 다뤄보도록..

 

예제 1 : Binomial

 

$X \sim B(n,\theta)$ 라고 하자. $f_{\theta}(x_{i}) = {n \choose k} \theta^{k}(1-\theta)^{n-k} $ 가능도 함수는 $\mathcal{L}(\theta)$는 $\mathcal{L}(\theta) ={\underset{i=1}{\overset{N}{\prod}}} {f_{\theta}(x_i)} $ 가 된다.

$\hat{\theta} = \underset{\theta}{\text{argmax} \mathcal{L(\theta)}} = \underset{\theta}{\text{argmaxln} \mathcal{L(\theta)}} $ , $\text{ln}\mathcal{L}(\theta)$가 max가 되는 $\theta$를 찾으면 된다.

 

${\partial \over \partial \theta}(\text{ln}( {n \choose k} \theta^{k}(1-\theta)^{n-k} ))$

 

= ${\partial  \over \partial \theta}(\text{ln}( { n! \over k!(n-k)!} +\text{ln}(\theta^{k}) + \text{ln}({(1-\theta)}^{n-k}))$ 

 

= $ {k \over \theta} + {n-k \over \theta - 1} $ = 0 

 

 $ k(\theta - 1) + (n-k)\theta = 0 $

 

$  k\theta - k + n\theta - k\theta = 0 $

 

$i.e.\ \theta = { k \over n} $

 

 

예제 2 : Gaussian distribution

위와 동일한 방법으로 진행할 것이다. 가우시안 분포에 변수는 $\mu$와 $\sigma$가 있기 때문에 $\mu$,$\sigma$에 대해 각각 최댓값을 찾을 수 있는 식을 구할 수 있다.

 

$ f_{\theta}x = {1 \over \sqrt{2\pi \sigma^2}}e^{- {(x-\mu)^2 \over 2\sigma^2}} $

 

  $ \mathcal{L}(\theta)  = {\underset{i=1}{\overset{N}{\prod}}}{{1 \over \sqrt{2\pi \sigma^2}}e^{- {(x_{i}-\mu)^2 \over 2\sigma^2}}} $

 

 $ \text{ln} \mathcal{L}(\theta) = \Sigma \text{ln}({1 \over \sqrt{2\pi \sigma^2}} e^{- {(x_{i}-\mu)^2 \over 2\sigma^2}})$

 

= $ \Sigma (\text{ln}( {1 \over \sqrt{2\pi \sigma^2}} ) + \text{ln}(e^{- {(x_{i}-\mu)^2 \over 2\sigma^2}}))$

 

= $ \text{ln}({n \over \sqrt{2\pi \sigma^2}}) - \Sigma{(x_{i} - \mu)^2 \over 2\sigma^2} $

 

 

$ {\partial \mathcal{L} \over \partial \mu} \text{ln}(\mathcal{L}(\theta)) = {\partial  \over \partial \mu}(\text{ln}({n \over \sqrt{2\pi \sigma^2}}) - \Sigma{(x_{i} - \mu)^2 \over 2\sigma^2}) $

 

= $  \Sigma{ 1 \over \sigma^2 } ( x_{i} - \mu ) = 0 $

 

$ i.e.\ \hat{\mu} =  {\Sigma x_{i} \over n} $

 

 

 

$ {\partial \mathcal{L} \over \partial \sigma} \text{ln}(\mathcal{L}(\theta)) = {\partial  \over \partial \sigma}(\text{ln}({n \over \sqrt{2\pi \sigma^2}}) - \Sigma{(x_{i} - \mu)^2 \over 2\sigma^2}) $

 

= $ - {n \over \sigma}+ {1 \over \sigma^3}\Sigma {(x_{i}-\mu)^2}$ = 0

 

$ i.e.\ \hat{\sigma^2} = {\underset{i=1}{\overset{N}{\Sigma}}}{{(x_{i} - \mu)^2} \over n}$