Beispiel #1
0
def test_nth_variation():
    a, b = create_cases()
    assert (close(nth_variation(a, b, 0), 178)
            and close(nth_variation(a, b, 1), 1.80865306195869)
            and close(nth_variation(a, b, 2), 0.02414940510773)
            and close(nth_variation(a, b, 3), 0.00036023819549)
            and close(nth_variation(a, b, 4), 5.71352726e-06))
Beispiel #2
0
def test_minkowsky():
    a, b = create_cases()

    try:
        minkowsky(a, b, 0)
        assert False
    except ValueError:
        assert True

    assert close(minkowsky(a, b, 1), 1.80865306195869) and close(
        minkowsky(a, b, 2), 0.15540078863291) and close(
            minkowsky(a, b, 3), 0.07115355218523) and close(
                minkowsky(a, b, 4), 0.04889067980003)
Beispiel #3
0
def test_symmetry():
    errors = []
    a, b = create_cases()
    for distance_name, distance in [("squared_variation", squared_variation),
                                    ("euclidean", euclidean),
                                    ("jensen_shannon", jensen_shannon),
                                    ("bhattacharyya", bhattacharyya),
                                    ("total_variation", total_variation),
                                    ("hellinger", hellinger),
                                    ("canberra", canberra),
                                    ("chebyshev", chebyshev),
                                    ("cosine", cosine), ("hamming", hamming),
                                    ("mae", mae), ("manhattan", manhattan),
                                    ("mse", mse), ("pearson", pearson)]:
        # replace assertions by conditions
        if not close(distance(a, b), distance(b, a)):
            errors.append("Metric '%s' is not symmetric" % distance_name)

    # assert no error message has been registered, else print messages
    assert not errors, "errors occured:\n{}".format("\n".join(errors))
def test_normal_total_variation():
    a, b = create_cases()
    assert close(normal_total_variation(a, b), 0.90432653097935)
Beispiel #5
0
def test_cosine():
    a, b = create_cases()
    assert close(cosine(a, b), 0.88709336978023)
Beispiel #6
0
def test_hellinger():
    a, b = create_cases()
    assert close(hellinger(a, b), 0.9361741043264331)
Beispiel #7
0
def test_mae():
    a, b = create_cases()
    assert close(mae(a, b), 0.01016097225819)
Beispiel #8
0
def test_hamming():
    a, b = create_cases()
    assert hamming(a, b) == 167
Beispiel #9
0
def test_jensen_shannon():
    a, b = create_cases()
    assert close(jensen_shannon(a, b), 0.6098897698032)
def test_squared_variation():
    a, b = create_cases()
    assert close(squared_variation(a, b), 0.02414940510773)
def test_kullback_leibler():
    a, b = create_cases()
    assert close(kullback_leibler(a, b), 0) and close(kullback_leibler(b, a),
                                                      0.01247704999657)
Beispiel #12
0
def test_manhattan():
    a, b = create_cases()
    assert close(manhattan(a, b), 1.80865306195869)
Beispiel #13
0
def test_euclidean():
    a, b = create_cases()
    assert close(euclidean(a, b), 0.15540078863291)
Beispiel #14
0
def test_pearson():
    a, b = create_cases()
    assert close(pearson(a, b), 0.89895209792992)
Beispiel #15
0
def test_bhattacharyya():
    a, b = create_cases()
    assert close(bhattacharyya(a, b), 2.09088236794973)
def test_total_variation():
    a, b = create_cases()
    assert close(total_variation(a, b), 1.80865306195869)
Beispiel #17
0
def test_mse():
    a, b = create_cases()
    assert close(mse(a, b), 0.00013567081521)
Beispiel #18
0
def test_chebyshev():
    a, b = create_cases()
    assert close(chebyshev(a, b), 0.02015304120034)
Beispiel #19
0
def test_canberra():
    a, b = create_cases()
    assert close(canberra(a, b), 170.27780598478526)