def test_maxent_1(vars): """ Test xor only fixing individual marginals. """ d1 = uniform(['000', '011', '101', '110']) d2 = uniform(['000', '001', '010', '011', '100', '101', '110', '111']) d1_maxent = maxent_dist(d1, vars) assert d2.is_approx_equal(d1_maxent, rtol=1e-3, atol=1e-3)
def test_maxent_2(): """ Text a distribution with differing alphabets. """ d1 = uniform(['00', '10', '21', '31']) d2 = uniform(['00', '01', '10', '11', '20', '21', '30', '31']) d1_maxent = maxent_dist(d1, [[0], [1]]) assert d2.is_approx_equal(d1_maxent, rtol=1e-3, atol=1e-3)
def test_1(): """ """ d = uniform(['0000', '0001', '0010', '0100', '0101', '1000', '1001', '1010']) assert necessary_conditional_entropy(d, [0,1], [2,3]) == pytest.approx(0.68872187554086695) assert necessary_conditional_entropy(d, [2,3], [0,1]) == pytest.approx(0.68872187554086695) assert necessary_conditional_entropy(d, [1], [2,3]) == pytest.approx(0.68872187554086695)
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)
def test_minent_1(): """ Test minent """ d = uniform(['000', '001', '010', '011', '100', '101', '110', '111']) meo = MinEntOptimizer(d, [[0], [1], [2]]) meo.optimize() dp = meo.construct_dist() assert H(dp) == pytest.approx(1)
def test_dtc_2(): """ test min dtc """ d = uniform(['000', '111']) max_dtc = MinDualTotalCorrelationOptimizer(d, [[0], [1], [2]]) max_dtc.optimize() dp = max_dtc.construct_dist() assert B(dp) == pytest.approx(0.0, abs=1e-4)
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_maxent_3(): """ Test the RdnUnqXor distribution. """ X00, X01, X02, Y01, Y02 = 'rR', 'aA', [0, 1], 'bB', [0, 1] inputs = product(X00, X01, X02, Y01, Y02) events = [(x00+x01+str(x02), x00+y01+str(y02), x00+x01+y01+str(x02^y02)) for x00, x01, x02, y01, y02 in inputs] RdnUnqXor = uniform(events) d = maxent_dist(RdnUnqXor, [[0, 1], [0, 2], [1, 2]]) assert H(d) == pytest.approx(6)
def test_maxent_3(): """ Test the RdnUnqXor distribution. """ X00, X01, X02, Y01, Y02 = 'rR', 'aA', [0, 1], 'bB', [0, 1] inputs = product(X00, X01, X02, Y01, Y02) events = [(x00 + x01 + str(x02), x00 + y01 + str(y02), x00 + x01 + y01 + str(x02 ^ y02)) for x00, x01, x02, y01, y02 in inputs] RdnUnqXor = uniform(events) d = maxent_dist(RdnUnqXor, [[0, 1], [0, 2], [1, 2]]) assert H(d) == pytest.approx(6)
from hypothesis import given from dit.distconst import uniform from dit.multivariate import cohesion, dual_total_correlation, total_correlation from dit.utils.testing import distributions reed_solomon = uniform([ '0000', '0123', '0231', '0312', '1111', '1032', '1320', '1203', '2222', '2301', '2013', '2130', '3333', '3210', '3102', '3021', ]) @given(dist=distributions(alphabets=(2, ) * 4)) def test_cohesion_1(dist): """ Test that k=1 is the total correlation. """