コード例 #1
0
ファイル: test_measure.py プロジェクト: aglucaci/cogent3
 def test_jsm(self):
     """evaluate jsm between identical, and non-identical distributions"""
     case1 = [
         [0.0, 0.0, 0.0],
         [0.0, 0.0, 0.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",
             atol=self.atol,
         )
         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",
         atol=self.atol,
     )
     # 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",
         atol=self.atol,
     )
     # case4 is testing if the jsm between two identical uniform distributions is 0.0
     case4 = [
         [1 / 10] * 10,
         [1 / 10] * 10,
     ]
     assert_allclose(
         jsm(case4[0], case4[1], validate=True),
         0.0,
         err_msg="Testing case4 for jsm failed",
         atol=self.atol,
     )
コード例 #2
0
 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],
     ]
     for pointer in range(10):
         case1[0][pointer] = 1.0
         case1[1][pointer] = 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]]
     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]]
     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 = [
         [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],
     ]
     assert_allclose(
         jsm(case4[0], case4[1], validate=True),
         0.0,
         err_msg="Testing case4 for jsm failed",
     )
コード例 #3
0
ファイル: test_profile.py プロジェクト: mr-c/cogent3
    def test_pairwise_jsm(self):
        """correctly constructs pairwise JS metric dict"""
        from numpy.random import random

        from cogent3.maths.measure import jsm

        data = [[0.25, 0.25, 0.25, 0.25], [0.5, 0.5, 0, 0]]
        expect = jsm(data[0], data[1])
        freqs = MotifFreqsArray(array(data), "ACGT")
        got = freqs.pairwise_jsm()
        assert_allclose(list(got.values())[0], expect)

        data = []
        for _ in range(6):
            freqs = random(4)
            freqs = freqs / freqs.sum()
            data.append(freqs)

        freqs = MotifFreqsArray(array(data), "ACGT")
        pwise = freqs.pairwise_jsm()
        self.assertEqual(len(pwise), 6 * 6 - 6)