用iain-couzin等人的模型模拟鱼群行为。
couzinswarm的Python项目详细描述
用Iain Couzin et al.模型模拟鱼群行为 小心使用,因为我似乎无法复制某些行为(例如 环面蜂拥而至)。
示例
fromcouzinswarmimportSwarmswarm=Swarm()r,v=swarm.simulate(1000)
安装
pip install couzinswarm
详细示例
importnumpyasnpimportmatplotlib.pyplotasplfrommpl_toolkits.mplot3dimportAxes3DfromcouzinswarmimportSwarm# note: the dimension of space is measure in fish length,# such that r = 1 means a length of one fishswarm=Swarm(number_of_fish=20,repulsion_radius=1,orientation_width=10,attraction_width=10,# this angle is given in radians# up to np.pi (not 360 degrees as in# the paper)angle_of_perception=np.pi,# radians per unit of timeturning_rate=0.1,# fish lengths per unit of timespeed=0.1,# in units of fish lengthnoise_sigma=0.1,dt=0.1,# geometry of boxbox_lengths=[100,100,100],# boundary conditionsreflect_at_boundary=[True,True,True],verbose=False,)fig=pl.figure()ax=fig.add_subplot(111,projection='3d')N_t=1000t=np.arange(N_t+1)# Note that r.shape = v.shape = ( N_fish, N_t+1, 3 )positions,directions=swarm.simulate(N_t)r,v=positions,directionsforiinrange(swarm.number_of_fish):ax.plot(r[i,:,0],r[i,:,1],r[i,:,2])pl.show()