def _build_cross_ent(self, weights, means, covars, kernel_chol):
cross_ent = 0.0
for i in xrange(self.num_components):
sum_val = 0.0
for j in xrange(self.num_latent):
if self.diag_post:
# TODO(karl): this is a bit inefficient since we're not making use of the fact
# that covars is diagonal. A solution most likely involves a custom tf op.
trace = tf.trace(tf.cholesky_solve(kernel_chol[j, :, :],
tf.diag(covars[i, j, :])))
else:
trace = tf.reduce_sum(util.diag_mul(
tf.cholesky_solve(kernel_chol[j, :, :], covars[i, j, :, :]),
tf.transpose(covars[i, j, :, :])))
sum_val += (util.CholNormal(means[i, j, :], kernel_chol[j, :, :]).log_prob(0.0) -
0.5 * trace)
cross_ent += weights[i] * sum_val
return cross_ent
评论列表
文章目录