本文整理汇总了Python中pystruct.models.GraphCRF.psi方法的典型用法代码示例。如果您正苦于以下问题:Python GraphCRF.psi方法的具体用法?Python GraphCRF.psi怎么用?Python GraphCRF.psi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pystruct.models.GraphCRF
的用法示例。
在下文中一共展示了GraphCRF.psi方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_graph_crf_energy_lp_relaxed
# 需要导入模块: from pystruct.models import GraphCRF [as 别名]
# 或者: from pystruct.models.GraphCRF import psi [as 别名]
def test_graph_crf_energy_lp_relaxed():
crf = GraphCRF(n_states=2, inference_method="lp")
for i in xrange(10):
w_ = np.random.uniform(size=w.shape)
inf_res, energy_lp = crf.inference((x_1, g_1), w_, relaxed=True, return_energy=True)
assert_almost_equal(energy_lp, -np.dot(w_, crf.psi((x_1, g_1), inf_res)))
# now with fractional solution
x = np.array([[0, 0], [0, 0], [0, 0]])
inf_res, energy_lp = crf.inference((x, g_1), w, relaxed=True, return_energy=True)
assert_almost_equal(energy_lp, -np.dot(w, crf.psi((x, g_1), inf_res)))
示例2: test_graph_crf_loss_augment
# 需要导入模块: from pystruct.models import GraphCRF [as 别名]
# 或者: from pystruct.models.GraphCRF import psi [as 别名]
def test_graph_crf_loss_augment():
x = (x_1, g_1)
y = y_1
crf = GraphCRF(n_states=2, inference_method="lp")
y_hat, energy = crf.loss_augmented_inference(x, y, w, return_energy=True)
# check that y_hat fulfills energy + loss condition
assert_almost_equal(np.dot(w, crf.psi(x, y_hat)) + crf.loss(y, y_hat), -energy)
示例3: test_graph_crf_energy_lp_integral
# 需要导入模块: from pystruct.models import GraphCRF [as 别名]
# 或者: from pystruct.models.GraphCRF import psi [as 别名]
def test_graph_crf_energy_lp_integral():
crf = GraphCRF(n_states=2, inference_method="lp")
inf_res, energy_lp = crf.inference((x_1, g_1), w, relaxed=True, return_energy=True)
# integral solution
assert_array_almost_equal(np.max(inf_res[0], axis=-1), 1)
y = np.argmax(inf_res[0], axis=-1)
# energy and psi check out
assert_almost_equal(energy_lp, -np.dot(w, crf.psi((x_1, g_1), y)))
示例4: test_graph_crf_loss_augment
# 需要导入模块: from pystruct.models import GraphCRF [as 别名]
# 或者: from pystruct.models.GraphCRF import psi [as 别名]
def test_graph_crf_loss_augment():
x = (x_1, g_1)
y = y_1
crf = GraphCRF()
crf.initialize([x], [y])
y_hat, energy = crf.loss_augmented_inference(x, y, w, return_energy=True)
# check that y_hat fulfills energy + loss condition
assert_almost_equal(np.dot(w, crf.psi(x, y_hat)) + crf.loss(y, y_hat),
-energy)