两个物种共演化

种群动态演化之—— Gillespie Algorithm
在这个模型系统中只有两个物种,分别命名为x,y。对这两个物种给定固定的出生率,死亡率,然后根据中间竞争和种类竞争,观察两个种群的动态演化过程。

class X_population:
         def __init__(self,num):
             self.num = num
             self.num_list = []
             self.time_list = []
             
         def X_population_birth(self):
             self.num += 1
             
         def X_population_death(self):
             self.num -= 1
             
         def X_competition(self):
             self.num -=1
             
         def Record_data1(self,time)
            self.time_list.append(time)
            self.num_list.append(num)
 class Y_population:
         def __init__(self,num):
             self.num = num
             self.num_list = []
             self.time_list = []
             
         def Y_population_birth(self):
             self.num += 1
             
         def Y_population_death(self):
             self.num -= 1
             
         def Y_competition(self):
             self.num -=1
             
         def Record_data2(self,time)
            self.time_list.append(time)
            self.num_list.append(num)
            
def findreaction(*reactionrates):
    sum_rs = np.array([sum(i) for i in reactionrates], dtype=np.float64)
    sum_all = sum(sum_rs)
    tau = - np.log(np.random.rand())/sum_all
    i = int(randchoice(sum_rs)[0])
    index = randchoice(reactionrates[i])
    return tau, i , index

def randchoice(a):
    veca = a.reshape(np.prod(a.shape))
    onea = veca / sum(veca)
    index = np.argwhere(a == np.random.choice(a, p = onea))
    return index
    
def extinction_check(current_population, extinct_population, i=0):
    while i < len(current_population):
        if current_population[i].num == 0:
            extinct_population.append(current_population[i])
            del current_population[i]
        else:
            i += 1      

你可能感兴趣的:(物种共演化)