Пример #1
0
def test_uniform1():
    """ Test uniform distribution """
    for n in range(2, 10):
        d = uniform(n)
        assert_equal(d.outcomes, tuple(range(n)))
        assert_almost_equal(d[0], 1/n)
        assert_almost_equal(entropy(d), np.log2(n))
Пример #2
0
def test_uniform3():
    _as = [1, 2, 3, 4, 5]
    _bs = [5, 7, 9, 11, 13]
    for a, b in zip(_as, _bs):
        d = uniform(a, b)
        assert_equal(len(d.outcomes), b-a)
        assert_almost_equal(d[a], 1/(b-a))
Пример #3
0
def test_renyi_entropy_1(alpha):
    """
    Test that the Renyi entropy of a uniform distirbution is indipendent of the
    order.
    """
    d = uniform(8)
    assert renyi_entropy(d, alpha) == pytest.approx(3)
Пример #4
0
def test_disequilibrium3():
    """
    Test that uniform ScalarDistributions have zero disequilibrium.
    """
    for n in range(2, 11):
        d = uniform(n)
        yield assert_almost_equal, disequilibrium(d), 0
Пример #5
0
def test_renyi_entropy_1(alpha):
    """
    Test that the Renyi entropy of a uniform distirbution is indipendent of the
    order.
    """
    d = uniform(8)
    assert renyi_entropy(d, alpha) == pytest.approx(3)
Пример #6
0
def test_renyi_entropy_3(alpha):
    """
    Test that negative orders raise ValueErrors.
    """
    d = uniform(8)
    with pytest.raises(ValueError):
        renyi_entropy(d, alpha)
Пример #7
0
def test_gcre_4():
    """
    Test that equal-length uniform distributions all have the same GCRE.
    """
    gcres = [GCRE(uniform(i, i + 5)) for i in range(-5, 1)]
    for gcre in gcres:
        yield assert_almost_equal, gcre, gcres[0]
Пример #8
0
def test_uniform1():
    """ Test uniform distribution """
    for n in range(2, 10):
        d = uniform(n)
        assert_equal(d.outcomes, tuple(range(n)))
        assert_almost_equal(d[0], 1 / n)
        assert_almost_equal(entropy(d), np.log2(n))
def test_gcre_4():
    """
    Test that equal-length uniform distributions all have the same GCRE.
    """
    gcres = [ GCRE(uniform(i, i+5)) for i in range(-5, 1) ]
    for gcre in gcres:
        yield assert_almost_equal, gcre, gcres[0]
Пример #10
0
def test_disequilibrium4():
    """
    Test that uniform Distributions have zero disequilibrium.
    """
    for n in range(2, 11):
        d = Distribution.from_distribution(uniform(n))
        yield assert_almost_equal, disequilibrium(d), 0
Пример #11
0
def test_LMPR_complexity2():
    """
    Test that uniform ScalarDistirbutions have zero complexity.
    """
    for n in range(2, 11):
        d = uniform(n)
        yield assert_almost_equal, LMPR_complexity(d), 0
Пример #12
0
def test_uniform1():
    """ Test uniform distribution """
    for n in range(2, 10):
        d = uniform(n)
        assert d.outcomes == tuple(range(n))
        assert d[0] == pytest.approx(1 / n)
        assert entropy(d) == pytest.approx(np.log2(n))
Пример #13
0
def test_LMPR_complexity3():
    """
    Test that uniform Distirbutions have zero complexity.
    """
    for n in range(2, 11):
        d = Distribution.from_distribution(uniform(n))
        yield assert_almost_equal, LMPR_complexity(d), 0
Пример #14
0
def test_uniform1():
    """ Test uniform distribution """
    for n in range(2, 10):
        d = uniform(n)
        assert d.outcomes == tuple(range(n))
        assert d[0] == pytest.approx(1/n)
        assert entropy(d) == pytest.approx(np.log2(n))
Пример #15
0
def test_renyi_entropy_3():
    """
    Test that negative orders raise ValueErrors.
    """
    d = uniform(8)
    for alpha in [-np.inf, -5, -1, -1/2, -0.0000001]:
        yield assert_raises, ValueError, renyi_entropy, d, alpha
Пример #16
0
def test_renyi_entropy_3(alpha):
    """
    Test that negative orders raise ValueErrors.
    """
    d = uniform(8)
    with pytest.raises(ValueError):
        renyi_entropy(d, alpha)
Пример #17
0
def test_renyi_entropy_1():
    """
    Test that the Renyi entropy of a uniform distirbution is indipendent of the
    order.
    """
    d = uniform(8)
    for alpha in [0, 1/2, 1, 2, 5, np.inf]:
        yield assert_almost_equal, renyi_entropy(d, alpha), 3
Пример #18
0
def test_ccre_2():
    """
    Test a correlated distribution.
    """
    d = conditional_uniform1()
    ccre = CCRE(d, 1, [0])
    uniforms = [CRE(uniform(i)) for i in range(1, 6)]
    assert_array_almost_equal(ccre.outcomes, uniforms)
def test_cgcre_1():
    """
    Test the CGCRE against known values.
    """
    d = conditional_uniform2()
    cgcre = CGCRE(d, 1, [0])
    uniforms = [ GCRE(uniform(i)) for i in range(1, 6) ]
    assert np.allclose(cgcre.outcomes, uniforms)
def test_ccre_3():
    """
    Test a correlated distribution.
    """
    d = conditional_uniform2()
    ccre = CCRE(d, 1, [0])
    uniforms = sorted([ CRE(uniform(i-2, 3)) for i in range(5) ])
    assert np.allclose(ccre.outcomes, uniforms)
def test_ccre_2():
    """
    Test a correlated distribution.
    """
    d = conditional_uniform1()
    ccre = CCRE(d, 1, [0])
    uniforms = [ CRE(uniform(i)) for i in range(1, 6) ]
    assert np.allclose(ccre.outcomes, uniforms)
Пример #22
0
def test_ccre_3():
    """
    Test a correlated distribution.
    """
    d = conditional_uniform2()
    ccre = CCRE(d, 1, [0])
    uniforms = sorted([CRE(uniform(i - 2, 3)) for i in range(5)])
    assert_array_almost_equal(ccre.outcomes, uniforms)
Пример #23
0
def test_cgcre_1():
    """
    Test the CGCRE against known values.
    """
    d = conditional_uniform2()
    cgcre = CGCRE(d, 1, [0])
    uniforms = [GCRE(uniform(i)) for i in range(1, 6)]
    assert_array_almost_equal(cgcre.outcomes, uniforms)
Пример #24
0
def test_ccre_3():
    """
    Test a correlated distribution.
    """
    d = conditional_uniform2()
    ccre = CCRE(d, 1, [0])
    uniforms = sorted(CRE(uniform(i - 2, 3)) for i in range(5))
    assert np.allclose(ccre.outcomes, uniforms)
Пример #25
0
def test_uniform3():
    """ Test uniform distribution construction """
    _as = [1, 2, 3, 4, 5]
    _bs = [5, 7, 9, 11, 13]
    for a, b in zip(_as, _bs):
        d = uniform(a, b)
        assert_equal(len(d.outcomes), b - a)
        assert_almost_equal(d[a], 1 / (b - a))
Пример #26
0
def test_uniform3():
    """ Test uniform distribution construction """
    _as = [1, 2, 3, 4, 5]
    _bs = [5, 7, 9, 11, 13]
    for a, b in zip(_as, _bs):
        d = uniform(a, b)
        assert_equal(len(d.outcomes), b-a)
        assert_almost_equal(d[a], 1/(b-a))
def test_gcre_1():
    """
    Test the GCRE against known values for the uniform distribution.
    """
    dists = [ uniform(-n//2, n//2) for n in range(2, 23, 2) ]
    results = [0.5, 1.31127812, 2.06831826, 2.80927657, 3.54316518, 4.27328199,
               5.00113503, 5.72751654, 6.45288453, 7.17752308, 7.90161817]
    for d, r in zip(dists, results):
        yield assert_almost_equal, r, GCRE(d)
def test_cre_1():
    """
    Test the CRE against known values for several uniform distributions.
    """
    dists = [ uniform(-n//2, n//2) for n in range(2, 23, 2) ]
    results = [0.5, 0.81127812, 1.15002242, 1.49799845, 1.85028649, 2.20496373,
               2.56111354, 2.91823997, 3.27604979, 3.6343579, 3.99304129]
    for d, r in zip(dists, results):
        yield assert_almost_equal, r, CRE(d)
Пример #29
0
def test_gcre_1():
    """
    Test the GCRE against known values for the uniform distribution.
    """
    dists = [uniform(-n // 2, n // 2) for n in range(2, 23, 2)]
    results = [
        0.5, 1.31127812, 2.06831826, 2.80927657, 3.54316518, 4.27328199,
        5.00113503, 5.72751654, 6.45288453, 7.17752308, 7.90161817
    ]
    for d, r in zip(dists, results):
        yield assert_almost_equal, r, GCRE(d)
Пример #30
0
def test_cre_1():
    """
    Test the CRE against known values for several uniform distributions.
    """
    dists = [uniform(-n // 2, n // 2) for n in range(2, 23, 2)]
    results = [
        0.5, 0.81127812, 1.15002242, 1.49799845, 1.85028649, 2.20496373,
        2.56111354, 2.91823997, 3.27604979, 3.6343579, 3.99304129
    ]
    for d, r in zip(dists, results):
        yield assert_almost_equal, r, CRE(d)
Пример #31
0
def test_LMPR_complexity3(n):
    """
    Test that uniform Distirbutions have zero complexity.
    """
    d = Distribution.from_distribution(uniform(n))
    assert LMPR_complexity(d) == pytest.approx(0)
Пример #32
0
def test_LMPR_complexity2(n):
    """
    Test that uniform ScalarDistirbutions have zero complexity.
    """
    d = uniform(n)
    assert LMPR_complexity(d) == pytest.approx(0)
Пример #33
0
def test_disequilibrium4(n):
    """
    Test that uniform Distributions have zero disequilibrium.
    """
    d = Distribution.from_distribution(uniform(n))
    assert disequilibrium(d) == pytest.approx(0)
Пример #34
0
def test_disequilibrium3(n):
    """
    Test that uniform ScalarDistributions have zero disequilibrium.
    """
    d = uniform(n)
    assert disequilibrium(d) == pytest.approx(0)
Пример #35
0
def test_LMPR_complexity3(n):
    """
    Test that uniform Distirbutions have zero complexity.
    """
    d = Distribution.from_distribution(uniform(n))
    assert LMPR_complexity(d) == pytest.approx(0)
Пример #36
0
def test_H6():
    """ Test H for uniform distributions using ScalarDistributions """
    for i in range(2, 10):
        d = uniform(i)
        yield assert_almost_equal, H(d), np.log2(i)
def test_gcre_1(n, val):
    """
    Test the GCRE against known values for the uniform distribution.
    """
    dist = uniform(-n // 2, n // 2)
    assert GCRE(dist) == pytest.approx(val)
Пример #38
0
def test_H7(i):
    """ Test H for uniform distributions using SDs in various bases """
    d = uniform(i)
    d.set_base(i)
    assert H(d) == pytest.approx(1)
Пример #39
0
def test_H4(i):
    """ Test H for uniform distributions """
    d = D.from_distribution(uniform(i))
    assert H(d) == pytest.approx(np.log2(i))
Пример #40
0
def test_H6(i):
    """ Test H for uniform distributions using ScalarDistributions """
    d = uniform(i)
    assert H(d) == pytest.approx(np.log2(i))
Пример #41
0
def test_H5(i):
    """ Test H for uniform distributions in various bases """
    d = D.from_distribution(uniform(i))
    d.set_base(i)
    assert H(d) == pytest.approx(1)
Пример #42
0
def test_H4(i):
    """ Test H for uniform distributions """
    d = D.from_distribution(uniform(i))
    assert H(d) == pytest.approx(np.log2(i))
Пример #43
0
def test_uniform4(a, b):
    """ Test uniform distribution failures """
    with pytest.raises(ValueError):
        uniform(a, b)
Пример #44
0
def test_H4():
    """ Test H for uniform distributions """
    for i in range(2, 10):
        d = D.from_distribution(uniform(i))
        yield assert_almost_equal, H(d), np.log2(i)
Пример #45
0
def test_uniform3(a, b):
    """ Test uniform distribution construction """
    d = uniform(a, b)
    assert len(d.outcomes) == b - a
    assert d[a] == pytest.approx(1 / (b - a))
Пример #46
0
def test_uniform3(a, b):
    """ Test uniform distribution construction """
    d = uniform(a, b)
    assert len(d.outcomes) == b-a
    assert d[a] == pytest.approx(1/(b-a))
def test_cre_1(n, val):
    """
    Test the CRE against known values for several uniform distributions.
    """
    dist = uniform(-n // 2, n // 2)
    assert CRE(dist) == pytest.approx(val)
Пример #48
0
def test_uniform4(a, b):
    """ Test uniform distribution failures """
    with pytest.raises(ValueError):
        uniform(a, b)
Пример #49
0
def test_H4():
    """ Test H for uniform distributions """
    for i in range(2, 10):
        d = D.from_distribution(uniform(i))
        yield assert_almost_equal, H(d), np.log2(i)
Пример #50
0
def test_H6(i):
    """ Test H for uniform distributions using ScalarDistributions """
    d = uniform(i)
    assert H(d) == pytest.approx(np.log2(i))
Пример #51
0
def test_H5():
    """ Test H for uniform distributions in various bases """
    for i in range(2, 10):
        d = D.from_distribution(uniform(i))
        d.set_base(i)
        yield assert_almost_equal, H(d), 1
Пример #52
0
def test_H5():
    """ Test H for uniform distributions in various bases """
    for i in range(2, 10):
        d = D.from_distribution(uniform(i))
        d.set_base(i)
        yield assert_almost_equal, H(d), 1
Пример #53
0
def test_H7():
    """ Test H for uniform distributions using SDs in various bases """
    for i in range(2, 10):
        d = uniform(i)
        d.set_base(i)
        yield assert_almost_equal, H(d), 1
Пример #54
0
def test_H6():
    """ Test H for uniform distributions using ScalarDistributions """
    for i in range(2, 10):
        d = uniform(i)
        yield assert_almost_equal, H(d), np.log2(i)
Пример #55
0
def test_H5(i):
    """ Test H for uniform distributions in various bases """
    d = D.from_distribution(uniform(i))
    d.set_base(i)
    assert H(d) == pytest.approx(1)
Пример #56
0
def test_H7():
    """ Test H for uniform distributions using SDs in various bases """
    for i in range(2, 10):
        d = uniform(i)
        d.set_base(i)
        yield assert_almost_equal, H(d), 1
Пример #57
0
def test_H7(i):
    """ Test H for uniform distributions using SDs in various bases """
    d = uniform(i)
    d.set_base(i)
    assert H(d) == pytest.approx(1)
Пример #58
0
def test_LMPR_complexity2(n):
    """
    Test that uniform ScalarDistirbutions have zero complexity.
    """
    d = uniform(n)
    assert LMPR_complexity(d) == pytest.approx(0)