コード例 #1
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)
コード例 #2
0
def test_J6():
    """ Test a property of J from result 2 of the paper with base 10 """
    for i in range(2, 10):
        d = SD([1 / i] * i)
        d.set_base(10)
        yield assert_almost_equal, J(d), (i - 1) * (np.log10(i) -
                                                    np.log10(i - 1))
コード例 #3
0
def test_J10():
    """ 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(J(p) for p in d.pmf)
    assert_almost_equal(h, s - j)
コード例 #4
0
ファイル: test_extropy.py プロジェクト: vreuter/dit
def test_J10():
    """ 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(J(p) for p in d.pmf)
    assert h == pytest.approx(s-j)
コード例 #5
0
ファイル: test_inequalities.py プロジェクト: psychon7/dit
def test_fanos_inequality(dist):
    """
    H(X|Y) <= hb(P_e) + P_e log(|X| - 1)
    """
    dist1 = SD.from_distribution(dist.marginal([0]))
    dist2 = SD.from_distribution(dist.marginal([1]))

    ce = H(dist, [0], [1])

    X = len(set().union(dist1.outcomes, dist2.outcomes))

    eq_dist = dist1 == dist2
    P_e = eq_dist[False] if False in eq_dist else 0

    hb = H(SD([P_e, 1 - P_e]))

    assert ce <= hb + P_e * np.log2(X - 1) + epsilon
コード例 #6
0
def test_R5():
    """ Test that R fails on SDs """
    d = SD([1 / 4] * 4)
    assert_raises(ditException, R, d)
コード例 #7
0
ファイル: test_shannon.py プロジェクト: psychon7/dit
def test_H1():
    """ Test the entropy of a fair coin """
    d = SD([1 / 2, 1 / 2])
    assert H(d) == pytest.approx(1.0)
コード例 #8
0
ファイル: test_perplexity.py プロジェクト: psychon7/dit
def test_p1(i):
    """ Test some simple base cases using SD """
    assert P(SD([1 / i] * i)) == pytest.approx(i)
コード例 #9
0
ファイル: test_perplexity.py プロジェクト: liangkai/dit
def test_p2():
    """ Test some simple base cases using SD with varying bases """
    for i in range(2, 10):
        d = SD([1 / i] * i)
        d.set_base(i)
        yield assert_almost_equal, P(d), i
コード例 #10
0
def test_J4():
    """ Test a property of J from result 2 of the paper """
    for i in range(2, 10):
        d = SD([1 / i] * i)
        yield assert_almost_equal, J(d), (i - 1) * (np.log2(i) -
                                                    np.log2(i - 1))
コード例 #11
0
ファイル: test_extropy.py プロジェクト: vreuter/dit
def test_J2():
    """ Test a simple base case using ScalarDistribution """
    d = SD([1/2]*2)
    assert J(d) == pytest.approx(1)
コード例 #12
0
ファイル: test_shannon.py プロジェクト: liangkai/dit
def test_H4():
    """ Test entropy in base 10 """
    d = SD([1 / 10] * 10)
    d.set_base(10)
    assert_almost_equal(H(d), 1.0)
コード例 #13
0
ファイル: test_shannon.py プロジェクト: liangkai/dit
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_R5():
    """ Test that R fails on SDs """
    d = SD([1 / 4] * 4)
    with pytest.raises(ditException):
        R(d)
コード例 #15
0
def test_B6():
    """ Test that B fails on SDs """
    d = SD([1 / 4] * 4)
    with pytest.raises(ditException):
        B(d)
コード例 #16
0
def test_tc8():
    """ Test that T fails on SDs """
    d = SD([1 / 3] * 3)
    assert_raises(ditException, T, d)
コード例 #17
0
def test_coi8():
    """ Test that I fails on ScalarDistributions """
    d = SD([1 / 3] * 3)
    with pytest.raises(ditException):
        I(d)
コード例 #18
0
def test_tc8():
    """ Test that T fails on SDs """
    d = SD([1/3]*3)
    with pytest.raises(ditException):
        T(d)
コード例 #19
0
def test_J2():
    """ Test a simple base case using ScalarDistribution """
    d = SD([1 / 2] * 2)
    assert_almost_equal(J(d), 1)
コード例 #20
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)
コード例 #21
0
ファイル: test_extropy.py プロジェクト: vreuter/dit
def test_J4(i):
    """ Test a property of J from result 2 of the paper """
    d = SD([1/i]*i)
    assert J(d) == pytest.approx((i-1)*(np.log2(i) - np.log2(i-1)))
コード例 #22
0
ファイル: test_perplexity.py プロジェクト: liangkai/dit
def test_p1():
    """ Test some simple base cases using SD """
    for i in range(2, 10):
        yield assert_almost_equal, P(SD([1 / i] * i)), i
コード例 #23
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)
コード例 #24
0
ファイル: test_extropy.py プロジェクト: vreuter/dit
def test_J5(i):
    """ Test a property of J from result 2 of the paper with a log base """
    d = SD([1/i]*i)
    d.set_base('e')
    assert J(d) == pytest.approx((i-1)*(np.log(i)-np.log(i-1)))
コード例 #25
0
ファイル: test_extropy.py プロジェクト: vreuter/dit
def test_J6(i):
    """ Test a property of J from result 2 of the paper with base 10 """
    d = SD([1/i]*i)
    d.set_base(10)
    assert J(d) == pytest.approx((i-1)*(np.log10(i)-np.log10(i-1)))
コード例 #26
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)
コード例 #27
0
ファイル: test_perplexity.py プロジェクト: psychon7/dit
def test_p2(i):
    """ Test some simple base cases using SD with varying bases """
    d = SD([1 / i] * i)
    d.set_base(i)
    assert P(d) == pytest.approx(i)
コード例 #28
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)
コード例 #29
0
ファイル: test_shannon.py プロジェクト: psychon7/dit
def test_H4():
    """ Test entropy in base 10 """
    d = SD([1 / 10] * 10)
    d.set_base(10)
    assert H(d) == pytest.approx(1.0)
コード例 #30
0
def test_B6():
    """ Test that B fails on SDs """
    d = SD([1 / 4] * 4)
    assert_raises(ditException, B, d)