Exemplo n.º 1
0
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)
Exemplo n.º 2
0
def test_coi1():
    """ Test I for xor """
    d = n_mod_m(3, 2)
    assert_almost_equal(I(d), -1.0)
    assert_almost_equal(I(d, [[0], [1], [2]]), -1.0)
    assert_almost_equal(I(d, [[0], [1], [2]], [2]), 0.0)
    assert_almost_equal(I(d, [[0], [1]], [2]), 1.0)
Exemplo n.º 3
0
def test_sp2():
    """ Test all possible info measures, with rv_names """
    d = n_mod_m(4, 2)
    d.set_rv_names('xyzw')
    ip = ShannonPartition(d)
    for meas in all_info_measures('xyzw'):
        yield assert_almost_equal, ip[meas], I(d, meas[0], meas[1])
Exemplo n.º 4
0
def test_coi1():
    """ Test I for xor """
    d = n_mod_m(3, 2)
    assert I(d) == pytest.approx(-1.0)
    assert I(d, [[0], [1], [2]]) == pytest.approx(-1.0)
    assert I(d, [[0], [1], [2]], [2]) == pytest.approx(0.0)
    assert I(d, [[0], [1]], [2]) == pytest.approx(1.0)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
def test_sp2():
    """ Test all possible info measures, with rv_names """
    d = n_mod_m(4, 2)
    d.set_rv_names('xyzw')
    ip = ShannonPartition(d)
    for meas in all_info_measures('xyzw'):
        yield assert_almost_equal, ip[meas], I(d, meas[0], meas[1])
Exemplo n.º 7
0
def test_coi1():
    """ Test I for xor """
    d = n_mod_m(3, 2)
    assert I(d) == pytest.approx(-1.0)
    assert I(d, [[0], [1], [2]]) == pytest.approx(-1.0)
    assert I(d, [[0], [1], [2]], [2]) == pytest.approx(0.0)
    assert I(d, [[0], [1]], [2]) == pytest.approx(1.0)
Exemplo n.º 8
0
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_dd2():
    """
    Test against known values.
    """
    d = n_mod_m(3, 2)
    d.set_rv_names('XYZ')
    dd = DependencyDecomposition(d)
    assert dd[(('X', 'Y', 'Z'), )]['H'] == pytest.approx(2.0)
Exemplo n.º 10
0
def test_dd2():
    """
    Test against known values.
    """
    d = n_mod_m(3, 2)
    d.set_rv_names('XYZ')
    dd = DependencyDecomposition(d)
    assert dd[(('X', 'Y', 'Z'),)]['H'] == pytest.approx(2.0)
Exemplo n.º 11
0
def test_dd3():
    """
    Test dependencies.
    """
    d = n_mod_m(3, 2)
    dd = DependencyDecomposition(d)
    deps = dd.get_dependencies()
    true_deps = {'012', '01:02:12', '01:02', '01:12', '02:12', '01:2', '02:1', '12:0', '0:1:2'}
    assert deps == true_deps
Exemplo n.º 12
0
def test_dd3():
    """
    Test dependencies.
    """
    d = n_mod_m(3, 2)
    dd = DependencyDecomposition(d)
    deps = dd.get_dependencies()
    true_deps = {'012', '01:02:12', '01:02', '01:12', '02:12', '01:2', '02:1', '12:0', '0:1:2'}
    assert deps == true_deps
def test_iimi1():
    """
    Test against known value.
    """
    iimi = interactive_intrinsic_mutual_information(n_mod_m(3, 2),
                                                    rvs=[[0], [1]],
                                                    crvs=[2],
                                                    rounds=1)
    assert iimi == pytest.approx(0.0)
def test_sp3():
    """ Test get_atoms() """
    d = n_mod_m(3, 2)
    ip = ShannonPartition(d)
    atoms1 = {
        'H[0|1,2]', 'H[1|0,2]', 'H[2|0,1]', 'I[0:1:2]', 'I[0:1|2]', 'I[0:2|1]',
        'I[1:2|0]'
    }
    atoms2 = ip.get_atoms()
    assert (atoms1 - atoms2) | (atoms2 - atoms1) == set()
def test_dd4():
    """
    Test dependencies.
    """
    d = n_mod_m(3, 2)
    dd = DependencyDecomposition(d)
    deps = dd.get_dependencies(string=False)
    true_deps = {((0, 1, 2), ), ((0, 1), (0, 2), (1, 2)), ((0, 1), (0, 2)),
                 ((0, 1), (1, 2)), ((0, 2), (1, 2)), ((0, 1), (2, )),
                 ((0, 2), (1, )), ((1, 2), (0, )), ((0, ), (1, ), (2, ))}
    assert deps == true_deps
Exemplo n.º 16
0
def test_sp3():
    """ Test get_atoms() """
    d = n_mod_m(3, 2)
    ip = ShannonPartition(d)
    atoms1 = set([
        'H[0|1,2]', 'H[1|0,2]', 'H[2|0,1]', 'I[0:1:2]', 'I[0:1|2]', 'I[0:2|1]',
        'I[1:2|0]'
    ])
    atoms2 = ip.get_atoms()
    assert_equal(atoms1 - atoms2, set())
    assert_equal(atoms2 - atoms1, set())
Exemplo n.º 17
0
def test_sp3():
    """ Test get_atoms() """
    d = n_mod_m(3, 2)
    ip = ShannonPartition(d)
    atoms1 = {'H[0|1,2]',
              'H[1|0,2]',
              'H[2|0,1]',
              'I[0:1:2]',
              'I[0:1|2]',
              'I[0:2|1]',
              'I[1:2|0]'
              }
    atoms2 = ip.get_atoms()
    assert (atoms1 - atoms2) | (atoms2 - atoms1) == set()
Exemplo n.º 18
0
def test_sp3():
    """ Test get_atoms() """
    d = n_mod_m(3, 2)
    ip = ShannonPartition(d)
    atoms1 = set(['H[0|1,2]',
                  'H[1|0,2]',
                  'H[2|0,1]',
                  'I[0:1:2]',
                  'I[0:1|2]',
                  'I[0:2|1]',
                  'I[1:2|0]'
                 ])
    atoms2 = ip.get_atoms()
    assert_equal(atoms1 - atoms2, set())
    assert_equal(atoms2 - atoms1, set())
Exemplo n.º 19
0
def test_dd4():
    """
    Test dependencies.
    """
    d = n_mod_m(3, 2)
    dd = DependencyDecomposition(d)
    deps = dd.get_dependencies(string=False)
    true_deps = {((0, 1, 2),),
                 ((0, 1), (0, 2), (1, 2)),
                 ((0, 1), (0, 2)),
                 ((0, 1), (1, 2)),
                 ((0, 2), (1, 2)),
                 ((0, 1), (2,)),
                 ((0, 2), (1,)),
                 ((1, 2), (0,)),
                 ((0,), (1,), (2,))}
    assert deps == true_deps
def test_sp4():
    """ Test printing """
    d = n_mod_m(3, 2)
    ip = ShannonPartition(d)
    string = """\
+----------+--------+
| measure  |  bits  |
+----------+--------+
| H[0|1,2] |  0.000 |
| H[1|0,2] |  0.000 |
| H[2|0,1] |  0.000 |
| I[0:1|2] |  1.000 |
| I[0:2|1] |  1.000 |
| I[1:2|0] |  1.000 |
| I[0:1:2] | -1.000 |
+----------+--------+"""
    assert str(ip) == string
Exemplo n.º 21
0
def test_sp4():
    """ Test printing """
    d = n_mod_m(3, 2)
    ip = ShannonPartition(d)
    string = """\
+----------+--------+
| measure  |  bits  |
+----------+--------+
| H[0|1,2] |  0.000 |
| H[1|0,2] |  0.000 |
| H[2|0,1] |  0.000 |
| I[0:1|2] |  1.000 |
| I[0:2|1] |  1.000 |
| I[1:2|0] |  1.000 |
| I[0:1:2] | -1.000 |
+----------+--------+"""
    assert str(ip) == string
def test_ep1():
    """
    Test against known values.
    """
    d = n_mod_m(3, 2)
    ep = ExtropyPartition(d)
    string = """\
+----------+--------+
| measure  | exits  |
+----------+--------+
| X[0|1,2] |  0.000 |
| X[1|0,2] |  0.000 |
| X[2|0,1] |  0.000 |
| X[0:1|2] |  0.245 |
| X[0:2|1] |  0.245 |
| X[1:2|0] |  0.245 |
| X[0:1:2] |  0.510 |
+----------+--------+"""
    assert str(ep) == string
Exemplo n.º 23
0
def test_ep1():
    """
    Test against known values.
    """
    d = n_mod_m(3, 2)
    ep = ExtropyPartition(d)
    string = """\
+----------+--------+
| measure  | exits  |
+----------+--------+
| X[0|1,2] |  0.000 |
| X[1|0,2] |  0.000 |
| X[2|0,1] |  0.000 |
| X[0:1|2] |  0.245 |
| X[0:2|1] |  0.245 |
| X[1:2|0] |  0.245 |
| X[0:1:2] |  0.510 |
+----------+--------+"""
    assert str(ep) == string
Exemplo n.º 24
0
def test_dd4():
    """
    Test dependencies.
    """
    d = n_mod_m(3, 2)
    dd = DependencyDecomposition(d)
    deps = dd.get_dependencies(string=False)
    a = frozenset([0])
    b = frozenset([1])
    c = frozenset([2])
    true_deps = {frozenset([a | b | c]),
                 frozenset([a | b, a | c, b | c]),
                 frozenset([a | b, a | c]),
                 frozenset([a | b, b | c]),
                 frozenset([a | c, b | c]),
                 frozenset([a | b, c]),
                 frozenset([a | c, b]),
                 frozenset([b | c, a]),
                 frozenset([a, b, c])}
    assert deps == true_deps
Exemplo n.º 25
0
def test_dd1():
    """
    Test against known values.
    """
    d = n_mod_m(3, 2)
    ep = DependencyDecomposition(d, measures={'B': B})
    string = """\
+------------+--------+
| dependency |   B    |
+------------+--------+
|    012     |  2.000 |
|  01:02:12  |  0.000 |
|   01:02    |  0.000 |
|   01:12    |  0.000 |
|   02:12    |  0.000 |
|    01:2    |  0.000 |
|    02:1    |  0.000 |
|    12:0    |  0.000 |
|   0:1:2    |  0.000 |
+------------+--------+"""
    assert str(ep) == string
def test_dd1():
    """
    Test against known values.
    """
    d = n_mod_m(3, 2)
    ep = DependencyDecomposition(d, measures={'B': B})
    string = """\
+------------+--------+
| dependency |   B    |
+------------+--------+
|    012     |  2.000 |
|  01:02:12  |  0.000 |
|   01:02    |  0.000 |
|   01:12    |  0.000 |
|   02:12    |  0.000 |
|    01:2    |  0.000 |
|    02:1    |  0.000 |
|    12:0    |  0.000 |
|   0:1:2    |  0.000 |
+------------+--------+"""
    assert str(ep) == string
Exemplo n.º 27
0
def test_n_mod_m2():
    """ Test that m < 1 fails """
    with pytest.raises(ValueError):
        n_mod_m(1, -1)
Exemplo n.º 28
0
def test_n_mod_m1():
    """ Test that n < 1 fails """
    with pytest.raises(ValueError):
        n_mod_m(-1, 1)
Exemplo n.º 29
0
def test_coi4():
    """ Test conditional I, with and without names """
    d = n_mod_m(4, 2)
    assert I(d, [[0], [1], [2]], [3]) == pytest.approx(-1.0)
    d.set_rv_names("XYZW")
    assert I(d, [['X'], ['Y'], ['Z']], ['W']) == pytest.approx(-1.0)
Exemplo n.º 30
0
def test_tc5():
    """ Test T with subvariables """
    d = n_mod_m(4, 2)
    assert T(d, [[0, 1], [2], [3]]) == pytest.approx(1.0)
    d.set_rv_names("XYZW")
    assert T(d, [['X', 'Y'], ['Z'], ['W']]) == pytest.approx(1.0)
Exemplo n.º 31
0
def test_tc2():
    """ Test T of subvariables, with names """
    d = n_mod_m(4, 2)
    assert T(d, [[0], [1], [2]]) == pytest.approx(0.0)
    d.set_rv_names("XYZW")
    assert T(d, [['X'], ['Y'], ['Z']]) == pytest.approx(0.0)
Exemplo n.º 32
0
def test_tc2():
    """ Test T of subvariables, with names """
    d = n_mod_m(4, 2)
    assert T(d, [[0], [1], [2]]) == pytest.approx(0.0)
    d.set_rv_names("XYZW")
    assert T(d, [['X'], ['Y'], ['Z']]) == pytest.approx(0.0)
Exemplo n.º 33
0
def test_n_mod_m5(n):
    """ Test that the interaction information is always 1 """
    d = n_mod_m(n, 2)
    assert II(d) == pytest.approx(1.0)
Exemplo n.º 34
0
def test_coi2():
    """ Test I for larger parity distribution """
    d = n_mod_m(4, 2)
    assert I(d) == pytest.approx(1.0)
Exemplo n.º 35
0
def test_n_mod_m5(n):
    """ Test that the interaction information is always 1 """
    d = n_mod_m(n, 2)
    assert II(d) == pytest.approx(1.0)
Exemplo n.º 36
0
def test_n_mod_m3():
    """ Test that noninteger n failes """
    with pytest.raises(ValueError):
        n_mod_m(3/2, 1)
Exemplo n.º 37
0
def test_n_mod_m1():
    """ Test that n < 1 fails """
    with pytest.raises(ValueError):
        n_mod_m(-1, 1)
Exemplo n.º 38
0
def test_n_mod_m5():
    """ Test that the interaction information is always 1 """
    for n in range(3, 6):
        d = n_mod_m(n, 2)
        yield assert_almost_equal, II(d), 1.0
Exemplo n.º 39
0
def test_coi3():
    """ Test I for subsets of variables, with and without names """
    d = n_mod_m(4, 2)
    assert I(d, [[0], [1], [2]]) == pytest.approx(0.0)
    d.set_rv_names("XYZW")
    assert I(d, [['X'], ['Y'], ['Z']]) == pytest.approx(0.0)
Exemplo n.º 40
0
def test_n_mod_m3():
    """ Test that noninteger n failes """
    with pytest.raises(ValueError):
        n_mod_m(3 / 2, 1)
Exemplo n.º 41
0
def test_n_mod_m4():
    """ Test that noninteger m fails """
    with pytest.raises(ValueError):
        n_mod_m(1, 3 / 2)
Exemplo n.º 42
0
def test_tc6():
    """ Test T with overlapping subvariables """
    d = n_mod_m(4, 2)
    assert T(d, [[0, 1, 2], [1, 2, 3]]) == pytest.approx(3.0)
    d.set_rv_names("XYZW")
    assert T(d, [['X', 'Y', 'Z'], ['Y', 'Z', 'W']]) == pytest.approx(3.0)
Exemplo n.º 43
0
def test_n_mod_m6(m):
    """ Test that II is the log of m """
    d = n_mod_m(3, m)
    assert II(d) == pytest.approx(log2(m))
Exemplo n.º 44
0
def test_tc5():
    """ Test T with subvariables """
    d = n_mod_m(4, 2)
    assert T(d, [[0, 1], [2], [3]]) == pytest.approx(1.0)
    d.set_rv_names("XYZW")
    assert T(d, [['X', 'Y'], ['Z'], ['W']]) == pytest.approx(1.0)
Exemplo n.º 45
0
def test_tc1(n):
    """ Test T of parity distributions """
    d = n_mod_m(n, 2)
    assert T(d) == pytest.approx(1.0)
Exemplo n.º 46
0
def test_tc4():
    """ Test conditional T """
    d = n_mod_m(4, 2)
    assert T(d, [[0], [1]], [2, 3]) == pytest.approx(1.0)
    d.set_rv_names("XYZW")
    assert T(d, [['X'], ['Y']], ['Z', 'W']) == pytest.approx(1.0)
Exemplo n.º 47
0
def test_tc4():
    """ Test conditional T """
    d = n_mod_m(4, 2)
    assert T(d, [[0], [1]], [2, 3]) == pytest.approx(1.0)
    d.set_rv_names("XYZW")
    assert T(d, [['X'], ['Y']], ['Z', 'W']) == pytest.approx(1.0)
Exemplo n.º 48
0
def test_GB(order, rvs, crvs, value):
    """
    Tests for the generalized dual total correlation.
    """
    d = n_mod_m(5, 2)
    assert GB(d, order=order, rvs=rvs, crvs=crvs) == pytest.approx(value)
Exemplo n.º 49
0
def test_tc6():
    """ Test T with overlapping subvariables """
    d = n_mod_m(4, 2)
    assert T(d, [[0, 1, 2], [1, 2, 3]]) == pytest.approx(3.0)
    d.set_rv_names("XYZW")
    assert T(d, [['X', 'Y', 'Z'], ['Y', 'Z', 'W']]) == pytest.approx(3.0)
Exemplo n.º 50
0
def test_coi6():
    """ Test conditional I, with and without names """
    d = n_mod_m(4, 2)
    assert I(d, [[0]], [1, 2, 3]) == pytest.approx(0.0)
    d.set_rv_names("XYZW")
    assert I(d, [['X']], ['Y', 'Z', 'W']) == pytest.approx(0.0)
Exemplo n.º 51
0
def test_n_mod_m2():
    """ Test that m < 1 fails """
    with pytest.raises(ValueError):
        n_mod_m(1, -1)
Exemplo n.º 52
0
def test_n_mod_m6():
    """ Test that II is the log of m """
    for m in range(2, 5):
        d = n_mod_m(3, m)
        yield assert_almost_equal, II(d), log2(m)
Exemplo n.º 53
0
def test_n_mod_m4():
    """ Test that noninteger m fails """
    with pytest.raises(ValueError):
        n_mod_m(1, 3/2)
def test_sp1(meas):
    """ Test all possible info measures """
    d = n_mod_m(4, 2)
    ip = ShannonPartition(d)
    assert ip[meas] == pytest.approx(I(d, meas[0], meas[1]))
Exemplo n.º 55
0
def test_n_mod_m6(m):
    """ Test that II is the log of m """
    d = n_mod_m(3, m)
    assert II(d) == pytest.approx(log2(m))
def test_sp2(meas):
    """ Test all possible info measures, with rv_names """
    d = n_mod_m(4, 2)
    d.set_rv_names('xyzw')
    ip = ShannonPartition(d)
    assert ip[meas] == pytest.approx(I(d, meas[0], meas[1]))
Exemplo n.º 57
0
def test_n_mod_m6():
    """ Test that II is the log of m """
    for m in range(2, 5):
        d = n_mod_m(3, m)
        yield assert_almost_equal, II(d), log2(m)
Exemplo n.º 58
0
def test_n_mod_m5():
    """ Test that the interaction information is always 1 """
    for n in range(3, 6):
        d = n_mod_m(n, 2)
        yield assert_almost_equal, II(d), 1.0