An agent-based modelling using the Mesa framework for Python. This repository includes the following exercises:
- The Flocking example of collective behaviour from mesa. The code for this example is included as both a Jupyter notebook and Python code. Also includes a JavaScript file that sets up a HTML5 canvas for visualization of a simple, continuous canvas.
- I've messed with the visualization by updating to the more recent version of Chart.js in order to add chart titles. This is currently not working, but when it does, in order for the script to work without chart titles, just remove the
chart_title=" "
fromChartModule
. - Preliminary attempts to adapt the boids model for a model of fish shoaling behaviour. So far, this version adds a data collector for spatial statistics with four functions. Others will be added in the future. The outputs are added to pandas dataframes and then exported as .csv files to be used in R.
- The Jupyter notebook versions of the data collection file are useful for running the model under various model conditions.
- I have also configured the data collector to output agent position (x,y) at every step. This can be used for other visualizations, i.e. animated plots in matplotlib, or exported to R, etc.
- Attempts to adapt the Boids model to various other models of collective behaviour from the literature, housed in the
alternative models
folder:- Define vision by a certain number of neighbours, rather than a static distance -
shoal_model_neighbours.py
- Include a blind spot behind the agent -
shoal_model_blindspot.py
- Alignment (velocity matching) removed as a behaviour rule & considered an emergent behaviour -
shoal_model_noalign.py
- 3D!
- Define vision by a certain number of neighbours, rather than a static distance -
- Collection, analysis, graphing, and export of model data, all in the
data_handling
folder. These collect data from, among others,:- a single run in
single_run.py
- multiple runs of the model under set conditions in
data_batch.py
, with graphing of those runs inbatch_graphs.py
- multiple runs of the model with varying conditions in
data_senstivity.py
- a single run in
- Import of position data from videos of sticklebacks and zebrafish, collected using LoggerPro. Once imported and cleaned, these data can be used in various statistics.
The basic shoal model is broken down into the following scripts:
shoal_model.py
contains the agent and model definitions, including the code for collecting the data within the model.data_collectors.py
contains the functions used to collect data on the polarization and spatial extent of the shoal.shoal_model_viz.py
contains the code for the visualization element of the model. Uses a Javascript canvas to create an HTML5 object.single_run.py
runs the model once without the visualization.
These installation instructions assume you are using macOS or Linux with Python 3.6 or newer installed.
-
Clone this repository to your computer:
git clone https://github.com/sowasser/fish-shoaling-model.git
-
Create a virtual environment so Python dependencies will not conflict with other Python projects you may have on your machine:
cd fish-shoaling-model python3 -m venv env
-
Activate the virtual environment:
source env/bin/activate
-
Make sure you have the latest version of pip (Python package installer):
pip install --upgrade pip
-
Install the third party dependencies the project require:
pip install -r requirements.txt
-
You should now be able to run the Python code in the project:
python3 test_run.py
-
If you're using PyCharm, you'll need to add Jupyter to the Project Interpreter in order to run the Jupyter notebooks.