def test_B4(): """ Test B for xor distribution """ d = D(['000', '011', '101', '110'], [1 / 4] * 4) assert_almost_equal(B(d), 2) assert_almost_equal(B(d, [[0], [1], [2]]), 2) assert_almost_equal(B(d, [[0], [1]], [2]), 1) assert_almost_equal(B(d, [[0], [2]], [1]), 1) assert_almost_equal(B(d, [[1], [2]], [0]), 1)
def test_B4(): """ Test B for xor distribution """ d = D(['000', '011', '101', '110'], [1 / 4] * 4) assert B(d) == pytest.approx(2) assert B(d, [[0], [1], [2]]) == pytest.approx(2) assert B(d, [[0], [1]], [2]) == pytest.approx(1) assert B(d, [[0], [2]], [1]) == pytest.approx(1) assert B(d, [[1], [2]], [0]) == pytest.approx(1)
def test_tse1(i, j): """ Test identity comparing TSE to B from Olbrich's talk """ d = n_mod_m(i, j) indices = [[k] for k in range(i)] tse = TSE(d) x = 1 / 2 * sum(B(d, rv) / nCk(i, len(rv)) for rv in powerset(indices)) assert tse == pytest.approx(x)
def test_tse1(): """ Test identity comparing TSE to B from Olbrich's talk """ for i, j in zip(range(3, 6), range(2, 5)): d = n_mod_m(i, j) indices = [[k] for k in range(i)] tse = TSE(d) x = 1/2 * sum(B(d, rv)/nCk(i, len(rv)) for rv in powerset(indices)) yield assert_almost_equal, tse, x
def test_dtc_1(): """ test max dtc """ d = uniform(['000', '111']) max_dtc = MaxDualTotalCorrelationOptimizer(d, [[0], [1], [2]]) max_dtc.optimize() dp = max_dtc.construct_dist() assert B(dp) == pytest.approx(2.0, abs=1e-4)
def test_mis1(d): """ Test that all the mutual informations match for bivariate distributions. """ i = I(d) t = T(d) b = B(d) j = J(d) ii = II(d) assert i == pytest.approx(t) assert t == pytest.approx(b) assert b == pytest.approx(j) assert j == pytest.approx(ii)
def test_cis2(dist): """ Test that the common informations are ordered correctly. """ k = K(dist) j = J(dist) b = B(dist) c = C(dist) g = G(dist) f = F(dist) m = M(dist) assert k <= j + epsilon assert j <= b + epsilon assert b <= c + epsilon assert c <= g + epsilon assert g <= f + epsilon assert f <= m + epsilon
def test_B1(): """ Test B for two dependent variables """ d = D(['00', '11'], [1 / 2, 1 / 2]) assert_almost_equal(B(d), 1)
def test_B1(): """ Test B for two dependent variables """ d = D(['00', '11'], [1 / 2, 1 / 2]) assert B(d) == pytest.approx(1)
def test_B6(): """ Test that B fails on SDs """ d = SD([1 / 4] * 4) with pytest.raises(ditException): B(d)
def test_BR1(): """ Test that B + R = H """ d = D(['000', '001', '010', '100', '111'], [1 / 5] * 5) assert B(d) + R(d) == pytest.approx(H(d))
def test_B2(): """ Test B for three dependent variables """ d = D(['000', '111'], [1 / 2, 1 / 2]) assert_almost_equal(B(d), 1) assert_almost_equal(B(d, [[0], [1]], [2]), 0)
def test_B5(): """ Test B = I for two variables """ d = D(['00', '01', '11'], [1 / 3] * 3) assert B(d) == pytest.approx(I(d, [0], [1]))
def test_B3(): """ Test B for four dependent variables """ d = D(['0000', '1111'], [1 / 2, 1 / 2]) assert B(d) == pytest.approx(1) assert B(d, [[0], [1, 2]], [3]) == pytest.approx(0)
def test_B2(): """ Test B for three dependent variables """ d = D(['000', '111'], [1 / 2, 1 / 2]) assert B(d) == pytest.approx(1) assert B(d, [[0], [1]], [2]) == pytest.approx(0)
def test_B3(): """ Test B for four dependent variables """ d = D(['0000', '1111'], [1 / 2, 1 / 2]) assert_almost_equal(B(d), 1) assert_almost_equal(B(d, [[0], [1, 2]], [3]), 0)
def test_B5(): """ Test B = I for two variables """ d = D(['00', '01', '11'], [1 / 3] * 3) assert_almost_equal(B(d), I(d, [0], [1]))
def test_BR1(): """ Test that B + R = H """ d = D(['000', '001', '010', '100', '111'], [1 / 5] * 5) assert_almost_equal(B(d) + R(d), H(d))