def test_inference_ad3():
    (x, y, pw_horz, pw_vert, res, n_states) = inference_data()
    crf = NodeTypeEdgeFeatureGraphCRF(1, [3], [3], [[2]], inference_method='ad3')
    crf.initialize(x, y)
    w = np.hstack([np.eye(3).ravel(), (- pw_horz.ravel()), (- pw_vert.ravel())])
    y_pred = crf.inference(x, w, relaxed=True)
    if isinstance(y_pred, tuple):
        assert_array_almost_equal(res[0], y_pred[0][0].reshape((- 1), n_states), 5)
        assert_array_almost_equal(res[1], y_pred[1][0], 5)
        assert_array_equal(y, np.argmax(y_pred[0][0], axis=(- 1)), 5)
    crf = NodeTypeEdgeFeatureGraphCRF(1, [3], [3], [[2]], inference_method='ad3')
    w = np.hstack([np.eye(3).ravel(), (- pw_horz.ravel()), (- pw_vert.ravel())])
    crf.initialize(x)
    y_pred = crf.inference(x, w, relaxed=False)
    assert_array_equal(y, y_pred)
def test_inference_ad3():
    (x, y, pw_horz, pw_vert, res, n_states) = inference_data()
    crf = NodeTypeEdgeFeatureGraphCRF(1, [3], [3], [[2]], inference_method='ad3')
    crf.initialize(x, y)
    w = np.hstack([np.eye(3).ravel(), (- pw_horz.ravel()), (- pw_vert.ravel())])
    y_pred = crf.inference(x, w, relaxed=True)
    if isinstance(y_pred, tuple):
        assert_array_almost_equal(res[0], y_pred[0][0].reshape((- 1), n_states), 5)
        assert_array_almost_equal(res[1], y_pred[1][0], 5)
        assert_array_equal(y, np.argmax(y_pred[0][0], axis=(- 1)), 5)
    crf = NodeTypeEdgeFeatureGraphCRF(1, [3], [3], [[2]], inference_method='ad3')
    w = np.hstack([np.eye(3).ravel(), (- pw_horz.ravel()), (- pw_vert.ravel())])
    crf.initialize(x)
    y_pred = crf.inference(x, w, relaxed=False)
    assert_array_equal(y, y_pred)