예제 #1
0
    def test_maskarrayp_changeQ_correctentriesmasked(self):
        tree = ivy.tree.read(u'(((A:1,B:1)C:1,D:2)E:1,F:3)root;')
        chars = [1, 0, 0, 0]

        Q1 = np.array([[-0.10, 0.10], [0.05, -0.05]])
        Q2 = np.array([[-1.5, 1.5], [1., -1.]])
        Q3 = np.array([[-0.15, 0.15], [0.1, -0.1]])
        Qs1 = np.array([Q2, Q1])
        Qs2 = np.array([Q2, Q3])

        switchpoint = [(tree["C"], 0.75)]
        ar = mk_mr.create_mkmr_mb_ar(tree, chars, 2)

        l1 = mk_mr.mk_mr_midbranch(tree,
                                   chars,
                                   Qs1,
                                   switchpoint,
                                   ar=ar,
                                   debug=False)

        l2 = mk_mr.mk_mr_midbranch(tree,
                                   chars,
                                   Qs2,
                                   switchpoint,
                                   ar=ar,
                                   debug=False)

        ar2 = mk_mr.create_mkmr_mb_ar(tree, chars, 2)
        l2True = mk_mr.mk_mr_midbranch(tree, chars, Qs2, switchpoint, ar=ar2)

        self.assertEqual(l2, l2True)
예제 #2
0
    def test_mkmr_largetree_correctlikelihood(self):
        tree = ivy.tree.read(u"support/hrm_600tips.newick")
        chars = [
            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, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1,
            1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1,
            0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 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, 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, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
            0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
            1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
            1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 1, 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, 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, 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
        ]
        Q0 = np.array([[-0.061457569587587413, 0.061457569587587413],
                       [0.061457569587587413, -0.061457569587587413]])
        Q1 = np.array([[-1.4976115055655292, 1.4976115055655292],
                       [1.4976115055655292, -1.4976115055655292]])
        Q2 = np.array([[-0.0014644343303779842, 0.0014644343303779842],
                       [0.0014644343303779842, -0.0014644343303779842]])
        Qs = np.array([Q0, Q1, Q2])
        switchpoint0 = (tree[579], 1.2)
        switchpoint1 = (tree[329], 3.0)

        true_L = -89.213330113632566

        ar = mk_mr.create_mkmr_mb_ar(tree, chars, 3)

        calculated_l = mk_mr.mk_mr_midbranch(tree,
                                             chars,
                                             Qs, [switchpoint0, switchpoint1],
                                             ar=ar,
                                             debug=True)

        self.assertTrue(np.isclose(calculated_l, true_L))
예제 #3
0
    def test_mkmr_benchmark(self):
        tree = ivy.tree.read(u'(((A:1,B:1)C:1,D:2)E:1,F:3)root;')
        chars = [1, 0, 0, 0]

        Q1 = np.array([[-0.10, 0.10], [0.05, -0.05]])
        Q2 = np.array([[-1.5, 1.5], [1., -1.]])
        Q3 = np.array([[-0.15, 0.15], [0.1, -0.1]])
        Qs1 = np.array([Q2, Q1])
        Qs2 = np.array([Q2, Q3])

        switchpoint_1 = [(tree["C"], 0.75)]
        switchpoint_2 = [(tree["D"], 0.5)]

        ar = mk_mr.create_mkmr_mb_ar(tree, chars, 2)

        def foo(tree=tree,
                chars=chars,
                Qs1=Qs1,
                switchpoint_1=switchpoint_1,
                ar=ar):
            mk_mr.mk_mr_midbranch(tree,
                                  chars,
                                  Qs1,
                                  switchpoint_1,
                                  ar=ar,
                                  debug=False)

        def dotime():
            t = timeit.Timer("foo()")
            time = t.timeit(1000)
            print("1000 loops took %fs\n" % (time, ))

        import __builtin__
        __builtin__.__dict__.update(locals())

        dotime()
예제 #4
0
            0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1,
            0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
            0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0,
            0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1,
            1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
            1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
            1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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]
data = dict(zip([n.label for n in tree.leaves()],mr_chars))
# The Q-matrices used to generate the character states
trueFastQ = np.array([[-.8,.8], [.8,-.8]])
trueSlowQ = np.array([[-.1,.1], [.1,-.1]])
trueQs = np.array([trueFastQ,trueSlowQ])
ar = mk_mr.create_mkmr_mb_ar(tree, mr_chars, 2)

switchpoint =[(tree[350],0.0)]

mods = [(2,2),(1,1)]

qidx = np.array([[0,0,1,0],
                 [0,1,0,0],
                 [1,0,1,1],
                 [1,1,0,1]])
switches = np.array([120])
lengths = np.array([1e-15])
f = cyexpokit.make_mklnl_func(tree, data, 2, 2, qidx)
f(np.array([0.1,0.05]),switches,lengths)