def all_rate_matrices_unique(self):
     """Returns True if every rate matrix is unique for its Psub matrix"""
     # get all possible Q, as products of t, and any rate-het terms
     all_Q = self.get_all_rate_matrices(calibrated=False)
     for Q in all_Q.values():
         Q = Q.to_array()
         if not is_generator_unique(Q):
             return False
     return True
Beispiel #2
0
    def test_is_generator_unique(self):
        """is_generator_unique should identify non-unique primary roots or
        raise a NotImplementedError for non-primary roots"""
        q_fail = array(
            [
                [-9.08955989, 4.50419008, 2.93729567, 1.64807414],
                [3.0820101213, -11.867582855, 3.0196380713, 5.7659346624],
                [3.1293061336, 0.6470353007, -4.340134955, 0.5637935206],
                [9.95494662, 0.63789574, 1.39069539, -11.98353775],
            ]
        )
        self.assertFalse(is_generator_unique(q_fail))

        q_pass = array(
            [
                [-3.764760594, 1.1273556812, 1.3310122018, 1.3063927109],
                [0.920950736, -2.6797373188, 0.4269374722, 1.3318491106],
                [1.1327752022, 1.1606494551, -2.7789984239, 0.4855737666],
                [1.2387180594, 0.1873997167, 0.9202488686, -2.3463666447],
            ]
        )
        self.assertTrue(is_generator_unique(q_pass))

        q_raise = array(
            [
                [-2.77453845e-03, 2.77453817e-03, 1.00809110e-10, 1.74200370e-10],
                [6.81595242e-11, -3.43166912e-10, 1.00810050e-10, 1.74197338e-10],
                [6.81605094e-11, 2.77453817e-03, -2.77453841e-03, 1.74198726e-10],
                [6.81594144e-11, 1.38727059e-10, 1.00808021e-04, -1.00808228e-04],
            ]
        )
        self.assertRaises(NotImplementedError, is_generator_unique, q_raise)

        # currently only support 3x3 or 4x4 matrices
        q_raise = array(
            [
                [1, 2, 3, 4, 5],
                [1, 2, 3, 4, 5],
                [1, 2, 3, 4, 5],
                [1, 2, 3, 4, 5],
                [1, 2, 3, 4, 5],
            ]
        )
        self.assertRaises(NotImplementedError, is_generator_unique, q_raise)