Beispiel #1
0
def test_cross_entropy_3(args):
    """
    Test that when p has outcomes that q doesn't have, that we raise an exception.
    """
    first, second, rvs, crvs = args
    with pytest.raises(ditException):
        cross_entropy(first, second, rvs, crvs)
Beispiel #2
0
def test_cross_entropy_3(args):
    """
    Test that when p has outcomes that q doesn't have, that we raise an exception.
    """
    first, second, rvs, crvs = args
    with pytest.raises(ditException):
        cross_entropy(first, second, rvs, crvs)
Beispiel #3
0
def test_cross_entropy_2():
    """
    Test that xH(d, d) = H(d).
    """
    ds = get_dists()
    for d in ds:
        yield assert_almost_equal, cross_entropy(d, d), entropy(d)
Beispiel #4
0
def test_cross_entropy_2():
    """
    Test that xH(d, d) = H(d).
    """
    ds = get_dists()
    for d in ds:
        yield assert_almost_equal, cross_entropy(d, d), entropy(d)
Beispiel #5
0
def test_cross_entropy_1():
    """
    Test against several known values.
    """
    d1, d2, d3, d4, d5 = get_dists()
    tests = [([d1, d3], 1.5849625007211563), ([d1, d4], 1.0294468445267841),
             ([d1, d3, [0]], 1.5849625007211563),
             ([d1, d4, [0]], 1.0294468445267841), ([d4, d1, [0]], 1),
             ([d4, d5], 1), ([d5, d4], 1.0294468445267841),
             ([d4, d5, [0], [1]], 0), ([d4, d5, [1], [0]], 0),
             ([d1, d2], np.inf), ([d2, d1], np.inf), ([d3, d1], np.inf)]
    for args, val in tests:
        yield assert_almost_equal, cross_entropy(*args), val
Beispiel #6
0
def test_cross_entropy_1():
    """
    Test against several known values.
    """
    d1, d2, d3, d4, d5 = get_dists()
    tests = [([d1, d3], 1.5849625007211563),
             ([d1, d4], 1.0294468445267841),
             ([d1, d3, [0]], 1.5849625007211563),
             ([d1, d4, [0]], 1.0294468445267841),
             ([d4, d1, [0]], 1),
             ([d4, d5], 1),
             ([d5, d4], 1.0294468445267841),
             ([d4, d5, [0], [1]], 0),
             ([d4, d5, [1], [0]], 0),
             ([d1, d2], np.inf),
             ([d2, d1], np.inf),
             ([d3, d1], np.inf)]
    for args, val in tests:
        yield assert_almost_equal, cross_entropy(*args), val
Beispiel #7
0
def test_cross_entropy_2(d):
    """
    Test that xH(d, d) = H(d).
    """
    assert cross_entropy(d, d) == pytest.approx(entropy(d))
Beispiel #8
0
def test_cross_entropy_1(args, expected):
    """
    Test against several known values.
    """
    assert cross_entropy(*args) == pytest.approx(expected)
Beispiel #9
0
def test_cross_entropy_2(d):
    """
    Test that xH(d, d) = H(d).
    """
    assert cross_entropy(d, d) == pytest.approx(entropy(d))
Beispiel #10
0
def test_cross_entropy_1(args, expected):
    """
    Test against several known values.
    """
    assert cross_entropy(*args) ==  pytest.approx(expected)