本文整理匯總了Python中utils.logSumExp方法的典型用法代碼示例。如果您正苦於以下問題:Python utils.logSumExp方法的具體用法?Python utils.logSumExp怎麽用?Python utils.logSumExp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類utils
的用法示例。
在下文中一共展示了utils.logSumExp方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _create_network
# 需要導入模塊: import utils [as 別名]
# 或者: from utils import logSumExp [as 別名]
def _create_network(self):
logF = self._create_loss()
self.optimizerLoss = tf.reduce_mean(self.optimizerLoss)
# Setup optimizer
grads_and_vars = self.optimizer_class.compute_gradients(self.optimizerLoss)
self._create_train_op(grads_and_vars)
# Create IWAE lower bound for evaluation
self.logF = self._reshape(logF)
self.iwae = tf.reduce_mean(U.logSumExp(self.logF, axis=1) -
tf.log(tf.to_float(self.n_samples)))
示例2: assertEqualMarginals
# 需要導入模塊: import utils [as 別名]
# 或者: from utils import logSumExp [as 別名]
def assertEqualMarginals(self, graph, all_sequences, sent_likelihood):
"""
Check factor/variable marginals are approximately equal
to marginals obtained from brute force inference
"""
# Check variable marginals
threshold = 0.01
eq = True
denom = -float('inf')
maxDiff = -float('inf')
for s, sequence in enumerate(all_sequences):
denom = utils.logSumExp(sent_likelihood[s], denom)
# Iterate over all timesteps
for t in range(graph.T):
for tag in self.model.uniqueTags:
tagBeliefs = graph.getVarByTimestepnTag(t, tag.idx).belief.cpu().data.numpy()
for labelIdx in range(tag.size()):
num = -float('inf')
for s, sequence in enumerate(all_sequences):
if sequence[t][tag.idx]==labelIdx:
num = utils.logSumExp(sent_likelihood[s], num)
# Check difference
# maxDiff = max(maxDiff, np.max(np.abs(tagBeliefs[labelIdx]- np.exp(num-denom))))
tagLogProb = np.exp(num-denom)
maxDiff = max(maxDiff, np.max(np.abs(np.exp(tagBeliefs[labelIdx]) - tagLogProb)))
if maxDiff > threshold:
eq = False
if not eq:
print("Marginals not equal. Max difference of %f" %maxDiff)
else:
print("Passed unit test!")
sys.exit(0)