Picture source: The Royal Society, Flickr

The programming section of this blog has been quite inactive lately. Hence, here’s an interesting little project I did last year.

The idea started off as a biophysics class presentation in collaboration with Abhilash Sahoo. From there, I adopted it into an optimization tool through Genetic Algorithms.

I’ve used MATLAB for all purposes. (Click here to view the code.)

The final animation:

The herding concept is inspired from Strogatz’s TED Talk: “How things in nature tend to sync up”.

Here is the basic skeleton:

  1. Green particles are prey
  2. Red particles are predators
  3. Each prey has 3 forces acting on it:
    1. a weak long-distance attractive force towards other prey
    2. a strong short-distance repulsive force away from other prey
    3. a strong repulsive force from predators
  4. The first two forces make the prey form a herd, while maintaining an equilibrium distance between themselves within the herd. The third force makes them flee from incoming predators.
  5. Each predator has 2 forces acting on it:
    1. A long-distance medium attractive force towards the general direction of a herd of prey
    2. A short-distance targeted strong attractive force towards a particular prey
  6. The predator starts its hunt using the first force. When it gets close to a prey, it switches to the second force to target the particular prey while ignoring the rest of the herd.
  7. The targeting is denoted in the video through red lines connecting the prey to the predator that appear when a prey is targeted.
  8. The green enclosure contains food for the prey.
  9. Predators have higher top speeds but are more massive. They can catch up to the prey in a straight line, but can’t turn as fast.
  10. The prey swerve automatically due to the nature of the forces, which sometimes allow them to escape.

Things get more interesting when we introduce natural selection. This can be done by creating survival parameters and the concepts of death, reproduction and imperfect copying.

Death happens when:

  1. A particle starves, that is:
    1. If a prey stays outside the green boundary for a long time
    2. If a predator cannot catch a prey for a long time
  2. A particle gets old, i.e. it runs out of its natural lifespan
  3. A prey gets caught by a predator

The survival parameters have different values for each prey/predator. I call them survival parameters as they are directly linked to the chances/duration of survival in our little virtual reality. The ones that I’ve included in this model are:

  1. The ability to accelerate (or inverse mass)
  2. Top speed
  3. Range of vision (e.g. from how far a prey can detect an approaching predator)
  4. Maximum duration of survival without food
  5. Natural lifespan
  6. The frequency of reproduction
  7. The strength of herding tendency (in case of preys)

Reproduction here is defined as a particle spawning a copy of itself. Each particle reproduces at a certain frequency. The child inherits the same values of parameters from the parent, but with small random errors. Over time these errors lead to a natural selection of parameter values in a way that maximizes the probable survival duration of the particles (since more survival duration means more number of offspring).

Leaving the model here would not be of any real use though. It’s a no-brainer that all the survival parameters will keep increasing in value over time; we don’t need a code to tell us that!

Hence we introduce interdependencies between the parameters to make them competitive. For example, we decide that a greater ability to accelerate (or less mass) would imply that the particle cannot survive without food for a long time. Thus we have created a trade-off between two desirable parameters.

This simple tweak makes this model a powerful tool of optimization. The code will ultimately maximize the survival duration and we can find out the values of the parameters that comprise the optimal solution. Basically, we will be able to quantify exactly how important each of these abstract survival parameters are for the particles in the simulation.

We can use similar techniques to optimize highly complex systems with several interdependent variables.

Join the conversation! 1 Comment

  1. This is beautiful



Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

About Debapriyo

A random person with few hobbies here and there.

Latest Posts By Debapriyo




, , ,