Working on a Model of Flocking Behavior

A month or so ago I started working on a simple model of “flocking” behavior, based on work presented at a seminar I attended. I implemented most of the math, but left the visualization for later. It lay fallow for a few weeks. Over the past two days, I dusted off the project and added some simple graphics. It works!

Try it out for yourself right here (Java plugin required). The current camera controls are designed with a three-button mouse in mind, but support for the center button (scroll wheel) seems inconsistent across browsers. Hey, it’s just a demo.

Here are a few slides from a brief presentation I gave to my colleagues when I began this project.

Iain Couzin gave a talk in March as part of the EvoS seminar series. Iain’s research program involves computer modeling and experimental observation of collective animal behavior systems (schools of fish, flocks of birds, herds of ungulates). Rigorous feedback between theory and observation was evident in his work. It was inspiring.

Iain’s presentation catalyzed interest in agent-based modeling in our lab (I am an affiliated staff member). Others jumped in with NetLogo, but I decided to see what I could do with Processing due mainly to my recently rekindled interest in the language. The Obsessive Camera Direction library makes it easy to navigate the visualization.

My implementation is derived from two of the publications which formed the basis for much of the work displayed during Iain’s EvoS seminar. The first paper describes the basic rules from which a variety of flocking behaviors can be elicited, depending on particular parameter values:

Couzin, I. D., Krause, J., James, R., Ruxton, G. D., & Franks, N. R. (2002). Collective Memory and Spatial Sorting in Animal Groups. Journal of Theoretical Biology, 218(1), 1-11. [PDF]

The second paper adds goal-oriented behavior to the model and explores the effect of different proportions of “leaders” in a group (how many cooks constitute too many cooks in the kitchen?):

Couzin, I. D., Krause, J., Franks, N. R., & Levin, S. A. (2005). Effective leadership and decision-making in animal groups on the move. Nature, 433(7025), 513-516. [PDF]

My implementation does not yet include any goal-oriented behavior, but it is designed with the addition of this and other extensions in mind:

Here’s a conceptual diagram of how the pieces of the simulation are arranged. Every speck you see flying about is an Agent, and every agent may exhibit one or more Behaviors. A Collective behavior dictates the direction an agent will move based on its proximity to other visible agents. This design may be be extended to model the interaction of multiple agent types.

Whether I proceed with all or any of the potential improvements to this model is an open question. I may decide to apply this approach to other problems more closely matched to existing research programs at BU. However, I do think it would be swell to develop and test this implementation sufficiently to replicate the varied patterns presented by Iain Couzin.

Posted on Tuesday, May 11th, 2010. Tags: , .

2 Responses to “Working on a Model of Flocking Behavior”

Posted by Ian Smith on Wednesday, May 12th, 2010 at 2:37 PM.

Awesome work, Jim. Could your model be modified to include pinch points? For instance, what if the entities within the model need to travel through a canyon or a doorway? Also, does the original model allow for/apply to the inclusion of human-specific movement? It would be interesting to see how humans disperse from a train onto a station platform. An accurate model of human movement within confined space could be of enormous benefit to the advertising industry. For instance, the MTA publishes numbers on how many people pass through turnstiles, but the motion of those people while traveling between subway cars and the turnstiles is a mystery.

Posted by Jim on Wednesday, May 12th, 2010 at 3:15 PM.

Thanks. There’s not currently any representation of terrain or obstacles in the model, but that would indeed be a valuable addition. I do hope to add “goal oriented behavior” to the model, which will allow the agents to pursue and/or avoid specific points while maintaining their group. It might be possible to approximate some pinch point situations this way.

Regarding humans – interestingly enough, yes, Couzin has studied human crowds. In some contexts we do behave like a herd of cattle. See PDFs 4 & 18 among publications linked above.

In addition to the sort of group games described in those papers, Couzin also presented some research where they recorded birds-eye-view footage of pedestrians moving about a sidewalk. Impressively, they developed video tracking software that identifies not only the pedestrian location but also the direction of their gaze. I wish we had a better recording of his presentation at BU, but you can also see it about 3 minutes in to this video. Unfortunately, that project is apparently funded by MI5, so there aren’t too many details available – but I would imagine that technology would be incredibly useful for advertisers as well as for Big Brother.