Social and professional networking

View Ian Clarke's profile on LinkedIn
Shameless plug

Does your company's revenue depend on being able to predict the future based on past data?  SenseArray may be able to help.

RSS
Links
« More on Genetic Algorithms | Main | British Computer Society wants software patents in the EU? »
Saturday
12Feb2005

Playing with Genetic Algorithms

Back when studying AI at University, Genetic Algorithms were always something I found quite exciting - a way to allow computers to figure out how to do things all by themselves.

I decided it was time to toy around with some of these ideas again. The first decision was to figure out the "building blocks" of our artificial creatures. I had to construct them in a way that was flexible enough that they could evolve novel strategies, but which is tolerant to mutation, and capable of merging.

For example, most computer software is not tolerant to mutation. If you change a random character in a typical computer program, chances are that it will stop working completely. Similarly, computer software is not tolerant to merging. You can't really take two computer programs, stick them together, and expect them to do anything sensible.

So I opted for an approach based on the way biological brains work. Essentially you have a bunch of "neurons", each of which is connected to every other neuron by two connections, one in each direction. Every neuron has an "activation", represented by a number between 0 and 1. For some neurons, this activation is set externally, this is the input to our little brain. Similarily, some of these neurons are treated as "outputs", their level of activation representing the output from the brain.

The brain proceeds in a series of discrete time steps. At each step, every neuron "transmits" its level of activation along all of its outgoing connections as an "impulse". The stronger the activation, the stronger the impulse. Neurons determine their level of activation for the next time step by adding up all of the incoming impulses from other neurons, the higher the impulse, the stronger the activation (this is determined according to a simple sigmoid function).

There is one last wrinkle. Not all connections are equal, each has a "weight" associated with it, represented by a positive or negative number. Any impulse going through the connection is multiplied by this number. So, for example, an impulse from a neuron with activation of 0.5 going through a connection with weight 0.5 would only be 0.25 by the time it reached the destination neuron.

It is by adjusting the weights of these connections that our genetic algorithm makes these creatures (hopefully) do something intelligent.

Next I wanted to test it on a simple problem. I decided to try to evolve simple brains which could solve the boolean "exclusive-or" function. Very simply, this has two input neurons and a single output neuron. If the inputs are different (ie. one is '1' and the other is '0') the the output should be '1', otherwise it should be '0'.

To illustrate the learning process, I set up a population of 10 creatures, each consisting of 4 neurons (this includes the input and output neurons), which runs through 4 iterations before we read the output.

I then drew a graph of what output is given for all input values between 0 and 1. Recall that we only care about the input and output for values of 0 and 1, but by looking at the intermediate values, we get an idea of the creature's internal thought process.

This output can be represented as a two dimensional image, where black indicates that the output was 0, and white indicates an output of 1. The goal is therefore that the top-left and bottom-right corners are black, while the other corners are white. You can see an animation representing one such "run" here:
You will note that it starts out grey, but quickly finds a way to achieve the desired goal.

That was my progress for this weekend, next weekend I will try to make these things do something far more interesting (I hope).

Update: More on Genetic Algorithms

Reader Comments (11)

I think this was an interesting experiment. And the video is so cool! It seems to me that you make visible the thinking process of the computer mind.
I would like to learn more about your work...
Questions now: how did you do it? Will you publish the codes? Which langage did you use? Java? how long was the process?

February 17, 2005 | Unregistered CommenterBrokenClock

The code is written in Java, its actually pretty simple but kinda messy. I am happy to share it if you send me an email.

The simulation in the video required about a minute to create, and much of that overhead is actually drawing the frames, rather than the evolutionary process itself, so its actually very fast.

February 18, 2005 | Unregistered CommenterIan

See what we (http://www.critticall.com) do. A real thing. Or should I say - even more real thing.

April 1, 2005 | Unregistered CommenterThomas

Hi
I'm doing project on 'pattern recognition' using GA. Can you help me?
i want some source code written in c/cpp. Right now I'm lost.

March 24, 2006 | Unregistered Commenterpingmi

hi,
i am a sophomore pursuing computer science engg. in india,and i am working on a paper on evolutionary hardware using genetic algorithms (the same thing u have implemented). can u pls suggest whether i shuld learn prolog or stick to cpp?? since you seem to have experience in this field, your suggestion is desirable and would be highly appreciated.
thanks a lot,
aakanksha

March 25, 2007 | Unregistered Commenteraakanksha

Uh, how come you haven't referred to "neural networks" at all?

May 9, 2008 | Unregistered CommenterBrian H

Uh, how come you haven’t referred to “neural networks” at all?

I called them neurons, didn't I?

May 9, 2008 | Unregistered Commenterian

Nice work! But I have a few questions.
From what I know, the neuron has any number of input connections but only one output connection. Your design connects all neurons between them, or that is what I understood from it. I'm not criticizing, I'm just asking why did you choose that design.
The second question is why did you need 4 neurons and not 3? And how were they connected?
The last one is how did you make your "creatures" learn? To be more exact, how did you make them "know" they were wrong?
I would really like to see the code. I've entered my email when submitting this reply.

May 12, 2008 | Unregistered CommenterGicanu

Neurons can be connected to multiple other output neurons in most or all neural net architectures I'm familiar with.

I did this a while ago, so my memory is a bit rusty, but I think basically I connected every neuron to every other neuron, so each of the 4 neurons had 3 inputs and three outputs.

I wanted this design because I wanted the neural net to feed into itself, so that it wouldn't be a simple feed-forward neural net which had no "memory".

I used a genetic algorithm to "evolve" improvements to the neural net. I created a bunch of these randomly, and then combined those which performed best to form each successive generation. See the "more on genetic algorithms" link (which I've now fixed).

May 12, 2008 | Unregistered Commenterian

awesome article, would love to receive and check source. we have done something similar on univercity classes but here I see good practical usage.

thanks

November 18, 2009 | Unregistered Commenteroleh

November 30, 2009 | Unregistered Commentera

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>