Exemple #1
0
def fast_etienne_likelihood(mod, params, kda=None, kda_x=None):
    '''
    same as Abundance inner function, but takes advantage of constant
    m value when varying only theta.

    :argument abd: Abundance object
    :argument params: list containing theta and m
    :argument kda_x: precomputed list of exp(kda + ind*immig)
    '''
    theta     = params[0]
    immig     = float (params[1]) / (1 - params[1]) * (mod.community.J - 1)
    log_immig = log (immig)
    theta_s   = theta + mod.community.S
    if not kda_x:
        kda_x = [exp(mod._kda[val] + val * log_immig) for val in \
                 xrange (mod.community.J - mod.community.S)]
    poch1 = exp (mod._factor + log (theta) * mod.community.S - \
                 lpoch (immig, mod.community.J) + \
                 log_immig * mod.community.S + lngamma(theta))
    gam_theta_s = gamma (theta_s)
    lik = mpfr(0.0)
    for val in xrange (mod.community.J - mod.community.S):
        lik += poch1 * kda_x[val] / gam_theta_s
        gam_theta_s *= theta_s + val
    return ((-log (lik)), kda_x)
Exemple #2
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)
Exemple #3
0
def lpoch (z, m):
    '''
    returns log Pochhammer symbol taking advantage of:
    Pochhammer symbol (z)_m = (z)(z+1)....(z+m-1) = gamma(z+m)/gamma(z)
    '''
    return lngamma(z+m) - lngamma(z)