def get_paralinear_metric(self, motif_probs=None): """returns {edge.name: paralinear, ...} Parameters ---------- motif_probs : dict or DictArray an item for each edge of the tree. Computed if not provided. """ from cogent3.evolve.ns_substitution_model import DiscreteSubstitutionModel is_discrete = isinstance(self.model, DiscreteSubstitutionModel) if motif_probs is None: motif_probs = self.get_motif_probs_by_node() plin = {} for edge in self.tree.get_edge_vector(include_root=False): parent_name = edge.parent.name pi = motif_probs[parent_name] P = self.get_psub_for_edge(edge.name) if is_discrete: para = paralinear_discrete_time(P.array, pi.array) else: Q = self.get_rate_matrix_for_edge(edge.name, calibrated=False) para = paralinear_continuous_time(P.array, pi.array, Q.array) plin[edge.name] = para return plin
def test_paralinear_discrete_time(self): """tests paralinear_discrete_time to compare it with the output of paralinear_continuous_time""" qp1, qp2, qp3 = gen_qs_ps() pi1 = random(4) pi1 /= pi1.sum() pi2 = next_pi(pi1, qp1[1]) pi3 = next_pi(pi2, qp2[1]) con_time_pl1 = paralinear_continuous_time(qp1[1], pi1, qp1[0]) dis_time_pl1 = paralinear_discrete_time(qp1[1], pi1) assert_allclose(con_time_pl1, dis_time_pl1) con_time_pl2 = paralinear_continuous_time(qp2[1], pi2, qp2[0]) dis_time_pl2 = paralinear_discrete_time(qp2[1], pi2) assert_allclose(con_time_pl2, dis_time_pl2) con_time_pl3 = paralinear_continuous_time(qp3[1], pi3, qp3[0]) dis_time_pl3 = paralinear_discrete_time(qp3[1], pi3) assert_allclose(con_time_pl3, dis_time_pl3)