Fit a Gaussian mixture by EM with one of four covariance structures (Murphy's book). Rows of X (shape (N, D)) are points; means0 is (K, D).
gmm_em(X, means0, cov_type, n_iter): initialise , = means0[k] and every covariance from the MLE data covariance (divisor ) reduced to the chosen structure. Then run n_iter iterations of: E step (responsibilities , computed with log-sum-exp), then M step: , , , and with (using the new means):
"full": ; "tied": every ; "diag": ; "spherical": .Add to the diagonal of every covariance after each M step (and to the initial ones). Return (pi, means, covs, labels, loglik) where covs is (K, D, D), labels are the argmax responsibilities under the final parameters (ties: smaller ) as a list, and loglik is the final total log-likelihood .
n_params(K, D, cov_type): the number of free parameters: means, weights, plus , , or covariance parameters.
bic(loglik, K, D, N, cov_type): (larger is better).