NetLogo banner

 Home
 Download
 Help
 Resources
 Extensions
 FAQ
 NetLogo Publications
 Contact Us
 Donate

 Models:
 Library
 Community
 Modeling Commons

 User Manuals:
 Web
 Printable
 Chinese
 Czech
 Farsi / Persian
 Japanese
 Spanish

  Donate

NetLogo Models Library:
Code Examples/Extensions Examples/py

(back to the library)

Python Flocking Clusters

[screen shot]

Note: If you download the NetLogo application, every model in the Models Library is included.

WHAT IS IT?

This model is based on the original Flocking model that has birds follow exactly the same set of rules, from which flocks emerge. It demonstrates using a Python package, sklearn, within a NetLogo model through the py extension in order to cluster the birds into groups, who are given matching colors in the view.

HOW IT WORKS

In the setup procedure, py:setup py:python is used to start the Python session and py:run is used to let Python import the numpy and sklearn packages for use during the model run. If you do not have these packages installed, the py extension will show an error. Please install these packages in your Python environment before running the model.

The modifications for clustering are in the go procedure, where py:set is used to pass turtle data to Python as the coords variable and the vision NetLogo variable as the eps variable.

Then py:runresult is called to use the dbscan() Python function on the NetLogo data and the resulting cluster data is sent back to NetLogo and stored in the clusters variable.

Finally, the clusters data is used to color the turtles into their groups.

RELATED MODELS

See the original Flocking model for details on how the flocking-specific code works.

There is a bundle of other Python extension demo models, py-demo-models.zip, available on the Python extension site.

(back to the NetLogo Models Library)