def log_marg_for_copy(self, copy_components):
"""Return log marginal of data and component assignments: p(X, z)"""
# Log probability of component assignment P(z|alpha)
# Equation (10) in Wood and Black, 2008
# Use \Gamma(n) = (n - 1)!
facts_ = gammaln(copy_components.counts[:copy_components.K])
facts_[copy_components.counts[:copy_components.K] == 0] = 0 # definition of log(0!)
log_prob_z = (
(copy_components.K - 1)*math.log(self.alpha) + gammaln(self.alpha)
- gammaln(np.sum(copy_components.counts[:copy_components.K])
+ self.alpha) + np.sum(facts_)
)
log_prob_X_given_z = copy_components.log_marg()
return log_prob_z + log_prob_X_given_z
评论列表
文章目录