Пример #1
0
	def optimize_branch_func(self, parent, child, t_a):
		"""
		<t_a> is the new branch length between <parent> --- <child>
		(t_a is dressed in an array...should always be just [t_a])

		We can cheat & speed up likelihood calculation
		 by re-using likelihods of subtrees below child and T'
		 where T' is the subtree under root that does not contain parent/child

		Returns: POSITIVE sum of log likelihood (so we try to minimize it)

		currently wrapped up by ::optimize_branch::
		NOTE: it is ::optimize_branch::'s responsibility to update
		      self.order and self.like when all is done!!!

		p.s. potentialy speed-up by simultaneously optimizing two child branches
		     of the same parent??
		"""
		#assert len(t_a) == 1
		g = MyMat.calc_likelihood
		
		child.edge_length = t_a[0]
		# TODO: make this more efficient!
		cheat_order = Tree.postorder_cheat_traverse(parent)

		L_single = g(self.single_model.gtr.R, self.S, self.log_freq_single, \
				cheat_order, range(self.ncol), self.nnode, self.ncol, self.nbase)
		L_paired = g(self.paired_model.gtr.R, self.P, self.log_freq_paired, \
				cheat_order, range(self.ncol_p), self.nnode_p, self.ncol_p, self.nbase_p)
		return -(L_single.sum() + L_paired.sum())
Пример #2
0
	def reversible_subtree_func(copy_S, copy_P, parent, child, t_a):
		#assert len(t_a) == 1

		child.edge_length = t_a[0]
		order = Tree.postorder_cheat_traverse(parent)

		L_single = g(tlobj.single_model.gtr.R, copy_S, tlobj.log_freq_single, \
				order, range(tlobj.ncol), tlobj.nnode, tlobj.ncol, tlobj.nbase)
		L_paired = g(tlobj.paired_model.gtr.R, copy_P, tlobj.log_freq_paired, \
				order, range(tlobj.ncol_p), tlobj.nnode_p, tlobj.ncol_p, tlobj.nbase_p)

		ans = -(L_single.sum() + L_paired.sum())
		return ans