Пример #1
0
 def likelihood(self, params):
     '''
     log-likelihood function
     
     :argument params: a list of 2 parameters:
     
       * theta = params[0]
       * m     = params[1]
     :returns: log likelihood of given theta and I
     
     '''
     kda       = self._kda
     theta     = params[0]
     immig     = float(params[1]) / (1 - params[1]) * (self.community.J - 1)
     log_immig = log(immig)
     theta_s   = theta + self.community.S
     poch1 = exp(self._factor + log(theta) * self.community.S - \
                 lpoch(immig, self.community.J) + \
                 log_immig * self.community.S + lngamma(theta))
     gam_theta_s = gamma(theta_s)
     lik = mpfr(0.0)
     for abd in xrange(int(self.community.J - self.community.S)):
         lik += poch1 * exp(kda[abd] + abd * log_immig) / gam_theta_s
         gam_theta_s *= theta_s + abd
     return -log(lik)
Пример #2
0
 def likelihood (self, theta):
     '''
     get likelihood value of Ewens according to Parthy/Tetame (Jabot 2008)
     
     :argument theta: value of theta
     :returns: likelihood
     '''
     factor = lgamma (self.community.J + 1)
     phi = table (self.community.abund)
     phi += [0] * int (max (self.community.abund) - len (phi))
     for spe in xrange (self.community.S):
         factor -= log (max (1, self.community.abund[spe]))
     for spe in xrange (max (self.community.abund)):
         factor -= lgamma (phi[spe] + 1)
     lnl = lpoch (theta, self.community.J) - log (theta) * self.community.S - factor
     self._factor = factor
     return lnl