

def test_objective():
    (X, Y) = generate_blocks_multinomial(n_samples=10, noise=0.3, seed=1)
    inference_method = get_installed(['qpbo', 'ad3', 'lp'])[0]
    n_labels = 3
    crfl = LatentGridCRF(n_labels=n_labels, n_states_per_label=1, inference_method=inference_method)
    clfl = SubgradientLatentSSVM(model=crfl, max_iter=20, C=10.0, learning_rate=0.001, momentum=0.98)
    crfl.initialize(X, Y)
    clfl.w = np.zeros(crfl.size_joint_feature)
    clfl.fit(X, Y)
    crf = GridCRF(n_states=n_labels, inference_method=inference_method)
    clf = SubgradientSSVM(model=crf, max_iter=20, C=10.0, learning_rate=0.001, momentum=0.98)
    clf.fit(X, Y)
    assert_array_almost_equal(clf.w, clfl.w)
    assert_almost_equal(clf.objective_curve_[(- 1)], clfl.objective_curve_[(- 1)])
    assert_array_equal(clf.predict(X), clfl.predict(X))
    assert_array_equal(clf.predict(X), Y)

dataset/ETHPy150Open pystruct/pystruct/pystruct/tests/test_learners/test_subgradient_latent_svm.py test_objective/original