def test_likelihood_leaf_root(self): nstates = 4 ov = (3, 2, 0, 1) pattern = np.array([-1, 0, 0, 1]) v_to_children = {1: [0], 0 : [2, 3]} Q_jc = get_jc_rate_matrix() de_to_P = { (1, 0) : scipy.linalg.expm(0.1 * Q_jc), (0, 2) : scipy.linalg.expm(0.2 * Q_jc), (0, 3) : scipy.linalg.expm(0.3 * Q_jc), } root_prior = np.ones(nstates) / float(nstates) expected_ll = -4.14671850148 ll = sitell.brute(ov, v_to_children, pattern, de_to_P, root_prior) testing.assert_allclose(ll, expected_ll) ll = sitell.fels(ov, v_to_children, pattern, de_to_P, root_prior) testing.assert_allclose(ll, expected_ll)
def test_single_branch_jc_change(self): """ Check against a formula for the Jukes-Cantor transition probability. """ nstates = 4 ov = (0, 1) pattern = np.array([0, 1]) v_to_children = {1 : [0]} Q = get_jc_rate_matrix() t = 0.1 de_to_P = { (1, 0) : scipy.linalg.expm(t * Q), } root_prior = np.ones(nstates) / float(nstates) expected_likelihood = (1.0 / 4.0) * ( (1.0 / 4.0) * (1 - math.exp(-(4.0 / 3.0) * t))) expected_ll = math.log(expected_likelihood) ll = sitell.brute(ov, v_to_children, pattern, de_to_P, root_prior) testing.assert_allclose(ll, expected_ll) ll = sitell.fels(ov, v_to_children, pattern, de_to_P, root_prior) testing.assert_allclose(ll, expected_ll)