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


Python LatentGridCRF.loss_augmented_inference方法代码示例

本文整理汇总了Python中pystruct.models.LatentGridCRF.loss_augmented_inference方法的典型用法代码示例。如果您正苦于以下问题:Python LatentGridCRF.loss_augmented_inference方法的具体用法?Python LatentGridCRF.loss_augmented_inference怎么用?Python LatentGridCRF.loss_augmented_inference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pystruct.models.LatentGridCRF的用法示例。


在下文中一共展示了LatentGridCRF.loss_augmented_inference方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_blocks_crf_directional

# 需要导入模块: from pystruct.models import LatentGridCRF [as 别名]
# 或者: from pystruct.models.LatentGridCRF import loss_augmented_inference [as 别名]
def test_blocks_crf_directional():
    # test latent directional CRF on blocks
    # test that all results are the same as equivalent LatentGridCRF
    X, Y = toy.generate_blocks(n_samples=1)
    x, y = X[0], Y[0]
    pairwise_weights = np.array([0, 0, 0, -4, -4, 0, -4, -4, 0, 0])
    unary_weights = np.repeat(np.eye(2), 2, axis=0)
    w = np.hstack([unary_weights.ravel(), pairwise_weights])
    pw_directional = np.array(
        [0, 0, -4, -4, 0, 0, -4, -4, -4, -4, 0, 0, -4, -4, 0, 0, 0, 0, -4, -4, 0, 0, -4, -4, -4, -4, 0, 0, -4, -4, 0, 0]
    )
    w_directional = np.hstack([unary_weights.ravel(), pw_directional])
    crf = LatentGridCRF(n_labels=2, n_states_per_label=2)
    directional_crf = LatentDirectionalGridCRF(n_labels=2, n_states_per_label=2)
    h_hat = crf.inference(x, w)
    h_hat_d = directional_crf.inference(x, w_directional)
    assert_array_equal(h_hat, h_hat_d)

    h = crf.latent(x, y, w)
    h_d = directional_crf.latent(x, y, w_directional)
    assert_array_equal(h, h_d)

    h_hat = crf.loss_augmented_inference(x, y, w)
    h_hat_d = directional_crf.loss_augmented_inference(x, y, w_directional)
    assert_array_equal(h_hat, h_hat_d)

    psi = crf.psi(x, h_hat)
    psi_d = directional_crf.psi(x, h_hat)
    assert_array_equal(np.dot(psi, w), np.dot(psi_d, w_directional))
开发者ID:hushell,项目名称:pystruct,代码行数:31,代码来源:test_latent_crf.py

示例2: test_loss_augmented_inference_exhaustive_grid

# 需要导入模块: from pystruct.models import LatentGridCRF [as 别名]
# 或者: from pystruct.models.LatentGridCRF import loss_augmented_inference [as 别名]
def test_loss_augmented_inference_exhaustive_grid():
    crf = LatentGridCRF(n_labels=2, n_features=2, n_states_per_label=2)
    for i in range(10):
        w = np.random.normal(size=18)
        y = np.random.randint(2, size=(2, 2))
        x = np.random.normal(size=(2, 2, 2))
        h_hat = crf.loss_augmented_inference(x, y * 2, w)
        h = exhaustive_loss_augmented_inference(crf, x, y * 2, w)
        assert_array_equal(h, h_hat)
开发者ID:KentChun33333,项目名称:pystruct,代码行数:11,代码来源:test_latent_crf.py


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