Simulating fish swarming behavior with the model by Iain Couzin et al.
Project description
Simulate fish swarming behavior with the model by Iain Couzin et al. Use with caution as I can’t seem to replicate some behavior (e.g. the torus swarming).
Example
from couzinswarm import Swarm
swarm = Swarm()
r, v = swarm.simulate(1000)
Install
pip install couzinswarm
Elaborate example
import numpy as np
import matplotlib.pyplot as pl
from mpl_toolkits.mplot3d import Axes3D
from couzinswarm import Swarm
# note: the dimension of space is measure in fish length,
# such that r = 1 means a length of one fish
swarm = 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 time
turning_rate=0.1,
# fish lengths per unit of time
speed=0.1,
# in units of fish length
noise_sigma=0.1,
dt=0.1,
# geometry of box
box_lengths=[100,100,100],
# boundary conditions
reflect_at_boundary = [True, True, True],
verbose=False,
)
fig = pl.figure()
ax = fig.add_subplot(111, projection='3d')
N_t = 1000
t = 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, directions
for i in range(swarm.number_of_fish):
ax.plot(r[i,:,0], r[i,:,1], r[i,:,2])
pl.show()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
couzinswarm-0.0.3.tar.gz
(7.2 kB
view details)
File details
Details for the file couzinswarm-0.0.3.tar.gz.
File metadata
- Download URL: couzinswarm-0.0.3.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cece5ae743b88b5bf6d9bee379f7551d9bb50a93c449924a1ccd8ad46075d91
|
|
| MD5 |
60dce4b71ca65d96a0f5f955fe8400a1
|
|
| BLAKE2b-256 |
02171f25d9cb02465d9edada195aa17bb6f85cea1d2917ff1c64a56566aa9374
|