gaussian_mixture_models
gaussian_mixture_models copied to clipboard
Wrong calculation for E-step
Thank you for your useful material! Correct me if I'm wrong, but there is wrong calculation for E-step?
def Estep(self):
"Perform an E(stimation)-step, freshening up self.loglike in the process"
# compute weights
self.loglike = 0. # = log(p = 1)
for datum in self.data:
# unnormalized weights
wp1 = self.one.pdf(datum) * self.mix
wp2 = self.two.pdf(datum) * (1. - self.mix)
# compute denominator
den = wp1 + wp2
# normalize
wp1 /= den
wp2 /= den
# add into loglike
self.loglike += log(wp1 + wp2)
# yield weight tuple
yield (wp1, wp2)
wp1
and wp2
are normalized so self.loglike += log(wp1 + wp2)
doesn't make sense since wp1 + wp2=1
. Also I think self.loglike += (log(wp1) + log(wp2))
is correct.
Thanks,