예제 #1
0
파일: test_extropy.py 프로젝트: vreuter/dit
def test_J9():
    """ Test a property of J from result 4 of the paper """
    d = SD([1/2, 1/4, 1/8, 1/16, 1/16])
    j = J(d)
    h = H(d)
    s = sum(H(p) for p in d.pmf)
    assert j == pytest.approx(s-h)
예제 #2
0
def test_J9():
    """ Test a property of J from result 4 of the paper """
    d = SD([1 / 2, 1 / 4, 1 / 8, 1 / 16, 1 / 16])
    j = J(d)
    h = H(d)
    s = sum(H(p) for p in d.pmf)
    assert_almost_equal(j, s - h)
예제 #3
0
def test_H3():
    """ Test joint and marginal entropies """
    outcomes = ['00', '01', '10', '11']
    pmf = [1 / 4] * 4
    d = D(outcomes, pmf)
    assert H(d, [0]) == pytest.approx(1.0)
    assert H(d, [1]) == pytest.approx(1.0)
    assert H(d, [0, 1]) == pytest.approx(2.0)
    assert H(d) == pytest.approx(2.0)
예제 #4
0
def test_H3():
    """ Test joint and marginal entropies """
    outcomes = ['00', '01', '10', '11']
    pmf = [1 / 4] * 4
    d = D(outcomes, pmf)
    assert_almost_equal(H(d, [0]), 1.0)
    assert_almost_equal(H(d, [1]), 1.0)
    assert_almost_equal(H(d, [0, 1]), 2.0)
    assert_almost_equal(H(d), 2.0)
예제 #5
0
def test_J11():
    """ Test a property of J from result 5 of the paper """
    pmf = np.array([1 / 2, 1 / 4, 1 / 8, 1 / 16, 1 / 16])
    N = len(pmf)
    d = SD(pmf)
    q = SD(1 / (N - 1) * (1 - pmf))
    j2 = (N - 1) * (H(q) - np.log2(N - 1))
    assert_almost_equal(J(d), j2)
예제 #6
0
def test_J8():
    """ Test a property of J from result 1 of the paper using log bases """
    for i in range(3, 10):
        d = SD([1 / i] * i)
        d.set_base(i)
        yield assert_true, J(d) < H(d)
예제 #7
0
def test_J7():
    """ Test a property of J from result 1 of the paper """
    for i in range(3, 10):
        d = SD([1 / i] * i)
        yield assert_true, J(d) < H(d)
예제 #8
0
def test_J1():
    """ Test that H = J for two probabilities """
    assert_almost_equal(H(0.25), J(0.25))
예제 #9
0
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))
예제 #10
0
def test_H1():
    """ Test the entropy of a fair coin """
    d = SD([1 / 2, 1 / 2])
    assert H(d) == pytest.approx(1.0)
예제 #11
0
def test_H4():
    """ Test entropy in base 10 """
    d = SD([1 / 10] * 10)
    d.set_base(10)
    assert_almost_equal(H(d), 1.0)
예제 #12
0
def test_H2():
    """ Test the entropy of a fair coin, float style """
    assert_almost_equal(H(1 / 2), 1.0)
예제 #13
0
def test_H1():
    """ Test the entropy of a fair coin """
    d = SD([1 / 2, 1 / 2])
    assert_almost_equal(H(d), 1.0)
예제 #14
0
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))
예제 #15
0
def test_R4():
    """ Test that R = H - I in two variables """
    d = D(['00', '01', '11'], [1 / 3] * 3)
    assert R(d) == pytest.approx(H(d) - I(d, [0], [1]))
예제 #16
0
파일: test_extropy.py 프로젝트: vreuter/dit
def test_J1():
    """ Test that H = J for two probabilities """
    assert H(0.25) == pytest.approx(J(0.25))
예제 #17
0
파일: test_extropy.py 프로젝트: vreuter/dit
def test_J7(i):
    """ Test a property of J from result 1 of the paper """
    d = SD([1/i]*i)
    assert J(d) < H(d)
예제 #18
0
def test_H2():
    """ Test the entropy of a fair coin, float style """
    assert H(1 / 2) == pytest.approx(1.0)
예제 #19
0
파일: test_extropy.py 프로젝트: vreuter/dit
def test_J8(i):
    """ Test a property of J from result 1 of the paper using log bases """
    d = SD([1/i]*i)
    d.set_base(i)
    assert J(d) < H(d)
예제 #20
0
def test_H4():
    """ Test entropy in base 10 """
    d = SD([1 / 10] * 10)
    d.set_base(10)
    assert H(d) == pytest.approx(1.0)
예제 #21
0
def test_R4():
    """ Test that R = H - I in two variables """
    d = D(['00', '01', '11'], [1 / 3] * 3)
    assert_almost_equal(R(d), H(d) - I(d, [0], [1]))