当前位置: 首页>>代码示例>>Python>>正文


Python GridCRF.loss_augmented_inference方法代码示例

本文整理汇总了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)))
开发者ID:martinsch,项目名称:pystruct,代码行数:11,代码来源:test_grid_crf.py

示例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)))
开发者ID:hushell,项目名称:pystruct,代码行数:14,代码来源:test_grid_crf.py

示例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)
开发者ID:martinsch,项目名称:pystruct,代码行数:18,代码来源:test_grid_crf.py

示例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)
开发者ID:hushell,项目名称:pystruct,代码行数:21,代码来源:test_grid_crf.py


注:本文中的pystruct.models.GridCRF.loss_augmented_inference方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。