csc 411 lectures 16 17 expectation maximization
play

CSC 411 Lectures 1617: Expectation-Maximization Roger Grosse, - PowerPoint PPT Presentation

CSC 411 Lectures 1617: Expectation-Maximization Roger Grosse, Amir-massoud Farahmand, and Juan Carrasquilla University of Toronto UofT CSC 411: 15-EM 1 / 33 A Generative View of Clustering Last time: hard and soft k-means algorithm Today:


  1. CSC 411 Lectures 16–17: Expectation-Maximization Roger Grosse, Amir-massoud Farahmand, and Juan Carrasquilla University of Toronto UofT CSC 411: 15-EM 1 / 33

  2. A Generative View of Clustering Last time: hard and soft k-means algorithm Today: statistical formulation of clustering → principled, justification for updates We need a sensible measure of what it means to cluster the data well ◮ This makes it possible to judge different methods ◮ It may help us decide on the number of clusters An obvious approach is to imagine that the data was produced by a generative model ◮ Then we adjust the model parameters to maximize the probability that it would produce exactly the data we observed UofT CSC 411: 15-EM 2 / 33

  3. Generative Models Recap We model the joint distribution as, p ( x , z ) = p ( x | z ) p ( z ) But in unsupervised clustering we do not have the class labels z . What can we do instead? � � p ( x | z ) p ( z ) p ( x ) = p ( x , z ) = z z This is a mixture model UofT CSC 411: 15-EM 3 / 33

  4. Gaussian Mixture Model (GMM) Most common mixture model: Gaussian mixture model (GMM) A GMM represents a distribution as K � p ( x ) = π k N ( x | µ k , Σ k ) k =1 with π k the mixing coefficients, where: K � π k = 1 and π k ≥ 0 ∀ k k =1 GMM is a density estimator GMMs are universal approximators of densities (if you have enough Gaussians). Even diagonal GMMs are universal approximators. In general mixture models are very powerful, but harder to optimize UofT CSC 411: 15-EM 4 / 33

  5. Visualizing a Mixture of Gaussians – 1D Gaussians If you fit a Gaussian to data: Now, we are trying to fit a GMM (with K = 2 in this example): [Slide credit: K. Kutulakos] UofT CSC 411: 15-EM 5 / 33

  6. Visualizing a Mixture of Gaussians – 2D Gaussians UofT CSC 411: 15-EM 6 / 33

  7. Fitting GMMs: Maximum Likelihood Maximum likelihood maximizes � K � N � � π k N ( x ( n ) | µ k , Σ k ) ln p ( X | π, µ, Σ) = ln n =1 k =1 w.r.t Θ = { π k , µ k , Σ k } Problems: ◮ Singularities: Arbitrarily large likelihood when a Gaussian explains a single point ◮ Identifiability: Solution is invariant to permutations ◮ Non-convex How would you optimize this? Can we have a closed form update? Don’t forget to satisfy the constraints on π k and Σ k UofT CSC 411: 15-EM 7 / 33

  8. Latent Variable Our original representation had a hidden (latent) variable z which would represent which Gaussian generated our observation x , with some probability � Let z ∼ Categorical ( π ) (where π k ≥ 0 , k π k = 1) Then: K � p ( x ) = p ( x , z = k ) k =1 K � p ( x | z = k ) = p ( z = k ) � �� � � �� � k =1 N ( x | µ k , Σ k ) π k This breaks a complicated distribution into simple components - the price is the hidden variable. UofT CSC 411: 15-EM 8 / 33

  9. Latent Variable Models Some model variables may be unobserved, either at training or at test time, or both If occasionally unobserved they are missing, e.g., undefined inputs, missing class labels, erroneous targets Variables which are always unobserved are called latent variables, or sometimes hidden variables We may want to intentionally introduce latent variables to model complex dependencies between variables – this can actually simplify the model Form of divide-and-conquer: use simple parts to build complex models In a mixture model, the identity of the component that generated a given datapoint is a latent variable UofT CSC 411: 15-EM 9 / 33

  10. Back to GMM A Gaussian mixture distribution: K � p ( x ) = π k N ( x | µ k , Σ k ) k =1 � We had: z ∼ Categorical ( π ) (where π k ≥ 0 , k π k = 1) Joint distribution: p ( x , z ) = p ( z ) p ( x | z ) Log-likelihood: N � ln p ( x ( n ) | π, µ, Σ) ℓ ( π , µ, Σ) = ln p ( X | π, µ, Σ) = n =1 N K � � p ( x ( n ) | z ( n ) ; µ, Σ) p ( z ( n ) | π ) = ln n =1 z ( n ) =1 Note: We have a hidden variable z ( n ) for every observation General problem: sum inside the log How can we optimize this? UofT CSC 411: 15-EM 10 / 33

  11. Maximum Likelihood If we knew z ( n ) for every x ( n ) , the maximum likelihood problem is easy: N N � � ln p ( x ( n ) , z ( n ) | π, µ, Σ) = ln p ( x ( n ) | z ( n ) ; µ, Σ)+ln p ( z ( n ) | π ) ℓ ( π , µ, Σ) = n =1 n =1 We have been optimizing something similar for Gaussian bayes classifiers We would get this: � N n =1 1 [ z ( n ) = k ] x ( n ) µ k = � N n =1 1 [ z ( n ) = k ] n =1 1 [ z ( n ) = k ] ( x ( n ) − µ k )( x ( n ) − µ k ) T � N Σ k = � N n =1 1 [ z ( n ) = k ] N 1 � = 1 [ z ( n ) = k ] π k N n =1 UofT CSC 411: 15-EM 11 / 33

  12. Intuitively, How Can We Fit a Mixture of Gaussians? Optimization uses the Expectation Maximization algorithm, which alternates between two steps: 1. E-step: Compute the posterior probability over z given our current model - i.e. how much do we think each Gaussian generates each datapoint. 2. M-step: Assuming that the data really was generated this way, change the parameters of each Gaussian to maximize the probability that it would generate the data it is currently responsible for. .95 .05 .05 .95 .5 .5 .5 .5 UofT CSC 411: 15-EM 12 / 33

  13. Relation to k-Means The K-Means Algorithm: 1. Assignment step: Assign each data point to the closest cluster 2. Refitting step: Move each cluster center to the center of gravity of the data assigned to it The EM Algorithm: 1. E-step: Compute the posterior probability over z given our current model 2. M-step: Maximize the probability that it would generate the data it is currently responsible for. UofT CSC 411: 15-EM 13 / 33

  14. Expectation Maximization for GMM Overview Elegant and powerful method for finding maximum likelihood solutions for models with latent variables 1. E-step: ◮ In order to adjust the parameters, we must first solve the inference problem: Which Gaussian generated each datapoint? ◮ We cannot be sure, so it’s a distribution over all possibilities. = p ( z ( n ) = k | x ( n ) ; π, µ, Σ) γ ( n ) k 2. M-step: ◮ Each Gaussian gets a certain amount of posterior probability for each datapoint. ◮ We fit each Gaussian to the weighted datapoints ◮ We can derive closed form updates for all parameters UofT CSC 411: 15-EM 14 / 33

  15. Where does EM come from? I Remember that optimizing the likelihood is hard because of the sum inside of the log. Using Θ to denote all of our parameters:   � � � P ( x ( i ) , z ( i ) = j ; Θ) log( P ( x ( i ) ; Θ)) = ℓ ( X , Θ) = log  i i j We can use a common trick in machine learning, introduce a new distribution, q :   P ( x ( i ) , z ( i ) = j ; Θ) � � ℓ ( X , Θ) = log q j  q j i j Now we can swap them! Jensen’s inequality - for concave function (like log) �� � � f ( E [ x ]) = f p i x i ≥ p i f ( x i ) = E [ f ( x )] i i UofT CSC 411: 15-EM 15 / 33

  16. Where does EM come from? II Applying Jensen’s,   P ( x ( i ) , z ( i ) = j ; Θ) � P ( x ( i ) , z ( i ) = j ; Θ) � � � � �  ≥ log q j log q j q j q j i j i j Maximizing this lower bound will force our likelihood to increase. But how do we pick a q i that gives a good bound? UofT CSC 411: 15-EM 16 / 33

  17. EM derivation We got the sum outside but we have an inequality. � � P ( x ( i ) , z ( i ) = j ; Θ) � � ℓ ( X , Θ) ≥ q j log q j i j Lets fix the current parameters to Θ old and try to find a good q i What happens if we pick q j = p ( z ( i ) = j | x ( i ) , Θ old )? P ( x ( i ) , z ( i ) ;Θ) p ( z ( i ) = j | x ( i ) , Θ old ) = P ( x ( i ) ; Θ old ) and the inequality becomes an equality! ◮ We can now define and optimize � � � � p ( z ( i ) = j | x ( i ) , Θ old ) log P ( x ( i ) , z ( i ) = j ; Θ) Q (Θ) = i j � � P ( x ( i ) , z ( i ) ; Θ) = E P ( z ( i ) | x ( i ) , Θ old ) [log ] We ignored the part that doesn’t depend on Θ UofT CSC 411: 15-EM 17 / 33

  18. EM derivation So, what just happened? Conceptually: We don’t know z ( i ) so we average them given the current model. Practically: We define a function � � P ( x ( i ) , z ( i ) ; Θ) Q (Θ) = E P ( z ( i ) | x ( i ) , Θ old ) [log ] that lower bounds the desired function and is equal at our current guess. If we now optimize Θ we will get a better lower bound! log( P ( X | Θ old )) = Q (Θ old ) ≤ Q (Θ new ) ≤ log( P ( X | Θ new )) We can iterate between expectation step and maximization step and the lower bound will always improve (or we are done) UofT CSC 411: 15-EM 18 / 33

  19. Visualization of the EM Algorithm The EM algorithm involves alternately computing a lower bound on the log likelihood for the current parameter values and then maximizing this bound to obtain the new parameter values. UofT CSC 411: 15-EM 19 / 33

  20. General EM Algorithm 1. Initialize Θ old 2. E-step: Evaluate p ( Z | X , Θ old ) and compute Q (Θ , Θ old ) = � p ( Z | X , Θ old ) ln p ( X , Z | Θ) z 3. M-step: Maximize Θ new = arg max Θ Q (Θ , Θ old ) 4. Evaluate log likelihood and check for convergence (or the parameters). If not converged, Θ old = Θ new , Go to step 2 UofT CSC 411: 15-EM 20 / 33

Recommend


More recommend