def test_inference_chain():
    # same with pairwise edges:
    features = np.array([-1, 1, -1, 1, -1, 1])
    unary_parameters = np.array([-1, 1])
    pairwise_parameters = np.array([+1,
                                    +0, 1,
                                    +3, 0, 0,
                                    +0, 3, 0, 0])
    w = np.hstack([unary_parameters, pairwise_parameters])
    crf = LatentNodeCRF(n_labels=2, n_features=1, n_hidden_states=2)
    edges = np.vstack([np.arange(5), np.arange(1, 6)]).T

    # edges for latent states. Latent states named 6, 7
    node_indices = np.arange(features.size)
    other_edges = []
    for n in node_indices[:3]:
        other_edges.append([n, 6])
    for n in node_indices[3:]:
        other_edges.append([n, 7])
    all_edges = np.vstack([edges, other_edges])

    x = (features.reshape(-1, 1), all_edges, 2)
    h, energy_lp = crf.inference(x, w, return_energy=True)
    y = np.argmax(crf._get_unary_potentials(x, w), axis=1)[:6]
    energy_joint_feature = np.dot(w, crf.joint_feature(x, h))

    assert_almost_equal(energy_joint_feature, -energy_lp)
    assert_array_equal(y, features != 0)
    assert_array_equal(h, [0, 0, 0, 1, 1, 1, 2, 3])

    # continuous inference and joint_feature:
    h, energy_lp = crf.inference(x, w, return_energy=True, relaxed=True)
    energy_joint_feature = np.dot(w, crf.joint_feature(x, h))
    assert_almost_equal(energy_joint_feature, -energy_lp)
dataset/ETHPy150Open pystruct/pystruct/pystruct/tests/test_models/test_latent_node_crf.py/test_inference_chain/operator `>` -> `!=`