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)
Beispiel #2
0
def test_loss_augmented_inference_exhaustive_grid():
    crf = LatentGridCRF(n_labels=2, n_features=2, n_states_per_label=2)
    for i in xrange(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)
Beispiel #3
0
def test_binary_crf_exhaustive_loss_augmented():
    # tests qpbo inference against brute force
    # on random data / weights
    np.random.seed(0)
    for inference_method in get_installed(["qpbo", "lp"]):
        crf = GridCRF(n_states=2, n_features=2, inference_method=inference_method)
        for i in xrange(10):
            # generate data and weights
            y = np.random.randint(2, size=(3, 2))
            x = np.random.uniform(-1, 1, size=(3, 2))
            x = np.dstack([-x, np.zeros_like(x)])
            w = np.random.uniform(-1, 1, size=7)
            # check loss augmented map inference
            y_hat = crf.loss_augmented_inference(x, y, w)
            y_ex = exhaustive_loss_augmented_inference(crf, x, y, w)
            assert_array_equal(y_hat, y_ex)
Beispiel #4
0
def test_binary_crf_exhaustive_loss_augmented():
    # tests qpbo inference against brute force
    # on random data / weights
    np.random.seed(0)
    for inference_method in get_installed(['qpbo', 'lp']):
        crf = GridCRF(n_states=2, n_features=2,
                      inference_method=inference_method)
        for i in xrange(10):
            # generate data and weights
            y = np.random.randint(2, size=(3, 2))
            x = np.random.uniform(-1, 1, size=(3, 2))
            x = np.dstack([-x, np.zeros_like(x)])
            w = np.random.uniform(-1, 1, size=7)
            # check loss augmented map inference
            y_hat = crf.loss_augmented_inference(x, y, w)
            y_ex = exhaustive_loss_augmented_inference(crf, x, y, w)
            assert_array_equal(y_hat, y_ex)
Beispiel #5
0
def test_binary_crf_exhaustive_loss_augmented():
    # tests graph cut inference against brute force
    # on random data / weights
    np.random.seed(0)
    for inference_method in ['qpbo', 'lp']:
        crf = GridCRF(inference_method=inference_method)
        for i in xrange(50):
            # generate data and weights
            y = np.random.randint(2, size=(3, 3))
            x = np.random.uniform(-1, 1, size=(3, 3))
            x = np.dstack([-x, np.zeros_like(x)])
            w = np.random.uniform(-1, 1, size=7)
            # check loss augmented map inference
            y_hat = crf.loss_augmented_inference(x, y, w)
            y_ex = exhaustive_loss_augmented_inference(crf, x, y, w)
            #print(y_hat)
            #print(y_ex)
            #print("++++++++++++++++++++++")
            assert_array_equal(y_hat, y_ex)