Tuesday 21 May 2013

Autonomous Agents, Genetic Algorithms and balancing Natural Selection

For the past week I've been working almost exclusively on a branch of the flocking algorithm used in FishBirds to create a Predator vs Prey program, however it has proved to be much more fruitful than that.
Since starting last friday I have learned how to implement effective natural selection and semi random evolution like this:

 - Predator dies constantly.

 - More prey is introduced when under a certain number.

 - Predator and preys values (speed, agility, weight, sight) are decided randomly with a bell curve around set values.

 - Some Predators are born better and hence do much better, and stay alive much longer.

 - Some prey are born better at escaping predators and hence also stay alive much longer.

I did however find this system lacking in its complexity and method of "evolution" so I decided to try my hand at a genetic algorithm. I wanted something where the offspring was given values similar to the parent, but that could also drastically deviate from them. So I put together a moving mean. And implemented 2 different types of reproduction, time and "well fed". This more detailed list:

 - Predators die constantly, and die faster the smaller the flock is.

 - Predators reproduce when a certain amount of prey is eaten in a certain timespan and when they are of reproducing age (this is to stop the predator slamming into a group and then all its children reproduce causing a huge increase in number of predators).

 - Predators spawn one offspring, and stay alive (this is to for competition between generations).

 - Prey reproduces by staying alive for  certain amount of time. Prey then has 2 offspring, and dies.

 - The moving mean: The normal of the gaussian distribution of random values for the offspring are the current values of the parent. This ensures a good development of genetics and keeps the gene pool relatively diverse.


Problems that I have encountered:

 - If the flock is under a certain number and there are a certain number of predators. The predators will continue to live on the small amount of food that the prey provide.

 - Performance. In a perfect world I would be able to have a flock size of anything. Unfortunately the components of a computer, and Processing have limits. I have been pushing these and I think its time to move on to something more powerful, at least for a language (Discussion in my next post)

 - The flock is limited at the moment. It stops multiplying once it reaches a certain size. This was implemented to reduce performance issues and hence has stopped me producing a more realistic simulation.

 - I couldn't work out how to implement a method of generation counting. I'm sure with more time I could work out how to do it, but I don't want to spend any longer on this project.

I've published a final video to Vimeo.

In conclusion I think I am now significantly more adept at coding than I was last week.
I had a more in depth exploration of OOP, and became much more experienced in balancing systems. I learned how to implement some more advanced random statistical tools to give more useful data. And I learned how to implement genetic algorithms.

Tuesday 14 May 2013

FishBirds updates

I've been working on the FishBirds continuously since my last post. In that time I have moved from the local branch to developing a networked version which no longer uses a ControlFrame and which supports MIDI, to developing a networked version which has no midi control and no control sketch, it is controlled using TouchOSC.

Currently the TouchOSC branch has the most features, just because its the branch which I'm using the most.

I think that they are as complete as I will have them for the foreseeable future, so for the time being I'm going to focus on developing my skills coding other methods of simulating behaviour and manipulating those algorithms. I'm working my way through Shiffmans "The Nature of Code", to help me get the skills that I need. Its a fascinating read, and my coding has already improved.

I will return to the FishBirds when I can write genetic algorithms.