本文整理汇总了Python中pystruct.models.GridCRF.loss_augmented_inference方法的典型用法代码示例。如果您正苦于以下问题:Python GridCRF.loss_augmented_inference方法的具体用法?Python GridCRF.loss_augmented_inference怎么用?Python GridCRF.loss_augmented_inference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pystruct.models.GridCRF
的用法示例。
在下文中一共展示了GridCRF.loss_augmented_inference方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_loss_augmentation
# 需要导入模块: from pystruct.models import GridCRF [as 别名]
# 或者: from pystruct.models.GridCRF import loss_augmented_inference [as 别名]
def test_loss_augmentation():
X, Y = generate_blocks(n_samples=1)
x, y = X[0], Y[0]
w = np.array([1, 0, 0, 1, 0, -4, 0]) # unary # pairwise
crf = GridCRF()
crf.initialize(X, Y)
y_hat, energy = crf.loss_augmented_inference(x, y, w, return_energy=True)
assert_almost_equal(energy + crf.loss(y, y_hat), -np.dot(w, crf.joint_feature(x, y_hat)))
示例2: test_loss_augmentation
# 需要导入模块: from pystruct.models import GridCRF [as 别名]
# 或者: from pystruct.models.GridCRF import loss_augmented_inference [as 别名]
def test_loss_augmentation():
X, Y = toy.generate_blocks(n_samples=1)
x, y = X[0], Y[0]
w = np.array([1, 0, # unary
0, 1,
0, # pairwise
-4, 0])
crf = GridCRF(inference_method='lp')
y_hat, energy = crf.loss_augmented_inference(x, y, w, return_energy=True)
assert_almost_equal(energy + crf.loss(y, y_hat),
-np.dot(w, crf.psi(x, y_hat)))
示例3: test_binary_crf_exhaustive_loss_augmented
# 需要导入模块: from pystruct.models import GridCRF [as 别名]
# 或者: from pystruct.models.GridCRF import loss_augmented_inference [as 别名]
def test_binary_crf_exhaustive_loss_augmented():
# tests qpbo inference against brute force
# on random data / weights
np.random.seed(0)
for inference_method in get_installed(["qpbo", "lp"]):
crf = GridCRF(n_states=2, n_features=2, inference_method=inference_method)
for i in xrange(10):
# generate data and weights
y = np.random.randint(2, size=(3, 2))
x = np.random.uniform(-1, 1, size=(3, 2))
x = np.dstack([-x, np.zeros_like(x)])
w = np.random.uniform(-1, 1, size=7)
# check loss augmented map inference
y_hat = crf.loss_augmented_inference(x, y, w)
y_ex = exhaustive_loss_augmented_inference(crf, x, y, w)
assert_array_equal(y_hat, y_ex)
示例4: test_binary_crf_exhaustive_loss_augmented
# 需要导入模块: from pystruct.models import GridCRF [as 别名]
# 或者: from pystruct.models.GridCRF import loss_augmented_inference [as 别名]
def test_binary_crf_exhaustive_loss_augmented():
# tests graph cut inference against brute force
# on random data / weights
np.random.seed(0)
for inference_method in ['qpbo', 'lp']:
crf = GridCRF(inference_method=inference_method)
for i in xrange(50):
# generate data and weights
y = np.random.randint(2, size=(3, 3))
x = np.random.uniform(-1, 1, size=(3, 3))
x = np.dstack([-x, np.zeros_like(x)])
w = np.random.uniform(-1, 1, size=7)
# check loss augmented map inference
y_hat = crf.loss_augmented_inference(x, y, w)
y_ex = exhaustive_loss_augmented_inference(crf, x, y, w)
#print(y_hat)
#print(y_ex)
#print("++++++++++++++++++++++")
assert_array_equal(y_hat, y_ex)