コード例 #1
0
ファイル: etienne_model.py プロジェクト: fransua/ecolopy
    def random_community (self, inds=None, theta=None, immig=None):
        '''
        generates random distribution according to J, theta and I

        :argument inds: number of individuals in community (J)
        :argument theta: corresponding to the model
        :argument immig: immigration rate (I)

        :returns: distribution of abundance (list)

        '''
        theta    = float (theta) if theta else self.theta
        inds     = inds or self.community.J
        immig    = float (immig) if immig else self.I
        mcnum    = [0] * int (inds)
        locnum   = [0] * int (inds)
        mcnum[0] = 1
        new = nxt = -1
        for ind in xrange (inds):
            if random () > immig / (ind + immig):
                locnum [ind] = locnum [int (random () * ind)]
            else:
                new += 1
                if random () <= theta / (theta + new):
                    nxt += 1
                    mcnum[new] = nxt + 1
                else:
                    mcnum[new] = mcnum[int (random () * (new))]
                locnum[ind] = mcnum[new]
        return table(locnum, new + 1)
コード例 #2
0
ファイル: untb_model.py プロジェクト: fransua/ecolopy
 def __compute_factor(self):
     self._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):
         self._factor -= log (max (1, self.community.abund[spe]))
     for spe in xrange (int(max(self.community.abund))):
         self._factor -= lgamma (phi[spe] + 1)
コード例 #3
0
ファイル: lognormal_model.py プロジェクト: fransua/ecolopy
 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
コード例 #4
0
ファイル: ewens_model.py プロジェクト: fransua/ecolopy
 def random_community(self, inds=None, theta=None):
     '''
     generates random distribution according to J and theta
     
     :argument inds: number of individuals in community (J)
     :argument theta: corresponding to the model
 
     :returns: distribution of abundance (list)
     
     '''
     theta = float (theta) if theta else self.theta
     inds = inds if inds else self.community.J
     out = [0] * int (inds)
     out [0] = spp = 1
     for ind in xrange (inds):
         if random () < theta/(theta + ind):
             spp += 1
             out[ind] = spp
         else:
             out[ind] = out [int (random () * ind)]
     return table (out, spp)