def test_blocks_crf_unaries(): X, Y = toy.generate_blocks(n_samples=1) x, y = X[0], Y[0] w = np.array([1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) crf = LatentGridCRF(n_labels=2, n_states_per_label=2) h_hat = crf.inference(x, w) assert_array_equal(h_hat / 2, np.argmax(x, axis=-1))
def test_blocks_crf(): X, Y = toy.generate_blocks(n_samples=1) x, y = X[0], Y[0] w = np.array([1, 1, 1, 1, 0, 0, 0, -4, -4, 0, -4, -4, 0, 0]) crf = LatentGridCRF(n_labels=2, n_states_per_label=2) h_hat = crf.inference(x, w) assert_array_equal(y, h_hat / 2) h = crf.latent(x, y, w) assert_equal(crf.loss(h, h_hat), 0)