def test_ii3(): """ Test II and conditional II for xor """ d = Xor() ii1 = interaction_information(d, [[0], [1], [2]], [2]) ii2 = interaction_information(d, [[0], [1]], [2]) assert ii1 == pytest.approx(0) assert ii2 == pytest.approx(1)
def test_cre_3(): """ Test that the CRE fails when the events are not numbers. """ dist = Xor() with pytest.raises(TypeError): CRE(dist)
def test_gcre_3(): """ Test that the GCRE fails on non-numeric events. """ dist = Xor() with pytest.raises(TypeError): GCRE(dist)
def test_ii3(): """ Test II and conditional II for xor """ d = Xor() ii1 = interaction_information(d, [[0], [1], [2]], [2]) ii2 = interaction_information(d, [[0], [1]], [2]) assert_almost_equal(ii1, 0) assert_almost_equal(ii2, 1)
def test_distribution_constraint1(): """ Test the xor distribution. """ d = Xor() ad = get_abstract_dist(d) A, b = distribution_constraint([0], [1], ad) true_A = np.array([[0, 0, 1, 1, -1, -1, 0, 0], [0, 0, -1, -1, 1, 1, 0, 0]]) true_b = np.array([0, 0, 0, 0, 0, 0, 0, 0]) assert (A == true_A).all() assert (b == true_b).all()
def test_xor(): """ Test the Xor distribution """ d = Xor() d = pruned_samplespace(d) d = insert_meet(d, -1, [[0], [1]]) i1 = mutual_information(d, [0], [2]) i2 = mutual_information(d, [1], [2]) i12 = mutual_information(d, [0, 1], [2]) r = mutual_information(d, [2], [3]) assert_almost_equal(i1, 0) assert_almost_equal(i2, 0) assert_almost_equal(i12, 1) assert_almost_equal(r, 0)
def test_xor(): """ Test the Xor distribution """ d = Xor() d = pruned_samplespace(d) d = insert_meet(d, -1, [[0], [1]]) i1 = mutual_information(d, [0], [2]) i2 = mutual_information(d, [1], [2]) i12 = mutual_information(d, [0, 1], [2]) r = mutual_information(d, [2], [3]) assert i1 == pytest.approx(0) assert i2 == pytest.approx(0) assert i12 == pytest.approx(1) assert r == pytest.approx(0)
def test_gcre_3(): """ Test that the GCRE fails on non-numeric events. """ dist = Xor() assert_raises(TypeError, GCRE, dist)
def test_cre_3(): """ Test that the CRE fails when the events are not numbers. """ dist = Xor() assert_raises(TypeError, CRE, dist)
def test_mincoinfo_1(): """ Test mincoinfo """ d = uniform(['000', '111']) mcio = MinCoInfoOptimizer(d, [[0], [1], [2]]) mcio.optimize() dp = mcio.construct_dist() assert I(dp) == pytest.approx(-1) @pytest.mark.skip(reason="This method if deprecated.") @pytest.mark.parametrize(('dist', 'vals'), [ (Rdn(), (1, 0, 0, 0)), (Unq(), (0, 1, 1, 0)), (Xor(), (0, 0, 0, 1)), ]) def test_broja_1(dist, vals): """ Test broja. """ with warnings.catch_warnings(): pid = pid_broja(dist, [[0], [1]], [2]) assert pid == pytest.approx(vals, abs=1e-4) @pytest.mark.flaky(reruns=5) def test_dtc_1(): """ test max dtc """
def test_constructor(func, fast): """ Test that constructor and opt give same answer """ slow = deweese_constructor(func) val_1 = slow(Xor()) val_2 = fast(Xor(), deterministic=True) assert val_1 == pytest.approx(val_2)