Gaussian Mixture Models and EM algorithm
2.5.7· AI-ML › Unsupervised Learning
Overview
Gaussian Mixture Models (GMM) ek probabilistic model hai jo assume karta hai ki data kai Gaussian distributions ke mixture se aata hai, jisme har ek ek cluster represent karta hai. Expectation-Maximization (EM) algorithm ek iterative method hai jo in Gaussians ke parameters find karta hai jab hume pata nahi hota ki kaunsa data point kis cluster ka hai.
Ise genres ki tarah socho: ek movie purely "action" ya "drama" nahi hoti — woh 60% action, 40% drama hoti hai. GMMs is blend ko naturally capture karte hain.
The Mathematical Foundation
jahan:
- = mixture components (clusters) ki sankhya
- = component ka mixing coefficient (satisfies , )
- = Gaussian distribution jiska mean aur covariance hai
Yeh form kyun? Hum keh rahe hain: "Cluster ko probability se chuno, phir us cluster ke Gaussian se ek point generate karo." Sum saare possible cluster choices par marginalize karta hai.
Gaussian Component Derive Karna
Multivariate Gaussian distribution hai:
Yeh formula kyun?
- Exponent squared Mahalanobis distance hai — yeh measure karta hai ki , se kitna dur hai, correlations ko account karte hue (jo mein captured hai)
- Normalizing constant ensure karta hai ki
- aata hai dimensions par Gaussian integrate karne se
- covariance ellipsoid ke "volume" ko account karta hai
The EM Algorithm: First Principles Se
PROBLEM: Hamare paas data hai lekin hume nahi pata ki kis cluster ne har point generate kiya. Hume estimate karna hai.
Yeh mushkil kyun hai? Agar hume cluster assignments pata hoti, toh parameters estimate karna easy hota (sirf means aur covariances compute karo). Agar hume parameters pata hote, toh assignments compute karna easy hota (sirf Bayes' rule use karo). Hume dono nahi pata! Yeh ek chicken-and-egg problem hai.
Latent Variables Introduce Karna
Maano ka hidden cluster label hai. Complete-data log-likelihood hogi:
Yeh form kyun? Indicator pick karta hai ki kis cluster ka hai, aur hum us choice () ki probability aur us Gaussian ke under ki probability ko log karte hain.
Lekin hum observe nahi karte! Toh hum incomplete-data log-likelihood maximize karte hain:
Ise directly maximize karna mushkil hai kyunki sum ke log ka koi closed form nahi hota.
Jensen's inequality se, kisi bhi distribution ke liye:
Yeh kyun help karta hai? Lower bound maximize karna aasaan hai. Hum alternate karte hain:
- E-step: fix karo, choose karo taaki bound tight ho:
- M-step: fix karo, ko ke respect mein maximize karo taaki mile
E-Step: Responsibilities Compute Karna
Hume chahiye, jise responsibility kehte hain.
Bayes' rule se:
Yeh step kyun? Numerator: cluster ki prior probability times cluster ke under ki likelihood. Denominator: saare clusters par total probability (normalization).
ka matlab kya hai? Probability ki point cluster se generate hua tha. Agar , toh point 80% likely cluster 3 se hai.
M-Step: Parameters Update Karna
Hum expected complete-data log-likelihood maximize karte hain:
Responsibilities substitute karne par:
update derive karna:
Yeh derivative kyun? Gaussian mein sirf quadratic term par depend karta hai.
Zero set karne par:
jahan cluster mein effective number of points hai.
Iska matlab kya hai? Naya mean saare points ka weighted average hai, jisme weights unki cluster ke liye responsibility hai. Points jo strongly cluster mein hain () mean ko apni taraf kheenchte hain; mein weakly hone wale points ka kam effect hota hai.
update derive karna:
Isi tarah (log-determinant aur quadratic terms ka derivative lete hue):
Kyun? Mean se squared deviations ka weighted average — covariance ki definition, responsibility-weighted.
update derive karna:
Hum maximize karte hain subject to , Lagrange multiplier use karke:
Suming over :
Iska matlab kya hai? Mixing coefficient wo fraction hai jo cluster ko assign ki gayi total responsibility hai.
Initialize: choose karo, , , randomly ya K-means se initialize karo
Convergence tak repeat karo:
E-step: Saare ke liye responsibilities compute karo:
M-step: Saare ke liye parameters update karo:
Convergence: Ruko jab log-likelihood change < threshold ho ya max iterations reach ho jaayein.
Worked Examples
Data: ,
Initialize:
- (data endpoints se)
- (arbitrary small variance)
E-step iteration 1:
ke liye:
Yeh values kyun? Plug into the Gaussian formula. Point 1, ke bahut paas hai (distance 0.5) lekin se bahut door (distance 8.5).
Iska matlab kya hai? Point 1 essentially 100% cluster 1 ko assign hai.
Isi tarah:
- (point 2 → cluster 1)
- (point 9 → cluster 2)
- (point 10 → cluster 2)
M-step iteration 1:
Kyun? Do points strongly cluster 1 mein hain, do cluster 2 mein.
Yeh step kyun? Saare points ka weighted average, lekin sirf points 1 aur 2 ka cluster 1 ke liye non-zero weight hai.
Kyun? Variance squared deviations ka weighted average hai. Dono points mean 1.5 se 0.5 door hain.
Result: Ek iteration ke baad, clusters tight ho gaye ( 1 se 0.25 ho gaya), means stable hain. Algorithm jaldi converge hoga kyunki data well-separated hai.
Data:
- Cluster 1:
- Cluster 2:
- Ambiguous point:
Convergence ke baad:
- Ambiguous point ke liye:
50/50 kyun? Yeh point dono cluster centers se equidistant hai, isliye dono ke liye equal responsibility hai. Yahi GMM ka key advantage hai: soft assignments uncertainty capture karte hain.
Agar hum hard assignment force karte (jaise K-means), toh hum ise arbitrarily ek cluster mein daal dete, information kho dete. GMM kehta hai "yeh point genuinely ambiguous hai — yeh aadha dono clusters se hai."
Convergence check ke liye, hum compute karte hain:
Point ke liye ke saath:
Agar , , aur Gaussians aur evaluate karte hain:
Sum kyun? Total probability dono components ka mixture hai.
Total log-likelihood ke liye saare points par sum karo. Agar yeh iterations ke beech se kam change ho, toh hum converge ho gaye hain.
Common Mistakes and Fixes
Galat: compute karo aur directly use karo.
Kyun sahi lagta hai: Humne cluster ke under ki probability compute ki, toh yahi responsibility honi chahiye!
Kyun galat hai: Denominator ke bina, . Responsibilities conditional probabilities hain aur har point ke liye 1 sum honi chahiye.
Fix: Hamesha normalizing sum include karo:
Galat: Ek cluster ek single point par collapse ho jaata hai, jisse ho jaata hai, jo Gaussian evaluation break karta hai (divide by zero).
Kyun hota hai: Agar ek cluster mein saare points identical coordinates (ya numerical issues ki wajah se nearly identical) hain, toh covariance singular ho jaati hai.
Kyun dangerous hai: Algorithm crash ho jaata hai ya NaN values produce karta hai.
Fix: Regularization add karo ek small diagonal term daalke: jahan ek small constant hai. Yeh ensure karta hai ki hamesha positive definite ho.
Steel-man: "Main artificial variance add nahi karna chahta — yeh data mein nahi hai!" Sach hai, lekin zero variance ke saath, model keh raha hai "yeh cluster sirf ek exact point generate karta hai infinite precision ke saath," jo physically unrealistic hai. Regularization measurement noise ya model uncertainty represent karta hai.
Galat: Saare ko data dekhe bina uniform distribution se randomly initialize karo.
Kyun sahi lagta hai: Random initialization neural networks mein gradient descent ke liye kaam karta hai, toh yahan bhi kaam karna chahiye!
Kyun galat hai: EM initialization ke liye sensitive hai. Agar do means bahut paas se start hote hain, toh woh paas hi reh sakte hain (dono same cluster model karne ki koshish karte hain) jabki koi aur cluster bilkul miss ho jaata hai.
Fix: Initialization ke liye K-means++ use karo:
- K-means convergence tak chalao (fast, simple)
- K-means cluster centers ko ki tarah use karo
- K-means cluster covariances ko ki tarah use karo
- initialize karne ke liye K-means cluster sizes use karo
Kyun kaam karta hai: K-means ek achha rough clustering deta hai, aur EM usse soft assignments ke saath refine karta hai.
Galat: EM ek baar chalao, result lo, assume karo ki yeh best possible clustering hai.
Kyun sahi lagta hai: EM guaranteed hai ki har iteration mein likelihood badhega, toh yeh global maximum par converge hona chahiye!
Kyun galat hai: EM guaranteed hai ki local maximum par converge kare, necessarily global nahi. Alag-alag initializations alag local maxima par le jaate hain.
Fix: EM multiple times (5-10) alag random initializations ke saath chalao, sabse zyada final log-likelihood wala result chuno.
Steel-man: "Lekin yeh computationally expensive hai!" Haan, lekin zaroori hai. Log-likelihood landscape non-convex hai aur iske kai local maxima hain. Socho jaise neural networks train karna: tum alag random seeds try karte ho aur best chuno.
Clusters Ki Sankhya K Choose Karna
K-means ke unlike, GMM probabilistic hai, isliye hum model selection criteria use kar sakte hain:
Akaike Information Criterion (AIC):
jahan parameters ki sankhya hai, maximum likelihood hai.
Bayesian Information Criterion (BIC):
BIC, AIC se kyun behtar? BIC model complexity ko zyada heavily penalize karta hai (factor of vs. 2). GMM ke liye, BIC aksar overfitting se bachne mein better perform karta hai.
Kaise use karo: ke saath GMMs fit karo aur BIC plot karo. Sabse kam BIC wala chuno.
GMM ke liye parameter count:
- mixing coefficients (constraint: sum to 1)
- means
- covariance parameters (symmetric matrices)
Total:
Connections
- K-Means Clustering: GMM, K-means ka soft version hai; K-means, GMM hai spherical covariances aur hard assignments ke saath
- Maximum Likelihood Estimation: EM mixture model ke under observed data ki likelihood maximize karta hai
- Bayes Theorem: Responsibilities Bayes' rule se compute ki jaati hain
- Expectation Maximization Algorithm: GMM general EM framework ka sabse common application hai
- Principal Component Analysis: GMM covariances data spread capture karti hain jaise PCA, lekin per-cluster
- Hidden Markov Models: HMMs, EM ko similar E-step (forward-backward) aur M-step updates ke saath use karte hain
- Variational Inference: Modern Bayesian GMs, variational EM use karte hain (zyada robust, automatic selection)
- Anomaly Detection: Points jo saare mixture components ke under kam probability rakhte hain woh outliers hain
- Density Estimation: GMs full probability density model karte hain, generative modeling ke liye useful
Ya socho: Evaluate, phir Modify. Tum evaluate karte ho ki points kahan belong karte hain, phir cluster parameters accordingly modify karte ho.
Recall Ek 12 Saal ke Bachhe ko Explain Karo
Socho tere paas ek bag mein red aur blue marbles mixed hain, lekin kisi ne unhe sabko gray paint kar diya toh tum bata nahi sakte ki kaunsa kaun sa hai. Tum jaante ho ki lagbhag aadhe red aur aadhe blue hain, aur tum pata karna chahte ho ki kaunsa gray marble originally kaun sa color tha.
Tum guess se shuru karte ho: "Main sochta hoon chhote marbles red the aur bade wale blue."
Phir tum har marble dekhte ho aur kehte ho: "Yeh medium-sized hai... yeh probably 60% likely red aur 40% likely blue hai." Tum sure nahi ho, toh tum apne bets hedge karte ho.
Ab tum apna guess update karte ho: "Okay, agar main is marble ko 60% red treat karun, toh red marbles ki average size probably itni hogi..." Tum in partial assignments ke basis par reds aur blues ki average size recalculate karte ho.
Phir tum apne naye averages ke saath har marble phir dekhte ho: "Hmm, is naye average ke saath, shayad yeh marble actually 70% red hai, 60% nahi."
Tum baar baar jaate rehte ho — apna guess update karo ki kaunse marbles kaun sa color hain, phir apna guess update karo ki average red aur blue sizes kya hain — jab tak tumhare guesses badalna band nahi ho jaate. Yahi EM algorithm hai! Tum assignments estimate karne (E-step) aur parameters update karne (M-step) ke beech alternate kar rahe ho.
GMMs yahi data points aur clusters ke saath karte hain marbles aur colors ki jagah.
Flashcards
#flashcards/ai-ml
GMM ka matlab kya hai aur K-means par uska key advantage kya hai? :: Gaussian Mixture Model. Key advantage: soft assignments — har point ki har cluster mein belong karne ki probability hoti hai, uncertainty capture karte hue, ek cluster mein hard assignment ki jagah.
GMM component ke teen parameters kya hain?
Responsibility γ_ik ka formula kya hai?
GMM ke liye EM mein E-step kya compute karta hai?
GMM ke liye EM mein M-step kya update karta hai?
EM M-step mein N_k kya hai?
EM local maximum par kyun converge karta hai, global nahi?
GM mean μ_k ka update formula kya hai?
GM mixing coefficient π_k ka update formula kya hai?
GMM mein singular covariance matrices ko kaise rokein?
Kya