treetime/treeanc.py
def ancestral_likelihood(self):
        """
        Calculate the likelihood of the given realization of the sequences in
        the tree

        Returns
        -------

         log_lh : float
            The tree likelihood given the sequences
        """
        log_lh = np.zeros(self.multiplicity.shape[0])
        for node in self.tree.find_clades(order='postorder'):

            if node.up is None: #  root node
                # 0-1 profile
                profile = seq2prof(node.cseq, self.gtr.profile_map)
                # get the probabilities to observe each nucleotide
                profile *= self.gtr.Pi
                profile = profile.sum(axis=1)
                log_lh += np.log(profile) # product over all characters
                continue

            t = node.branch_length

            indices = np.array([(np.argmax(self.gtr.alphabet==a),
                        np.argmax(self.gtr.alphabet==b)) for a, b in zip(node.up.cseq, node.cseq)])

            logQt = np.log(self.gtr.expQt(t))
            lh = logQt[indices[:, 1], indices[:, 0]]
            log_lh += lh

        return log_lh
def ancestral_likelihood(self):
        log_lh = np.zeros(self.multiplicity.shape[0])
        for node in self.tree.find_clades(order='postorder'):

            if node.up is None: #  root node
                # 0-1 profile
                profile = seq2prof(node.cseq, self.gtr.profile_map)
                # get the probabilities to observe each nucleotide
                profile *= self.gtr.Pi
                profile = profile.sum(axis=1)
                log_lh += np.log(profile) # product over all characters
                continue

            t = node.branch_length

            indices = np.array([(np.argmax(self.gtr.alphabet==a),
                        np.argmax(self.gtr.alphabet==b)) for a, b in zip(node.up.cseq, node.cseq)])

            logQt = np.log(self.gtr.expQt(t))
            lh = logQt[indices[:, 1], indices[:, 0]]
            log_lh += lh

        return log_lh
def ancestral_likelihood ( self ) : log_lh = np . zeros ( self . multiplicity . shape [ 0 ] ) for node in self . tree . find_clades ( order = 'postorder' ) : if node . up is None : #  root node # 0-1 profile profile = seq2prof ( node . cseq , self . gtr . profile_map ) # get the probabilities to observe each nucleotide profile *= self . gtr . Pi profile = profile . sum ( axis = 1 ) log_lh += np . log ( profile ) # product over all characters continue t = node . branch_length indices = np . array ( [ ( np . argmax ( self . gtr . alphabet == a ) , np . argmax ( self . gtr . alphabet == b ) ) for a , b in zip ( node . up . cseq , node . cseq ) ] ) logQt = np . log ( self . gtr . expQt ( t ) ) lh = logQt [ indices [ : , 1 ] , indices [ : , 0 ] ] log_lh += lh return log_lh
Calculate the likelihood of the given realization of the sequences in
        the tree

        Returns
        -------

         log_lh : float
            The tree likelihood given the sequences
Calculate the likelihood of the given realization of the sequences in the tree