コード例 #1
0
ファイル: test_latent_crf.py プロジェクト: hushell/pystruct
def test_loss_augmented_inference_energy_graph():
    crf = LatentGraphCRF(n_labels=2, n_states_per_label=2, inference_method="lp")
    for i in xrange(10):
        w = np.random.normal(size=18)
        y = np.random.randint(2, size=(2))
        x = np.random.normal(size=(2, 2))
        e = np.array([[0, 1], [1, 2], [2, 0]], dtype=np.int)
        h_hat, energy = crf.loss_augmented_inference((x, e), y * 2, w, relaxed=True, return_energy=True)
        assert_almost_equal(-energy, np.dot(w, crf.psi((x, e), h_hat)) + crf.loss(y * 2, h_hat))
コード例 #2
0
ファイル: test_latent_crf.py プロジェクト: tesla1060/pystruct
def test_loss_augmented_inference_energy_graph():
    crf = LatentGraphCRF(n_labels=2,
                         n_features=2,
                         n_states_per_label=2,
                         inference_method='lp')
    for i in xrange(10):
        w = np.random.normal(size=18)
        y = np.random.randint(2, size=(2))
        x = np.random.normal(size=(2, 2))
        e = np.array([[0, 1], [1, 2], [2, 0]], dtype=np.int)
        h_hat, energy = crf.loss_augmented_inference((x, e),
                                                     y * 2,
                                                     w,
                                                     relaxed=True,
                                                     return_energy=True)
        assert_almost_equal(
            -energy,
            np.dot(w, crf.psi((x, e), h_hat)) + crf.loss(y * 2, h_hat))