Friday, June 24, 2011

Simulating Genetics at the bit level

Early in my programming years I had an instructor who recommended the book about simulated artificial intelligence titled Genetic Algorithms in C++ by Scott Robert Ladd. Computer programs are coded to perform in predefined ways like displaying output based on what a user entered, or calculate digits based on solid mathematical principles. In short, programs are coded with the specific actions the programmer decided in advance - there is no deviation.

Genetic Algorithms (GA) allows a programmer to define a set outcome - that's it. The concept of GA allows the program to figure out how to accomplish the outcome in the most efficient way. Some examples would be an outcome to figure out the optional setup to allow five trains to efficiently utilize the same set of tracks, or an outcome could be a finish point located randomly on a maze created for a mouse - the program would not only have to figure out the optimal movements from start to finish, but would have the extra tasks of figuring out first that a mouse needs to be able to move (somehow), realize that a mouse has four legs (the programmer didn't tell it what those legs were for), and then teach itself how to make those four legs work together in an optimal fashion.

Let's look at this mouse maze issue a bit more and tackle each section in more detail; there's a lot of GA ideas that can be discussed using the mouse maze scenario. Working from the beginning, let's look at the mouse maze issue. Here we have a maze with a starting point and the goal is to find the finish point in the most expedient way possible. in a non-GA program, the programmer might write code that defines a rule to solve this maze problem. I would probably write code that says to start the maze by moving right until a wall is encountered, then turn 90 degrees and continue trying to move right. Eventually this program would solve the maze. This isn't efficient. GA allows mini populations of mice to wander the maze for a certain length of time. The top mice to go the furthest would (programmable) breed and their offspring would continue on adventuring until generations later a single mouse makes it from start to finish without any misstep. Keep in mind that these mini populations are like thoughts, and it isn't until the single mouse succeeds that an actual "real" move is made.

Now we have the additional issue of learning that the mouse has four legs. A normal program would have instructions for using all four legs to move the mouse along the maze. a GA programmer would not bog down the program with this information. Perhaps for this particular maze, a mouse that moves its body in a snakelike fashion is better than using four legs - who are we as programmers to decide this?

One of my last accomplishments as a programmer was to write a GA System to simulate an ant colony. Using the Java programming language I created ant objects with specific methods for movement, searching, acquiring food, and a detailed method for ants to leave pheromone trails for others in the colony to follow. I created a maze object based on random parameters - complete with start and finish locations, and randomly added in food sources for the ants to find. So what I had created was a maze environment for ants to explore. The main goal was to find the shortest path from start to finish, and to use the located food sources to sustain the ants that ventured further from the colony in search of the finish point. If you're wondering how this complicated program differs from a simple, brute force program for finding a finish point, well here's how GA shines. Let's say that we give each ant a 10 movement limit before it expires with food sources found in the maze adding 5 more movement allotments. Ants in the brute force program would expire quickly due to the unnecessary backtracking taking place, and especially so if the food sources were far and few between. A GA program would virtually send out ants to find the finish point. The ants making it the furthest would be selected to mate ( programming for mixing or combining actual bits of data to create offspring with inherited traits from both parents. Essentially the offspring will know more about the maze that any single parent learned. Again I stress that no computer ant has actually moved in the maze. Over generations of progressing offspring learning more about the maze, eventually a super generation will be created that has the information to successfully traverse the maze from start to finish without expiring. Once a solution is found, as defined by the programmer, the GA program will create an actual ant to make the trip with the foreknowledge of how to succeed.

Deion "Mule" Christopher

No comments:

Post a Comment