Exemplo n.º 1
0
 def __log_likelihood__(self, phi, tp):
     ll = []
     for mu_r, log_pi_r in zip(self.mu_r, self.log_pi_r):
         for mu_v, log_pi_v in zip(self.mu_v, self.log_pi_v):
             ll.append(
                 self.__log_complete_likelihood__(phi, mu_r, mu_v, tp) +
                 log_pi_r + log_pi_v)
     return u.logsumexp(ll)
Exemplo n.º 2
0
	def __log_complete_likelihood1__(self, phi, mu_r, mu_v, new_state=0):	
		llh = []
		if self.cnv: 
			self.compute_n_genomes(0,new_state) # maternal
			mu = (self.nr * mu_r + self.nv*(1-mu_r) ) / (self.nr+ self.nv)
			llh.append(u.log_binomial_likelihood(self.a, self.d, mu) + log(0.5) +  self._log_bin_norm_const)
			self.compute_n_genomes(1,new_state) # paternal
			mu = (self.nr * mu_r + self.nv*(1-mu_r) ) / (self.nr+ self.nv)
			llh.append(u.log_binomial_likelihood(self.a, self.d, mu) + log(0.5) +  self._log_bin_norm_const)
			llh = u.logsumexp(ll)
		else: ## CNV datum or SSM with no CNV
			mu = (1 - phi) * mu_r + phi*mu_v # (mu_r=0.999, mu_v=0.5)
			llh = u.log_binomial_likelihood(self.a, self.d, mu) +  self._log_bin_norm_const
		return 	llh
Exemplo n.º 3
0
	def __log_complete_likelihood1__(self, phi, mu_r, mu_v, new_state=0):	
		llh = []
		if self.cnv: 
			self.compute_n_genomes(0,new_state) # maternal
			mu = (self.nr * mu_r + self.nv*(1-mu_r) ) / (self.nr+ self.nv)
			llh.append(u.log_binomial_likelihood(self.a, self.d, mu) + log(0.5) +  self._log_bin_norm_const)
			self.compute_n_genomes(1,new_state) # paternal
			mu = (self.nr * mu_r + self.nv*(1-mu_r) ) / (self.nr+ self.nv)
			llh.append(u.log_binomial_likelihood(self.a, self.d, mu) + log(0.5) +  self._log_bin_norm_const)
			llh = u.logsumexp(ll)
		else: ## CNV datum or SSM with no CNV
			mu = (1 - phi) * mu_r + phi*mu_v # (mu_r=0.999, mu_v=0.5)
			llh = u.log_binomial_likelihood(self.a, self.d, mu) +  self._log_bin_norm_const
		return 	llh
Exemplo n.º 4
0
	def __log_complete_likelihood__(self, phi, mu_r, mu_v, tp, new_state=0):	
		
		if self.cnv:
			ll = []
			poss_n_genomes = self.compute_n_genomes(tp,new_state)
			poss_n_genomes = [x for x in poss_n_genomes if x[1] > 0]
			for (nr,nv) in poss_n_genomes:
				mu = (nr * mu_r + nv*(1-mu_r) ) / (nr+ nv)
				ll.append(u.log_binomial_likelihood(self.a[tp], self.d[tp], mu) + log(1.0/len(poss_n_genomes)) +  self._log_bin_norm_const[tp])
			if len(poss_n_genomes) == 0:
				ll.append(log(1e-99)) # to handle cases with zero likelihood
			llh = u.logsumexp(ll)
		else: ## CNV datum
			mu = (1 - phi) * mu_r + 0.5*phi
			llh = u.log_binomial_likelihood(self.a[tp], self.d[tp], mu) +  self._log_bin_norm_const[tp]
		return 	llh
Exemplo n.º 5
0
	def __log_complete_likelihood__(self, phi, mu_r, mu_v, tp, new_state=0):	
		
		if self.cnv:
			ll = []
			poss_n_genomes = self.compute_n_genomes(tp,new_state)
			poss_n_genomes = [x for x in poss_n_genomes if x[1] > 0]
			for (nr,nv) in poss_n_genomes:
				mu = (nr * mu_r + nv*(1-mu_r) ) / (nr+ nv)
				ll.append(u.log_binomial_likelihood(self.a[tp], self.d[tp], mu) + log(1.0/len(poss_n_genomes)) +  self._log_bin_norm_const[tp])
			if len(poss_n_genomes) == 0:
				ll.append(log(1e-99)) # to handle cases with zero likelihood
			llh = u.logsumexp(ll)
		else: ## CNV datum
			mu = (1 - phi) * mu_r + phi*mu_v # (mu_r=0.999, mu_v=0.5)
			llh = u.log_binomial_likelihood(self.a[tp], self.d[tp], mu) +  self._log_bin_norm_const[tp]
		return 	llh
Exemplo n.º 6
0
	def __log_complete_likelihood__(self, phi, mu_r, mu_v, tp, new_state=0):	
		sd_d = std(self.d)
		
		##Specify which method to use - binom or negbinom
		model_distribution = self.calcLogLikelihoodBinom
		if self.tssb.neg_binom:
			model_distribution = self.calcLogLikelihoodNegBinom
		
		if self.cnv:
			ll = []
			poss_n_genomes = self.compute_n_genomes(tp,new_state)
			poss_n_genomes = [x for x in poss_n_genomes if x[1] > 0]
			for (nr,nv) in poss_n_genomes:
				mu = (nr * mu_r + nv*(1-mu_r) ) / (nr+ nv)
				ll.append(model_distribution(mu, tp, sd_d) + log(1.0/len(poss_n_genomes)))
			if len(poss_n_genomes) == 0:
				ll.append(log(1e-99)) # to handle cases with zero likelihood
			llh = u.logsumexp(ll)
		else: ## SSM datum
			mu = (1 - phi) * mu_r + phi*mu_v # (mu_r=0.999, mu_v=0.5)
			llh = model_distribution(mu, tp)
		return 	llh
Exemplo n.º 7
0
 def __log_likelihood__(self, phi, tp):
     ll = []
     for mu_r, log_pi_r in zip(self.mu_r, self.log_pi_r):
         for mu_v, log_pi_v in zip(self.mu_v, self.log_pi_v):
             ll.append(self.__log_complete_likelihood__(phi, mu_r, mu_v, tp) + log_pi_r + log_pi_v)
     return u.logsumexp(ll)