A Bernoulli mixture model (BMM) describes binary vectors xn∈{0,1}D with K clusters. Cluster k has weight πk and a vector of bit probabilities μk∈(0,1)D:
p(xn∣θ)=∑k=1Kπk∏d=1Dμkdxnd(1−μkd)1−xnd
Implement bmm_em(X, pi0, mu0, iters, a) that fits the model by expectation maximization starting from the given parameters:
X: binary array of shape (N, D); pi0: shape (K,); mu0: shape (K, D) with entries strictly inside (0,1); a > 0: a pseudo-count.
- Run exactly
iters iterations. Each iteration:
- E-step with the current parameters: compute the responsibilities rnk=p(zn=k∣xn,θ) in log space, and record the total log-likelihood ∑nlogp(xn∣θ) of the current parameters.
- M-step: with Nk=∑nrnk, set πk=Nk/N and
μkd=Nk+2a∑nrnkxnd+a
Return (pi, mu, loglik): the parameters after the last M-step and a list of the iters recorded log-likelihoods (natural log). The computation must stay finite for large D, where products of hundreds of probabilities underflow.