SlideShare a Scribd company logo
1 of 43
ML study
6번째
Mixture models and the EM algorithm
11.1 Latent variable models
11.2 Mixture models
11.4 The EM algorithm
11.5 Model selection for latent variable models
11.6 Fitting models with missing data
11.1 Latent variable models
• 10장에서 graphical models로 고차원 결합확률을 그래프로 표현했음
• 서로 의존관계가 있는 두 변수는 그래프 상에서 edge를 이음
• Latent variable models
• 관찰된 변수는 숨겨진 공통 원인으로부터 발생했으므로 서로 연관되어 있다
• fit이 어렵다
• hidden 변수로 모델의 파라메터를 줄일 수 있다
• 그림 설명, 히든 변수가 있는 것(왼), 비져블 공간에서 바로 습관과 증상을 모델링(오)

•
11.2 Mixture models
• VM의 가장 간단한 형태
• zi ∈{1,...,K}

• p(zi)=Cat(π)
• p(xi|zi =k)=pk(xi)
• pk : 관찰치에 대한 k번째 base 분포
• 혼합 모델 (mixture model): pk들의 convex combination
11.2 Mixture models
11.2.1 Mixtures of Gaussians
• 가우시안 혼합 = mixture of Gaussians = MOG = Gaussian Mixture Model = GMM

• 충분히 많은 수 혼합 컴포넌트가 있으면, GMM은 RD 에서 정의되는 모든 분포를 근사해 낼 수 있다
11.2 Mixture models
11.2.2 Mixture of multinoullis(여기서는 베르누이)
• 데이터가 D차원 bit vectors x라고 하자.
• class conditional density는 다음과 같이 베르누이 분포의 곱으로 표현할 수 있다 (=binomial)
• μjk 는 클러스터 k에서 j번재 비트가 켜질 확률
.

모든 차원에 대해서 곱한 것 (각 차원은 베르누이)= binomial
• 위의 수식을 아래에 대입하면 카테고리 분포의 믹스쳐가 만들어진다
•
11.2.3 Using mixture models for clustering
• Mixture model을 이용해 클러스터링할 수도 있다(GMM에서 는 각 데이터가 어느 가우시안에 속하는지?).
• 혼합 모델을 학습 후(M-step) compute p(zi =k|xi,θ) (E-step) // EM은 나중에 다룬다

• DA 랑 비슷하다는 것을 알 수가 있습니다. (http://play.daumcorp.com/display/~sweaterr/4.+Gaussian+Model)
• 사실

• 소프트 클러스터링이라고 부른다.
• MAP 추정으로 hard-clustering 할 수 있다.
11.2.4 Mixtures of experts
• 입력 공간의 특정 지역마다 하나의 전문가가 있다
• wk는 각 latent 변수의 상태 k마다 다르다
gating function
• 어떤 전문가를 쓸 것인가? gating function이라고 한다.
Mixture Model
• discuss how to fit this model in Section 11.4.3.
11.3 Parameter estimation for mixture models
• zi가 관찰됐다면, d-분리에 의해서 θz⊥θx|D이 성립하고, posterior도 factorize될 수 있다
• 하지만 LVM에서 zi는 hidden이므로, 파라메터들은 더이상 독립적이지 않고, posterior도 factorize되지 않는다.

• 이는 MAP, MLE의 계산도 어렵게 만든다
11.3.1 Unidentifiability
• LVM에서 p(θ|D) 계산하는 것에 대한 가장 큰 문제는 multiple mode(다중 봉우리)를 가졌다는 것이다.
• 예를 들어 GMM에서, zi 가 관찰되었다면, 파라메터에 대한 unimodal posterior를 갖게 된다.

•

NIW는 평균과 분산에 대한 분포

• 결과적으로, global optimal한 MAP 추정을 얻을 수 있다
• 그러나,zi이 히든이면, 각 zi를 채우는 가능한 방법마다, 다른 unimodal한 likelihood를 얻는다
• 그러므로, posterior p(θ|D)를 얻기위해, zi를 marginalize할 때, posterior는 multimodal이 된다.
11.3.1 Unidentifiability
• 그림 설명
• (왼쪽) x축=1차원 데이터 포인트, y차원이 빈도수, 2개의 Gaussian(평균 -10,10)의 혼합이다.

• (오른쪽) p(D|mu1,mu2) 의 표면, 두개의 mode가 존재한다.(평균벡터=(10,-10) 또는 (-10,10)))
• 즉 z에 따라, 첫번째, 두번째 가우신안의 순서가 바뀔 수 있다. K!개의 가능한 레이블링
• 파라메터가 identifiable하지 않다고 한다
11.3.1 Unidentifiability
• Unidentifiability는 베이지안 추론에서 문제를 일으킨다
• 예를 들어, posterior mean을 근사하기 위해, θ(s)∼p(θ|D)로 몇개의 θ를 샘플링하고 그것을 다음과 같이 평균낸
다면:

• 만약 샘플이 서로 다른 mode에서 나왔다면, 평균은 의미가 없어진다.
11.3.2 Computing a MAP estimate is non-convex
• 이전 섹션에, 다소 휴리스틱하게 likelihood는 multiple mode를 갖을수 있고 그래서, MAP 또는 ML 추정이 어려
워진다고 했다.
• 이번 섹션에서, 좀 더 대수적으로 그것을 보이겠다.

• 불행히도, 위의 목적함수의 최적화는 log가 sum_z에 안들어가기 때문에 할 수 없다
• 결합 확률 분포(joint probability distribution) p(zi,xi|θ)이 지수족이라고 가정하면

• φ(x,z) are the sufficient statistics
Z(θ) is the normalization constant
• complete data log likelihood는 다음과 같다(x, z 둘다 관찰가능)

•

첫번째 term은 θ 에 linear하고, Z(θ)는 convex 함수(see 9.2.3 Log partition function)이기 때문에 전체 목적함수
는 concave(마이너스 기호때문에)하므로, 하나의 maximum이 있다
11.3.2 Computing a MAP estimate is non-convex
• latent 변수가 있는 likelihood는 z는 관찰 못하므로 데이터도 없다

•

p(x,z)는 exponential family라고 가정하였으므로,

• log-sum-exp 함수는 convex하고 Z(θ)도 convex하다
• 하지만, 두 convex 함수들의 차는 일반적으로 convex하지 않다
• 그러므로, 위의 likelihood는 local optima를 가진다
• 대부분 최적화 알고리즘은 local optimum만을 찾을 수 있다
• simulated annealing 이나 유전자 알고리즘이 global optimum을 찾을 수 있다고 하지만, 무한대 시간에서라든
지 하는 이상적인 가정하에서 일 뿐이다
• 실제로는, random restart를 여러번 하는 방식을 쓴다
11.4 The EM algorithm
• 모든 관련있는 랜덤 변수의 모든 값이 관찰된다면, ML 또는 MAP을 계산하는 것은 쉽다
• 하지만, missing 데이터나 latent 변수들을 가지고 있다면, ML이나 MAP 추정은 어려워진다(앞 섹션에서 convex
해지지 않는다고 했다 )
• 한가지 방법은 negative log likelihood or NLL의 지역 최저점을 찾기 위해 경사 강하 최적기(gradient-based
optimizer)를 쓰는 것이다.

• 하지만, mixing weight의 합은 1이여야 한다와 같은 제약 조건을 가해줘야 하는 경우가 많다
• 좀 더 심플한 방법(하지만 항상 빠르지는 않은)이 바로 EM(expectation maximization)을 쓰는 것이다
• EM은 데이터 완전히 관찰되었다면, ML/ MAP 추정은 계산하기 쉽다는 사실을 이용한다
• EM은 모델의 파라메터가 주어졌을 때, missing values를 추론하는 E-step과 E-step에서 데이터가 채워졌을 때,
parameters를 최적화하는 M-step으로 이루어져 있다.
•
11.4.1 Basic idea
• xi는 i번째 볼수 있거나 관찰된 변수라고 하고, zi는 숨겨졌거나 missing된 변수라고 하자.
• 목적은 다음과 같은 likelihood를 maximize하는 것이다

• 로그는 sum 안에 들어갈 수 없기 때문에, 최적화하기 어렵다.
• EM은 이 문제를 다음과 같이 푼다.

• complete data log likelihood를 정의한다

• Z를 관찰할수 없으므로, 계산할 수 없다
• 그래서 다음과 같은 expected complete data log likelihood을 정의한다.

• t는 현재 iteration을 의미한다.
• 현재 iteration에서 한 단계 이전 iteration에서의 파라메터와 데이터가 주어졌을 때, complete data log likelihood
의 기대값

• Estep: Q(θ,θt−1)을 계산한다 또는 MLE를 구하는데 필요한 term(GMM에서는 z)
• Mstep: Q함수를 θ에 대해서 최적화한다.

EM algorithm은 the log likelihood of the observed data를 단조 증가시킨다고
알려져 있다.(만약 그렇지 않다면 math 또는 code에 bug가 있는 것이다.)
(by jensen's inequality, 이 정리에 대한 참고자료)
과정 PASS, 결론만으로 진행
11.4.2 EM for GMMs
11.4.2.1 Auxiliary function

기대값 성질
11.4.2 EM for GMMs
M-step
• rik을 안다고 가정하면 MLE를 이용해서 GMM의 paramter들을 업데이트할 수 있다.
• 
(11.26)을 π에 대해서 미분해서 0을 놓고 정리하면(모든 k에 대해서 πk의 합은 1인 제약조건을 추가 ,다음장)

• μk and Σk 를 최적화하기 위해서(11.26)에서 π관련된 항을 지우고, 나머지에 정규분포 수식을 대입하면

• 역시 마찬가지로 MLE 추정을 하면
GDA에서는 각 클래스끼리의 평균이었지만,
soft하게 각 클래스가 될 확률의 가중치 평균이 되었다.

GDA에서는 각 클래스끼리의 분산이었지만,
soft하게 각 클래스가 될 확률의 가중치 분산이 되었다.
11.4.2 EM for GMMs
E-step

위의 수식은 Gaussian discriminant
Analysis(see 4.2.1)와 비슷해진다
11.4.2 EM for GMMs
• 초기 상태: 랜덤하게 두 가우시안의 평균과 분산을 정해준다(분산은 I행렬)
• e-step: 데이타와 두 가우시안의 파라메터가 주어졌을 때, k클러스터에 속할 확률(p(zi=k|xi,θ) = rik)을 계산한다
• m-step: (p(zi=k|xi,θ) = rik)을 이용해서 두 가우시안의 파라메터(평균과 분산)을 MLE로 업데이트한다
11.4.2.5 K-means algorithm
•

How to work
11.4.2.5 K-means algorithm
• K-means는 GMM의 special case로 볼 수 있음
• 다음과 같이 가정한다:

• Σk=σ2 ID is fixed, //모든 가우시안의 공분산은 같고 동그랗다
• πk =1/K is fixed // 가우시안의 혼합율로 모두 동일하다.
• E step: 가장 resonsibility가 큰 z로 hard assign한다.

• 모든 정규분포이 동일한 동그란 공분산을 가정했기 때문에 xi에 대해서 가장 그럴듯한 cluster k는

•
•

각 클러스터에는 중심이 있고, xi에서 가장 가까운 중심을 가지고 있는 클러스터로 고른다
11.4.2.8 MAP estimation of GMM
• EM에서 M단계의 MLE는 overfit 될 수 있다.

• K=2, Σk=σ2kI 라고 가정하고 하나의 가우시안에 하나의 데이터 x1만 할당되었을 때, 그 데이터는 likelihood에 다
음과 같이 기여한다.

• 하나의 데이터 자체가 평균이 되기 때문에 exp위에 올라가는 수치가 0이된다.

• 즉 σ2→0 이 될수록 값이 너무 커져버려서 likelihood에 비이상적으로 기여하게 된다
11.4.2.8 MAP estimation of GMM
• 간단한 해결책은 MAP을 쓰는 것이다.
• 새로운 auxiliary 함수는 log prior가 추가된 형태이다:

• E-step은 변함이 없고, M-step은 다음과 같이 수정이 필요하다.
11.4.3 EM for mixture of experts
• Expected log likelihood Q 정의하기
정규분포

11.4.3 EM for mixture of experts
• w,에 대해서, MLE를 하기 위해서 Q에서 관계없는 term은 지운다.

• rik가 작으면, ith training example에 대한 에러는 작게 취급한다.(locally weighted linear regression)
11.4.3 EM for mixture of experts
• V에 대해서 MLE하기 위해서, 관계없는 term은 지운다

• We recognize this as equivalent to the log-likelihood for multinomial logistic regression in Equation 8.34,
• Thus we can estimate V by fitting a logistic regression model to soft target labels
Log-likelihood of multi-class logistic regression
11.4.3 EM for mixture of experts
• E-step

• M-step: maximize Q(θ,θold) wrt wk, σ2k and V

Linear regression

estimate V by fitting a logistic regression model to soft target labels
Logistic regression
11.4.4 EM for DGMs with hidden variables
• complete data log likelihood
11.4.4 EM for DGMs with hidden variables
N=데이터수, V=노드수, Kpa(t) = 노드 t의 부모의 상태수, Kt = t노드의 상태수

모든 데이터 xi에서 노드t의 상태가 k였고, t의 부모조합이 c
이였을 횟수
11.4.4 EM for DGMs with hidden variables
• 데이터 노드 x에 hidden이나 missing이 있으면, Ntck를 셀 수가 없다.

사실 Ntck는 세봐야 아는 건데 관찰
이 안되거나 히든이면 모르니까 GM
조건부파라메터를 이용해서 확률
추론으로 기대값을 구함
11.4.4 EM for DGMs with hidden variables
• E-Step
• 앞장과 같이 ESS=Ntck 구하기
• M-Step
• Given these ESS, the M step has the simple form(ML 추정으로 구함)
11.5 Model selection for latent variable models
• K를 반드시 명시해주어야 함 = K는 클러스터의 갯수 = 모델 셀렉션 문제
• marginal likelihood: likelihood가 가장 큰 K를 고른다

• F-fold 교차 검증(cross-validated)으로 구할 때, F번 그리고 K의 상태 수만큼 돌려야해서 너무 귀찮..--> 샘플링 하
는 방법이 있다고(MCMC), Section 25.2 for details
• K-means는 likelihood는 없는데 K값은 어떻게 구하나?

Probability Model이 좀 더 찾기
쉬워서 더 선호하는 이유가 되
기도 함
Conclusion
• MLE 를 하고 싶은데, 관찰 불가능한 변수가 있어서 MLE를 하지 못한다.
• MLE를 하는데 관찰 불가능한 변수를 ESS( Expected Sufficient Statistics)라고 부른다.

• ESS를 Bayes rule(GMM, Expert Mixture), inference(DGM)를 통해 추측한다.(E-step)
• 추측된 ESS를 가지고, MLE를 한다.

More Related Content

What's hot

PRML Chapter 9
PRML Chapter 9PRML Chapter 9
PRML Chapter 9Sunwoo Kim
 
Variational Autoencoder
Variational AutoencoderVariational Autoencoder
Variational AutoencoderMark Chang
 
PR-231: A Simple Framework for Contrastive Learning of Visual Representations
PR-231: A Simple Framework for Contrastive Learning of Visual RepresentationsPR-231: A Simple Framework for Contrastive Learning of Visual Representations
PR-231: A Simple Framework for Contrastive Learning of Visual RepresentationsJinwon Lee
 
Topic 1.4: Randomized Algorithms
Topic 1.4: Randomized AlgorithmsTopic 1.4: Randomized Algorithms
Topic 1.4: Randomized AlgorithmsKM Bappi
 
Build an efficient Machine Learning model with LightGBM
Build an efficient Machine Learning model with LightGBMBuild an efficient Machine Learning model with LightGBM
Build an efficient Machine Learning model with LightGBMPoo Kuan Hoong
 
Deep Belief nets
Deep Belief netsDeep Belief nets
Deep Belief netsbutest
 
Cross-validation Tutorial: What, how and which?
Cross-validation Tutorial: What, how and which?Cross-validation Tutorial: What, how and which?
Cross-validation Tutorial: What, how and which?Pradeep Redddy Raamana
 
Jonathan Ronen - Variational Autoencoders tutorial
Jonathan Ronen - Variational Autoencoders tutorialJonathan Ronen - Variational Autoencoders tutorial
Jonathan Ronen - Variational Autoencoders tutorialJonathan Ronen
 
MobileNet - PR044
MobileNet - PR044MobileNet - PR044
MobileNet - PR044Jinwon Lee
 
Introduction to XGBoost
Introduction to XGBoostIntroduction to XGBoost
Introduction to XGBoostJoonyoung Yi
 
Feature Selection in Machine Learning
Feature Selection in Machine LearningFeature Selection in Machine Learning
Feature Selection in Machine LearningUpekha Vandebona
 
Manifold learning with application to object recognition
Manifold learning with application to object recognitionManifold learning with application to object recognition
Manifold learning with application to object recognitionzukun
 
InfoGAN: Interpretable Representation Learning by Information Maximizing Gene...
InfoGAN: Interpretable Representation Learning by Information Maximizing Gene...InfoGAN: Interpretable Representation Learning by Information Maximizing Gene...
InfoGAN: Interpretable Representation Learning by Information Maximizing Gene...Joonhyung Lee
 

What's hot (20)

PRML Chapter 9
PRML Chapter 9PRML Chapter 9
PRML Chapter 9
 
Variational Autoencoder
Variational AutoencoderVariational Autoencoder
Variational Autoencoder
 
PR-231: A Simple Framework for Contrastive Learning of Visual Representations
PR-231: A Simple Framework for Contrastive Learning of Visual RepresentationsPR-231: A Simple Framework for Contrastive Learning of Visual Representations
PR-231: A Simple Framework for Contrastive Learning of Visual Representations
 
Topic 1.4: Randomized Algorithms
Topic 1.4: Randomized AlgorithmsTopic 1.4: Randomized Algorithms
Topic 1.4: Randomized Algorithms
 
Support vector machine
Support vector machineSupport vector machine
Support vector machine
 
Dbscan algorithom
Dbscan algorithomDbscan algorithom
Dbscan algorithom
 
vector QUANTIZATION
vector QUANTIZATIONvector QUANTIZATION
vector QUANTIZATION
 
Build an efficient Machine Learning model with LightGBM
Build an efficient Machine Learning model with LightGBMBuild an efficient Machine Learning model with LightGBM
Build an efficient Machine Learning model with LightGBM
 
Deep Belief nets
Deep Belief netsDeep Belief nets
Deep Belief nets
 
Analysis of Algorithm
Analysis of AlgorithmAnalysis of Algorithm
Analysis of Algorithm
 
Cross-validation Tutorial: What, how and which?
Cross-validation Tutorial: What, how and which?Cross-validation Tutorial: What, how and which?
Cross-validation Tutorial: What, how and which?
 
GMM
GMMGMM
GMM
 
Jonathan Ronen - Variational Autoencoders tutorial
Jonathan Ronen - Variational Autoencoders tutorialJonathan Ronen - Variational Autoencoders tutorial
Jonathan Ronen - Variational Autoencoders tutorial
 
MobileNet - PR044
MobileNet - PR044MobileNet - PR044
MobileNet - PR044
 
Introduction to XGBoost
Introduction to XGBoostIntroduction to XGBoost
Introduction to XGBoost
 
Feature Selection in Machine Learning
Feature Selection in Machine LearningFeature Selection in Machine Learning
Feature Selection in Machine Learning
 
String matching algorithms
String matching algorithmsString matching algorithms
String matching algorithms
 
Manifold learning with application to object recognition
Manifold learning with application to object recognitionManifold learning with application to object recognition
Manifold learning with application to object recognition
 
Knn 160904075605-converted
Knn 160904075605-convertedKnn 160904075605-converted
Knn 160904075605-converted
 
InfoGAN: Interpretable Representation Learning by Information Maximizing Gene...
InfoGAN: Interpretable Representation Learning by Information Maximizing Gene...InfoGAN: Interpretable Representation Learning by Information Maximizing Gene...
InfoGAN: Interpretable Representation Learning by Information Maximizing Gene...
 

Similar to 머피's 머신러닝, Mixture model and EM algorithm

머피의 머신러닝 : Gaussian Processes
머피의 머신러닝 : Gaussian Processes머피의 머신러닝 : Gaussian Processes
머피의 머신러닝 : Gaussian ProcessesJungkyu Lee
 
Coursera Machine Learning (by Andrew Ng)_강의정리
Coursera Machine Learning (by Andrew Ng)_강의정리Coursera Machine Learning (by Andrew Ng)_강의정리
Coursera Machine Learning (by Andrew Ng)_강의정리SANG WON PARK
 
Variational inference intro. (korean ver.)
Variational inference intro. (korean ver.)Variational inference intro. (korean ver.)
Variational inference intro. (korean ver.)Kiho Hong
 
머피의 머신러닝: Undirencted Graphical Model
머피의 머신러닝: Undirencted Graphical Model머피의 머신러닝: Undirencted Graphical Model
머피의 머신러닝: Undirencted Graphical ModelJungkyu Lee
 
KOOC Ch8. k-means & GMM
KOOC Ch8. k-means & GMMKOOC Ch8. k-means & GMM
KOOC Ch8. k-means & GMMsuman_lim
 
[신경망기초] 소프트맥스회귀분석
[신경망기초] 소프트맥스회귀분석[신경망기초] 소프트맥스회귀분석
[신경망기초] 소프트맥스회귀분석jaypi Ko
 
Chapter 19 Variational Inference
Chapter 19 Variational InferenceChapter 19 Variational Inference
Chapter 19 Variational InferenceKyeongUkJang
 
Computational Complexity
Computational ComplexityComputational Complexity
Computational Complexityskku_npc
 
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 4장. 모델 훈련
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 4장. 모델 훈련[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 4장. 모델 훈련
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 4장. 모델 훈련Haesun Park
 
알고리즘 연합캠프 세미나 1-C (알고리즘 설계와 모델링 및 수학)
알고리즘 연합캠프 세미나 1-C (알고리즘 설계와 모델링 및 수학)알고리즘 연합캠프 세미나 1-C (알고리즘 설계와 모델링 및 수학)
알고리즘 연합캠프 세미나 1-C (알고리즘 설계와 모델링 및 수학)HYUNJEONG KIM
 
8. Logistic Regression
8. Logistic Regression8. Logistic Regression
8. Logistic RegressionJungkyu Lee
 
Data Visualization and t-SNE
Data Visualization and t-SNEData Visualization and t-SNE
Data Visualization and t-SNEHyeongmin Lee
 
[기초개념] Graph Convolutional Network (GCN)
[기초개념] Graph Convolutional Network (GCN)[기초개념] Graph Convolutional Network (GCN)
[기초개념] Graph Convolutional Network (GCN)Donghyeon Kim
 
(Book Summary) Classification and ensemble(book review)
(Book Summary) Classification and ensemble(book review)(Book Summary) Classification and ensemble(book review)
(Book Summary) Classification and ensemble(book review)MYEONGGYU LEE
 
[컴퓨터비전과 인공지능] 7. 합성곱 신경망 2
[컴퓨터비전과 인공지능] 7. 합성곱 신경망 2[컴퓨터비전과 인공지능] 7. 합성곱 신경망 2
[컴퓨터비전과 인공지능] 7. 합성곱 신경망 2jdo
 
Mlp logical input pattern classfication report doc
Mlp logical input pattern classfication report docMlp logical input pattern classfication report doc
Mlp logical input pattern classfication report doc우진 신
 

Similar to 머피's 머신러닝, Mixture model and EM algorithm (17)

머피의 머신러닝 : Gaussian Processes
머피의 머신러닝 : Gaussian Processes머피의 머신러닝 : Gaussian Processes
머피의 머신러닝 : Gaussian Processes
 
Coursera Machine Learning (by Andrew Ng)_강의정리
Coursera Machine Learning (by Andrew Ng)_강의정리Coursera Machine Learning (by Andrew Ng)_강의정리
Coursera Machine Learning (by Andrew Ng)_강의정리
 
Variational inference intro. (korean ver.)
Variational inference intro. (korean ver.)Variational inference intro. (korean ver.)
Variational inference intro. (korean ver.)
 
머피의 머신러닝: Undirencted Graphical Model
머피의 머신러닝: Undirencted Graphical Model머피의 머신러닝: Undirencted Graphical Model
머피의 머신러닝: Undirencted Graphical Model
 
KOOC Ch8. k-means & GMM
KOOC Ch8. k-means & GMMKOOC Ch8. k-means & GMM
KOOC Ch8. k-means & GMM
 
[신경망기초] 소프트맥스회귀분석
[신경망기초] 소프트맥스회귀분석[신경망기초] 소프트맥스회귀분석
[신경망기초] 소프트맥스회귀분석
 
Chapter 19 Variational Inference
Chapter 19 Variational InferenceChapter 19 Variational Inference
Chapter 19 Variational Inference
 
Computational Complexity
Computational ComplexityComputational Complexity
Computational Complexity
 
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 4장. 모델 훈련
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 4장. 모델 훈련[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 4장. 모델 훈련
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 4장. 모델 훈련
 
Gan
GanGan
Gan
 
알고리즘 연합캠프 세미나 1-C (알고리즘 설계와 모델링 및 수학)
알고리즘 연합캠프 세미나 1-C (알고리즘 설계와 모델링 및 수학)알고리즘 연합캠프 세미나 1-C (알고리즘 설계와 모델링 및 수학)
알고리즘 연합캠프 세미나 1-C (알고리즘 설계와 모델링 및 수학)
 
8. Logistic Regression
8. Logistic Regression8. Logistic Regression
8. Logistic Regression
 
Data Visualization and t-SNE
Data Visualization and t-SNEData Visualization and t-SNE
Data Visualization and t-SNE
 
[기초개념] Graph Convolutional Network (GCN)
[기초개념] Graph Convolutional Network (GCN)[기초개념] Graph Convolutional Network (GCN)
[기초개념] Graph Convolutional Network (GCN)
 
(Book Summary) Classification and ensemble(book review)
(Book Summary) Classification and ensemble(book review)(Book Summary) Classification and ensemble(book review)
(Book Summary) Classification and ensemble(book review)
 
[컴퓨터비전과 인공지능] 7. 합성곱 신경망 2
[컴퓨터비전과 인공지능] 7. 합성곱 신경망 2[컴퓨터비전과 인공지능] 7. 합성곱 신경망 2
[컴퓨터비전과 인공지능] 7. 합성곱 신경망 2
 
Mlp logical input pattern classfication report doc
Mlp logical input pattern classfication report docMlp logical input pattern classfication report doc
Mlp logical input pattern classfication report doc
 

More from Jungkyu Lee

7. Linear Regression
7. Linear Regression7. Linear Regression
7. Linear RegressionJungkyu Lee
 
4. Gaussian Model
4. Gaussian Model4. Gaussian Model
4. Gaussian ModelJungkyu Lee
 
3 Generative models for discrete data
3 Generative models for discrete data3 Generative models for discrete data
3 Generative models for discrete dataJungkyu Lee
 
From A Neural Probalistic Language Model to Word2vec
From A Neural Probalistic Language Model to Word2vecFrom A Neural Probalistic Language Model to Word2vec
From A Neural Probalistic Language Model to Word2vecJungkyu Lee
 
머피의 머신러닝: 17장 Markov Chain and HMM
머피의 머신러닝: 17장  Markov Chain and HMM머피의 머신러닝: 17장  Markov Chain and HMM
머피의 머신러닝: 17장 Markov Chain and HMMJungkyu Lee
 
Murpy's Machine Learning 9. Generalize Linear Model
Murpy's Machine Learning 9. Generalize Linear ModelMurpy's Machine Learning 9. Generalize Linear Model
Murpy's Machine Learning 9. Generalize Linear ModelJungkyu Lee
 
Murpy's Machine Learning:14. Kernel
Murpy's Machine Learning:14. KernelMurpy's Machine Learning:14. Kernel
Murpy's Machine Learning:14. KernelJungkyu Lee
 
머피의 머신러닝 13 Sparse Linear Model
머피의 머신러닝 13 Sparse Linear Model머피의 머신러닝 13 Sparse Linear Model
머피의 머신러닝 13 Sparse Linear ModelJungkyu Lee
 
머피's 머신러닝: Latent Linear Model
머피's 머신러닝: Latent Linear Model머피's 머신러닝: Latent Linear Model
머피's 머신러닝: Latent Linear ModelJungkyu Lee
 
머피's 머신러닝: Latent Linear Model
머피's 머신러닝: Latent Linear Model머피's 머신러닝: Latent Linear Model
머피's 머신러닝: Latent Linear ModelJungkyu Lee
 
파이널 판타지 3 루트 공략
파이널 판타지 3 루트 공략파이널 판타지 3 루트 공략
파이널 판타지 3 루트 공략Jungkyu Lee
 
1. boolean 검색
1. boolean 검색1. boolean 검색
1. boolean 검색Jungkyu Lee
 
ThinkBayes: chapter 13  simulation
ThinkBayes: chapter 13  simulationThinkBayes: chapter 13  simulation
ThinkBayes: chapter 13  simulationJungkyu Lee
 
ThinkBayes: Chapter 9 two_dimensions
ThinkBayes: Chapter 9 two_dimensionsThinkBayes: Chapter 9 two_dimensions
ThinkBayes: Chapter 9 two_dimensionsJungkyu Lee
 
Jensen's inequality, EM 알고리즘
Jensen's inequality, EM 알고리즘 Jensen's inequality, EM 알고리즘
Jensen's inequality, EM 알고리즘 Jungkyu Lee
 
앙상블 학습 기반의 추천시스템 개발
앙상블 학습 기반의 추천시스템 개발앙상블 학습 기반의 추천시스템 개발
앙상블 학습 기반의 추천시스템 개발Jungkyu Lee
 
TETRIS AI WITH REINFORCEMENT LEARNING
TETRIS AI WITH REINFORCEMENT LEARNINGTETRIS AI WITH REINFORCEMENT LEARNING
TETRIS AI WITH REINFORCEMENT LEARNINGJungkyu Lee
 
Eigenvalues of regular graphs
Eigenvalues of regular graphsEigenvalues of regular graphs
Eigenvalues of regular graphsJungkyu Lee
 
Support Vector Machine Tutorial 한국어
Support Vector Machine Tutorial 한국어Support Vector Machine Tutorial 한국어
Support Vector Machine Tutorial 한국어Jungkyu Lee
 

More from Jungkyu Lee (19)

7. Linear Regression
7. Linear Regression7. Linear Regression
7. Linear Regression
 
4. Gaussian Model
4. Gaussian Model4. Gaussian Model
4. Gaussian Model
 
3 Generative models for discrete data
3 Generative models for discrete data3 Generative models for discrete data
3 Generative models for discrete data
 
From A Neural Probalistic Language Model to Word2vec
From A Neural Probalistic Language Model to Word2vecFrom A Neural Probalistic Language Model to Word2vec
From A Neural Probalistic Language Model to Word2vec
 
머피의 머신러닝: 17장 Markov Chain and HMM
머피의 머신러닝: 17장  Markov Chain and HMM머피의 머신러닝: 17장  Markov Chain and HMM
머피의 머신러닝: 17장 Markov Chain and HMM
 
Murpy's Machine Learning 9. Generalize Linear Model
Murpy's Machine Learning 9. Generalize Linear ModelMurpy's Machine Learning 9. Generalize Linear Model
Murpy's Machine Learning 9. Generalize Linear Model
 
Murpy's Machine Learning:14. Kernel
Murpy's Machine Learning:14. KernelMurpy's Machine Learning:14. Kernel
Murpy's Machine Learning:14. Kernel
 
머피의 머신러닝 13 Sparse Linear Model
머피의 머신러닝 13 Sparse Linear Model머피의 머신러닝 13 Sparse Linear Model
머피의 머신러닝 13 Sparse Linear Model
 
머피's 머신러닝: Latent Linear Model
머피's 머신러닝: Latent Linear Model머피's 머신러닝: Latent Linear Model
머피's 머신러닝: Latent Linear Model
 
머피's 머신러닝: Latent Linear Model
머피's 머신러닝: Latent Linear Model머피's 머신러닝: Latent Linear Model
머피's 머신러닝: Latent Linear Model
 
파이널 판타지 3 루트 공략
파이널 판타지 3 루트 공략파이널 판타지 3 루트 공략
파이널 판타지 3 루트 공략
 
1. boolean 검색
1. boolean 검색1. boolean 검색
1. boolean 검색
 
ThinkBayes: chapter 13  simulation
ThinkBayes: chapter 13  simulationThinkBayes: chapter 13  simulation
ThinkBayes: chapter 13  simulation
 
ThinkBayes: Chapter 9 two_dimensions
ThinkBayes: Chapter 9 two_dimensionsThinkBayes: Chapter 9 two_dimensions
ThinkBayes: Chapter 9 two_dimensions
 
Jensen's inequality, EM 알고리즘
Jensen's inequality, EM 알고리즘 Jensen's inequality, EM 알고리즘
Jensen's inequality, EM 알고리즘
 
앙상블 학습 기반의 추천시스템 개발
앙상블 학습 기반의 추천시스템 개발앙상블 학습 기반의 추천시스템 개발
앙상블 학습 기반의 추천시스템 개발
 
TETRIS AI WITH REINFORCEMENT LEARNING
TETRIS AI WITH REINFORCEMENT LEARNINGTETRIS AI WITH REINFORCEMENT LEARNING
TETRIS AI WITH REINFORCEMENT LEARNING
 
Eigenvalues of regular graphs
Eigenvalues of regular graphsEigenvalues of regular graphs
Eigenvalues of regular graphs
 
Support Vector Machine Tutorial 한국어
Support Vector Machine Tutorial 한국어Support Vector Machine Tutorial 한국어
Support Vector Machine Tutorial 한국어
 

머피's 머신러닝, Mixture model and EM algorithm

  • 1. ML study 6번째 Mixture models and the EM algorithm
  • 2. 11.1 Latent variable models 11.2 Mixture models 11.4 The EM algorithm 11.5 Model selection for latent variable models 11.6 Fitting models with missing data
  • 3. 11.1 Latent variable models • 10장에서 graphical models로 고차원 결합확률을 그래프로 표현했음 • 서로 의존관계가 있는 두 변수는 그래프 상에서 edge를 이음 • Latent variable models • 관찰된 변수는 숨겨진 공통 원인으로부터 발생했으므로 서로 연관되어 있다 • fit이 어렵다 • hidden 변수로 모델의 파라메터를 줄일 수 있다 • 그림 설명, 히든 변수가 있는 것(왼), 비져블 공간에서 바로 습관과 증상을 모델링(오) •
  • 4. 11.2 Mixture models • VM의 가장 간단한 형태 • zi ∈{1,...,K} • p(zi)=Cat(π) • p(xi|zi =k)=pk(xi) • pk : 관찰치에 대한 k번째 base 분포 • 혼합 모델 (mixture model): pk들의 convex combination
  • 5. 11.2 Mixture models 11.2.1 Mixtures of Gaussians • 가우시안 혼합 = mixture of Gaussians = MOG = Gaussian Mixture Model = GMM • 충분히 많은 수 혼합 컴포넌트가 있으면, GMM은 RD 에서 정의되는 모든 분포를 근사해 낼 수 있다
  • 6. 11.2 Mixture models 11.2.2 Mixture of multinoullis(여기서는 베르누이) • 데이터가 D차원 bit vectors x라고 하자. • class conditional density는 다음과 같이 베르누이 분포의 곱으로 표현할 수 있다 (=binomial) • μjk 는 클러스터 k에서 j번재 비트가 켜질 확률 . 모든 차원에 대해서 곱한 것 (각 차원은 베르누이)= binomial • 위의 수식을 아래에 대입하면 카테고리 분포의 믹스쳐가 만들어진다 •
  • 7. 11.2.3 Using mixture models for clustering • Mixture model을 이용해 클러스터링할 수도 있다(GMM에서 는 각 데이터가 어느 가우시안에 속하는지?). • 혼합 모델을 학습 후(M-step) compute p(zi =k|xi,θ) (E-step) // EM은 나중에 다룬다 • DA 랑 비슷하다는 것을 알 수가 있습니다. (http://play.daumcorp.com/display/~sweaterr/4.+Gaussian+Model) • 사실 • 소프트 클러스터링이라고 부른다. • MAP 추정으로 hard-clustering 할 수 있다.
  • 8. 11.2.4 Mixtures of experts • 입력 공간의 특정 지역마다 하나의 전문가가 있다 • wk는 각 latent 변수의 상태 k마다 다르다
  • 9. gating function • 어떤 전문가를 쓸 것인가? gating function이라고 한다.
  • 11. • discuss how to fit this model in Section 11.4.3.
  • 12. 11.3 Parameter estimation for mixture models • zi가 관찰됐다면, d-분리에 의해서 θz⊥θx|D이 성립하고, posterior도 factorize될 수 있다 • 하지만 LVM에서 zi는 hidden이므로, 파라메터들은 더이상 독립적이지 않고, posterior도 factorize되지 않는다. • 이는 MAP, MLE의 계산도 어렵게 만든다
  • 13. 11.3.1 Unidentifiability • LVM에서 p(θ|D) 계산하는 것에 대한 가장 큰 문제는 multiple mode(다중 봉우리)를 가졌다는 것이다. • 예를 들어 GMM에서, zi 가 관찰되었다면, 파라메터에 대한 unimodal posterior를 갖게 된다. • NIW는 평균과 분산에 대한 분포 • 결과적으로, global optimal한 MAP 추정을 얻을 수 있다 • 그러나,zi이 히든이면, 각 zi를 채우는 가능한 방법마다, 다른 unimodal한 likelihood를 얻는다 • 그러므로, posterior p(θ|D)를 얻기위해, zi를 marginalize할 때, posterior는 multimodal이 된다.
  • 14. 11.3.1 Unidentifiability • 그림 설명 • (왼쪽) x축=1차원 데이터 포인트, y차원이 빈도수, 2개의 Gaussian(평균 -10,10)의 혼합이다. • (오른쪽) p(D|mu1,mu2) 의 표면, 두개의 mode가 존재한다.(평균벡터=(10,-10) 또는 (-10,10))) • 즉 z에 따라, 첫번째, 두번째 가우신안의 순서가 바뀔 수 있다. K!개의 가능한 레이블링 • 파라메터가 identifiable하지 않다고 한다
  • 15. 11.3.1 Unidentifiability • Unidentifiability는 베이지안 추론에서 문제를 일으킨다 • 예를 들어, posterior mean을 근사하기 위해, θ(s)∼p(θ|D)로 몇개의 θ를 샘플링하고 그것을 다음과 같이 평균낸 다면: • 만약 샘플이 서로 다른 mode에서 나왔다면, 평균은 의미가 없어진다.
  • 16. 11.3.2 Computing a MAP estimate is non-convex • 이전 섹션에, 다소 휴리스틱하게 likelihood는 multiple mode를 갖을수 있고 그래서, MAP 또는 ML 추정이 어려 워진다고 했다. • 이번 섹션에서, 좀 더 대수적으로 그것을 보이겠다. • 불행히도, 위의 목적함수의 최적화는 log가 sum_z에 안들어가기 때문에 할 수 없다 • 결합 확률 분포(joint probability distribution) p(zi,xi|θ)이 지수족이라고 가정하면 • φ(x,z) are the sufficient statistics Z(θ) is the normalization constant • complete data log likelihood는 다음과 같다(x, z 둘다 관찰가능) • 첫번째 term은 θ 에 linear하고, Z(θ)는 convex 함수(see 9.2.3 Log partition function)이기 때문에 전체 목적함수 는 concave(마이너스 기호때문에)하므로, 하나의 maximum이 있다
  • 17. 11.3.2 Computing a MAP estimate is non-convex • latent 변수가 있는 likelihood는 z는 관찰 못하므로 데이터도 없다 • p(x,z)는 exponential family라고 가정하였으므로, • log-sum-exp 함수는 convex하고 Z(θ)도 convex하다 • 하지만, 두 convex 함수들의 차는 일반적으로 convex하지 않다 • 그러므로, 위의 likelihood는 local optima를 가진다 • 대부분 최적화 알고리즘은 local optimum만을 찾을 수 있다 • simulated annealing 이나 유전자 알고리즘이 global optimum을 찾을 수 있다고 하지만, 무한대 시간에서라든 지 하는 이상적인 가정하에서 일 뿐이다 • 실제로는, random restart를 여러번 하는 방식을 쓴다
  • 18. 11.4 The EM algorithm • 모든 관련있는 랜덤 변수의 모든 값이 관찰된다면, ML 또는 MAP을 계산하는 것은 쉽다 • 하지만, missing 데이터나 latent 변수들을 가지고 있다면, ML이나 MAP 추정은 어려워진다(앞 섹션에서 convex 해지지 않는다고 했다 ) • 한가지 방법은 negative log likelihood or NLL의 지역 최저점을 찾기 위해 경사 강하 최적기(gradient-based optimizer)를 쓰는 것이다. • 하지만, mixing weight의 합은 1이여야 한다와 같은 제약 조건을 가해줘야 하는 경우가 많다 • 좀 더 심플한 방법(하지만 항상 빠르지는 않은)이 바로 EM(expectation maximization)을 쓰는 것이다 • EM은 데이터 완전히 관찰되었다면, ML/ MAP 추정은 계산하기 쉽다는 사실을 이용한다 • EM은 모델의 파라메터가 주어졌을 때, missing values를 추론하는 E-step과 E-step에서 데이터가 채워졌을 때, parameters를 최적화하는 M-step으로 이루어져 있다. •
  • 19. 11.4.1 Basic idea • xi는 i번째 볼수 있거나 관찰된 변수라고 하고, zi는 숨겨졌거나 missing된 변수라고 하자. • 목적은 다음과 같은 likelihood를 maximize하는 것이다 • 로그는 sum 안에 들어갈 수 없기 때문에, 최적화하기 어렵다. • EM은 이 문제를 다음과 같이 푼다. • complete data log likelihood를 정의한다 • Z를 관찰할수 없으므로, 계산할 수 없다
  • 20. • 그래서 다음과 같은 expected complete data log likelihood을 정의한다. • t는 현재 iteration을 의미한다. • 현재 iteration에서 한 단계 이전 iteration에서의 파라메터와 데이터가 주어졌을 때, complete data log likelihood 의 기대값 • Estep: Q(θ,θt−1)을 계산한다 또는 MLE를 구하는데 필요한 term(GMM에서는 z) • Mstep: Q함수를 θ에 대해서 최적화한다. EM algorithm은 the log likelihood of the observed data를 단조 증가시킨다고 알려져 있다.(만약 그렇지 않다면 math 또는 code에 bug가 있는 것이다.) (by jensen's inequality, 이 정리에 대한 참고자료)
  • 21. 과정 PASS, 결론만으로 진행 11.4.2 EM for GMMs 11.4.2.1 Auxiliary function 기대값 성질
  • 22.
  • 23. 11.4.2 EM for GMMs M-step • rik을 안다고 가정하면 MLE를 이용해서 GMM의 paramter들을 업데이트할 수 있다. •  (11.26)을 π에 대해서 미분해서 0을 놓고 정리하면(모든 k에 대해서 πk의 합은 1인 제약조건을 추가 ,다음장) • μk and Σk 를 최적화하기 위해서(11.26)에서 π관련된 항을 지우고, 나머지에 정규분포 수식을 대입하면 • 역시 마찬가지로 MLE 추정을 하면 GDA에서는 각 클래스끼리의 평균이었지만, soft하게 각 클래스가 될 확률의 가중치 평균이 되었다. GDA에서는 각 클래스끼리의 분산이었지만, soft하게 각 클래스가 될 확률의 가중치 분산이 되었다.
  • 24.
  • 25. 11.4.2 EM for GMMs E-step 위의 수식은 Gaussian discriminant Analysis(see 4.2.1)와 비슷해진다
  • 26. 11.4.2 EM for GMMs • 초기 상태: 랜덤하게 두 가우시안의 평균과 분산을 정해준다(분산은 I행렬)
  • 27. • e-step: 데이타와 두 가우시안의 파라메터가 주어졌을 때, k클러스터에 속할 확률(p(zi=k|xi,θ) = rik)을 계산한다
  • 28. • m-step: (p(zi=k|xi,θ) = rik)을 이용해서 두 가우시안의 파라메터(평균과 분산)을 MLE로 업데이트한다
  • 29.
  • 31. 11.4.2.5 K-means algorithm • K-means는 GMM의 special case로 볼 수 있음 • 다음과 같이 가정한다: • Σk=σ2 ID is fixed, //모든 가우시안의 공분산은 같고 동그랗다 • πk =1/K is fixed // 가우시안의 혼합율로 모두 동일하다. • E step: 가장 resonsibility가 큰 z로 hard assign한다. • 모든 정규분포이 동일한 동그란 공분산을 가정했기 때문에 xi에 대해서 가장 그럴듯한 cluster k는 • • 각 클러스터에는 중심이 있고, xi에서 가장 가까운 중심을 가지고 있는 클러스터로 고른다
  • 32. 11.4.2.8 MAP estimation of GMM • EM에서 M단계의 MLE는 overfit 될 수 있다. • K=2, Σk=σ2kI 라고 가정하고 하나의 가우시안에 하나의 데이터 x1만 할당되었을 때, 그 데이터는 likelihood에 다 음과 같이 기여한다. • 하나의 데이터 자체가 평균이 되기 때문에 exp위에 올라가는 수치가 0이된다. • 즉 σ2→0 이 될수록 값이 너무 커져버려서 likelihood에 비이상적으로 기여하게 된다
  • 33. 11.4.2.8 MAP estimation of GMM • 간단한 해결책은 MAP을 쓰는 것이다. • 새로운 auxiliary 함수는 log prior가 추가된 형태이다: • E-step은 변함이 없고, M-step은 다음과 같이 수정이 필요하다.
  • 34. 11.4.3 EM for mixture of experts • Expected log likelihood Q 정의하기
  • 35. 정규분포 11.4.3 EM for mixture of experts • w,에 대해서, MLE를 하기 위해서 Q에서 관계없는 term은 지운다. • rik가 작으면, ith training example에 대한 에러는 작게 취급한다.(locally weighted linear regression)
  • 36. 11.4.3 EM for mixture of experts • V에 대해서 MLE하기 위해서, 관계없는 term은 지운다 • We recognize this as equivalent to the log-likelihood for multinomial logistic regression in Equation 8.34, • Thus we can estimate V by fitting a logistic regression model to soft target labels Log-likelihood of multi-class logistic regression
  • 37. 11.4.3 EM for mixture of experts • E-step • M-step: maximize Q(θ,θold) wrt wk, σ2k and V Linear regression estimate V by fitting a logistic regression model to soft target labels Logistic regression
  • 38. 11.4.4 EM for DGMs with hidden variables • complete data log likelihood
  • 39. 11.4.4 EM for DGMs with hidden variables N=데이터수, V=노드수, Kpa(t) = 노드 t의 부모의 상태수, Kt = t노드의 상태수 모든 데이터 xi에서 노드t의 상태가 k였고, t의 부모조합이 c 이였을 횟수
  • 40. 11.4.4 EM for DGMs with hidden variables • 데이터 노드 x에 hidden이나 missing이 있으면, Ntck를 셀 수가 없다. 사실 Ntck는 세봐야 아는 건데 관찰 이 안되거나 히든이면 모르니까 GM 조건부파라메터를 이용해서 확률 추론으로 기대값을 구함
  • 41. 11.4.4 EM for DGMs with hidden variables • E-Step • 앞장과 같이 ESS=Ntck 구하기 • M-Step • Given these ESS, the M step has the simple form(ML 추정으로 구함)
  • 42. 11.5 Model selection for latent variable models • K를 반드시 명시해주어야 함 = K는 클러스터의 갯수 = 모델 셀렉션 문제 • marginal likelihood: likelihood가 가장 큰 K를 고른다 • F-fold 교차 검증(cross-validated)으로 구할 때, F번 그리고 K의 상태 수만큼 돌려야해서 너무 귀찮..--> 샘플링 하 는 방법이 있다고(MCMC), Section 25.2 for details • K-means는 likelihood는 없는데 K값은 어떻게 구하나? Probability Model이 좀 더 찾기 쉬워서 더 선호하는 이유가 되 기도 함
  • 43. Conclusion • MLE 를 하고 싶은데, 관찰 불가능한 변수가 있어서 MLE를 하지 못한다. • MLE를 하는데 관찰 불가능한 변수를 ESS( Expected Sufficient Statistics)라고 부른다. • ESS를 Bayes rule(GMM, Expert Mixture), inference(DGM)를 통해 추측한다.(E-step) • 추측된 ESS를 가지고, MLE를 한다.