Coder Social home page Coder Social logo

couzinswarm's Introduction

couzinswarm

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()

couzinswarm's People

Contributors

benmaier avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.