Tuesday, September 05, 2006

Basic Genetics Algorithm

Finally, after two days of programming -I feel so good to be back at it- I wrote a basic Genetic Algorithm simulation. The algorithm aims to find a solution to a problem through natural selection of population members. This selection process can go on for generations to find a solution.

Actually, a solution may or may not be found which if anyone thinks about it; it's like humans eveolving. the chances of a flying human is quite silly since our genes cannot evolve towards that -at least that's what history has shown so far since humans came to this earth-. However, if no solution is found, you get a pretty close one. This is my first attempt at it and maybe I can tinker with the algorithm and its parameters to get better results.

The concept is really cool and neat, because a solution seems to evolve on its own after a while and suddenly the whole population is fit and close to the solution. Seeing this work is even better ;)

So, what the Algorithm here is trying to solve?
  1. I pick a number which is my target solution (say 23) and I have number 0 to 9 and operators +,-,* and / all encoded as binary strings (those are the genes).
  2. I pick the sequence ...etc at random depending on the length that I choose -always odd length- and then this is a cromosome or a member of the population.
  3. After constructing the population, each cromosome has a fitness score. i.e how close it is at solving the problem.
  4. Using a method called the rollette wheel, I mate every two chosen random members of the population and apply all the concepts of a genetic algorithim until I get a new population.
  5. This procss is continued for a certain number of generations and hopefully a solution is found.

The algorithm solves problems untraditionally and its strength lies in the fact that it is almost impossible for anyone to do it manually -that would take years and years- and that -given its done right- a solution seems to evolve.

This was based on the tutorial I read by Mat Buckland at http://www.ai-junkie.com

3 comments:

BuZain said...

This is one cool thing to work on. share us some code mate. Let's see it working.

I wonder though how can this be used in a real-life challenge. Any ideas?

Shark Hunter said...

I am not an expert yet but it seems that you can construct cromosomes to fit a model of your own creation. for instance, customer characteristics. We could encode customer loyalty, channel usage behavior and other attributes. Once done we can test how each customer evolves with respect to a specific solution. Let's suppose we encode a good customer by giving them good genes such as profitability above 100, monthly usage of channels etc. By doing so we can track which cromosomes (Customers) from the original population have the potential to be as close as possible to the good customer cromosome. This can be furthure used by marketing or whoever to get more business. I hope I am making sense.

Ayman said...

That is cool. The code in the tutorial is C/C++. I can see very good potential, and good exercise too for Ruby. Mainly for OOP and it's easy string handling.