Skip to content

Commit

Permalink
MAINT: refactor tests of jsd and jsm calculations to make more numeri…
Browse files Browse the repository at this point in the history
…cally stable

This relates to #534. As I don't have access to those systems
I cannot be sure this solves one of the test failures (which was for the expected
value of 0.0).
  • Loading branch information
GavinHuttley committed Feb 16, 2020
1 parent 5baf827 commit 96ab670
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions tests/test_maths/test_measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,37 +166,37 @@ def test_jsd_validation(self):
def test_jsd(self):
"""case1 is testing if the jsd between two identical distributions is 0.0"""
case1 = [
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
]
for pointer in range(10):
case1[0][pointer] = 1.0
case1[1][pointer] = 1.0
for index in range(len(case1[0])):
case1[0][index] = 1.0
case1[1][index] = 1.0
assert_allclose(
jsd(case1[0], case1[1], validate=True),
0.0,
err_msg="Testing case1 for jsd failed",
)
case1[0][pointer] = 0.0
case1[1][pointer] = 0.0
"""case2 is testing the numerical output of jsd between two random distributions"""
case2 = [[1.0 / 10, 9.0 / 10, 0], [0, 1.0 / 10, 9.0 / 10]]
case1[0][index] = 0.0
case1[1][index] = 0.0
# case2 is testing the numerical output of jsd between two distant distributions
case2 = [[1 / 10, 9 / 10, 0], [0, 1 / 10, 9 / 10]]
assert_allclose(
jsd(case2[0], case2[1], validate=True),
0.7655022032053593,
err_msg="Testing case2 for jsd failed",
)
"""case3 is testing the numerical output of jsd between two random distributions"""
case3 = [[1.0, 0.0], [0.5, 0.5]]
# case3 is testing the numerical output of jsd between two distant distributions
case3 = [[1.0, 0.0], [1 / 2, 1 / 2]]
assert_allclose(
jsd(case3[0], case3[1], validate=True),
0.3112781244591328,
err_msg="Testing case3 for jsd failed",
)
"""case4 is testing if the jsd between two identical uniform distributions is 0.0"""
# case4 - the jsd between two identical uniform distributions is 0.0
case4 = [
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
[1 / 10] * 10,
[1 / 10] * 10,
]
assert_allclose(
jsd(case4[0], case4[1], validate=True),
Expand All @@ -207,37 +207,37 @@ def test_jsd(self):
def test_jsm(self):
"""case1 is testing if the jsm between two identical distributions is 0.0"""
case1 = [
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
]
for pointer in range(10):
case1[0][pointer] = 1.0
case1[1][pointer] = 1.0
for index in range(len(case1[0])):
case1[0][index] = 1.0
case1[1][index] = 1.0
assert_allclose(
jsm(case1[0], case1[1], validate=True),
0.0,
err_msg="Testing case1 for jsm failed",
)
case1[0][pointer] = 0.0
case1[1][pointer] = 0.0
"""case2 is testing the numerical output of jsm between two random distributions"""
case2 = [[1.0 / 10, 9.0 / 10, 0], [0, 1.0 / 10, 9.0 / 10]]
case1[0][index] = 0.0
case1[1][index] = 0.0
# case2 is testing the numerical output of jsm between two random distributions
case2 = [[1 / 10, 9 / 10, 0], [0, 1 / 10, 9 / 10]]
assert_allclose(
jsm(case2[0], case2[1], validate=True),
0.8749298275892526,
err_msg="Testing case2 for jsm failed",
)
"""case3 is testing the numerical output of jsm between two random distributions"""
case3 = [[1.0, 0.0], [0.5, 0.5]]
# case3 is testing the numerical output of jsm between two random distributions
case3 = [[1.0, 0.0], [1 / 2, 1 / 2]]
assert_allclose(
jsm(case3[0], case3[1], validate=True),
0.5579230452841438,
err_msg="Testing case3 for jsm failed",
)
"""case4 is testing if the jsm between two identical uniform distributions is 0.0"""
# case4 is testing if the jsm between two identical uniform distributions is 0.0
case4 = [
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
[1 / 10] * 10,
[1 / 10] * 10,
]
assert_allclose(
jsm(case4[0], case4[1], validate=True),
Expand Down

0 comments on commit 96ab670

Please sign in to comment.