
인공지능 및 기계학습 개론 2(8.4~8.5) 정리
Dobby-HJ
·2023. 10. 15. 18:53
8.4 Multivariate Gaussian Distribution
Multivariate Gaussian Distribution
- Probability density function of the Gaussian distribution
- $N(x |\mu, \sigma^2) = \frac{1}{\sqrt{2\pi\sigma^2}}\exp(-\frac{1}{\sigma^2}(x - \mu)^2)$
- $N(x |\mu, \sum) = \frac{1}{(2\pi)^{D/2}}\frac{1}{|\sum|^{1/2}}\exp(-\frac{1}{2}(x-\mu)^T\sum^{-1}(x-\mu))$
→ 여기서 $\sum$은 covariance matrix가 된다.
→ 이제 우리는 Multivariate Guassian Distribution 상에서의 MLE estimator를 찾으려고 하는 상황. 그래서 log likelihood를 만들어서 estimate를 하면 된다. 고로 미분해서 0이 나오도록 하면 된다.- $\ln N(x |\mu, \sum) = -\frac{1}{2}\ln|\sum| - \frac{1}{2}(x - \mu)^T\sum^{-1}(x - \mu) + C$
- $\ln N(x |\mu, \sum) = -\frac{N}{2}\ln|\sum| - \frac{1}{2}\sum_{n=1}^N(x_n-\mu)^T\sum^{-1}(x_n-\mu) + C$
- $\propto -\frac{N}{2}\ln|\sum| - \frac{1}{2}\sum_{n=1}^N Tr[\sum^{-1}(x_n -\mu)(x_n-\mu)^T]$
- $= -\frac{N}{2}\ln|\sum| - \frac{1}{2}Tr[\sum^{-1}\sum_{n=1}^N((x_n-\mu)(x_n-\mu)^T)]$
- $\frac{d}{d\mu}\ln N(X|\mu,\sum) = 0$ → $\frac{1}{2}\times 2 \times -1 \times \sum^{-1}\sum^{N}{n=1}(x_n-\hat{\mu}) = 0$
→ $\hat{\mu} = \frac{\sum_{n=1}^N x_n}{N}$
→ 여기서 $\mu$에 대해서 미분하는 이유는 우리가 추정하고자 하는 값이 $\mu$이기 때문. - $\frac{d}{d\sum^{-1}}\ln N(X|\mu, \sum) = 0$ → $\hat{\sum} = \frac{1}{N} \sum^N_{n=1}(x_n-\hat{\mu})(x_n - \hat{\mu})^T$
→ 공분산 행렬도 우리가 추정하고 싶은 분포의 parameter이기 때문.- Beyond the scope of the course
- Use “trace trick” and
1) $\frac{d}{dA}\log|A| = A^{-T}$
2) $\frac{d}{dA}Tr[AB] = \frac{d}{dA}Tr[BA] = B^T$
Samples of Multivariate Gaussian Distribution
- Samples of multivariate Gaussian distribution
- With various covarious matrixes
- Convariance matrix should a positive-definite matrix
- $Z^T\sum_z > 0$ for every non-zero column vector $z$
- $\begin{bmatrix}
a & b
\end{bmatrix}\begin{bmatrix}
1 & 0 \
0 & 1
\end{bmatrix}
\begin{bmatrix}
a \ b
\end{bmatrix} =
\begin{bmatrix}
a & 0 \
0 & b
\end{bmatrix}\begin{bmatrix}
a \ b
\end{bmatrix} = a^2 + b^2 > 0$ when a, b are non-zero
- 아래 그림에서 $\begin{bmatrix}
1 & 0\
0 & 1
\end{bmatrix}$해당 covariance matrix를 보면 “원”의 형태로 구성되어있는데, 그 이유를 직관적으로 설명하면 covariance가 0이라는 것은 밀접하게 correlation이 없다는 것과 유사하다.
나는 그래서 $\begin{bmatrix}
a & c\
c & b
\end{bmatrix}$라는 covariance matrix가 주어졌다면, 가로로 $a$ 길이를 가지고, 세로로 $b$라는 길이를 가지는 높이가 $c$인 “타원”을 생각할 수 있을 것 같습니다.
Mixture Model
지금 우리는 2개의 distribution을 배웠습니다. Multinomial distribution, Multivariate Gaussian distribution. 이 2개를 연결시켜주어야 합니다. 그 방법이 바로 Mixture Model입니다.
아래의 그림에서 nature한 생각으로 가장 왼쪽의 분포는 크게 “3개의 distribution”으로 표현하는게 맞을 것입니다. 즉, 하나의 Dataset안에 여러개의 Data의 종류가 있는 것입니다. 이렇게 여러 종류의 Data를 mixing되어있는 Dataset을 모델링할 때 쓰는게 Mixture Modeling입니다.
- Imagine that the samples are drawn from three different normal distributions
- Subpopulation(부분 모집단)이 존재하는 것.
- The conventional(전형적인) distributions cannot explain the distribution accurately
- We need to mix the three normal distribution
→ Create a new distribution adapted to the samples - Mixture distribution
- $P(x) = \sum_{k=1}^K \pi_k N(x|\mu_k, \sigma_k)$
→ 여기서 $\pi_k$는 weighting하는 parameter, Mixing할 때 사용하는 mixing coefficients라는 것.(여기서 $K$는 Class의 갯수.
→ $N$ term은 Multivariate Gaussian Distribution을 사용할 예정이고
→ $\pi$ term은 Multinomial Distribution을 사용할 예정이다.- Mixing coefficients, $\pi_k$ : A normal distribution is chosen out of $K$ options with probability
- Works as weghting
- $\sum_{k=1}^K \pi_k = 1, 0 \le\pi_k \le 1$
- This is a probability (as well as weighting!)
- Then, which distribution?
- New variable? Let’s say $Z$!
→ 여기서 $Z$는 Multinomial distribution을 따른다.
- 여기서 subpopulation들을 Mixture component라 부르고, 이는 곳 subpopulation에 대해 fitting된 distribution이다.
$N(x |\mu_k, \sigma_k)$: A distribution for the subpopulation
- Mixing coefficients, $\pi_k$ : A normal distribution is chosen out of $K$ options with probability
- $P(x) = \sum_{k=1}^KP(z_k)P(x|z)$
- Why this ordering of variables?
알게된 것
- 보통 벡터는 column vector여서 Multivariate Gaussian Distribution의 notation에서 row vector로써 각각의 원소를 공분산의 역행렬과의 연산을 통해 각각의 값들을(?) 얻어내는 과정입니다.
- Trace Trick을 통해 간편하게 notation을 할 수 있다.(공부해야함)
8.5 Gaussian Mixture Model
Gaussian Mixture Model
- Let’s assume that the data points are drawn from a mixture distribution of multiple multivariate Gaussian distributions
- $P(x) = \sum_{k=1}^KP(z_k)P(x|z) = \sum_{k=1}^K\pi_kN(x|\mu_k, \sum_k)$
→ 현재 $K$개의 Gaussian Distribution이 있고, 이 중 1개를 selection하고, 해당 distribution에서 selection을 진행할 때의 확률 값. - How to model such mixture?
- Mixing coefficient, or Selection variables : $z_k$
- The selection is stochastic which follows the multinomial distribution
- $z_k \in {0, 1}, \sum_k z_k = 1, P(z_k = 1) = \pi_k$, $\sum_{k=1}^K \pi_k = 1$, $0\le \pi_k \le 1$
- $P(Z) = \Pi_{k=1}^K \pi_k ^{z_k}$
→ 각각의 selection의 결과는 $z_k$에 저장되어 있음 $z_0, \dots , z_k = 0, \dots, 1, \dots, 0$ 이때 selection을 하는 “행위”의 확률은 $\pi_k$로 나타내는 notation
- Mixture component
- $P(X | z_k=1) = N(x|\mu_k, \sum_k)$ → $P(X|Z) = \Pi_{k=1}^KN(x|\mu_k, \sum_k)^{z_k}$
- Mixing coefficient, or Selection variables : $z_k$
- $P(x) = \sum_{k=1}^KP(z_k)P(x|z) = \sum_{k=1}^K\pi_kN(x|\mu_k, \sum_k)$
→ 파란색은 parameter, 만약이게 baysian이라면 파란색은 prior probability가 된다.
→ 카키색은 Observation이 되었다라는 뜻이다.This is the marginalized probability. How about conditional?
- $\gamma(z_{nk}) \equiv p(z_k=1|x_n) = \frac{P(z_k=1)P(X|Z_k=1)}{\sum_{j=1}^KP(z_j=1)P(x|Z_j=1)}\
= \cfrac{\pi_kN(x|\mu_k, \sum_k}{\sum_{j=1}^K\pi_jN(x|\mu_j, \sum_j)}$
→ $P(\text{posterior} | \text{data}) = \frac{P(\text{likelihood} | \text{data}) \cdot P(\text{prior})}{P(\text{data})}$이므로 첫번째 식이 다음과 같이 변형됩니다.
- $\gamma(z_{nk}) \equiv p(z_k=1|x_n) = \frac{P(z_k=1)P(X|Z_k=1)}{\sum_{j=1}^KP(z_j=1)P(x|Z_j=1)}\
Log likelihood of the entire dataset is
- $\ln P(X|\pi, \mu, \sum) = \sum_{n=1}^N \ln{\sum_{k=1}^K \pi_kN(x|\mu_k, \sum_k)}$
→ likelihood를 optimize하겠다는 것은 우리가 가진 parameter를 잘 수정해서 현재 관측한 “$X$”가 가장 잘 표현되는 distribution을 찾는것과 의미가 동일함.
- $\ln P(X|\pi, \mu, \sum) = \sum_{n=1}^N \ln{\sum_{k=1}^K \pi_kN(x|\mu_k, \sum_k)}$
'DeepLearning > 인공지능 개론' 카테고리의 다른 글
인공지능 및 기계학습 개론 2(8.1~8.3) 정리 (1) | 2023.10.14 |
---|---|
인공지능 및 기계학습 개론 2(7.7~7.9) 정리 (1) | 2023.10.09 |
인공지능 및 기계학습 개론 2(7.4~7.6) 정리 (1) | 2023.10.02 |
인공지능 및 기계학습 개론 2(7.1~7.3) 정리 (0) | 2023.10.01 |