def calcELBOForSingleDocFromCountVec(
DocTopicCount_K=None,
cts_U=None,
sumResp_U=None,
alphaEbeta_K=None,
logLik_UK=None,
L_max=0.0):
''' Compute ELBO for single doc as function of doc-topic counts.
Returns
-------
L : scalar float
equals ELBO as function of local parameters of single document
up to an additive constant independent of DocTopicCount
'''
theta_K = DocTopicCount_K + alphaEbeta_K
logPrior_K = digamma(theta_K)
L_theta = np.sum(gammaln(theta_K)) - np.inner(DocTopicCount_K, logPrior_K)
explogPrior_K = np.exp(logPrior_K)
if sumResp_U is None:
maxlogLik_U = np.max(logLik_UK, axis=1)
explogLik_UK = logLik_UK - maxlogLik_U[:,np.newaxis]
np.exp(explogLik_UK, out=explogLik_UK)
sumResp_U = np.dot(explogLik_UK, explogPrior_K)
L_max = np.inner(cts_U, maxlogLik_U)
L_resp = np.inner(cts_U, np.log(sumResp_U))
return L_theta + L_resp + L_max
评论列表
文章目录