I have a code for the E-step in the EM algorithm for Document Clustering in the version of hard-EM algorithm. I'm trying to implement the E-step for soft-EM algorithm. Here is my code for Hard-EM:
E.step <- function(gamma, model, counts){
N <- dim(counts)[2] # number of documents
K <- dim(model$mu)[1]
for (n in 1:N){
for (k in 1:K){
gamma[n,k] <- log(model$rho[k,1]) + sum(counts[,n] * log(model$mu[k,]))
}
logZ = logSum(gamma[n,])
gamma[n,] = gamma[n,] - logZ
}
gamma <- exp(gamma)
return (gamma)
}
I want to implement a E-step for SOFT - EM algorithm. Any suggestions will be helpful.
Thanks in advance.