當前位置: 首頁>>代碼示例>>Python>>正文


Python utils.logSumExp方法代碼示例

本文整理匯總了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))) 
開發者ID:rky0930,項目名稱:yolo_v2,代碼行數:14,代碼來源:rebar.py

示例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) 
開發者ID:chaitanyamalaviya,項目名稱:NeuralFactorGraph,代碼行數:41,代碼來源:unit.py


注:本文中的utils.logSumExp方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。