本文整理匯總了Python中utils.log_sum_exp方法的典型用法代碼示例。如果您正苦於以下問題:Python utils.log_sum_exp方法的具體用法?Python utils.log_sum_exp怎麽用?Python utils.log_sum_exp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類utils
的用法示例。
在下文中一共展示了utils.log_sum_exp方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __call__
# 需要導入模塊: import utils [as 別名]
# 或者: from utils import log_sum_exp [as 別名]
def __call__(self, elbo):
elbo = elbo.view(self.mc, self.iw, -1)
elbo = torch.mean(log_sum_exp(elbo, dim=1, sum_op=torch.mean), dim=0)
return elbo.view(-1)
示例2: forward
# 需要導入模塊: import utils [as 別名]
# 或者: from utils import log_sum_exp [as 別名]
def forward(self, x, logdet, dsparams, mollify=0.0, delta=nn_.delta):
ndim = self.num_ds_dim
a_ = self.act_a(dsparams[:,:,0*ndim:1*ndim])
b_ = self.act_b(dsparams[:,:,1*ndim:2*ndim])
w = self.act_w(dsparams[:,:,2*ndim:3*ndim])
a = a_ * (1-mollify) + 1.0 * mollify
b = b_ * (1-mollify) + 0.0 * mollify
pre_sigm = a * x[:,:,None] + b
sigm = torch.sigmoid(pre_sigm)
x_pre = torch.sum(w*sigm, dim=2)
x_pre_clipped = x_pre * (1-delta) + delta * 0.5
x_ = log(x_pre_clipped) - log(1-x_pre_clipped)
xnew = x_
logj = F.log_softmax(dsparams[:,:,2*ndim:3*ndim], dim=2) + \
nn_.logsigmoid(pre_sigm) + \
nn_.logsigmoid(-pre_sigm) + log(a)
logj = utils.log_sum_exp(logj,2).sum(2)
logdet_ = logj + np.log(1-delta) - \
(log(x_pre_clipped) + log(-x_pre_clipped+1))
logdet = logdet_.sum(1) + logdet
return xnew, logdet